Advertisement
sufokmpc

YENC DECODER MULTI

Dec 20th, 2011
211
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. Procedure decode(sourcefile.s, destfile.s, multipart.i)
  12.  
  13.   part.i = 0
  14.   buff.s = ""
  15.   myC.a = 0
  16.   position.i = 0
  17.  
  18.   If CreateFile(#Destfilebuff, destfile)
  19.     Repeat
  20.       If ReadFile(#Sourcefilebuff, sourcefile)
  21.         While Eof(#Sourcefilebuff) = 0
  22.          
  23.           buff = ReadString(#Sourcefilebuff)
  24.           position= FindString(buff, "name=", 1)
  25.          
  26.           ; if we found the yenc section we read the next line
  27.           If position
  28.             buff = ReadString(#Sourcefilebuff)
  29.             If multipart ; if multi part we must read the next line again
  30.               buff = ReadString(#Sourcefilebuff)
  31.             EndIf
  32.           EndIf
  33.                
  34.           While Not FindString(buff, "=yend", 1) And position
  35.             *Buffer.character = AllocateMemory(1000)
  36.             *Pointer = *Buffer
  37.             CopyMemoryString(buff, @*Pointer)
  38.            
  39.             ; Decode each ascii char of our string
  40.             While Not *Buffer\c = #Null
  41.               myC = PeekA(*Buffer)
  42.               *Buffer = *Buffer + 1
  43.               If myC = '='
  44.                 myC = PeekA(*Buffer)
  45.                 *Buffer = *Buffer + 1
  46.                 WriteAsciiCharacter(#Destfilebuff,myC-106)
  47.               Else
  48.                 WriteAsciiCharacter(#Destfilebuff,myC-42)
  49.               EndIf
  50.             Wend  
  51.            
  52.             buff = ReadString(#Sourcefilebuff)
  53.           Wend
  54.           position=0
  55.         Wend
  56.         CloseFile(#Sourcefilebuff) ; Close the source file 
  57.         part+1
  58.         stringpart.s = Str(part) + ".ntx"
  59.         sourcefile = Mid(sourcefile, 1,Len(sourcefile)-Len(stringpart)) + stringpart
  60.       Else
  61.         multipart=0
  62.       EndIf
  63.     Until Not multipart
  64.   Else
  65.     PrintN("Error file " + destfile )
  66.   EndIf
  67.  
  68.   CloseFile(#Destfilebuff) ;
  69. EndProcedure
  70.  
  71.  
  72. If OpenConsole()
  73.  
  74.   PrintN("* yEnc Decoder")
  75.   PrintN("* Version 1.0")
  76.   PrintN("* x0rc1zt")
  77.   PrintN("")
  78.  
  79.   Print("Enter the file name: ")
  80.  
  81.   sourcefile.s = Input()
  82.   sourcefilesize.q = FileSize(sourcefile)
  83.   checkcrc32.s = ""
  84.   destcrc32.s = ""
  85.   crc32found = 0
  86.  
  87.   If ReadFile(#Sourcefilebuff, sourcefile) ; Open the source file
  88.    
  89.     While Eof(#Sourcefilebuff) = 0
  90.      
  91.       ;get the name of our file
  92.       buff.s = ReadString(#Sourcefilebuff)
  93.       position= FindString(buff, "name=", 1)
  94.       If position
  95.         name.s = Mid(buff, position+5)
  96.       EndIf
  97.      
  98.       position= FindString(buff, "part=", 1)
  99.       If position
  100.         multipart = 1
  101.         buff = ReadString(#Sourcefilebuff)
  102.       EndIf
  103.      
  104.       position= FindString(buff, "crc32=", 1)
  105.       If position
  106.         checkcrc32.s = Mid(buff, position+6,8)
  107.         crc32found = 1
  108.       EndIf      
  109.     Wend  
  110.    
  111.   Else
  112.     PrintN("Couldn't open the file!")
  113.   EndIf
  114.    
  115.   CloseFile(#Sourcefilebuff) ; Close the source file   
  116.  
  117.   decode(sourcefile, name, multipart)
  118.  
  119.   ; check crc32
  120.   destcrc32.s = Hex(CRC32FileFingerprint(name))
  121.   If CompareMemoryString(@checkcrc32,@destcrc32,#PB_String_NoCase) = #PB_String_Equal
  122.     PrintN("CRC32 is okay.")
  123.   ElseIf crc32found
  124.     PrintN("CRC32 failed")
  125.   Else
  126.     PrintN("CRC32 not found")
  127.   EndIf  
  128.  
  129.   Print("Press enter to exit")
  130.   Input()
  131. EndIf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement