Skip to content

Commit 23e3414

Browse files
committed
support ssa_dest_and_src with a hack
fixes #3
1 parent 58237b0 commit 23e3414

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

__init__.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
if sys.version_info > (3,):
5050
long = int
5151

52+
5253
def graph_il_insn(g, head, il, label=None):
5354
# type: (FlowGraph, FlowGraphNode, LowLevelILInstruction, Optional[str]) -> None
5455

@@ -75,9 +76,19 @@ def graph_il_insn(g, head, il, label=None):
7576
)
7677
)
7778

78-
for i, o in enumerate(il.operands):
79-
edge_label = il.ILOperations[il.operation][i][0]
80-
graph_il_insn(g, record, o, edge_label)
79+
ops = enumerate(il.operands)
80+
for i, o in ops:
81+
edge_label, ty = il.ILOperations[il.operation][i]
82+
83+
if ty == 'reg_stack_ssa_dest_and_src' or ty == 'var_ssa_dest_and_src':
84+
# handle the ssa_dest_and_src operand types
85+
next_label = 'next' if edge_label == 'prev' else 'dest'
86+
graph_il_insn(g, record, o, next_label)
87+
i, o2 = next(ops)
88+
graph_il_insn(g, record, o2, edge_label)
89+
else:
90+
# handle everything else
91+
graph_il_insn(g, record, o, edge_label)
8192
elif isinstance(il, list):
8293
tokens.append(
8394
InstructionTextToken(
@@ -223,11 +234,24 @@ def match_condition(name, o):
223234
]
224235
match += [" return False\n"]
225236

226-
for i, oo in enumerate(o.operands):
227-
oo_name = o.ILOperations[o.operation][i][0]
228-
full_name = "{}.{}".format(name, oo_name)
229-
cond = match_condition(full_name, oo)
230-
match += cond
237+
ops = enumerate(o.operands)
238+
for i, oo in ops:
239+
oo_name, ty = o.ILOperations[o.operation][i]
240+
if ty == 'reg_stack_ssa_dest_and_src' or ty == 'var_ssa_dest_and_src':
241+
next_name = 'next' if oo_name == 'prev' else 'dest'
242+
full_name = "{}.{}".format(name, next_name)
243+
cond = match_condition(full_name, oo)
244+
match += cond
245+
246+
i, oo = next(ops)
247+
full_name = "{}.{}".format(name, oo_name)
248+
cond = match_condition(full_name, oo)
249+
match += cond
250+
else:
251+
full_name = "{}.{}".format(name, oo_name)
252+
cond = match_condition(full_name, oo)
253+
match += cond
254+
231255

232256
elif isinstance(o, list):
233257
match += ["if len({}) != {}:".format(name, len(o))]

0 commit comments

Comments
 (0)