-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstruction_trace_and_count.cpp
More file actions
59 lines (41 loc) · 1.02 KB
/
Copy pathInstruction_trace_and_count.cpp
File metadata and controls
59 lines (41 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <fstream>
#include <stdio.h>
#include "pin.H"
std::map <ADDRINT, std::string> instructions;
static UINT64 ins_count = 0;
std::ofstream TraceFile;
std::ofstream InsCountFile;
VOID instruction_count()
{
ins_count++;
}
void Instruction_trace(INS ins, VOID *v)
{
ADDRINT insaddr=INS_Address(ins);
INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)instruction_count, IARG_END);
std::string disass(INS_Disassemble(ins));
TraceFile<<insaddr<<" "<<disass<<endl;
}
VOID Fini(INT32 code, VOID *v)
{
InsCountFile<< "Instruction Count " << ins_count << endl;
TraceFile.close();
InsCountFile.close();
}
INT32 Usage()
{
return -1;
}
int main(int argc, char * argv[])
{
TraceFile.open("ins_trace.out");
TraceFile<<hex;
TraceFile.setf(ios::showbase);
InsCountFile.open("ins_count.out");
if (PIN_Init(argc, argv)) return Usage();
INS_AddInstrumentFunction(Instruction_trace, 0);
PIN_AddFiniFunction(Fini, 0);
PIN_StartProgram();
return 0;
}