Hey guys.
Please bare with me since I'm only learning asm for about 48 hours or so..
I've learned enough to open files, read from/write to them...
I know how to use the WIN API from within ASM and ..honestly, it's much simpler than C++ (IMHO)...
So..I've written this basic program wich should be pretty simple to read..
It(should) basically copy a file...
.386
.model flat, stdcall
option casemap :none
Include windows.inc
Include user32.inc
Include kernel32.inc
IncludeLib user32.lib
IncludeLib kernel32.lib
.data
theFile DB "n_Copy.exe", 0
inputText DD 0
inputFile DB "C:\WINDOWS\NOTEPAD.EXE", 0
iFile DD 0
File DD 0
written DD 0
iwritten DD 0
fSize DD 0
.code
start:
;=================== open file ================;
push 0
push FILE_ATTRIBUTE_NORMAL
Push OPEN_EXISTING
push 0
push FILE_SHARE_READ
Push GENERIC_READ
Push Offset inputFile
call CreateFile
Mov iFile, Eax
;=================== set write head at 0 ================;
Push FILE_BEGIN
push 0
push 0
Push iFile
call SetFilePointer
Push 0
Push iFile
Call GetFileSize
; at this point eax should be equal to the file size right?
;=================== read from file ================;
Push 0
Push Offset iwritten
Push Eax ;
Push Offset inputText
Push iFile
Call ReadFile
;=================== close file ================;
Push iFile
Call CloseHandle
;=================== create file ================;
Push 0
push FILE_ATTRIBUTE_NORMAL
push OPEN_ALWAYS
push 0
push FILE_SHARE_READ
push GENERIC_WRITE
push offset theFile
call CreateFile
mov File,eax
;=================== set write head at 0 ================;
push FILE_END
push 0
push 0
push File
call SetFilePointer
;=================== get string length ================;
Push Offset inputText
call lstrlen
;=================== write to file ================;
push 0
Push Offset written
Push iwritten ;iwritten how holds the number of bytes read...
Push Offset inputText
push File
call WriteFile
;=================== close file ================;
push File
call CloseHandle
;=================== exit app ================;
invoke ExitProcess,eax
invoke PostQuitMessage,0
end start
the problem is that the code works great for a givven number of bytes to be read, but since I couldn't possibly compile my program everytime I copy another file, I tried using the GetFileSize API to ..well..get the file size :D
But there's something wrong in that GetFileSize area because the resulting file is always 0 byte in length...
if I change
Push 0
Push Offset iwritten
Push Eax ;
Push Offset inputText
Push iFile
Call ReadFile
with
Push 0
Push Offset iwritten
Push 1048 ;just an example....
Push Offset inputText
Push iFile
Call ReadFile
it works like a charm...
I would appreciate if someone would have a quick look and guide me on my way...
Cheers and thanks in advance