#include <stdio.h> #include "pin.H" FILE * trace; // This function is called before every instruction is executed // and prints the IP VOID printip(VOID *ip) { fprintf(trace, "%p ", ip); } VOID printdisassembly(string *s) { fprintf(trace, "%s\n", s); } // Pin calls this function every time a new instruction is encountered VOID Instruction(INS ins, VOID *v) { // Insert a call to printip before every instruction, and pass it the IP INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)printip, IARG_INST_PTR, IARG_END); INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)printdisassembly, IARG_PTR, new string(INS_Disassemble(ins)), IARG_END); } // This function is called when the application exits VOID Fini(INT32 code, VOID *v) { fprintf(trace, "#eof\n"); fclose(trace); } /* ===================================================================== */ /* Print Help Message */ /* ===================================================================== */ INT32 Usage() { PIN_ERROR("This Pintool prints the IPs of every instruction executed\n" + KNOB_BASE::StringKnobSummary() + "\n"); return -1; } /* ===================================================================== */ /* Main */ /* ===================================================================== */ int main(int argc, char * argv[]) { trace = fopen("itrace.out", "w"); printf("Hello\n"); // Initialize pin if (PIN_Init(argc, argv)) return Usage(); // Register Instruction to be called to instrument instructions INS_AddInstrumentFunction(Instruction, 0); // Register Fini to be called when the application exits PIN_AddFiniFunction(Fini, 0); // Start the program, never returns PIN_StartProgram(); return 0; }
instruction을 disassemble 하는 코드!
기존의 Instruction Address Trace에서 printdisassembly 추가해주었다.
'pintool' 카테고리의 다른 글
helloworld출력 프로그램에서 출력하는 문자열 바꾸기 (0) | 2018.10.15 |
---|---|
Find executable img, section, code (0) | 2018.10.12 |
Managed platforms support2 (0) | 2018.10.02 |
Managed platforms support1 (0) | 2018.10.02 |
Instrumenting Before and After Forks (0) | 2018.10.02 |