-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay.py
72 lines (52 loc) · 1.69 KB
/
play.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
71
import ssa
import util
def get_block(callgraph, address):
for block in callgraph:
if block.start == address:
return block
return None
def propagate_ssa_values(source, dest):
print "-- propagate %x to %x --"%(source.start, dest.start)
for symbol in source.ssa_vals:
#propagate each possible value to the dest node
reference = source.ssa_vals[symbol].get_states(source.end+1) #returns last
#oops, circular references appear if new states arent created
#note that the states still refernce the original symbols
#TODO: depth...
states = []
for r in reference:
if isinstance(r, ssa.ssa_state):
n = r.copy()
states.append(n)
else:
states.append(r)
#print '>'
addr = dest.start
aux = -1
dest.ssa_vals[symbol].update(states, addr, aux)
#print '<'
def prop_blocks(arch, bin, callgraph):
sg = callgraph.keys()
sg.sort()
for r in arch.registers:
if "stack" in r.aliases:
stack_reg = r
elif "pc" in r.aliases:
pc_reg = r
stack_reg_name = str(stack_reg.register_name)
visited = {}
for func in sg:
print "\n>>>>>>> func 0x%x <<<<<<<<"%func
#top down value propagation, does not do loops for now !!!!
for block in callgraph[func]:
if block.start in visited:
continue
visited[block.start] = 1
if block.next:
next = get_block(callgraph[func], block.next)
if next and next.start not in visited:
propagate_ssa_values(block, next)
if block.branch:
branch = get_block(callgraph[func], block.branch)
if branch and branch.start not in visited:
propagate_ssa_values(block, branch)