flat assembler
Message board for the users of flat assembler.
Index
> Main > How attach c lib to fasm code ? |
Author |
|
Roman 10 Dec 2024, 14:25
I found this (revolution writed)
Code: macro link objfile { virtual at 0 theobj:: file objfile end virtual ;linker code goes here ;what is mean ? I must write realization? ;... } format ... mov eax,0x12345678 invoke DoWhatIWantWhenIWant,eax invoke ExitProcess,0x87654321 link 'MyUberObj.obj' |
|||
10 Dec 2024, 14:25 |
|
revolution 10 Dec 2024, 14:34
Roman wrote: ;what is mean ? I must write realization? |
|||
10 Dec 2024, 14:34 |
|
Roman 10 Dec 2024, 14:36
ok. I compiled this obj file:
Code: format MS COFF extrn '__imp__MessageBoxA@16' as MessageBox:dword section '.text' code readable executable public demo demo: push 0 push _caption push _message push 0 call [MessageBox] ;MessageBox empty value = 0 ret section '.data' data readable writeable _caption db 'Win32 assembly',0 _message db 'Coffee time!',0 When I do link obj file in my main program. How I put in [MessageBox] correct address from my pe gui 4.0 program ? |
|||
10 Dec 2024, 14:36 |
|
revolution 10 Dec 2024, 15:01
If you want to support recursive linking then there are entire books that have been written to explain all the various complications and problems that you might encounter.
For simple leaf non-recursive linking, you can parse the DLL file at assembly time within fasm quite easily. The "real" solution is just to use the normal external linker program, that is its job, that is what it is for. And you make your code linkable instead of executable. Last edited by revolution on 10 Dec 2024, 15:41; edited 1 time in total |
|||
10 Dec 2024, 15:01 |
|
Roman 10 Dec 2024, 15:38
ok.
load can in macro find text '__imp__MessageBoxA@16' ? |
|||
10 Dec 2024, 15:38 |
|
revolution 10 Dec 2024, 15:43
Roman wrote: ok. |
|||
10 Dec 2024, 15:43 |
|
Roman 10 Dec 2024, 15:55
Ok.
How I understood linker do steps: 1)find text '__imp__' 2)load library and GetProcAddress MessageBoxA 3) put address to '__imp__' |
|||
10 Dec 2024, 15:55 |
|
revolution 10 Dec 2024, 15:58
Erm. Are you doing runtime linking, or compile time linking?
I thought you wanted to to static linking at compile time. But now you are asking about runtime linking. |
|||
10 Dec 2024, 15:58 |
|
Roman 10 Dec 2024, 16:05
compile time linking
|
|||
10 Dec 2024, 16:05 |
|
revolution 10 Dec 2024, 16:36
Then you shouldn't be trying to link the system DLLs. Things like MessageBox should be linked at runtime.
|
|||
10 Dec 2024, 16:36 |
|
Roman 10 Dec 2024, 16:45
obj or lib file its compiled code.
In this files not exist text 'call [MessageBox]'. Exist asm opcodes. And I must something put address MessageBox from section import dll in pe gui 4.0 main code, to lib data. This is my problem. |
|||
10 Dec 2024, 16:45 |
|
macomics 10 Dec 2024, 16:56
Then you need to refer to the name of this function, which the linker will provide to it after the import is formed. This name is __imp__MessageBoxA.
Or you can create your own lib file that will export other names for the imported functions from the dll file. |
|||
10 Dec 2024, 16:56 |
|
Roman 10 Dec 2024, 19:57
if I do
Code: macro link objfile { virtual at 0 theobj:: file objfile end virtual ;linker code goes here ;what is mean ? I must write realization? ;... } Start: call fun1 fun1: link 'mscoff.obj' IDA Pro show dd 77h dup(0) in fun1 |
|||
10 Dec 2024, 19:57 |
|
macomics 10 Dec 2024, 20:00
Roman wrote: if I do |
|||
10 Dec 2024, 20:00 |
|
Roman 10 Dec 2024, 21:46
Code: macro link objfile { virtual at 0 theobj:: file objfile end virtual ;linker code goes here ;what is mean ? I must write realization? load q word from theobj:100 store word q at fun1 ;fasm error value out of range } Start: call fun0 invoke ExitProcess, 0 align 4 link 'l.obj' fun0: fun1: dd 0 |
|||
10 Dec 2024, 21:46 |
|
Roman 10 Dec 2024, 22:06
Code: macro link objfile { virtual at 0 theobj:: file objfile end virtual ;linker code goes here ;what is mean ? I must write realization? load q word from theobj:100 ;store q at fun1:0 dw q load q byte from theobj:102 db q load q dword from theobj:103 dd $+q } Start: call fun1 invoke ExitProcess, 0 fun1: link 'l.obj' |
|||
10 Dec 2024, 22:06 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.