Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; --------------
- ; YENC DECODER
- ; x0rc1zt
- ; v1.0
- ; jully 2011
- ; --------------
- #Sourcefilebuff = 0
- #Destfilebuff = 1
- Procedure decode(sourcefile.s, destfile.s, multipart.i)
- part.i = 0
- buff.s = ""
- myC.a = 0
- position.i = 0
- If CreateFile(#Destfilebuff, destfile)
- Repeat
- If ReadFile(#Sourcefilebuff, sourcefile)
- While Eof(#Sourcefilebuff) = 0
- buff = ReadString(#Sourcefilebuff)
- position= FindString(buff, "name=", 1)
- ; if we found the yenc section we read the next line
- If position
- buff = ReadString(#Sourcefilebuff)
- If multipart ; if multi part we must read the next line again
- buff = ReadString(#Sourcefilebuff)
- EndIf
- EndIf
- While Not FindString(buff, "=yend", 1) And position
- *Buffer.character = AllocateMemory(1000)
- *Pointer = *Buffer
- CopyMemoryString(buff, @*Pointer)
- ; 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
- position=0
- Wend
- CloseFile(#Sourcefilebuff) ; Close the source file
- part+1
- stringpart.s = Str(part) + ".ntx"
- sourcefile = Mid(sourcefile, 1,Len(sourcefile)-Len(stringpart)) + stringpart
- Else
- multipart=0
- EndIf
- Until Not multipart
- Else
- PrintN("Error file " + destfile )
- EndIf
- CloseFile(#Destfilebuff) ;
- EndProcedure
- If OpenConsole()
- PrintN("* yEnc Decoder")
- PrintN("* Version 1.0")
- PrintN("* x0rc1zt")
- PrintN("")
- Print("Enter the file name: ")
- sourcefile.s = Input()
- sourcefilesize.q = FileSize(sourcefile)
- checkcrc32.s = ""
- destcrc32.s = ""
- crc32found = 0
- 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
- position= FindString(buff, "part=", 1)
- If position
- multipart = 1
- buff = ReadString(#Sourcefilebuff)
- EndIf
- position= FindString(buff, "crc32=", 1)
- If position
- checkcrc32.s = Mid(buff, position+6,8)
- crc32found = 1
- EndIf
- Wend
- Else
- PrintN("Couldn't open the file!")
- EndIf
- CloseFile(#Sourcefilebuff) ; Close the source file
- decode(sourcefile, name, multipart)
- ; check crc32
- destcrc32.s = Hex(CRC32FileFingerprint(name))
- If CompareMemoryString(@checkcrc32,@destcrc32,#PB_String_NoCase) = #PB_String_Equal
- PrintN("CRC32 is okay.")
- ElseIf crc32found
- PrintN("CRC32 failed")
- Else
- PrintN("CRC32 not found")
- EndIf
- Print("Press enter to exit")
- Input()
- EndIf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement