forked from m000/dtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dtracker_debug.cpp
55 lines (49 loc) · 1.64 KB
/
dtracker_debug.cpp
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
#include "dtracker_debug.H"
#include "libdft_api.h"
#include "pin.H"
VOID CheckMagicOnRead(VOID *ip, VOID *addr) {
if (debug_gotmagic_backward(addr)) {
LOG("DEBUG " DT_DBG_MAGIC " identified b-reading from " + ptrstr((char *)addr-DT_DBG_MAGICLEN+1) + "\n " +
"DEBUG " + tag_memrange_sprint((ADDRINT)addr-DT_DBG_MAGICLEN+1, DT_DBG_MAGICLEN) + "\n"
);
}
else if (debug_gotmagic_forward(addr)) {
LOG("DEBUG " DT_DBG_MAGIC " identified f-reading from " + ptrstr((char *)addr) + "\n " +
"DEBUG " + tag_memrange_sprint((ADDRINT)addr, DT_DBG_MAGICLEN) + "\n"
);
}
}
VOID CheckMagicOnWrite(VOID *ip, VOID *addr) {
if (debug_gotmagic_backward(addr)) {
LOG("DEBUG " DT_DBG_MAGIC " identified b-writing to " + ptrstr((char *)addr-DT_DBG_MAGICLEN+1) + "\n " +
"DEBUG " + tag_memrange_sprint((ADDRINT)addr-DT_DBG_MAGICLEN+1, DT_DBG_MAGICLEN) + "\n"
);
}
else if (debug_gotmagic_forward(addr)) {
LOG("DEBUG " DT_DBG_MAGIC " identified f-writing to " + ptrstr((char *)addr) + "\n " +
"DEBUG " + tag_memrange_sprint((ADDRINT)addr, DT_DBG_MAGICLEN) + "\n"
);
}
}
VOID CheckMagicValue(INS ins, VOID *v) {
UINT32 memOperands = INS_MemoryOperandCount(ins);
for (UINT32 memOp = 0; memOp < memOperands; memOp++) {
if (INS_MemoryOperandIsRead(ins, memOp)) {
INS_InsertPredicatedCall(
ins, IPOINT_BEFORE, (AFUNPTR)CheckMagicOnRead,
IARG_INST_PTR,
IARG_MEMORYOP_EA, memOp,
IARG_END
);
}
if (INS_MemoryOperandIsWritten(ins, memOp)) {
INS_InsertPredicatedCall(
ins, IPOINT_BEFORE, (AFUNPTR)CheckMagicOnWrite,
IARG_INST_PTR,
IARG_MEMORYOP_EA, memOp,
IARG_END
);
}
}
}
/* vim: set noet ts=4 sts=4 sw=4 ai : */