修改elf文件

发布于 2024-07-18 05:55:31 字数 229 浏览 6 评论 0原文

我想向 elf 文件添加一个新标志。 该标志应该可用 到进程描述符中的内核。 我的第一个想法是使用 libelf,但不幸的是 Ubuntu 上似乎有一个错误。 Elfedit 可能是一个不错的工具,但我还没有找到适用于 Linux 的版本,特别是 Ubuntu。

所以,我想知道是否有人可以向我建议是否还有其他有用的工具 向 elf 文件添加自定义标志?

非常感谢您的帮助!

I would like to add a new flag to an elf file. This flag should then be available
to the kernel in the process descriptor. My first idea was to use libelf, but unfortunately
there seems to be a bug with it on Ubuntu. Elfedit would have probably been a nice tool but I have not found a version for Linux, in particular Ubuntu.

So, I am wondering if anyone can suggest to me if there is any other useful tool out there
to add a custom flag to an elf file?

Many thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

俏︾媚 2024-07-25 05:55:31

能够修改内核以利用新标志的人可能不会问如何将标志添加到 ELF 库。

那么,您打算如何让内核使用这个新标志呢? 国旗的目的是什么?

既然你要添加到标准 libelf,你不能修复 Ubuntu 的错误并让他们知道你已经这样做了(让他们可以使用修复程序 - 尽管他们可能需要将其转发到链上) 。

People who are able to modify the kernel to take advantage of the new flag probably wouldn't be asking how to add the flag to the ELF libraries.

So, how do you plan to have the kernel use this new flag? What is the purpose of the flag?

Since you are adding to the standard libelf, can't you fix the bug for Ubuntu and let them know that you've done so (make the fix available to them - though they'll probably need to relay it back up the chain).

作妖 2024-07-25 05:55:31

请查看ELFIO 库。 它包含 WriteObj 和 Writer 示例。 通过使用该库,您将能够创建和/或修改 ELF 二进制文件。

Please look at ELFIO library. It contains WriteObj and Writer examples. By using the library, you will be able to create and/or modify ELF binary files.

内心旳酸楚 2024-07-25 05:55:31

(虽然是老问题,但仅供参考,我正在根据自己的经验编写答案)

我建议读取内存结构中的 elf 文件,更改标志并使用内存结构加载进程内存。 与错误修正相比,此方法需要更少的精力。 首先,检查文件 elf.c 中的 elf、程序头、节头结构。 您可以读取结构中的文件头,该结构应该具有 elf、program、section 三个结构成员。 开始从 elf 标头读取您的结构。 然后根据 elf header 中给定的偏移量读取程序头(对于所有程序头迭代)。 以同样的方式,您可以通过节标题阅读所有节。
在您自己的结构中封装 3 个标头结构还使您有机会在其他结构成员中拥有额外所需的数据。

(although old question but for reference I am writing answer based on my own experience)

I suggest to read elf file in memory struct, make changes to flags and load process memory with your in-memory struct. This method will need less efford as compare to bug correction. To start, check file elf.c for elf, program header, section headers struct. you can read file header in your struct which should have three struct members for elf, program, section. start read in your struct from elf header. then read program header on offset given in elf header (iteratively for all program headers). In same way you can read all sections through section headers.
encapsulating 3 headers struct in your own struct also give you oppertunity to have extra needed data in your other struct member.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文