我在我的一个项目中篡改了glibc的printf()并遇到了一些问题。你能提供一些线索吗?我关心的一个问题是为什么malloc/free的相同解决方案完美无缺!使用LD_PRELOAD方法注入到printf中的问题
作为附件,“PrintfHank.c”包含我自己的printf()解决方案,它将在标准库之前预先加载;和“main.c”只是使用printf()输出一个句子。编辑两个文件后,我发出以下命令:
- 编译main.c中 的gcc -o -Wall主要的main.c
- 创建自己的库 的gcc -Wall -shared -fPIC -o PrintfHank.so PrintfHank.c -ldl
- 测试新图书馆 LD_PRELOAD =” $ mypath中/ PrintfHank.so” $ mypath中/主
但是我在控制台中收到了“hello world”而不是“我自己的printf”。当骇客malloc /免费功能,没关系。
我以“root”身份登录系统,并使用2.6.23.1-42.fc8-i686。任何意见将高度赞赏!
的main.c
#include <stdio.h>
int main(void)
{
printf("hello world\n");
return 0;
}
PrintfHank.c
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdio.h>
#include <dlfcn.h>
static int (*orig_printf)(const char *format, ...) = NULL;
int printf(const char *format, ...)
{
if (orig_printf == NULL)
{
orig_printf = (int (*)(const char *format, ...))dlsym(RTLD_NEXT, "printf");
}
// TODO: print desired message from caller.
return orig_printf("within my own printf\n");
}
有没有办法从改变函数printf()来放关闭海湾合作委员会()? – bawejakunal 2017-04-10 01:59:12