0

在我的程序中,我想在同一进程中拦截用户级别的每个系统调用(我不想使用单独的进程,例如ptrace或工具strace)。我也不想使用 LD_PRELOAD。我怎样才能做到这一点?

4

1 回答 1

4

Use C macros. It works like this:

  1. Create a header file which defines a macro for each system call that you want to track. Example: open()

    #define open(path,flags,mode)  mySpecialOpen(path,flags,mode)
    
  2. Create a library which contains the mySpecial*() functions which forward the calls to the syscall. Compile the library without the header file.

  3. Compile your code (and all libraries that you use) with the header file above. Link with the library.

于 2012-05-09T12:11:21.070 回答