I am currently using Pin and I want to get the value that a store instruction is writing. The problem that I am facing is that even though I can insert a callback before the write instruction (using IPOINT_BEFORE) and get a value from the memory address that will be written, it obviously isn't the correct one since the writing hasn't happened yet. I cannot use IARG_MEMORYWRITE_EA and IPOINT_AFTER as arguments together.
I have managed to make it work when there is a load instruction, since the value is already in memory. The code for that is below.
void Read(THREADID tid, ADDRINT addr, ADDRINT inst){
PIN_GetLock(&globalLock, 1);
ADDRINT * addr_ptr = (ADDRINT*)addr;
ADDRINT value;
PIN_SafeCopy(&value, addr_ptr, sizeof(ADDRINT));
fprintf(stderr,"Read: ADDR, VAL: %lx, %lu\n", addr, value);
.
.
.
PIN_ReleaseLock(&globalLock);
}
VOID instrumentTrace(TRACE trace, VOID *v)
{
for (BBL bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl = BBL_Next(bbl)) {
for (INS ins = BBL_InsHead(bbl); INS_Valid(ins); ins = INS_Next(ins)) {
if(INS_IsMemoryRead(ins)) {
INS_InsertCall(ins,
IPOINT_BEFORE,
(AFUNPTR)Read,
IARG_THREAD_ID,
IARG_MEMORYREAD_EA,
IARG_INST_PTR,
IARG_END);
} else if(INS_IsMemoryWrite(ins)) {
INS_InsertCall(ins,
IPOINT_BEFORE,
(AFUNPTR)Write,
IARG_THREAD_ID,//thread id
IARG_MEMORYWRITE_EA,//address being accessed
IARG_INST_PTR,//instruction address of write
IARG_END);
}
}
}
}
How can I grab the value that a store instruction writes to memory?