选择性调用写包装器
我已经拦截了 write 库函数来重定向写入,但只想对 uae 包装器进行一些写入,而其他(用于写入套接字)应该转到原始 libc 函数。已尝试使用 dlsym 但似乎不起作用。
已使用 LD-PRELOAD 环境变量
希望得到帮助
编辑: 部分代码
int call_execute()
{
.....
static ssize_t (*real_write)(int,const void*,size_t) = NULL;
...
real_write= (size_t(*)(int,const void*,size_t)dlsym(RTLD_NEXT,"write");
...
real_write(sockfd,argcalls[i],strlen(argcalls[i]));
}
I have intercepted the write library function to redirect writes but want only a few writes to uae the wrapper whereas others(used for writing to sockets) should go to the original libc function. Have tried using dlsym but does no seem to work.
have used the LD-PRELOAD environment variable
Would appreciate help
An Edit:
A portion of the code
int call_execute()
{
.....
static ssize_t (*real_write)(int,const void*,size_t) = NULL;
...
real_write= (size_t(*)(int,const void*,size_t)dlsym(RTLD_NEXT,"write");
...
real_write(sockfd,argcalls[i],strlen(argcalls[i]));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
$gcc -W -Wall -shared -o /tmp/libpre.so test.c -ldl
$env LD_PRELOAD=/tmp/libpre.so cat /dev/null
上面应该产生如下输出:
传递 read 32768 字节
$gcc -W -Wall -shared -o /tmp/libpre.so test.c -ldl
$env LD_PRELOAD=/tmp/libpre.so cat /dev/null
Above should produce output like this:
passing read with 32768 bytes
如果 dlsym(RTLD_NEXT, "write") 不返回 libc 函数,您可以显式声明您想要的库,例如
- 但如果您没有在首先在主程序中放置并定义您的写入包装器 - 然后 RTLD_NEXT 应该可以工作。
If
dlsym(RTLD_NEXT, "write")
doesn't return the libc function, you can explicitly state the library you want, e. g.- but easier perhaps it would be if you didn't use LD_PRELOAD in the first place and defined your write wrapper in the main program - then RTLD_NEXT should work.