Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 x86-64 上使用 Linux。我需要在用户程序开始执行其代码之前(但在加载器/链接器映射库等之后)插入一个系统调用(本质上需要对操作系统的陷阱)。有没有人建议在不需要二进制修改/重新编译的情况下实现这一目标的最佳方法是什么?
使用 LD_PRELOAD 环境变量在 libc 之前加载自定义库,这将拦截对 __libc_start_main 的调用,_start 似乎使用该调用来开始实际的 main() 函数。
或者使用 ptrace() 像调试器一样附加到进程。