Re: How do I link to C Library functions in windows?
- From: Tim Roberts <spamtrap@xxxxxxxxxx>
- Date: Thu, 10 Jan 2008 04:32:10 GMT
"bwaichu@xxxxxxxxx" <spamtrap@xxxxxxxxxx> wrote:
...
Nevertheless, I'm trying to figure out how the CreateFile and
WriteFile API works.
I import it like:
import CreateFileA kernel32.dll ; how do I know if I need to tag an A
to the end?
Any Win32 API that takes or returns a string will have an A and a W
variant.
Now, do I need to setup the stack like I do in BSD? My printf
program worked without it, but I'm not sure if that is correct.
What do you mean by "setup the stack"? For a Win32 process, the stack is
set up before your main gets called.
push dword 80h ; normal file operation
That's FILE_READ_ATTRIBUTES, but that won't allow you read or write access
to the file. To read the file, you need 00120089h; to write the file, you
need 00120116h.
The file handle should be put in eax, which I can use later to write,
read, or close to depending how I set the above parameters. Now,
should the above generate a file, or do I need to write to the file?
It depends on the 5th parameter. Your example was CREATE_ALWAYS, which
creates the file as 0 bytes. OPEN_ALWAYS and OPEN_EXISTING opens it for
reading but doesn't create it.
I run the program, and I do not even see any empty file. How do I
check for errors in assembly? eax should return something. Is there
an equivalent of errno?
You need to check the APIs in MSDN. If CreateFile returns
INVALID_HANDLE_VALUE, which is -1, then you call GetLastError will return
an error code.
I also need a way to step through the
execution, so I can see how the registers change.
Right, you need a debugger. OllyDbg is a good one, or you can use
Microsoft's windbg.
I should be able to close the file handle by:
push eax ; which I should save to the stack
call [CloseHandle]
Right.
--
Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.
.
- References:
- How do I link to C Library functions in windows?
- From: bwaichu@xxxxxxxxx
- Re: How do I link to C Library functions in windows?
- From: Tim Roberts
- Re: How do I link to C Library functions in windows?
- From: bwaichu@xxxxxxxxx
- How do I link to C Library functions in windows?
- Prev by Date: Re: Accessing USB pendrive from assembly program
- Next by Date: How to determine the total size of the RAM in pure assembly language?
- Previous by thread: Re: How do I link to C Library functions in windows?
- Next by thread: What debugger do I use for win32 programs?
- Index(es):
Relevant Pages
|