我想知道open(2)bash 脚本中进行了哪些调用。
我编写了以下拦截系统调用的程序:
#include <fcntl.h>
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#define DYLD_INTERPOSE(_replacment,_replacee) \
__attribute__((used)) static struct{ const void* replacment; const void* replacee; } _interpose_##_replacee \
__attribute__ ((section ("__DATA,__interpose"))) = { (const void*)(unsigned long)&_replacment, (const void*)(unsigned long)&_replacee };
static
int
my_open(const char *filename, int oflag, mode_t mode)
{
printf("$jason$ open: %s\n", filename);
return open(filename, oflag, mode);
}
DYLD_INTERPOSE(my_open, open)
Run Code Online (Sandbox Code Playgroud)
然后我使用以下命令运行:
clang -dynamiclib libfile.c -o libfile.dylib
export DYLD_INSERT_LIBRARIES=libfile.dylib
touch /tmp/testingtesting
Run Code Online (Sandbox Code Playgroud)
这不起作用。
我用自己编译的程序尝试了一下,效果很好。我用brew编译的程序尝试了一下,效果很好。我阅读了touch.c的源代码。它调用open(2).
然后我禁用了 …