how to open a file in assembly language and read contents ?

any sample code welcome :)
Posted on 2004-02-10 22:49:35 by monty
Get your hands on the Win32 api programmer's reference helpfile.
There's more than one way to skin a cat.
In order to read and write file data, you need a file handle.
To get a file handle, use the CreateFile api function, in your case you might like to pass the OPEN_EXISTING flag.
Now you would use the returned file handle with other file-oriented api functions like ReadFile.
Other possibilities exist of course, like "file mapping".
Posted on 2004-02-10 23:27:38 by Homer
data
szFile db "file.txt", 0

data?
szBuffer BYTE 1024 dup (?) ; buffer to store file data in
dwBytesRead DWORD ? ; return from ReadFile, contains number of bytes read from file
dwFile DWORD ? ;file handle

code
invoke CreateFile, addr szFile, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0
mov dwFile, eax ; move the return value of CreateFile, into dwFile, this will be the file handle
cmp dwFile, -1 ; check if dwFile is equal to -1
je @fileerror ; if dwFile is equal to -1, then there was an error, so jump to end and close handle
invoke ReadFile, dwFile, addr szBuffer, 1024, addr dwBytesRead, 0
; first bit of file is now in szBuffer
@fileerror:
invoke CloseHandle, dwFile

hope this helps
Posted on 2004-02-11 00:31:35 by someone