hdarwin

rtnWTF

Dec 4th, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. #include "pin.H"
  2. #include <fstream>
  3.  
  4. static ofstream o;
  5.  
  6. VOID fun_image(IMG img, VOID *v)
  7. {
  8.     UINT32 start = IMG_LoadOffset(img);
  9.     UINT32 end = start + IMG_SizeMapped(img);
  10.     o << IMG_Name(img) << " : " << hex << start << "-" << hex << end << "\n";
  11.     if (!IMG_Name(img).compare("/root/git/study/pin/flow/test")) {
  12.         for (SEC sec = IMG_SecHead(img); SEC_Valid(sec); sec = SEC_Next(sec)) {
  13.             if (!SEC_Name(sec).compare(".text")) {
  14.                 for (RTN rtn = SEC_RtnHead(sec); RTN_Valid(rtn); rtn = RTN_Next(rtn)) {
  15.                     o << "\t" << RTN_Name(rtn) << " : " << RTN_Address(rtn) << "\n";
  16.                 }
  17.             }
  18.         }
  19.     }
  20. }
  21.  
  22. VOID close(INT32 code, VOID *v)
  23. {
  24.     o.close();
  25. }
  26.  
  27. int main(int argc, char *argv[])
  28. {
  29.     PIN_Init(argc,argv);
  30.     PIN_InitSymbols();
  31.     IMG_AddInstrumentFunction(fun_image, 0);
  32.     PIN_AddFiniFunction(close, 0);
  33.     o.open("out.txt");
  34.     PIN_StartProgram();
  35.     return 0;
  36. }
  37.  
  38. /*
  39. root@ubuntu:~/git/study/pin/flow# cat test.c
  40. #include <stdio.h>
  41.  
  42. void call4()
  43. {
  44.     puts("I'm call4");
  45. }
  46.  
  47. void call3()
  48. {
  49.     puts("I'm call3");
  50. }
  51.  
  52. void call2(int argc)
  53. {
  54.     if (argc == 2) call3();
  55.     else call4();
  56. }
  57. void call1(int argc)
  58. {
  59.     call2(argc);
  60. }
  61. int main(int argc, char *argv[])
  62. {
  63.     call1(argc);
  64. }
  65. root@ubuntu:~/git/study/pin/flow# gcc -o test test.c
  66. root@ubuntu:~/git/study/pin/flow# pin -t flow.so -- ./test
  67. I'm call4
  68. root@ubuntu:~/git/study/pin/flow# cat out.txt
  69. /root/git/study/pin/flow/test : 0-21b6
  70.     _start : 400440
  71.     deregister_tm_clones : 400470
  72.     register_tm_clones : 4004a0
  73.     __do_global_dtors_aux : 4004e0
  74.     frame_dummy : 400500
  75.     call4 : 40052d
  76.     call3 : 40053d
  77.     call2 : 40054d
  78.     call1 : 400576
  79.     main : 40058d
  80.     __libc_csu_init : 4005b0
  81.     __libc_csu_fini : 400620
  82. /lib64/ld-linux-x86-64.so.2 : 36dde000-36e02680
  83. /lib/x86_64-linux-gnu/libc.so.6 : 23a6c000-23c2e720
  84. */
Advertisement
Add Comment
Please, Sign In to add comment