无法使用 dlsym 获取统计信息 [英] Unable to get stat with dlsym
问题描述
我正在尝试为 stat
/lstat
/fstat
编写一个钩子,但我似乎无法从dlsym
.我正在使用以下代码获取原始指针.
orig_stat = dlsym(RTLD_NEXT, "stat");orig_lstat = dlsym(RTLD_NEXT, "lstat");orig_fstat = dlsym(RTLD_NEXT, "fstat");
然而,所有三个变量都设置为 null
并且调用 dlerror
也会返回 null
.
我正在创建共享对象:
clang fakestat.c -shared -fPIC -ldl -o fakestat.so
并通过运行带有 LD_PRELOAD=fakestat.so ./test
stat
系列函数实际上是 glibc 中内部函数的包装器.您可以在调用任何标准 [lf]stat
调用的二进制文件上查看 objdump
的输出,您将看到二进制文件中这些函数的实际符号.所以你必须挂钩这些功能.以下是您要挂钩/dlsym
的函数:
__xstat
&__xstat64
用于 stat
.
__lxstat
&__lxstat64
用于 lstat
.
__fxstat
&__fxstat64
用于 fstat
.
I'm trying to write a hook for stat
/lstat
/fstat
but I can't seem to get the original version from dlsym
. I'm using the following code to obtain the original pointers.
orig_stat = dlsym(RTLD_NEXT, "stat");
orig_lstat = dlsym(RTLD_NEXT, "lstat");
orig_fstat = dlsym(RTLD_NEXT, "fstat");
However, all three variables are set to null
and calling dlerror
also returns null
.
I'm creating the shared object with:
clang fakestat.c -shared -fPIC -ldl -o fakestat.so
and using my library by running a test program with LD_PRELOAD=fakestat.so ./test
The stat
family functions are actually wrappers to internal functions in glibc. You can look at the output of objdump
on your binary that calls any of the standard [lf]stat
calls and you'll see the actual symbols in the binary for these functions. So you'll have to hook those functions. The following are the functions you want to hook/dlsym
on:
__xstat
& __xstat64
for stat
.
__lxstat
& __lxstat64
for lstat
.
__fxstat
& __fxstat64
for fstat
.
The 64
suffixed functions are for LFS support. See the feature test macros.
这篇关于无法使用 dlsym 获取统计信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!