News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Change code to work with masm

Started by Magnum, December 05, 2011, 08:15:45 PM

Previous topic - Next topic

Magnum

Can this be modified to work with masm?


.386
.model flat,stdcall
option casemap:none

CREATE_ALWAYS                        equ 2
GMEM_FIXED                           equ 0h
FILE_ATTRIBUTE_ARCHIVE               equ 20h
GENERIC_WRITE                        equ 40000000h

CloseHandle PROTO :DWORD
CreateFileA PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
CreateFile equ <CreateFileA>

ExitProcess PROTO :DWORD
GlobalAlloc PROTO :DWORD,:DWORD
GlobalFree PROTO :DWORD
WriteFile PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD

extractfile                                 PROTO :DWORD, :DWORD, :DWORD
JCALG1_Decompress_Fast                      PROTO :DWORD, :DWORD
JCALG1_GetUncompressedSizeOfCompressedBlock PROTO :DWORD


includelib  \masm32\lib\kernel32.lib

.data

pData:
INCBIN day.jc ; name of compressed file
file db 'day.exe',0

.data?

hMem dd ?
fSize dd ?
hFile dd ?
size1 dd ?

.code

start:

invoke JCALG1_GetUncompressedSizeOfCompressedBlock,ADDR pData
mov fSize,eax
invoke GlobalAlloc,GMEM_FIXED,eax
mov hMem,eax
invoke JCALG1_Decompress_Fast,ADDR pData,eax
invoke CreateFile,ADDR file,GENERIC_WRITE,\
0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,0
mov hFile,eax
invoke WriteFile,eax,hMem,fSize,ADDR size1,0
invoke CloseHandle,hFile
invoke GlobalFree,hMem
invoke ExitProcess,0

END start
Have a great day,
                         Andy

jj2007

No. But JWasm can do it.

.data
pData dd ?
INCBIN <day.jc> ; name of compressed file

...
.code

start:
invoke JCALG1_GetUncompressedSizeOfCompressedBlock, offset pData+4

Magnum

Can only the gcc linker work or will link work as well ?
Have a great day,
                         Andy

jj2007

#3
link, polink, wlink all work fine with JWasm.

Alternatively, try this code for use with ML.exe:

Quoteinclude \masm32\MasmBasic\MasmBasic.inc   ; download
.data
   Init
   Let ebx=CL$()   ; drag an executable over CreateIncBin.exe
   Let esi=FileRead$(ebx)
   mov ecx, LastFileSize
   shr ecx, 3
   Open "O", #1, Cat$(Left$(ebx, Instr_(ebx, ".exe", 1))+"dat")
   Print #1, "pBinString"
   .Repeat
      lodsd
      push eax
      lodsd
      Print #1, Tb$, "dq 0", Hex$(eax)
      pop eax
      Print #1, Hex$(eax),"h", CrLf$
      dec ecx
   .Until Zero? ; EDIT: put Zero? instead of Sign?
   Close
   Inkey "ok"
   Exit
end start

Usage:
include \masm32\include\masm32rt.inc
.686

.data
if 1
include test.dat ; generated with CreateIncBin.exe
else
incbin <test.exe> ; JWasm only
endif

.code
start: MsgBox 0, "Hello World", "Masm is great", MB_OK
exit
end start


Executable attached.