flat assembler
Message board for the users of flat assembler.

Index > Main > How attach c lib to fasm code ?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 10 Dec 2024, 14:04
Havok physic using many libs:

hkBase.lib ,hkCompat.lib

hkGeometryUtilities.lib, hkInternal.lib

hkSceneData.lib , hkSerialize.lib

hkVisualize.lib , hkpConstraintSolver.lib

hkpCollide.lib ,hkpDynamics.lib

hkpInternal.lib, hkpUtilities.lib

hkpVehicle.lib , hkcdCollide.lib

hkcdInternal.lib

How I understood lib its something like mscoff format.
How using or attaching this files in fasm code ?
Post 10 Dec 2024, 14:04
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
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'    
Post 10 Dec 2024, 14:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 10 Dec 2024, 14:34
Roman wrote:
;what is mean ? I must write realization?
Yes. You write some while/end while if/else/end if to do the linking.
Post 10 Dec 2024, 14:34
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
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 ?
Post 10 Dec 2024, 14:36
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
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
Post 10 Dec 2024, 15:01
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 10 Dec 2024, 15:38
ok.
load can in macro find text '__imp__MessageBoxA@16' ?
Post 10 Dec 2024, 15:38
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 10 Dec 2024, 15:43
Roman wrote:
ok.
load can in macro find text '__imp__MessageBoxA@16' ?
Do you want to do fully recursive linking? Because that is what you are suggesting with this question. I would recommend against it unless you want to spend a lot of time on it.
Post 10 Dec 2024, 15:43
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
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__'
Post 10 Dec 2024, 15:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
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. Question
Post 10 Dec 2024, 15:58
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 10 Dec 2024, 16:05
compile time linking
Post 10 Dec 2024, 16:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
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.
Post 10 Dec 2024, 16:36
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
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.
Post 10 Dec 2024, 16:45
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1041
Location: Russia
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.
Post 10 Dec 2024, 16:56
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
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
Post 10 Dec 2024, 19:57
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1041
Location: Russia
macomics 10 Dec 2024, 20:00
Roman wrote:
if I do
Either this or make source files on fasm with extern for existing libs. Such files have already been created for dll, but they are not available for lib.
Post 10 Dec 2024, 20:00
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
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     
    
Post 10 Dec 2024, 21:46
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1847
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'   
    
Post 10 Dec 2024, 22:06
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.