flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > [solved] Use C with FASM

Author
Thread Post new topic Reply to topic
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 31 May 2018, 15:15
Hello, i have question. Is it possible to link C code for kernel with fasm, and how ? Is it possible to do flat binary with gcc (no specific format)?

Because i found how to do that, but i don't have any success ...
Post 31 May 2018, 15:15
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 31 May 2018, 15:53
You can use the "format elf ..." directive to create a file that can be linked with the standard C linkers.
Code:
; fasm example of using the C library in Unix systems

; compile the source with commands like:
;   fasm libcdemo.asm libcdemo.o
;   gcc libcdemo.o -o libcdemo
;   strip libcdemo

format ELF

include 'ccall.inc'

section '.text' executable

 public main
 extrn printf
 extrn getpid

 main:
        call    getpid
        ccall   printf, msg,eax
        ret

section '.data' writeable

 msg db "Current process ID is %d.",0xA,0    
Post 31 May 2018, 15:53
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 31 May 2018, 16:46
Is it not possible without elf or any format ?

And how you link your program and specify start address point ?

When i use ld, i have error because i have 64 bits platform...
Post 31 May 2018, 16:46
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 31 May 2018, 16:50
For 64 bits I think you need "format ELF64".

You might be able to link other formats (mscoff maybe?), but it depends upon your linker, and it depends upon your C code generating something compatible also.
Post 31 May 2018, 16:50
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 31 May 2018, 19:40
I need ELF64 ? But the output is ELF ?
Post 31 May 2018, 19:40
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 01 Jun 2018, 02:12
You will have to ask your linker to make the raw binary after the linking stage.
Post 01 Jun 2018, 02:12
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 01 Jun 2018, 07:55
And how you do that ?
Post 01 Jun 2018, 07: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 01 Jun 2018, 08:05
That depends upon your linker program. Are you using ld?

I remember that MASM had a separate program called exe2bin for converting PE files to binary.
Post 01 Jun 2018, 08:05
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 276
Fulgurance 01 Jun 2018, 09:07
It's good boy, i have successfully do it ! Just internet don't have many explicit tutorials...

Thanks !
Post 01 Jun 2018, 09:07
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.