Skip to content

Instantly share code, notes, and snippets.

@sudhackar sudhackar/rese.cpp
Created Jan 6, 2019

Embed
What would you like to do?
#include "pin.H"
#include <iostream>
#include <map>
typedef long long LL;
typedef pair<int, int> pii;
#define forup(i, a, b) for (int i = (a); i < (b); ++i)
#define fordn(i, a, b) for (int i = (a); i > (b); --i)
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
map<string, vector<pair<UINT64, UINT64>>> RtnToRead;
VOID RecordMemRead(ADDRINT address, UINT64 memOp, string rname) {
RtnToRead[rname].pb(mp(address, memOp));
}
VOID Routine(RTN rtn, VOID *v) {
RTN_Open(rtn);
string name = RTN_Name(rtn);
for (INS ins = RTN_InsHead(rtn); INS_Valid(ins); ins = INS_Next(ins)) {
UINT32 memOperands = INS_MemoryOperandCount(ins);
for (UINT32 memOp = 0; memOp < memOperands; memOp++) {
if (INS_MemoryOperandIsRead(ins, memOp)) {
INS_InsertPredicatedCall(ins, IPOINT_BEFORE,
(AFUNPTR)RecordMemRead, IARG_INST_PTR,
IARG_MEMORYOP_EA, memOp, IARG_PTR,
new string(name), IARG_END);
}
}
}
RTN_Close(rtn);
}
VOID Fini(INT32 code, VOID *v) {
for (auto &rtn : RtnToRead) {
cout << rtn.fs << " :" << endl;
for (auto &e : rtn.second) {
cout << "\t" << hex << e.fs << " : " << e.sc << endl;
}
}
}
INT32 Usage() {
cerr << "This Pintool prints the addresses being read" << endl;
cerr << endl << KNOB_BASE::StringKnobSummary() << endl;
return -1;
}
int main(int argc, char *argv[]) {
PIN_InitSymbols();
if (PIN_Init(argc, argv))
return Usage();
RTN_AddInstrumentFunction(Routine, 0);
PIN_AddFiniFunction(Fini, 0);
PIN_StartProgram();
return 0;
}
@dilmailid

This comment has been minimized.

Copy link

commented Jan 7, 2019

VOID Fini(INT32 code, VOID *v) {
for (auto &rtn : RtnToRead) {
cout << rtn.fs << " :" << endl;
for (auto &e : rtn.second) {
cout << "\t" << hex << e.fs << " : " << e.sc << endl; I am getting lot of errors in this..when i "make" it .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.