Advertisement
Guest User

min ldd

a guest
Jul 12th, 2012
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <sys/wait.h>
  2. #include <dlfcn.h>
  3. #include <err.h>
  4. #include <fcntl.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8.  
  9. int main(int argc, char *argv[])
  10. {
  11.     char* binary = "/path/to/a/binary";
  12.     int status;
  13.     setenv("LD_TRACE_LOADED_OBJECTS", "1", 1);
  14.  
  15.     switch (fork()) {
  16.     case -1:
  17.         err(1, "fork");
  18.         break;
  19.     default:
  20.         if (wait(&status) <= 0) {
  21.             printf("wait");
  22.         } else if (WIFSIGNALED(status)) {
  23.             fprintf(stderr, "-> %s: signal %d\n",
  24.                     binary, WTERMSIG(status));
  25.         } else if (WIFEXITED(status) && WEXITSTATUS(status)) {
  26.             fprintf(stderr, "->%s: exit status %d\n",
  27.                     binary, WEXITSTATUS(status));
  28.         }
  29.         break;
  30.     case 0:
  31.         char ld_so[] = "/lib64/ld-linux-x86-64.so.2";
  32.         execl(ld_so, ld_so, binary, (char *)NULL);
  33.         warn("--->%s", binary);
  34.     }
  35.  
  36.  
  37.     return 0;
  38. }
Advertisement
RAW Paste Data Copied
Advertisement