Linux 用户空间 ELF 加载器
我需要做一件相当不寻常的事情:手动执行 elf 可执行文件。即,将所有部分加载到正确的位置,查询 main() 并调用它(然后进行清理)。可执行文件将被静态链接,因此不需要链接库。我还控制基地址,所以不用担心可能的冲突。
那么,有没有相关的库呢?
我找到了 OSKit 和它的 liboskit_exec,但项目似乎自 2002 年以来就已经死了。
我可以接受部分项目(当然,尊重许可证)并根据我的需要定制它们,但因为我在 Linux 上是个菜鸟世界,我什至不知道在哪里可以找到这些零件! :)
PS。我需要 ARM 平台的那个。
UPD 嗯,加载 elf 的问题似乎需要一些很好的知识(叹气),所以我要阅读一些规格和手册。我想我会坚持使用 bionic/linker 和 libelfsh。谢谢你们!
调查结果总结:
- libelf:http://directory.fsf.org/project /libelf/
- elfsh 和 libelfsh (现在是 eresi 的一部分): http://www.eresi-project.org/
- elfio (另一个 elf 库):http://sourceforge.net/projects/elfio/
- OSKit 和 liboskit_exec(已过时):http://www.cs.utah.edu/flux/oskit/
- bionic/linker: https://android.googlesource.com/platform/bionic
I need to do a rather unusual thing: manually execute an elf executable. I.e. load all sections into right places, query main() and call it (and cleanup then). Executable will be statically linked, so there will be no need to link libraries. I also control base address, so no worries about possible conflicts.
So, is there are any libraries for that?
I found OSKit and its liboskit_exec, but project seems to be dead since 2002.
I'm OK with taking parts of projects (respecting licenses, of course) and tailoring them to my need, but as I'm quite a noob in the linux world, I dont even know where to find those parts! :)
PS. I need that for ARM platform.
UPD Well, the matter of loading elfs seems to require some good knowledge about it (sigh), so I'm out to read some specs and manuals. And I think I will stick to bionic/linker and libelfsh. Thanks guys!
Summarized findings:
- libelf: http://directory.fsf.org/project/libelf/
- elfsh and libelfsh (are now part of eresi): http://www.eresi-project.org/
- elfio (another elf library): http://sourceforge.net/projects/elfio/
- OSKit and liboskit_exec (outdated): http://www.cs.utah.edu/flux/oskit/
- bionic/linker: https://android.googlesource.com/platform/bionic
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
快速
apt-cache 搜索
会建议libelf1
、libelfg0
和/或libelfsh0
。我认为 elfsh 程序(在同名包中)可能是如何使用 libelfsh0 的一个有趣的实际示例。我自己没有尝试过,但我希望它们可能会有所帮助。祝你好运 :-)
A quick
apt-cache search
suggestslibelf1
,libelfg0
and/orlibelfsh0
. I think theelfsh
program (in the namesake package) might be an interesting practical example of how to uselibelfsh0
.I haven't tried any myself, but I hope they might be helpful. Good luck :-)
Google 的 Android 在其“仿生”libc 实现中具有完全重新实现的 ELF 加载程序。它相当干净,如果你正在寻找简单的东西,可能是比 gilbc 更好的来源。
Google's Android, in it's "bionic" libc implementation, has a completely reimplemented ELF loader. It's reasonably clean, and probably a better source than gilbc if you're looking for something simple.
查看 libelf 来读取可执行格式。我想你会遇到麻烦的。
听起来,既然您不需要任何库,为什么不直接 mmap 您的可执行文件,设置有关各种内存区域的数据并 jmp/b 呢?
我不知道 ARM 是否有 NX 位等效项,但值得检查。
Take a look at libelf for reading the executable format. You are going to have trouble with this I think.
Sounds like, as you don't need libraries for anything, why not just mmap your executable, set data about various memory areas and jmp/b in?
I don't know if ARM has an NX-bit equivalent, but worth checking.
该工具包含一个 ELF 加载程序:http://bitwagon.com/rtldi/rtldi.html
我在另一个项目中将 rtldi 的代码重新用于 ELF chainloader。代码在这里:
http://svn.gna.org/viewcvs/plash/trunk/chroot-jail/elf-chainloader/?rev=877
这里有一些背景:http://plash.beasts.org/wiki/Story16
。 (显然我必须断开这些链接,因为 stackoverflow 不允许我发布 >1 个链接!)This tool contains an ELF loader: http://bitwagon.com/rtldi/rtldi.html
I reused the code from rtldi for an ELF chainloader in another project. The code is here:
http://svn.gna.org/viewcvs/plash/trunk/chroot-jail/elf-chainloader/?rev=877
and there is some background here:http://plash.beasts.org/wiki/Story16
. (Apparently I have to break these links because stackoverflow won't let me post >1 link!)