diff options
Diffstat (limited to 'example/expression/access_c.py')
| -rw-r--r-- | example/expression/access_c.py | 55 |
1 files changed, 18 insertions, 37 deletions
diff --git a/example/expression/access_c.py b/example/expression/access_c.py index 48da53ff..f285eb55 100644 --- a/example/expression/access_c.py +++ b/example/expression/access_c.py @@ -1,16 +1,3 @@ -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 miasm2.arch.x86.ctype import CTypeAMD64_unk - -from miasm2.core.objc import CTypeAnalyzer, ExprToAccessC, CHandler -from miasm2.core.objc import CTypesManagerNotPacked -from miasm2.core.ctypesmngr import CAstTypes, CTypePtr, CTypeStruct - """ This example demonstrates the recovering of possible C types for an arbitrary @@ -54,6 +41,20 @@ ExprCompose(var1, 0) => var1 """ +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 miasm2.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 + + def find_call(ira): """Returns (irb, index) which call""" @@ -74,24 +75,10 @@ def find_call(ira): yield irb, index -class MyCTypeAnalyzer(CTypeAnalyzer): - """Custom CTypeAnalyzer to complete type analysis""" - - def reduce_compose(self, node, _): - """Custom reduction rule: {XXX, 0} -> typeof(XXX)""" - if not (isinstance(node.expr, ExprCompose) and - len(node.expr.args) == 2 and - node.expr.args[1].is_int(0)): - return None - return node.args[0].info - - reduction_rules = CTypeAnalyzer.reduction_rules + [reduce_compose] - - class MyExprToAccessC(ExprToAccessC): """Custom ExprToAccessC to complete expression traduction to C""" - def reduce_compose(self, node, _): + def reduce_compose(self, node, **kwargs): """Custom reduction rule: {XXX, 0} -> XXX""" if not (isinstance(node.expr, ExprCompose) and len(node.expr.args) == 2 and @@ -123,7 +110,6 @@ def get_funcs_arg0(ctx, ira, lbl_head): class MyCHandler(CHandler): """Custom CHandler to add complementary C handling rules""" - cTypeAnalyzer_cls = MyCTypeAnalyzer exprToAccessC_cls = MyExprToAccessC @@ -177,11 +163,6 @@ mychandler = MyCHandler(types_mngr, expr_types) for expr in get_funcs_arg0(ctx, ir_arch_a, lbl_head): print "Access:", expr - target_types = mychandler.expr_to_types(expr) - for target_type in target_types: - print '\tType:', target_type - c_strs = mychandler.expr_to_c(expr) - for c_str in c_strs: - print "\tC access:", c_str - print - + for c_str, ctype in mychandler.expr_to_c_and_types(expr): + print '\taccess:', c_str + print '\tc type:', ctype |