【问题标题】:playing around with LD_LIBRARY_PATH玩弄 LD_LIBRARY_PATH
【发布时间】: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


【解决方案1】:

您应该在 LD_PRELOAD 环境变量中命名库,而不是目录。

export LD_PRELOAD=/path/to/libmystuff.so.1.0.1

【讨论】:

  • LD_PRELOAD 和 LD_LIBRARY_PATH 可能会混淆,如果它指定的目录包含可执行文件使用的库的修改版本,则同样会改变行为。
猜你喜欢
  • 1970-01-01
  • 2013-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多