flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Tomasz Grysztar 09 Feb 2009, 11:01
The standard import macro create labels to the pointers, thus you need to call it this way:
Code: call [LoadIconA] |
|||
![]() |
|
blackoil 09 Feb 2009, 14:50
ok thanks
If I want to use direct addressing "call LoadIconA", how to modify it? |
|||
![]() |
|
revolution 09 Feb 2009, 14:58
blackoil wrote: If I want to use direct addressing "call LoadIconA", how to modify it? Code: invoke LoadIconA |
|||
![]() |
|
blackoil 09 Feb 2009, 15:16
the above code is compiler output, I need to use call instruction, what .inc file should I use for this?
|
|||
![]() |
|
vid 09 Feb 2009, 15:52
You program cannot call API directly, because it only has pointer to it in Import Table. You don't know address of function at compilation time.
Usual solution is to create "thunks" (or however it is called), something like: Code: ExitProcess: jmp [__imp__ExitProcess] MessageBoxA: jmp [__imp__MessageBoxA] where "__imp__ExitProcess" and "__imp__MessageBoxA" are pointers from the Import Table. I don't think there is a FASM include file, which creates those "thunks" (or however that "" is called) for you. What you can do: 1. Modify compiler if you can, to output "call [XY]" or "invoke XY" instead of "call XY" 2. Modify compiler to output code for OBJ file ("format MS COFF"), not directly to exe. In that case you can declare "extern XY", call it directly, and link with .LIB files that are part of every compiler kit. Those .LIB files contain that "ExitProcess: jmp [__imp__ExitProcess]" I mentioned. 3. Modify compiler to create those thunks for every imported function. |
|||
![]() |
|
Tomasz Grysztar 09 Feb 2009, 16:47
The other option is to use the import macros that would make those "jmp" functions for you. I already once posted such macros here, check out http://board.flatassembler.net/topic.php?p=40935#40935
|
|||
![]() |
|
vid 10 Feb 2009, 00:26
vid wrote: I don't think there is a FASM include file, which creates those "thunks" (or however that "" is called) for you. Tomasz Grysztar wrote: The other option is to use the import macros that would make those "jmp" functions for you. I already once posted such macros here So, I was wrong ![]() |
|||
![]() |
|
blackoil 10 Feb 2009, 00:50
I tried to rename them to
call [LoadIconA] invoke LoadIconA Both don't work. Addresses are still not correct. |
|||
![]() |
|
revolution 10 Feb 2009, 02:24
If you really need a direct call (what for?) then you need to make a runtime procedure to relink all the calls to OS APIs. You can't do it by just manipulating the imports section and thunks.
|
|||
![]() |
|
blackoil 10 Feb 2009, 05:11
making a runtime procedure is out of my action.
I tried NASM+ALINK with a WIN32.LIB ( 706,560 bytes ). It works. |
|||
![]() |
|
vid 10 Feb 2009, 12:09
Quote: I tried to rename them to That's because you didn't flag import data as such. You must either put them into separate section flagged as "import", or into "data import" blocks. Just look at the existing. examples. (Import data in your example are three lines with "library" macro and two "include"s) |
|||
![]() |
|
blackoil 10 Feb 2009, 13:14
It works now.
Quote:
|
|||
![]() |
|
revolution 10 Feb 2009, 13:33
You have used invoke. So how about using it to make the code more human friendly
![]() Code: invoke DefWindowProcA,[ebp+0x14],[ebp+0x18],[ebp+0x1C],[ebp+0x20] |
|||
![]() |
|
blackoil 10 Feb 2009, 13:52
well, I want my compiler outputs assembly code in general syntax.
so I just add: if ( calling_convention == stdcall ) emit_invoke(); else emit_call(); if ( calling_convention == stdcall ) do_nothing(); else clear_stack(); |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.