Text in French



quote:
--------------------------------------------------------------------------------

.386
.model flat, stdcall
option casemap :none ; case sensitive


include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
include \masm32\include\comdlg32.inc
includelib \masm32\lib\comdlg32.lib


.data

szFileFilter db 'Executables (*.exe)',0,'*.exe',0
db 'Tous (*.*)',0,'*.*',0,0
szTitle db 'nettoyeur',0
fbuf db 'nouveau.exe',0; 256 dup (?)
temp db '"nouveau.exe" cr?? ? %d octets. (%d ?conomis?s)',0

.data?
fHandle dd ?
pMapStart dd ?
hMapFile dd ?
Fsize dd ?
written dd ?
fh2 dd ?
tempbuf db 256 dup (?)
szFileName db 256 DUP (?)
ofn OPENFILENAMEA <?>

ALIGN 4
.code

start:

mov ofn.lStructSize,SIZEOF OPENFILENAMEA
mov ofn.lpstrFilter,offset szFileFilter
mov ofn.lpstrFile,offset szFileName
mov ofn.nMaxFile, 256
mov ofn.lpstrInitialDir,NULL
mov ofn.lpstrTitle,offset szTitle
mov ofn.Flags,OFN_EXPLORER + OFN_FILEMUSTEXIST + \
OFN_HIDEREADONLY + OFN_NODEREFERENCELINKS + \
OFN_PATHMUSTEXIST
invoke GetOpenFileNameA,offset ofn
test eax,eax
jz OpenErr

invoke CreateFileA,addr szFileName,GENERIC_READ + GENERIC_WRITE, \
0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
cmp eax,-1
jz OpenErr
mov fHandle,eax

invoke GetFileSize, fHandle, 0
mov Fsize,eax

invoke CreateFileA,addr fbuf,GENERIC_READ + GENERIC_WRITE, \
0,0,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,0

mov fh2,eax
invoke CreateFileMapping, fHandle,NULL,PAGE_READWRITE,0,0,NULL
mov hMapFile,eax
invoke MapViewOfFile,hMapFile, FILE_MAP_WRITE,0,0,0
mov pMapStart,eax

mov edi,pMapStart
mov ecx,dword ptr
push ecx
add edi,ecx
dec edi

xor al,al ;--------- same as std, rep scasb
@@:
cmp al, byte ptr
jnz @F
dec edi
dec ecx
jnz @b
@@:

pop eax
sub eax,ecx
mov ecx,eax
mov edx,eax
sub dword ptr ,ecx
mov ecx,dword ptr ; ecx = (Fsize - (Fsize-sizeof(code+data))

inc ecx

push ecx
invoke wsprintf, addr tempbuf, addr temp, ecx, edx
invoke MessageBox,0, addr tempbuf, addr szTitle,MB_ICONINFORMATION
pop ecx



invoke WriteFile, fh2, pMapStart, ecx, addr written,0
invoke UnmapViewOfFile, pMapStart
invoke CloseHandle, hMapFile
invoke CloseHandle, fHandle
invoke CloseHandle, fh2

jmp start ; WHILE OK CONTINUE
OpenErr:

invoke ExitProcess,eax



end start


--------------------------------------------------------------------------------



Axial
Posted on 2002-02-04 20:45:33 by Axial
lame indeed... the bytes in PE exe file sections have to
be padded to FileAlign, or the exe will not work on all windows versions.

But at least your source demonstrates how to use GetOpenFileName,
File Mapping, and some trivial byte scanning ;).
Posted on 2002-02-04 21:01:34 by f0dder
fodder,
Just out of curiousity (isn't it always)...

What do you have to change to make this works for all windows versions? Something in the PE?

Sliver
Posted on 2002-02-05 09:45:47 by Sliver
Well... you can realign most PE files... but you can't just go about
deleting zeroes :). If you want the PE to run everywhere, you also
can't go lower than 512 for FileAlign.
Posted on 2002-02-05 09:50:41 by f0dder