A typical PIN code snippet looks like this (taken from the official manual):
// This function is called before every instruction is executed
// and prints the IP
VOID printip(VOID *ip) { fprintf(trace, "%p\n", ip); }
// 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);
}
I just can't figure out how to access the ins object from within printip(VOID *p). The other way round seems easy, i.e. getting the IP from from the ins object:
INS_Address (INS ins)(see here)
I tried passing a INS *ins pointer to printip(VOID *ip, INS *ins) ins via IARG_PTR, &ins but this ended in either casting errors or Segmentation faults.
How can I access the ins object (type INS) from inside an analysis function?
Side note: I got to this problem when trying to call INS_Disassemble (INS ins) for every executed instruction.
INS_Disassemble(ins)into the analysis function to check (manually by looking at it) if the analysis function works as intended. If I place theINS_Disassemble(ins)into the Instrumentation function, the output ofINS_Disassemble(ins)is separated from the output of the analysis function. In other words: I wanted the output of the analysis function be entitled with the instruction to easily check if it is correct. – langlauf.io Apr 12 '16 at 11:02PIN_SafeCopyandINS_Size, then use whatever disassemble tool e.g. Capstone, or even Xed of Intel. – Ta Thanh Dinh Apr 12 '16 at 11:11insobject. – langlauf.io Apr 12 '16 at 11:14