ELF format manipulation

坚强是说给别人听的谎言 提交于 2019-12-09 06:46:42

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/7601344/elf-format-manipulation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!