diff options
| author | Camille Mougey <commial@gmail.com> | 2019-03-07 14:37:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-07 14:37:07 +0100 |
| commit | 4c2320b46250a8d6f8774e1218544b72a154cd8e (patch) | |
| tree | b67e7b072439f84109bd39dad8ed7f3f135224f8 /example/expression/access_c.py | |
| parent | eab809932871f91d6f4aa770fc321af9e156e0f5 (diff) | |
| parent | 26c1075723a02984da6d3bc7423c5c0c43082dc3 (diff) | |
| download | miasm-4c2320b46250a8d6f8774e1218544b72a154cd8e.tar.gz miasm-4c2320b46250a8d6f8774e1218544b72a154cd8e.zip | |
Merge pull request #990 from serpilliere/support_python2_python3
Support python2 python3
Diffstat (limited to 'example/expression/access_c.py')
| -rw-r--r-- | example/expression/access_c.py | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/example/expression/access_c.py b/example/expression/access_c.py index b23ba81b..c604a0bd 100644 --- a/example/expression/access_c.py +++ b/example/expression/access_c.py @@ -39,39 +39,41 @@ Then, in the C generator: ExprCompose(var1, 0) => var1 """ - +from __future__ import print_function import sys -from miasm2.analysis.machine import Machine -from miasm2.analysis.binary import Container -from miasm2.expression.expression import ExprOp, ExprCompose, ExprId, ExprInt -from miasm2.analysis.depgraph import DependencyGraph +from future.utils import viewitems, viewvalues + +from miasm.analysis.machine import Machine +from miasm.analysis.binary import Container +from miasm.expression.expression import ExprOp, ExprCompose, ExprId, ExprInt +from miasm.analysis.depgraph import DependencyGraph -from miasm2.arch.x86.ctype import CTypeAMD64_unk +from miasm.arch.x86.ctype import CTypeAMD64_unk -from miasm2.core.objc import ExprToAccessC, CHandler -from miasm2.core.objc import CTypesManagerNotPacked -from miasm2.core.ctypesmngr import CAstTypes, CTypePtr, CTypeStruct +from miasm.core.objc import ExprToAccessC, CHandler +from miasm.core.objc import CTypesManagerNotPacked +from miasm.core.ctypesmngr import CAstTypes, CTypePtr, CTypeStruct def find_call(ircfg): """Returns (irb, index) which call""" - for irb in ircfg.blocks.values(): + for irb in viewvalues(ircfg.blocks): out = set() if len(irb) < 2: continue assignblk = irb[-2] - for src in assignblk.itervalues(): + for src in viewvalues(assignblk): if not isinstance(src, ExprOp): continue if not src.op.startswith('call_func'): continue - out.add((irb, len(irb) - 2)) + out.add((irb.loc_key, len(irb) - 2)) if len(out) != 1: continue - irb, index = out.pop() - yield irb, index + loc_key, index = out.pop() + yield loc_key, index class MyExprToAccessC(ExprToAccessC): @@ -96,9 +98,10 @@ def get_funcs_arg0(ctx, ira, ircfg, lbl_head): g_dep = DependencyGraph(ircfg, follow_call=False) element = ira.arch.regs.RSI - for irb, index in find_call(ircfg): + for loc_key, index in find_call(ircfg): + irb = ircfg.get_block(loc_key) instr = irb[index].instr - print 'Analysing references from:', hex(instr.offset), instr + print('Analysing references from:', hex(instr.offset), instr) g_list = g_dep.get(irb.loc_key, set([element]), index, set([lbl_head])) for dep in g_list: emul_result = dep.emul(ira, ctx) @@ -113,7 +116,7 @@ class MyCHandler(CHandler): -data = open(sys.argv[1]).read() +data = open(sys.argv[1], 'rb').read() # Digest C information text = """ struct human { @@ -160,7 +163,7 @@ expr_types = {arg0: (ptr_llhuman,), mychandler = MyCHandler(types_mngr, expr_types) for expr in get_funcs_arg0(ctx, ir_arch_a, ircfg, lbl_head): - print "Access:", expr + print("Access:", expr) for c_str, ctype in mychandler.expr_to_c_and_types(expr): - print '\taccess:', c_str - print '\tc type:', ctype + print('\taccess:', c_str) + print('\tc type:', ctype) |