5

I have a requirement where I want to associate an index with a file(in a certain format). I was wondering if I can do any ELF manipulation and still ensure that, consistency is maintained so, the file works fine on linux. The idea here is to create a file format which can be queried by a certain API[self-defined] to get me the index.

a)is it possible to modify the ELF header to store the index(mentioned above).

b)if yes, what is the process?

Umashankar Das
  • 601
  • 4
  • 12
  • I think you misunderstand: ELF is a file format for an executable file. Unless one of these two files is an executable file, you're asking the wrong thing. – Dark Falcon Sep 29 '11 at 17:55
  • You are being very vague. Can you clarify what you want to index / info you want to keep in the index? Tinkering with ELF is of course possible, but the more info you give the more help you're likely to get. – Michael Foukarakis Sep 29 '11 at 17:55
  • Are you allowed to recompile the ELF file? Or must you use the existing one? – rodrigo Sep 29 '11 at 17:57
  • Have you tried the readelf program? Maybe it shows already what you want. – ott-- Sep 29 '11 at 18:06

1 Answers1

9

You can add a new ELF section with whatever data you want to an existing executable. e.g.

$ echo 42 > /tmp/index
$ objcopy --add-section .my_index=/tmp/index /bin/ls myls
$ objdump -s myls | tail
.
.
. 

Contents of section .my_index:
 0000 34320a                               42.    

You can then figure out where to read this data from using libelf.

sigjuice
  • 28,661
  • 12
  • 68
  • 93