The following is a method of unpacking a compressed file compiled into
the .exe file as a resource. It makes use of Jeremy Collake's MASM
compression libraries found at (http://www.collakesoftware.com/). Please
note that "dialog.txt" is the product of pre-compressing another win32asm
application previously made for example.
My version works as one stand-alown exe:
RESOURCE CODE:
500 ICON MOVEABLE PURE LOADONCALL DISCARDABLE "MAINICON.ICO"
MOSTUFF RCDATA dialog.tst /* this is the compressed data */
600 MENUEX MOVEABLE IMPURE LOADONCALL DISCARDABLE
BEGIN
POPUP "&File", , , 0
BEGIN
MENUITEM "&Open", 1000
MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/
MENUITEM "&Decompress", 1001
MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/
MENUITEM "&Exit", 1010
END
POPUP "&Help", , , 0
BEGIN
MENUITEM "&About", 1900
END
END
Extra Includes (Thanx to Jeremy Collake for his hard work)
include \MASM32\INCLUDE\jcalg1_proto.inc
includelib \MASM32\LIB\jcalg1_static.lib
And the SaveFile Addin's
invoke FillBuffer,ADDR szFileName,length szFileName,0
invoke SaveFileName,hWin,ADDR szTitleS,ADDR szFilterS
cmp szFileName[0],0 ;<< zero if cancel pressed in dlgbox
je @F
invoke GetModuleHandle, NULL
mov hMod, eax
szText rsrcName2, "MOSTUFF"
invoke FindResource, hMod, addr rsrcName2, RT_RCDATA
mov hData, eax
invoke LoadResource, hMod, eax
mov lpData, eax
invoke SizeofResource, hMod, hData
mov lsize, eax
invoke JCALG1_GetUncompressedSizeOfCompressedBlock, lpData
mov ucsize, eax
DPrintValD eax, "Uncompressed Size" ; Ernie's DMacros
mov ebx, ucsize
add ebx, 1000
DPrintValD ebx, "Uncompressed Size + 1000"
invoke GlobalAlloc, GMEM_MOVEABLE or GMEM_ZEROINIT, ebx
mov hMem, eax
invoke GlobalLock, hMem
mov lpBuffer, eax
; --- ACTUAL DECOMPRESION HERE ---
;nFilesize=JCALG1_Decompress_Fast((void *)pData,pBuffer);
invoke JCALG1_Decompress_Fast, lpData, lpBuffer
mov lsize, eax
invoke CreateFile, ADDR szFileName,
GENERIC_WRITE, \
NULL, \
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,\
NULL
mov hFile, eax
mov ebx, lsize
;WriteFile(hOutputFile,pBuffer,nFilesize,&nBytesRead,0);
invoke WriteFile, hFile,lpBuffer,ebx, ADDR lsize, NULL
mov ebx, lsize
DPrintValD ebx, "Size Written"
invoke GlobalUnlock, lpBuffer
invoke GlobalFree, hMem
invoke CloseHandle, hFile
@@:
...
Well there it is when added and ran, this exe file succesfully decompresses
the resouced data stored within itself into another .exe file that will
run perfectly.
NaN
|