【发布时间】:2012-04-28 01:29:34
【问题描述】:
我阅读了this article recently,并尝试通过执行以下操作来覆盖 libc printf 函数:-
- 创建一个使用 printf 打印
this is a test(printer.c) 的可执行文件 - 创建一个带有自定义puts的c文件以打印
muhahaha, this is a test(custom.c) - 创建对象文件
gcc -fPIC -g -c -Wall custom.c - 创建一个so文件
gcc -shared -Wl,-soname,libmystuff.so.1 -o libmystuff.so.1.0.1 custom.o - 我将包含 so 文件的目录添加到 LD_PRELOAD 环境变量中。
export LD_PRELOAD=$(pwd) - 尝试运行打印机
我想muhahaha, this is a test 会被打印出来,但似乎我做错了什么。我有什么概念错了吗?还是我只是做错了什么?
[编辑]
涉及的代码sn-ps有:-
// printer.c
int main() {
printf("this is a test");
return 0;
}
// custom.c
void printf(char *t) {
puts("muhahaha, this is a test");
}
【问题讨论】:
-
如果没有看到您的代码,我们如何猜测? (一般评论。)
-
抱歉,我马上修改。
标签: linux gcc ld ld-preload