#PPERR_OK = 0
#PPERR_ARGS = -1
#PPERR_OPEN = -2
#PPERR_READ = -3
#PPERR_SEEK = -4
#PPERR_NOMEMORY = -5
#PPERR_DATAFORMAT = -6
#PPERR_PASSWORD = -7
#PPERR_DECRUNCH = -8
#PPMODE_PP11 = $50503131
#PPMODE_PP20 = $50503230
#PPMODE_PPBK = $5050626B
#PPMODE_PPLS = $50504C53
#PPMODE_PX20 = $50583230
Structure PP20
DLL.q
*GetDecrunchSize
*GetCrunchMode
*DecrunchMemory
*EncodeMemory
*DecrunchFile
*CalcPasskey
*CalcChecksum
EndStructure : PP.PP20
PP\DLL = OpenLibrary(#PB_Any, "C:\pp20_dll\dll\pp20.dll")
With PP
If \DLL
\GetDecrunchSize = GetFunction(\DLL, "ppGetDecrunchSize")
\DecrunchMemory = GetFunction(\DLL, "ppDecrunchMemory")
\EncodeMemory = GetFunction(\DLL, "ppEncodeMemory")
\DecrunchFile = GetFunction(\DLL, "ppDecrunchFile")
\CalcPasskey = GetFunction(\DLL, "ppCalcPasskey")
\CalcChecksum = GetFunction(\DLL, "ppCalcChecksum")
Else
Debug "Error: cannot access to pp20.dll"
End
EndIf
EndWith
InFile.s = "test\AgonySea.pp"
OutFile.s = "test\AgonySea.mod"
Password.s = "Amiga"
CkSum = CallCFunctionFast(PP\CalcChecksum,
@Password)
PassKey = CallCFunctionFast(PP\CalcPasskey, @Password)
#PP20 = 2
CompilerSelect #PP20
CompilerCase 0
Debug "Decrunch file..."
err = CallCFunctionFast(PP\DecrunchFile, @InFile, @OutFile, @Password)
If err = #PPERR_OK
InSize = FileSize(InFile)
OutSize= FileSize(OutFile)
EndIf
CompilerCase 1
Debug "Decrunch memory..."
hF = ReadFile(#PB_Any, InFile)
If hF
InSize = Lof(hF)
*InBuf = AllocateMemory(InSize)
ReadData(hF, *InBuf, InSize)
CloseFile(hF)
OutSize = CallCFunctionFast(PP\GetDecrunchSize, *InBuf, InSize)
If OutSize > 0
*OutBuf = AllocateMemory(OutSize)
err = CallCFunctionFast(PP\DecrunchMemory, *InBuf, *OutBuf, InSize, OutSize, @Password)
If err = #PPERR_OK
hF = CreateFile(#PB_Any, OutFile)
If hF
WriteData(hF, *OutBuf, OutSize)
CloseFile(hF)
Else
err = #PPERR_OPEN
EndIf
EndIf
FreeMemory(*OutBuf)
Else
err = OutSize
EndIf
FreeMemory(*InBuf)
Else
err = #PPERR_OPEN
EndIf
CompilerCase 2
Debug "Encrypt memory..."
hF = ReadFile(#PB_Any, InFile)
If hF
InSize = Lof(hF)
*InBuf = AllocateMemory(InSize)
ReadData(hF, *InBuf, InSize)
CloseFile(hF)
OutSize = CallCFunctionFast(PP\GetDecrunchSize, *InBuf, InSize)
If OutSize > 0
PassKey = $610F436
*TmpBuf = AllocateMemory(InSize)
CopyMemory(*InBuf, *TmpBuf, InSize)
*OutBuf = AllocateMemory(OutSize)
Repeat
loop + 1
PassKey + 1
err = CallCFunctionFast(PP\EncodeMemory, *InBuf, *OutBuf, InSize, OutSize, PassKey, *TmpBuf)
If err = #PPERR_OK
Debug "Checked keys: " + Str(loop) + " - Detected passkey: $" + Hex(PassKey)
Break
EndIf
If loop % $FD0 = 0
Debug Str(loop) + ": $" + Hex(PassKey)
If GetAsyncKeyState_(#VK_ESCAPE)
Break
EndIf
Delay(15)
EndIf
Until PassKey = $FFFFFFFF
EndIf
Else
err = #PPERR_OPEN
EndIf
CompilerEndSelect
CloseLibrary(PP\DLL)
Debug "Infile: " + InFile + " - Size: " + Str(InSize)
Debug "OutFile: " + OutFile + " - Size: " + Str(OutSize)
Debug "Password: " + Password + " - CkSum: $" + Hex(CkSum) + " - PassKey: $" + Hex(PassKey)
Debug "Errorcode: " + Str(err)
If err = #PPERR_OK
Debug "All successful decrunched!"
EndIf
End