小编Jul*_*enz的帖子

拦截对GNU tar的openat()系统调用

我正在尝试openat()使用我可以通过加载的自定义共享库拦截Linux上的系统调用LD_PRELOAD.一个例子intercept-openat.c有这样的内容:

#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <dlfcn.h>

int (*_original_openat)(int dirfd, const char *pathname, int flags, mode_t mode);

void init(void) __attribute__((constructor));
int openat(int dirfd, const char *pathname, int flags, mode_t mode);

void init(void)
{
        _original_openat = (int (*)(int, const char *, int, mode_t))
                dlsym(RTLD_NEXT, "openat");
}

int openat(int dirfd, const char *pathname, int flags, mode_t mode)
{
        fprintf(stderr, "intercepting openat()...\n");
        return _original_openat(dirfd, pathname, flags, mode);
}
Run Code Online (Sandbox Code Playgroud)

我通过编译它gcc -fPIC …

gcc libc system-calls intercept ld-preload

5
推荐指数
1
解决办法
2082
查看次数

标签 统计

gcc ×1

intercept ×1

ld-preload ×1

libc ×1

system-calls ×1