-
Notifications
You must be signed in to change notification settings - Fork 29
/
PathConditions.py
71 lines (50 loc) · 2.06 KB
/
PathConditions.py
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
"""
This file is part of SEA.
reserbot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
reserbot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SEA. If not, see <http://www.gnu.org/licenses/>.
Copyright 2013 by neuromancer
"""
import SSA
from Instruction import *
from Condition import *
from SMT import SMT
from Reil import parse_reil
def getPathConditions(trace, filename):
callstack = list(trace["callstack"])
inss = list(trace["raw_code"])
mem_access = trace["memaccess"]
SSA.SSAinit()
mvars = set()
smt_conds = SMT()
#assert(False)
for ins_str in inss:
#print ins_str.strip("\n")
# Instruction parsing
pins = parse_reil(ins_str)
# Instruction processing
current_call = trace["current_call"]
mem_access = trace["memaccess"].getAccess(pins.address)
ins = Instruction(pins,current_call,mem_access)
ins_write_vars = set(ins.getWriteVarOperands())
ins_read_vars = set(ins.getReadVarOperands())
if pins.instruction == "jcc" or len(ins_write_vars.intersection(mvars)) > 0:
ssa_map = SSA.SSAMapping(ins_read_vars.difference(mvars), ins_write_vars, ins_read_vars.intersection(mvars))
cons = conds.get(pins.instruction, Condition)
condition = cons(ins, ssa_map)
mvars = mvars.difference(ins_write_vars)
mvars = ins_read_vars.union(mvars)
mvars = set(filter(lambda o: o.name <> "ebp", mvars))
smt_conds.add(condition.getEq())
#print "mvars ops:"
#for op in mvars:
# print op
smt_conds.write_smtlib_file(filename+".smt2")
smt_conds.write_sol_file(filename+".sol")