Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ********************************************************************************
- ; XUP Module v2.6.5.1 (x86) [ eXtended UnPack Library ]
- ; --------------------------------------------------------------------------------
- ; Coded ® 29-12-2011 by Peace^TST (PB 4.51) - build: 27-08-2017 (PB 5.44 LTS)
- ; --------------------------------------------------------------------------------
- ; Unpack: PP20, FIMP, XPK->SQSH|PWPK|IMPL|BZP2|GZIP|NONE, ICE!|ATM5, JCalG1, ZIP
- ; ********************************************************************************
- XIncludeFile "i_xup_structure.pbi"
- DeclareModule XUP
- Declare Free(*RS)
- Declare Unpack(*RS)
- EndDeclareModule
- Module XUP
- #XUP_WINAPI = 1 ; Windows API -> 0 = off / 1 = on
- ; *************************************************************************************************************
- ; i_XUP.pbi : Main-Structure / Error enumeration (s. i_xup_structure.pbi)
- ; *************************************************************************************************************
- Structure RS_XUP
- *IN_Ptr ;*Ptr to packed data or @Filename
- IN_Len.i ;Size of packed data or NULL if Filename
- *OUT_Ptr ;*Ptr to unpacked data
- OUT_Len.i ;Size of unpacked data
- PK_Mode.i ;Mode of packing (Zip/JCalG1)**
- PK_Level.i ;Efficiency (0-9)**
- Error.i ;Errorcode -> 0 = all OK or error
- Flags.i ;Private! (if not NULL, *IN_Ptr init by XUP_Unpack)
- EndStructure
- Enumeration ; *** Errors
- #XUPERR_OK = 0
- #XUPERR_FILE
- #XUPERR_UNPACK
- #XUPERR_NOTPACKED
- #XUPERR_UNKNOWN
- EndEnumeration
- ; *************************************************************************************************************
- ; i_XUP.pbi : Macros
- ; *************************************************************************************************************
- CompilerIf #XUP_WINAPI
- Macro MA_MemAlloc(SIZE) : GlobalAlloc_(#GMEM_ZEROINIT, SIZE) : EndMacro
- Macro MA_MemFree(PTR) : GlobalFree_(PTR) : EndMacro
- Macro MA_MemSize(PTR) : GlobalSize_(PTR) : EndMacro
- Macro MA_MemMove(SRC, DST, SIZE) : MoveMemory_(DST, SRC, SIZE) : EndMacro
- Macro MA_MemCopy(SRC, DST, SIZE) : CopyMemory_(DST, SRC, SIZE) : EndMacro
- Macro MA_MemFill(PTR, SIZE, VAL) : FillMemory_(PTR, SIZE, VAL) : EndMacro
- Macro MA_FileOpen(FILENAME)
- CreateFile_(FILENAME, #GENERIC_READ, #FILE_SHARE_READ, #NUL, #OPEN_EXISTING, #FILE_ATTRIBUTE_NORMAL, #NUL)
- EndMacro
- Macro MA_FileSize(HFILE) : GetFileSize_(HFILE, #NUL) : EndMacro
- Macro MA_FileRead(HFILE, PTR, SIZE) : ReadFile_(HFILE, PTR, SIZE, @SIZE, #NUL) : EndMacro
- Macro MA_FileClose(HFILE) : CloseHandle_(HFILE) : EndMacro
- CompilerElse
- Macro MA_MemAlloc(SIZE) : AllocateMemory(SIZE) : EndMacro
- Macro MA_MemFree(PTR) : FreeMemory(PTR) : EndMacro
- Macro MA_MemSize(PTR) : MemorySize(PTR) : EndMacro
- Macro MA_MemMove(SRC, DST, SIZE) : MoveMemory(SRC, DST, SIZE) : EndMacro
- Macro MA_MemCopy(SRC, DST, SIZE) : CopyMemory(SRC, DST, SIZE) : EndMacro
- Macro MA_MemFill(PTR, SIZE, VAL) : FillMemory(PTR, SIZE, VAL) : EndMacro
- Macro MA_FileOpen(FILENAME) : ReadFile(#PB_Any, PeekS(FILENAME)) : EndMacro
- Macro MA_FileSize(HFILE) : Lof(HFILE) : EndMacro
- Macro MA_FileRead(HFILE, PTR, SIZE) : ReadData(HFILE, PTR, SIZE) : EndMacro
- Macro MA_FileClose(HFILE) : CloseFile(HFILE) : EndMacro
- CompilerEndIf
- Macro MA_Error(VAL)
- If *RS\OUT_Len <= #Null
- *RS\Error = VAL
- Else
- *RS\Error = #XUPERR_OK
- EndIf
- ProcedureReturn *RS\Error
- EndMacro
- Macro UINT32(a)
- ((((a)&$FF)<<24)|(((a)&$FF00)<<8)|(((a)>>8)&$FF00)|(((a)>>24)&$FF))
- EndMacro
- Macro ID_LONG(a,b,c,d)
- (a)|(b<<8)|(c<<16)|(d<<24)
- EndMacro
- Macro ID_WORD(a,b)
- (a)|(b<<8)
- EndMacro
- ; *************************************************************************************************************
- ; i_XUP.pbi : Enumeration
- ; *************************************************************************************************************
- EnumerationBinary ; *** Flags
- #XUPFLG_MEMORY
- #XUPFLG_FILE
- EndEnumeration
- ; *************************************************************************************************************
- ; i_XUP.pbi : #XUP_MODE = 1<<? or #NUL
- ; *************************************************************************************************************
- EnumerationBinary ; *** UnPack Bitwise Modes
- #XUP_PP20 ; Amiga PowerPacker
- #XUP_FIMP ; Amiga FileImploder
- #XUP_XPKF ; Amiga XPK [SQSH|PWPK|IMPL|BZP2|GZIP|NONE]
- #XUP_NONE ; Amiga XPK NONE
- #XUP_JCAL ; JCalG1
- #XUP_BZP2 ; BZip2
- #XUP_GZIP ; GZip & Zip
- #XUP_NPKZ ; NoisePlug Zip
- #XUP_ICEI ; ICE! & ATOMIK
- #XUP_PACK ; Allow compression
- EndEnumeration
- #XUP_MC68 = #XUP_PP20|#XUP_FIMP|#XUP_NONE|#XUP_XPKF ; *** Small AMIGA unpacker only
- ;#XUP_MODE = #XUP_MC68|#XUP_JCAL|#XUP_BZP2|#XUP_GZIP ; *** Used unpacker
- CompilerIf Defined(XUP_MODE, #PB_Constant) = 0
- #XUP_MODE = $FFFFFFFF!(#XUP_PACK);|#XUP_JCAL|#XUP_ICEI) ; All unpackers but no JCalG1/ICEI and no packing (Default)
- CompilerEndIf
- CompilerIf Defined(NUL, #PB_Constant) = 0
- #NUL = 0
- CompilerEndIf
- CompilerIf Defined(XUP_PATH$, #PB_Constant) = 0
- #XUP_PATH$ = #PB_Compiler_FilePath + "Include\"
- CompilerEndIf
- ; NoisePlug JCalG1 + Zipped
- #XUPID_JCAL = ID_WORD('J','C') ;'CJ' ; NoisePlug JCalG1
- #XUPID_NPKZ = ID_WORD('Z','C') ;'CZ' ; NoisePlug Zipped
- ; PP20
- #XUPID_PP10 = ID_LONG('P','P','1','0') ;'01PP' ; PowerPacker v1.0
- #XUPID_PP11 = ID_LONG('P','P','1','1') ;'11PP' ; PowerPacker v1.1
- #XUPID_PP15 = ID_LONG('P','P','1','5') ;'51PP' ; PowerPacker v1.5
- #XUPID_PP20 = ID_LONG('P','P','2','0') ;'02PP' ; PowerPacker v2.0+
- #XUPID_PPLS = ID_LONG('P','P','L','S') ;'SLPP' ; PowerPacker LoadSeg
- #XUPID_PPBK = ID_LONG('P','P','b','k') ;'kbPP' ; PowerPacker AMOSPro PPBank
- ; FIMP
- #XUPID_FIMP = ID_LONG('I','M','P','!') ;'!PMI'
- #XUPID_MADE = ID_LONG('M','A','D','E') ;'EDAM'
- #XUPID_IFHC = ID_LONG('I','F','H','C') ;'CHFI'
- #XUPID_PARA = ID_LONG('P','A','R','A') ;'ARAP'
- #XUPID_9CDR = ID_LONG('9','C','D','R') ;'RDC9'
- #XUPID_FLTI = ID_LONG('F','L','T','!') ;'!TLF'
- #XUPID_DUPA = ID_LONG('D','u','p','a') ;'apuD'
- ; XPK Compressors
- #XUPID_XPKF = ID_LONG('X','P','K','F') ;'FKPX'
- #XUPID_SQSH = ID_LONG('S','Q','S','H') ;'HSQS'
- #XUPID_PWPK = ID_LONG('P','W','P','K') ;'KPWP'
- #XUPID_BZP2 = ID_LONG('B','Z','P','2') ;'2PZB'
- #XUPID_NONE = ID_LONG('N','O','N','E') ;'ENON'
- #XUPID_GZIP = ID_LONG('G','Z','I','P') ;'PIZG'
- #XUPID_IMPL = ID_LONG('I','M','P','L') ;'LPMI' ; XPKF -> IMPL = Bug > 64Kb
- #XUPID_RLEN = ID_LONG('R','L','E','N') ;'NELR'
- ; ICE & ATOMIK (Atari)
- #XUPID_IC21 = ID_LONG('I','c','e','!') ;'!ecI' ; ICE Packer 2.1
- #XUPID_IC24 = ID_LONG('I','C','E','!') ;'!ECI' ; ICE Packer 2.4
- #XUPID_ATM5 = ID_LONG('A','T','M','5') ;'5MTA' ; Atomik Packer 3.5
- #XUPPAK_JCAL = 1<<0 ; JCalG1 CompressMem
- #XUPPAK_ZIPM = 1<<1 ; Zip CompressMem
- ; *************************************************************************************************************
- ; i_XUP.pbi : Includelibs
- ; *************************************************************************************************************
- #XUPLIB_BZP2$ = "bzip2_x86.lib"
- #XUPLIB_GZIP$ = "zlib_x86.lib"
- #XUPLIB_PP20$ = "pp20_x86.lib"
- #XUPLIB_FIMP$ = "fimp_x86.lib"
- #XUPLIB_SQSH$ = "xpk_sqsh_x86.a"
- #XUPLIB_JCAL$ = "jcalg1_static_x86.lib"
- #XUPLIB_ICEI$ = "unicelib_x86.lib"
- CompilerIf #XUP_MODE & #XUP_PP20
- ; *** Amiga PowerPacker Data (PP20)
- ImportC #XUPLIB_PP20$
- PPK_GetSize(*src, srclen) As "_ppGetDecrunchSize"
- PPK_Decrunch(*src, *dest, srclen, destlen) As "_ppDecrunchMemory"
- EndImport
- CompilerEndIf
- CompilerIf #XUP_MODE & #XUP_FIMP
- ; *** Amiga FileImploder (FImp)
- ImportC #XUPLIB_FIMP$
- IMP_GetSize(*src) As "_impGetExplodeSize"
- IMP_Decrunch(*src, srclen, *dest, destlen) As "_impExplode"
- EndImport
- CompilerEndIf
- CompilerIf #XUP_MODE & #XUP_XPKF
- ; *** Amiga eXtendedPacKer (XPK\compressors)
- ImportC #XUPLIB_SQSH$
- XPK_Check(*src, *srclen, *dstlen) As "__Z9xpk_checkPhS_S_"
- XPK_Unpack(*src, *dst) As "__Z10xpk_unpackPhS_"
- ;XPK_GetSize(*src) As "_XPK_Length"
- ;XPK_Decrunch(*src, *dest) As "_XPK_Unpack"
- EndImport
- CompilerEndIf
- CompilerIf #XUP_MODE & #XUP_JCAL
- Import #XUPLIB_JCAL$
- JCA_Decrunch(*src, *dest) As "_JCALG1_Decompress_Fast@8"
- ;JCA_Decrunch(*src, *dest) As "_JCALG1_Decompress_Small@8"
- ;JCA_Crunch(*src, srclen, *dest, Windowsize.l, *pAlloc, *pDealloc, *pCallback, bDisableChecksum.l) As _JCALG1_Compress@32
- EndImport
- CompilerEndIf
- CompilerIf #XUP_MODE & #XUP_BZP2
- ; *** BZip2
- Import #XUPLIB_BZP2$
- BZ2_Decrunch(*DestBuff, *DestSize, *SourceBuff, iSourceSize, small, verbosity) As "_BZ2_bzBuffToBuffDecompress@24"
- ;BZ2_bzBuffToBuffCompress.i (*DestBuff, *DestSize, *SourceBuff, iSourceSize, iBlockSize, verbosity, workFactor)
- ;BZ2_bzBuffToBuffDecompress.i (*DestBuff, *DestSize, *SourceBuff, iSourceSize, small, verbosity)
- EndImport
- CompilerEndIf
- CompilerIf #XUP_MODE & (#XUP_GZIP | #XUP_NPKZ)
- ; *** Zip
- ImportC #XUPLIB_GZIP$
- ZIP_Decrunch(*DestBuff, *iDestSize, *SourceBuff, iSourceSize) As "_uncompress"
- CompilerIf #XUP_MODE&#XUP_PACK
- ZIP_Crunch(*DestBuff, *iDestSize, *SourceBuff, iSourceSize, iCompressionLevel) As "_compress2"
- CompilerEndIf
- ;compress2.i(*DestBuff, *iDestSize, *SourceBuff, iSourceSize, iCompressionLevel)
- ;uncompress.i(*DestBuff, *iDestSize, *SourceBuff, iSourceSize)
- EndImport
- CompilerEndIf
- CompilerIf #XUP_MODE & #XUP_ICEI
- ; *** Atari ICE! & Atomik Unpacker
- ImportC #XUPLIB_ICEI$
- ; Atomik Packer 3.5
- ; atm_35_get_long() As "_atm_35_get_long"
- ; atm_35_getbits() As "_atm_35_getbits"
- atm_35_header(*src) As "_atm_35_header"
- atm_35_packedsize(*src) As "_atm_35_packedsize"
- atm_35_origsize(*src) As "_atm_35_origsize"
- atm_35_depack(*src, *dest) As "_atm_35_depack"
- ; Pack Ice 2.1
- ; get_long() As "_get_long"
- ; ice_get_long() As "_ice_get_long"
- ; ice_getbits() As "_ice_getbits"
- ice_21_header(*src) As "_ice_21_header"
- ice_21_packedsize(*src) As "_ice_21_packedsize"
- ice_21_origsize(*src) As "_ice_21_origsize"
- ice_21_depack(*src, *dest) As "_ice_21_depack"
- ; Pack Ice 2.4
- ; get24_long() As "_get24_long"
- ; ice24_get_long() As "_ice24_get_long"
- ; ice24_getbits() As "_ice24_getbits"
- ice_24_header(*src) As "_ice_24_header"
- ice_24_packedsize(*src) As "_ice_24_packedsize"
- ice_24_origsize(*src) As "_ice_24_origsize"
- ice_24_depack(*src, *dest) As "_ice_24_depack"
- EndImport
- CompilerEndIf
- ; *************************************************************************************************************
- ; i_XUP.pbi : Functions(struc RS_XUP)
- ; *************************************************************************************************************
- Procedure Free(*RS.RS_XUP)
- ; Should be called before or after unpacking (free intern memory allocation)
- With *RS
- If \OUT_Ptr > #Null
- If \OUT_Ptr <> \IN_Ptr
- MA_MemFree(\OUT_Ptr)
- EndIf
- EndIf
- If \Flags & #XUPFLG_FILE
- If \IN_Ptr > #Null
- MA_MemFree(\IN_Ptr)
- EndIf
- \IN_Ptr = #Null
- \IN_Len = #Null
- EndIf
- \OUT_Ptr = #Null
- \OUT_Len = #Null
- \Flags = #Null
- \Error = #Null
- ;ClearStructure(@*RS, RS_XUP)
- EndWith
- EndProcedure
- Procedure Unpack(*RS.RS_XUP)
- ; *********************************************************************************
- ; In: RS\IN_Ptr -> *Ptr to membuf of packed data -> or *StrPtr of @Filename$
- ; RS\IN_Len -> Size of packed membuf. If *Ptr = @Filename$ MUST! be #NULL
- ;
- ; Out: RS\OUT_Ptr -> *Ptr to unpacked data
- ; RS\OUT_Len -> Size of unpacked membuf -> NUL if error
- ;
- ; Pack: RS\PK_Mode -> Unpack = *Ptr to Suffix / Pack = Mode (JC/ZC)
- ; RS\PK_Level -> Level of pack-effiziency (0-9)
- ;
- ; Misc: RS\Error -> <> NUL = Error when packing
- ; RS\Flags -> #XUP_FLAG_FILE -> IN_Ptr = @Filename$ (free intern memory)
- ; *********************************************************************************
- Protected i, hFile
- With *RS
- ; ******************************************************************
- ; * IN_LEN <= 0 then -> IN_PTR = @Filename$ -> Flag = #XUP_FLAG_FILE
- ; ******************************************************************
- If \IN_Len <= #Null
- hFile = MA_FileOpen(\IN_Ptr)
- If hFile
- \Flags = #XUPFLG_FILE ; s. XUP_Free()
- \IN_Len = MA_FileSize(hFile)
- \IN_Ptr = MA_MemAlloc(\IN_Len+SizeOf(Long)) ; Add long if text (zero-ending)
- MA_FileRead(hFile, \IN_Ptr, \IN_Len)
- MA_FileClose(hFile)
- Else
- \Error = #XUPERR_FILE
- ProcedureReturn \Error
- EndIf
- EndIf
- If \IN_Len > #NUL
- \OUT_Ptr = \IN_Ptr
- \OUT_Len = \IN_Len
- ;*********************************************
- ;* NPK Z -> ZC
- ;*********************************************
- CompilerIf #XUP_MODE & #XUP_NPKZ
- If PeekW(\IN_Ptr) = #XUPID_NPKZ
- \OUT_Len = PeekL(\IN_Ptr+SizeOf(Word))
- If \OUT_Len > 0 And \OUT_Len < $FFFFF
- For i = \IN_Len - 32 To \IN_Len
- If PeekL(\IN_Ptr + i) = 'DIPN' ;NPID TAG -> iNPID+lSIZE+szEXT$
- \PK_Mode = \IN_Ptr + i
- \IN_Len = i
- Break
- EndIf
- Next
- \OUT_Ptr = MA_MemAlloc(\OUT_Len)
- If ZIP_Decrunch(\OUT_Ptr, @\OUT_Len, \IN_Ptr+6, \IN_Len)
- MA_MemFree(\OUT_Ptr)
- \OUT_Ptr = #NUL
- \OUT_Len = #NUL
- EndIf
- EndIf
- MA_Error(#XUPERR_UNPACK)
- EndIf
- CompilerEndIf
- ;*********************************************
- ;* NPK JCalG1 -> JC
- ;*********************************************
- CompilerIf #XUP_MODE & #XUP_JCAL
- If PeekW(\IN_Ptr) = #XUPID_JCAL
- \OUT_Len = PeekL(\IN_Ptr+SizeOf(Word))
- If \OUT_Len > 0 And \OUT_Len < $FFFFF
- For i = \IN_Len - 32 To \IN_Len
- If PeekL(\IN_Ptr + i) = 'DIPN' ;NPID (NoisePlug)
- \PK_Mode = \IN_Ptr + i
- \IN_Len = i
- Break
- EndIf
- Next
- If \PK_Mode
- \OUT_Ptr = MA_MemAlloc(\OUT_Len)
- If \OUT_Ptr
- \OUT_Len = JCA_Decrunch(\IN_Ptr, \OUT_Ptr) ; \OUT_Len = UnpackMemory(\IN_Ptr, \OUT_Ptr)
- If \OUT_Len = #NUL
- MA_MemFree(\OUT_Ptr)
- \OUT_Ptr = #NUL
- EndIf
- Else
- \OUT_Len = #NUL
- EndIf
- Else
- \OUT_Len = #NUL
- EndIf
- EndIf
- MA_Error(#XUPERR_UNPACK)
- EndIf
- CompilerEndIf
- ;*********************************************
- ;* Amiga XPKF -> PWPK|IMPL|SQSH|BZP2|GZIP|NONE
- ;*********************************************
- CompilerIf #XUP_MODE & #XUP_XPKF
- If PeekL(\IN_Ptr) = #XUPID_XPKF
- Select PeekL(\IN_Ptr+8)
- CompilerIf #XUP_MODE & #XUP_PP20
- Case #XUPID_PWPK ;Convert XPKF -> PWPK = PP20...
- Select PeekB(\IN_Ptr+\IN_Len-13)
- Case 0 : i = $09090909
- Case 1 : i = $0A0A0A09 ;01010100
- Case 2 : i = $0B0B0A09 ;02020100
- Case 3 : i = $0C0C0A09 ;03030200
- Default : i = $0D0C0A09 ;04030100
- EndSelect
- MA_MemMove(\IN_Ptr + $30, \IN_Ptr + $8, \IN_Len - $38)
- PokeL(\IN_Ptr, #XUPID_PP20)
- PokeL(\IN_Ptr + 4, i)
- \IN_Len - $38
- CompilerEndIf
- CompilerIf #XUP_MODE & (#XUP_BZP2 | #XUP_GZIP)
- Case #XUPID_BZP2, #XUPID_GZIP ;Convert XPKF -> BZP2 = BZ / GZIP = ZIP...
- MA_MemMove(\IN_Ptr + $2C, \IN_Ptr, \IN_Len - $2C)
- \OUT_Len = PeekI(\IN_Ptr)
- \OUT_Len = UINT32(\OUT_Len)
- PokeI(\IN_Ptr, \OUT_Len)
- \IN_Len - $38
- CompilerEndIf
- CompilerIf #XUP_MODE & #XUP_NONE
- Case #XUPID_NONE ;Unpack XPKF -> NONE
- \OUT_Len = \IN_Len - $2C
- \OUT_Ptr = MA_MemAlloc(\OUT_Len) ; Important: Packed IN_Len > Unpacked OUT_Len
- MA_MemCopy(\IN_Ptr + $2C, \OUT_Ptr, \OUT_Len)
- ProcedureReturn #XUPERR_OK
- CompilerEndIf
- CompilerIf #XUP_MODE & #XUP_FIMP
- Case #XUPID_IMPL ;Convert XPKF = IMPL -> IMP!...
- MA_MemMove(\IN_Ptr + $30, \IN_Ptr, \IN_Len - $30)
- \IN_Len - $36
- CompilerEndIf
- Case #XUPID_SQSH ;Unpack XPKF -> SQSH / Bug? in returned \OUT_Len, must! calculated
- If XPK_Check(\IN_Ptr, @\IN_Len, @\OUT_Len) > #NUL
- \OUT_Len = PeekL(\IN_Ptr + $C)
- \OUT_Len = UINT32(\OUT_Len)
- \OUT_Ptr = MA_MemAlloc(\OUT_Len * 2)
- If XPK_Unpack(\IN_Ptr, \OUT_Ptr) < #NUL
- MA_MemFree(\OUT_Ptr)
- \OUT_Ptr = #NUL
- \OUT_Len = #NUL
- EndIf
- EndIf
- MA_Error(#XUPERR_UNPACK) ; If ERROR then EndProcedure
- EndSelect
- EndIf
- CompilerEndIf
- ;*********************************************
- ;* Amiga PowerPacker PP20|PP11|PPLS|PPbk
- ;*********************************************
- CompilerIf #XUP_MODE & #XUP_PP20
- Select PeekL(\IN_Ptr)
- Case #XUPID_PP20,#XUPID_PPBK,#XUPID_PP10,#XUPID_PP11,#XUPID_PP15,#XUPID_PPLS
- \OUT_Len = PPK_GetSize(\IN_Ptr, \IN_Len)
- If \OUT_Len > 0
- \OUT_Ptr = MA_MemAlloc(\OUT_Len)
- If PPK_Decrunch(\IN_Ptr, \OUT_Ptr, \IN_Len, \OUT_Len) >= #NUL
- If PeekL(\IN_Ptr) = #XUPID_PPBK ;AMOSPro Bank? ID="Work"+SPC[4]
- MA_MemMove(\OUT_Ptr+8, \OUT_Ptr, \OUT_Len-8)
- \OUT_Len - 8
- EndIf
- Else
- MA_MemFree(\OUT_Ptr)
- \OUT_Len = #NUL
- \OUT_Ptr = #NUL
- EndIf
- EndIf
- MA_Error(#XUPERR_UNPACK) ; If ERROR then EndProcedure
- EndSelect
- CompilerEndIf
- ;*********************************************
- ;* Amiga FileImploder (FImp) IMP!
- ;*********************************************
- CompilerIf #XUP_MODE & #XUP_FIMP
- Select PeekL(\IN_Ptr)
- Case #XUPID_FIMP,#XUPID_MADE,#XUPID_IFHC,#XUPID_PARA,#XUPID_9CDR,#XUPID_FLTI,#XUPID_DUPA
- \OUT_Len = IMP_GetSize(\IN_Ptr)
- If \OUT_Len > 0
- \OUT_Ptr = MA_MemAlloc(\OUT_Len * 2)
- If IMP_Decrunch(\IN_Ptr, \IN_Len, \OUT_Ptr, \OUT_Len) < #NUL ;ERROR?
- MA_MemFree(\OUT_Ptr)
- \OUT_Ptr = #NUL
- \OUT_Len = #NUL
- EndIf
- EndIf
- MA_Error(#XUPERR_UNPACK) ; If ERROR then EndProcedure
- EndSelect
- CompilerEndIf
- ;*********************************************
- ;* Atari ICE! & ATOMIK -> Ice!|ICE!|ATM5
- ;*********************************************
- CompilerIf #XUP_MODE & #XUP_ICEI
- Select PeekL(\IN_Ptr)
- Case #XUPID_IC21,#XUPID_IC24,#XUPID_ATM5
- Select PeekL(\IN_Ptr)
- Case #XUPID_IC21 : \OUT_Len = ice_21_origsize(\IN_Ptr)
- Case #XUPID_IC24 : \OUT_Len = ice_24_origsize(\IN_Ptr)
- Case #XUPID_ATM5 : \OUT_Len = atm_35_origsize(\IN_Ptr)
- EndSelect
- If \OUT_Len > 0
- \OUT_Ptr = MA_MemAlloc(\OUT_Len)
- Select PeekL(\IN_Ptr)
- Case #XUPID_IC21 : \OUT_Len = ice_21_depack(\IN_Ptr, \OUT_Ptr)
- Case #XUPID_IC24 : \OUT_Len = ice_24_depack(\IN_Ptr, \OUT_Ptr)
- Case #XUPID_ATM5 : \OUT_Len = atm_35_depack(\IN_Ptr, \OUT_Ptr)
- EndSelect
- If \OUT_Len <= #NUL ;ERROR
- MA_MemFree(\OUT_Ptr)
- \OUT_Ptr = #NUL
- \OUT_Len = #NUL
- EndIf
- EndIf
- MA_Error(#XUPERR_UNPACK) ; If ERROR then EndProcedure
- EndSelect
- CompilerEndIf
- ;*********************************************
- ;* BZip2 (Buffer)
- ;*********************************************
- CompilerIf #XUP_MODE & #XUP_BZP2
- If PeekW(\IN_Ptr+SizeOf(Long)) = 'ZB'
- \OUT_Len = PeekL(\IN_Ptr)
- \OUT_Ptr = MA_MemAlloc(\OUT_Len)
- If BZ2_Decrunch(\OUT_Ptr, @\OUT_Len, \IN_Ptr + SizeOf(Long), \IN_Len - SizeOf(Long), 0, 0)
- MA_MemFree(\OUT_Ptr)
- \OUT_Ptr = #NUL
- \OUT_Len = #NUL
- EndIf
- MA_Error(#XUPERR_UNPACK) ; If ERROR then EndProcedure
- EndIf
- CompilerEndIf
- ;*********************************************
- ;* GZip (Buffer)
- ;*********************************************
- CompilerIf #XUP_MODE & #XUP_GZIP
- If PeekB(\IN_Ptr+SizeOf(Long)) = 'x'
- \OUT_Len = PeekL(\IN_Ptr)
- \OUT_Ptr = MA_MemAlloc(\OUT_Len)
- If ZIP_Decrunch(\OUT_Ptr, @\OUT_Len, \IN_Ptr + SizeOf(Long), \IN_Len - SizeOf(Long))
- MA_MemFree(\OUT_Ptr)
- \OUT_Ptr = #NUL
- \OUT_Len = #NUL
- EndIf
- MA_Error(#XUPERR_UNPACK) ; If ERROR then EndProcedure
- EndIf
- CompilerEndIf
- EndIf
- If \IN_Len = \OUT_Len Or \IN_Ptr = \OUT_Ptr
- ProcedureReturn #XUPERR_NOTPACKED
- EndIf
- EndWith
- ProcedureReturn #XUPERR_OK ; All OK, return #NULL
- EndProcedure
- EndModule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement