Advertisement
sufokmpc

YENC DECODER

Dec 20th, 2011
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; --------------
  2. ; YENC DECODER
  3. ; x0rc1zt
  4. ; v1.0
  5. ; jully 2011
  6. ; --------------
  7.  
  8. #Sourcefilebuff = 0
  9. #Destfilebuff = 1
  10.  
  11. If OpenConsole()
  12.  
  13.   PrintN("* yEnc Decoder")
  14.   PrintN("* Version 1.0")
  15.   PrintN("* x0rc1zt")
  16.   PrintN("")
  17.  
  18.   Print("Enter the file name: ")
  19.  
  20.   sourcefile$ = Input()
  21.   sourcefilesize.q = FileSize(sourcefile$)
  22.  
  23.   If ReadFile(#Sourcefilebuff, sourcefile$) ; Open the source file
  24.    
  25.     While Eof(#Sourcefilebuff) = 0
  26.      
  27.       ;get the name of our file
  28.       buff.s = ReadString(#Sourcefilebuff)
  29.       position= FindString(buff, "name=", 1)
  30.       If position
  31.         name.s = Mid(buff, position+5)
  32.       EndIf
  33.       If position
  34.       ;create our file
  35.       If CreateFile(#Destfilebuff, name) ; Create the destination file
  36.         buff = ReadString(#Sourcefilebuff)
  37.        
  38.         ; Read each strings till "=yend"
  39.         While Not FindString(buff, "=yend", 1)
  40.           *Buffer.character = AllocateMemory(1000)
  41.           *Pointer = *Buffer
  42.           CopyMemoryString(buff, @*Pointer)
  43.           myC.a = 0
  44.          
  45.           ; Decode each ascii char of our string
  46.           While Not *Buffer\c = #Null
  47.             myC = PeekA(*Buffer)
  48.             *Buffer = *Buffer + 1
  49.             If myC = '='
  50.               myC = PeekA(*Buffer)
  51.               *Buffer = *Buffer + 1
  52.               WriteAsciiCharacter(#Destfilebuff,myC-106)
  53.             Else
  54.               WriteAsciiCharacter(#Destfilebuff,myC-42)
  55.             EndIf
  56.           Wend      
  57.           buff = ReadString(#Sourcefilebuff)
  58.         Wend
  59.         ;FreeMemory(*Buffer)
  60.        
  61.         ;get crc32
  62.         position= FindString(buff, "crc32=", 1)
  63.  
  64.         If position
  65.           checkcrc32.s = Mid(buff, position+6,8)
  66.         EndIf
  67.        
  68.         CloseFile(#Destfilebuff) ; Close the destination file
  69.        
  70.         destcrc32.s = Hex(CRC32FileFingerprint(name))
  71.        
  72.         If CompareMemoryString(@checkcrc32,@destcrc32,#PB_String_NoCase) = #PB_String_Equal
  73.           PrintN("CRC32 is okay.")
  74.         Else
  75.           PrintN("CRC32 failed")
  76.         EndIf    
  77.        
  78.         Debug checkcrc32 + "   " + destcrc32
  79.         position = 0
  80.       Else
  81.         PrintN("Couldn't create the file")
  82.       EndIf
  83.       EndIf
  84.     Wend
  85.      
  86.      
  87.     CloseFile(#Sourcefilebuff) ; Close the source file 
  88.   Else
  89.     PrintN("Couldn't open the file!")
  90.   EndIf
  91.  
  92.   Print("Press enter to exit")
  93.   Input()
  94. EndIf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement