flat assembler
Message board for the users of flat assembler.

Index > Linux > Manipulating the ELF header

Author
Thread Post new topic Reply to topic
ronware



Joined: 08 Jan 2004
Posts: 179
Location: Israel
ronware 25 Feb 2005, 16:54
Hi (esp Privalov!)

I am trying to make a set of macros to allow dynamic link entries in the ELF file. What I am attempting (at the moment) is overriding an entry in the ELF header. But I am not having any success.

This code does not put 'JOE!' anywhere in the image, which is not what I expect:

ELFORG = 0x08048000

Code:
format ELF executable at ELFORG
entry main

      virtual at ELFORG+24
        db 'JOE!' ; phdr
  end virtual

     db 'hi there'
main: 
    



I suppose the ELF header gets written last, and so I cannot override any of its entries; this makes doing what I want a bit difficult Sad
Post 25 Feb 2005, 16:54
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 25 Feb 2005, 18:14
Does the word virtual tell you anything? Try the "store" directive.. Wink (I haven't tested it myself, but if there's a way of doing it, that should be the way to go)
Post 25 Feb 2005, 18:14
View user's profile Send private message Visit poster's website Reply with quote
ronware



Joined: 08 Jan 2004
Posts: 179
Location: Israel
ronware 25 Feb 2005, 18:46
Tommy wrote:
Does the word virtual tell you anything? Try the "store" directive.. Wink (I haven't tested it myself, but if there's a way of doing it, that should be the way to go)


I've tried using 'org', I've tried 'virtual' and now I've tried 'store'.

The phrase:

store dword 0x1234 at 24

gives me a message: "error: value out of range".
Sad

Apparently, 'load' can only load in the current section; what I need to be able to do is to modify any part of the file (org does nothing useful here). 'virtual' is only useful at runtime. <arggggh>
Post 25 Feb 2005, 18:46
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger Reply with quote
ronware



Joined: 08 Jan 2004
Posts: 179
Location: Israel
ronware 29 Mar 2005, 05:59
Privalov -

Is there any relatively easy way to accomplish what I want? That is, to add a dynamic imports section to my ELF program?

Thanks!
Post 29 Mar 2005, 05:59
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 31 Mar 2005, 12:31
No, you cannot alter the formatter-generated structures. The only way is to build ELF executable from scratch (with binary output mode), here is the simplest sample of such executable (this way it was done with the very early Linux versions of fasm):
Code:
        program_base = 0x700000

        org     program_base
        use32

        macro   align value { rb (value-1) - ($ + value-1) mod value }

file_header:
        db      0x7F,'ELF',1,1,1
        rb      file_header+0x10-$
        dw      2,3
        dd      1,start
        dd      program_header-file_header,0,0
        dw      program_header-file_header,0x20,1,0,0,0

program_header:
        dd      1,0,program_base,0
        dd      bss-program_base,program_end-program_base,7,0x1000

  msg db 'Hello world!',0xA
  msg_size = $-msg

start:


        mov     eax,4
        mov     ebx,1
        mov     ecx,msg
        mov     edx,msg_size
        int     0x80

        mov     eax,1
        xor     ebx,ebx
        int     0x80

bss:

program_end:    
Post 31 Mar 2005, 12:31
View user's profile Send private message Visit poster's website Reply with quote
ronware



Joined: 08 Jan 2004
Posts: 179
Location: Israel
ronware 31 Mar 2005, 17:20
Privalov wrote:
No, you cannot alter the formatter-generated structures. The only way is to build ELF executable from scratch...


Hi, Privalov -

Thank you, that is what I thought.

I'm trying to "do the right thing" to import "dlopen" and "dlsym" from "libdl.so.2". and I get dlopen ok, but dlsym is not importing for me...

Anyway, I would like to make the request that there be an 'imports' directive for ELF format, something like:

imports 'libdl.so.6', 'dlopen'

Which would simply make 'dlopen' callable fron within the ELF executable. This is something you can do pretty easily as you generate the headers, but it's a real pain to do manually. Plus, it's nice for the end user.

At the moment, I am creating an ELF object and linking with gcc to get the result I want. The problem I have with that is twofold: first, it requires an external tool besides FASM. Second, it doesn't work when I want to generate the ELF file on Windows, since the import libs I need to link with are not there (and my Windows gcc doesn't output ELF!).

Please do consider adding the feature, it will be greatly loved...
All the best,
Ron
Post 31 Mar 2005, 17:20
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 01 Apr 2005, 15:34
I will put it on my TODO list.
Post 01 Apr 2005, 15:34
View user's profile Send private message Visit poster's website Reply with quote
ronware



Joined: 08 Jan 2004
Posts: 179
Location: Israel
ronware 01 Apr 2005, 15:45
Thank you! I'll anxiously look for it.
Post 01 Apr 2005, 15:45
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger Reply with quote
Raedwulf



Joined: 13 Jul 2005
Posts: 375
Location: United Kingdom
Raedwulf 15 Nov 2006, 08:27
Any progress on this?
Post 15 Nov 2006, 08:27
View user's profile Send private message MSN Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 15 Nov 2006, 08:37
No.

EDIT: The creation of dynamic linking structures was finally introduced three years later, with the 1.69.05 release.


Last edited by Tomasz Grysztar on 04 Aug 2017, 14:37; edited 1 time in total
Post 15 Nov 2006, 08:37
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 16 Nov 2006, 02:25
Okay, this may be wrong/unhelpful (I'm very unexperienced in this area), but there does exist a GCC-ELF port for DOS. Octavio uses it to compile a few things (e.g., ZLIB) for his OS.
Post 16 Nov 2006, 02:25
View user's profile Send private message Visit poster's website Reply with quote
Raedwulf



Joined: 13 Jul 2005
Posts: 375
Location: United Kingdom
Raedwulf 16 Nov 2006, 06:27
Nice I'll try it thanks
Post 16 Nov 2006, 06:27
View user's profile Send private message MSN Messenger 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.