-
Notifications
You must be signed in to change notification settings - Fork 524
/
pop.cpp
80 lines (58 loc) · 2.15 KB
/
pop.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "pin.H"
#include "Triton.h"
/*
* TODO :
*
* reg <- done
*
* mem <- todo
*
* */
static VOID setMem(std::string insDis, ADDRINT insAddr, CONTEXT *ctx, REG reg1, UINT64 mem, UINT32 readSize)
{
UINT64 i = 0;
std::stringstream expr, taint;
UINT64 reg1_ID = translatePinRegToID(reg1);
if (symbolicEngine->isMemoryReference(mem) != -1)
expr << "#" << std::dec << symbolicEngine->isMemoryReference(mem);
else
expr << smt2lib_bv(derefMem(mem, readSize), readSize);
symbolicElement *elem = symbolicEngine->newSymbolicElement(expr);
symbolicEngine->symbolicReg[reg1_ID] = elem->getID();
taintEngine->untaintReg(reg1_ID);
elem->isTainted = !TAINTED;
/* Check if the source addr is tainted */
for (i = 0 ; i < readSize ; i++){
if (taintEngine->isMemoryTainted(mem + i)){
taintEngine->taintReg(reg1_ID);
elem->isTainted = TAINTED;
break;
}
}
if (elem->isTainted)
taint << "#" << symbolicEngine->symbolicReg[reg1_ID] << " is controllable";
std::cout << boost::format(outputInstruction) % boost::io::group(hex, showbase, insAddr) % insDis % elem->getExpression() % taint.str();
}
static VOID alignStack(std::string insDis, ADDRINT insAddr, CONTEXT *ctx, UINT64 mem)
{
std::stringstream expr, taint;
/* Add RSP */
if (symbolicEngine->symbolicReg[ID_RSP] != (UINT64)-1)
expr << "(+ #" << std::dec << symbolicEngine->symbolicReg[ID_RSP] << " " << smt2lib_bv(8, REG_Size(REG_RSP)) << ")";
else
expr << "(+ " << smt2lib_bv(PIN_GetContextReg(ctx, REG_RSP), REG_Size(REG_RSP)) << " " << smt2lib_bv(8, REG_Size(REG_RSP)) << ")";
symbolicElement *elem = symbolicEngine->newSymbolicElement(expr);
symbolicEngine->symbolicReg[ID_RSP] = elem->getID();
/* Memory reference */
symbolicEngine->addMemoryReference(mem, elem->getID());
std::cout << boost::format(outputInstruction) % "" % "" % elem->getExpression() % taint.str();
return;
}
VOID popReg(std::string insDis, ADDRINT insAddr, CONTEXT *ctx, REG reg1, UINT64 mem, UINT32 readSize)
{
if (_analysisStatus == LOCKED)
return;
setMem(insDis, insAddr, ctx, reg1, mem, readSize);
alignStack(insDis, insAddr, ctx, mem);
return;
}