Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pin.H"
- #include <fstream>
- static ofstream o;
- VOID fun_image(IMG img, VOID *v)
- {
- UINT32 start = IMG_LoadOffset(img);
- UINT32 end = start + IMG_SizeMapped(img);
- o << IMG_Name(img) << " : " << hex << start << "-" << hex << end << "\n";
- if (!IMG_Name(img).compare("/root/git/study/pin/flow/test")) {
- for (SEC sec = IMG_SecHead(img); SEC_Valid(sec); sec = SEC_Next(sec)) {
- if (!SEC_Name(sec).compare(".text")) {
- for (RTN rtn = SEC_RtnHead(sec); RTN_Valid(rtn); rtn = RTN_Next(rtn)) {
- o << "\t" << RTN_Name(rtn) << " : " << RTN_Address(rtn) << "\n";
- }
- }
- }
- }
- }
- VOID close(INT32 code, VOID *v)
- {
- o.close();
- }
- int main(int argc, char *argv[])
- {
- PIN_Init(argc,argv);
- PIN_InitSymbols();
- IMG_AddInstrumentFunction(fun_image, 0);
- PIN_AddFiniFunction(close, 0);
- o.open("out.txt");
- PIN_StartProgram();
- return 0;
- }
- /*
- root@ubuntu:~/git/study/pin/flow# cat test.c
- #include <stdio.h>
- void call4()
- {
- puts("I'm call4");
- }
- void call3()
- {
- puts("I'm call3");
- }
- void call2(int argc)
- {
- if (argc == 2) call3();
- else call4();
- }
- void call1(int argc)
- {
- call2(argc);
- }
- int main(int argc, char *argv[])
- {
- call1(argc);
- }
- root@ubuntu:~/git/study/pin/flow# gcc -o test test.c
- root@ubuntu:~/git/study/pin/flow# pin -t flow.so -- ./test
- I'm call4
- root@ubuntu:~/git/study/pin/flow# cat out.txt
- /root/git/study/pin/flow/test : 0-21b6
- _start : 400440
- deregister_tm_clones : 400470
- register_tm_clones : 4004a0
- __do_global_dtors_aux : 4004e0
- frame_dummy : 400500
- call4 : 40052d
- call3 : 40053d
- call2 : 40054d
- call1 : 400576
- main : 40058d
- __libc_csu_init : 4005b0
- __libc_csu_fini : 400620
- /lib64/ld-linux-x86-64.so.2 : 36dde000-36e02680
- /lib/x86_64-linux-gnu/libc.so.6 : 23a6c000-23c2e720
- */
Advertisement
Add Comment
Please, Sign In to add comment