yEnc decoder
Posted: Tue Jul 12, 2011 12:07 pm
I wrote a yEnc encoder here : http://www.purebasic.fr/english/viewtop ... 12&t=46849
There is the decoder :
There is the decoder :
Code: Select all
; --------------
; YENC DECODER
; x0rc1zt
; v1.0
; jully 2011
; --------------
#Sourcefilebuff = 0
#Destfilebuff = 1
If OpenConsole()
PrintN("* yEnc Decoder")
PrintN("* Version 1.0")
PrintN("* x0rc1zt")
PrintN("")
Print("Enter the file name: ")
sourcefile$ = Input()
sourcefilesize.q = FileSize(sourcefile$)
If ReadFile(#Sourcefilebuff, sourcefile$) ; Open the source file
While Eof(#Sourcefilebuff) = 0
;get the name of our file
buff.s = ReadString(#Sourcefilebuff)
position= FindString(buff, "name=", 1)
If position
name.s = Mid(buff, position+5)
EndIf
;create our file
If CreateFile(#Destfilebuff, name) ; Create the destination file
buff = ReadString(#Sourcefilebuff)
; Read each strings till "=yend"
While Not FindString(buff, "=yend", 1)
*Buffer.character = AllocateMemory(1000)
*Pointer = *Buffer
CopyMemoryString(buff, @*Pointer)
myC.a = 0
; Decode each ascii char of our string
While Not *Buffer\c = #Null
myC = PeekA(*Buffer)
*Buffer = *Buffer + 1
If myC = '='
myC = PeekA(*Buffer)
*Buffer = *Buffer + 1
WriteAsciiCharacter(#Destfilebuff,myC-106)
Else
WriteAsciiCharacter(#Destfilebuff,myC-42)
EndIf
Wend
buff = ReadString(#Sourcefilebuff)
Wend
;FreeMemory(*Buffer)
;get crc32
position= FindString(buff, "crc32=", 1)
If position
checkcrc32.s = Mid(buff, position+6,8)
EndIf
CloseFile(#Destfilebuff) ; Close the destination file
destcrc32.s = Hex(CRC32FileFingerprint(name))
If CompareMemoryString(@checkcrc32,@destcrc32) = #PB_String_Equal
PrintN("CRC32 is okay.")
Else
PrintN("CRC32 failed")
EndIf
Else
PrintN("Couldn't create the file")
EndIf
Wend
CloseFile(#Sourcefilebuff) ; Close the source file
Else
PrintN("Couldn't open the file!")
EndIf
Print("Press enter to exit")
Input()
EndIf