ELF格式操作 [英] ELF format manipulation

查看:145
本文介绍了ELF格式操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,我想将 index 与文件(某种格式)相关联.我想知道我是否可以进行任何ELF操作,并且仍然确保保持一致性,因此该文件在Linux上可以正常工作.这里的想法是创建一种文件格式,该文件格式可以由某个API(自定义)查询以获取索引.

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)是否可以修改ELF标头以存储索引(如上所述).

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

b)如果是,请问该如何处理?

b)if yes, what is the process?

推荐答案

您可以将具有所需数据的新ELF节添加到现有可执行文件中.例如

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.    

然后您可以使用libelf找出从何处读取此数据.

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

这篇关于ELF格式操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆