执行机器codeS安装在一个可执行文件的结尾 [英] Executing machine codes attached at the end of an executable

查看:338
本文介绍了执行机器codeS安装在一个可执行文件的结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有内部有一个main()函数的目标文件,只需要与CRT链接...对象是一个可执行文件。不幸的是,我只能编译,我不能链接它是一个可执行文件。

I have a object file which has a main() function inside and just needs to be linked with crt... objects to be an executable . Unfortunately I can only compile and I can not link it to be an executable .

所以我决定创建一个C程序(在PC上使用工作GCC和链接),以在本身的一端连接对象(S)和执行codeS附着在运行时(模拟链接的对象)。

so I decided to create a c program ( on a pc with working GCC and linker ) to attach object(s) at the end of itself and execute the codes attached at run time (simulating a linked object ).

我看到DL API,但我do'nt知道如何使用它,因为我说的问题。

I saw DL API but I do'nt know how to use it for the problem I said .

可能某人帮助我知道,我怎么能执行附加在可执行文件的末尾code。

May sb help me to know , how I can executing a code attached at the end of an executable .

推荐答案

避免这样做;这将是一个烂摊子....而且它可能不会可靠地工作,至少如果程序动态链接到 libc6.so (例如由于<一个HREF =htt​​p://en.wikipedia.org/wiki/ASLR相对=nofollow> ASLR )

Avoid doing that; it would be a mess .... And it probably won't reliably work, at least if the program is dynamically linked to the  libc6.so (e.g. because of ASLR)

只要使用共享对象和动态链接库(见动态链接 Wiki页面)。你需要了解的dlopen(3)等。

Just use shared objects and dynamically linked libraries (See dynamic linker wikipage). You need to learn about dlopen(3) etc.

如果你真的坚持,需要几个星期来学习更多:莱文阅读的书在链接器和装载机,请参阅高级Linux编程,看了很多手册页(其中的的execve(2),的的mmap(2),的精灵(5) LD 。所以(8),...)研究内核code为的execve MMAP 的GNU 的libc 并的 MUSL的libc 源$ C ​​$ CS(有关动态链接器的实现细节),在的 x86-64的ABI ABI 为你的目标处理器(它是一个ARM?),了解更多的GNU 的binutils 等,等等等。

If you really insist, take many weeks to learn a lot more: read Levine's book on Linker and Loaders, read Advanced Linux Programming, read many man pages (including execve(2), mmap(2), elf(5), ld.so(8), ...) study the kernel code for execve and mmap, the GNU libc and MUSL libc source codes (for details about implementations of the dynamic linker), the x86-64 ABI or the ABI for your target processor (is it an ARM?), learn more about the GNU binutils etc, etc, etc.

总之,你的寿命太短做这样乱七八糟的事情,除非你已经是一个专家,例如能够实现自己的动态链接。

显然你真正的问题似乎使用 tinycc 在ARM(Android的下我猜测)。然后,我会问他们的邮件列表上(也许还包括一些补丁贡献),或者干脆使用的binutils,使自己的GNU LD的链接脚本,以使其发挥作用。接下来的问题是完全不同的,并完全无关你原来的问题。可能有一些previous试图解决这个问题,根据谷歌搜索。

Apparently your real issue seems to use tinycc on the ARM (under Android I am guessing). I would then ask on their mailing list (perhaps contribute with some patch), or simply use binutils and make your own GNU ld linker script to make it work. Then the question becomes entirely different and completely unrelated to your original question. There might be some previous attempts to solve that, according to Google searches.

这篇关于执行机器codeS安装在一个可执行文件的结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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