32-bit Windows Assembly coding

From: Nathan C. Baker (nbaker2328_at_charter.net)
Date: 12/18/03


Date: Thu, 18 Dec 2003 07:43:05 -0500

Okay, I am trying some Win32 programming using MASM32 and attempting to use
the MASM32.LIB functions that come with it. I am starting with one of the
example sources that came with the package so I can concentrate on the
critical code and not have to debug the rest of the framework. So, I pick
out a function...

Hmmm.. XorData proc lpSource:DWORD,ln:DWORD,lpKey:DWORD,lnKey:DWORD
looks like a good one to start with, and I will load up the FSTACKER.ASM
found in the EXAMPLE6 directory and just make some modifications to make
practical use of this function. First, I insert the neccessart INCLUDES and
PROTO statements:

include \masm32\include\masm32.inc

includelib \masm32\lib\masm32.lib

XorData PROTO :DWORD,:DWORD,:DWORD,:DWORD

Then, I edit the ".ELSEIF ax==IDM_STACK" section to look like this:

invoke GetDlgItemText,hWnd,IDC_IN1,ADDR File1, 512

invoke GetDlgItemText,hWnd,IDC_IN2,ADDR File2, 512

invoke GetDlgItemText,hWnd,IDC_OUT,ADDR File3, 512

invoke CreateFile, ADDR File1, GENERIC_READ, NULL, NULL, OPEN_EXISTING,
NULL, NULL

.if eax==INVALID_HANDLE_VALUE

invoke MessageBox, NULL, ADDR File1, ADDR Nonce, MB_ICONERROR

jmp Errore

.endif

mov hFile1,eax

invoke GetFileSize, eax, NULL

mov File1Size,eax

invoke CreateFileMapping, hFile1, NULL, PAGE_READONLY,NULL,NULL,NULL

mov hMFile1,eax

invoke MapViewOfFile, eax, FILE_MAP_READ, NULL, NULL, NULL

mov hMVFile1,eax

invoke CreateFile, ADDR File2, GENERIC_READ, NULL, NULL, OPEN_EXISTING,
NULL, NULL

.if eax==INVALID_HANDLE_VALUE

invoke MessageBox, NULL, ADDR File2, ADDR Nonce, MB_ICONERROR

jmp Errore

.endif

mov hFile2,eax

invoke GetFileSize, eax, NULL

mov File2Size,eax

mov edx, File1Size

mov eax,edx ;<<< was add eax,edx

mov File3Size,eax

invoke CreateFileMapping, hFile2, NULL, PAGE_READONLY,NULL,NULL,NULL

mov hMFile2,eax

invoke MapViewOfFile, eax, FILE_MAP_READ, NULL, NULL, NULL

mov hMVFile2,eax

invoke XorData, hMVFile1, ADDR File1Size, hMVFile2, ADDR File2Size ;<<< OUR
NEW FUNCTION

invoke CreateFile, ADDR File3, GENERIC_READ or GENERIC_WRITE, NULL, NULL,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL

mov hFile3,eax

invoke SetFilePointer, eax, File3Size, NULL, FILE_BEGIN

invoke SetEndOfFile, hFile3

invoke SetFilePointer, hFile3, 0, NULL, FILE_BEGIN

invoke WriteFile, hFile3, hMVFile1, File1Size, ADDR BytesWritten, NULL

;invoke WriteFile, hFile3, hMVFile2, File2Size, ADDR BytesWritten, NULL

invoke UnmapViewOfFile, hMVFile1

invoke UnmapViewOfFile, hMVFile2

invoke CloseHandle, hMFile1

invoke CloseHandle, hMFile2

mov hMFile1,0

mov hMFile2,0

invoke CloseHandle, hFile1

invoke CloseHandle, hFile2

invoke CloseHandle, hFile3

I have gotten rid of all the Assemble-time errors and have produced an EXE.
However, the program doesn't DO ANYTHING when run. Why?



Relevant Pages

  • Re: Bugs in donkey.lib
    ... NULL,NULL,NULL,NULL, \ ADDR st_info, \ ... push eax ... invoke CloseHandle, ... MOV EAX,-1 however requires a test of EAX on exit as the flags are not set with a MOV, something that I found unacceptable and early on decided not to allow in functions that simply returned a state value. ...
    (alt.lang.asm)
  • RegCreateKeyEx help
    ... SetRegKeyDW PROTO:DWORD,:DWORD,:DWORD ... invoke SetRegKeysz, ADDR RegistryText, ADDR szKeyName, ... addr pKey, addr Disp ...
    (comp.lang.asm.x86)
  • Re: rename file? masm32? i pay for solution
    ... Just try to open the file using the CreateFile function [more ... invoke CreateFile, ADDR OldFile, GENERIC_READ, NULL, NULL, ... cmp eax, INVALID_HANDLE_VALUE ... invoke GetStdHandle, STD_OUTPUT_HANDLE ...
    (comp.lang.asm.x86)
  • Re: Why RosAsm Breaks on a large number of symbols
    ... xor eax, eax ... SIZEOF STARTUPINFO; ... ADDR st_info, ... invoke GetExitCodeProcess,pr_info.hProcess,ADDR xc ...
    (alt.lang.asm)
  • Get rid of window without the "staying in memory loop"
    ... invoke GetModuleHandle, NULL ... mov CommandLine,eax ... .if eax == FALSE ... NORM_IGNORECASE, addr pe32.szExeFile, -1, lpszExecutable, -1 ...
    (alt.lang.asm)