diff options
| author | Ajax <commial@gmail.com> | 2015-04-28 09:08:42 +0200 |
|---|---|---|
| committer | Ajax <commial@gmail.com> | 2015-04-28 09:08:42 +0200 |
| commit | 73d3f770882d73f7c3814a4dc95cde1b2055fbda (patch) | |
| tree | a1dfbc40a02e2fa6175f2bdcaa0f911f160bd77a | |
| parent | 2a9ef019bc17c712c8e18a4704c69ef9f5875402 (diff) | |
| download | miasm-73d3f770882d73f7c3814a4dc95cde1b2055fbda.tar.gz miasm-73d3f770882d73f7c3814a4dc95cde1b2055fbda.zip | |
Example: Add an example "rename-args" argument for depgraph
| -rw-r--r-- | example/symbol_exec/depgraph.py | 17 | ||||
| -rw-r--r-- | test/test_all.py | 2 |
2 files changed, 16 insertions, 3 deletions
diff --git a/example/symbol_exec/depgraph.py b/example/symbol_exec/depgraph.py index 0a406b0b..5b6f373a 100644 --- a/example/symbol_exec/depgraph.py +++ b/example/symbol_exec/depgraph.py @@ -4,6 +4,7 @@ from pdb import pm from miasm2.analysis.machine import Machine from miasm2.analysis.binary import Container from miasm2.analysis.depgraph import DependencyGraph +from miasm2.expression.expression import ExprMem, ExprId, ExprInt32 parser = ArgumentParser("Dependency grapher") parser.add_argument("filename", help="Binary to analyse") @@ -20,6 +21,9 @@ parser.add_argument("--unfollow-call", help="Stop on call statements", action="store_true") parser.add_argument("--do-not-simplify", help="Do not simplify expressions", action="store_true") +parser.add_argument("--rename-args", + help="Rename common arguments (@32[ESP_init] -> Arg1)", + action="store_true") args = parser.parse_args() # Get architecture @@ -41,6 +45,15 @@ for element in args.element: mdis = machine.dis_engine(cont.bin_stream, dont_dis_nulstart_bloc=True) ir_arch = machine.ira(mdis.symbol_pool) +# Common argument forms +init_ctx = {} +if args.rename_args: + if arch == "x86_32": + # StdCall example + for i in xrange(4): + e_mem = ExprMem(ExprId("ESP_init") + ExprInt32(4 * (i + 1)), 32) + init_ctx[e_mem] = ExprId("arg%d" % i) + # Disassemble the targeted function blocks = mdis.dis_multibloc(int(args.func_addr, 16)) @@ -71,7 +84,7 @@ for sol_nb, sol in enumerate(dg.get(current_block.label, elements, line_nb, set( with open(fname, "w") as fdesc: fdesc.write(sol.graph.dot()) result = ", ".join("%s: %s" % (k, v) - for k, v in sol.emul().iteritems()) + for k, v in sol.emul(ctx=init_ctx).iteritems()) print "Solution %d: %s -> %s" % (sol_nb, result, fname) @@ -81,5 +94,5 @@ for sol_nb, sol in enumerate(dg.get(current_block.label, elements, line_nb, set( if sat: constraints = {} for element in sol.constraints: - constraints[element] = sol.constraints[element] + constraints[element] = hex(sol.constraints[element].as_long()) print "\tSatisfiability: %s %s" % (sat, constraints) diff --git a/test/test_all.py b/test/test_all.py index 07e1c509..c3367d43 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -322,7 +322,7 @@ class ExampleSymbolExec(Example): testset += ExampleSymbolExec(["single_instr.py"]) for options, nb_sol in [([], 8), - (["-i"], 12)]: + (["-i", "--rename-args"], 12)]: testset += ExampleSymbolExec(["depgraph.py", Example.get_sample("simple_test.bin"), "-m", "x86_32", "0x0", "0x8b", |