about summary refs log tree commit diff stats
path: root/example/expression/access_c.py
diff options
context:
space:
mode:
authorFabrice Desclaux <fabrice.desclaux@cea.fr>2017-02-20 14:41:08 +0100
committerFabrice Desclaux <fabrice.desclaux@cea.fr>2017-05-15 21:29:34 +0200
commit9e79f4338ad7cae991ee73902898e24782874ad5 (patch)
treebe4f8ecc5725357feff7a8aa364569665fee2eaa /example/expression/access_c.py
parent3260f7867827195ea7c6ec37bc3a8687ce998f6d (diff)
downloadfocaccia-miasm-9e79f4338ad7cae991ee73902898e24782874ad5.tar.gz
focaccia-miasm-9e79f4338ad7cae991ee73902898e24782874ad5.zip
Core/Objc: improuve internal type representation
Diffstat (limited to 'example/expression/access_c.py')
-rw-r--r--example/expression/access_c.py28
1 files changed, 14 insertions, 14 deletions
diff --git a/example/expression/access_c.py b/example/expression/access_c.py
index 923a3331..8a1e2962 100644
--- a/example/expression/access_c.py
+++ b/example/expression/access_c.py
@@ -8,9 +8,8 @@ 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 ObjCPtr
-from miasm2.core.ctypesmngr import CTypesManagerNotPacked
-
+from miasm2.core.objc import CTypesManagerNotPacked
+from miasm2.core.ctypesmngr import CAstTypes, CTypePtr, CTypeStruct
 
 """
 
@@ -52,9 +51,9 @@ ExprCompose(int, 0) => int
 Then, in the C generator:
 ExprCompose(var1, 0) => var1
 
-
 """
 
+
 def find_call(ira):
     """Returns (irb, index) which call"""
 
@@ -76,6 +75,7 @@ def find_call(ira):
 
 
 class MyCTypeAnalyzer(CTypeAnalyzer):
+    """Custom CTypeAnalyzer to complete type analysis"""
 
     def reduce_compose(self, node, _):
         """Custom reduction rule: {XXX, 0} -> typeof(XXX)"""
@@ -89,6 +89,7 @@ class MyCTypeAnalyzer(CTypeAnalyzer):
 
 
 class MyExprToAccessC(ExprToAccessC):
+    """Custom ExprToAccessC to complete expression traduction to C"""
 
     def reduce_compose(self, node, _):
         """Custom reduction rule: {XXX, 0} -> XXX"""
@@ -105,6 +106,7 @@ class MyExprToAccessC(ExprToAccessC):
 
 
 def get_funcs_arg0(ctx, ira, lbl_head):
+    """Compute DependencyGraph on the func @lbl_head"""
     g_dep = DependencyGraph(ira, follow_call=False)
     element = ira.arch.regs.RSI
 
@@ -119,6 +121,8 @@ 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
 
@@ -138,10 +142,11 @@ def test(data):
     };
     """
 
-    my_types = CTypeAMD64_unk()
-    types_mngr = CTypesManagerNotPacked(my_types.types)
+    base_types = CTypeAMD64_unk()
+    types_ast = CAstTypes()
+    types_ast.add_c_decl(text)
 
-    types_mngr.add_c_decl(text)
+    types_mngr = CTypesManagerNotPacked(types_ast, base_types)
 
     # Analyze binary
     cont = Container.fallback_container(data, None, addr=0)
@@ -161,11 +166,7 @@ def test(data):
     open('graph_irflow.dot', 'w').write(ir_arch_a.graph.dot())
 
     # Main function's first argument's type is "struct ll_human*"
-    void_ptr = types_mngr.void_ptr
-    ll_human = types_mngr.get_type(('ll_human',))
-    ptr_llhuman = ObjCPtr('noname', ll_human,
-                          void_ptr.align, void_ptr.size)
-
+    ptr_llhuman = types_mngr.get_objc(CTypePtr(CTypeStruct('ll_human')))
     arg0 = ExprId('ptr', 64)
     ctx = {ir_arch_a.arch.regs.RDI: arg0}
     expr_types = {arg0.name: ptr_llhuman}
@@ -184,5 +185,4 @@ def test(data):
 
 
 if __name__ == '__main__':
-    data = open(sys.argv[1]).read()
-    test(data)
+    test(open(sys.argv[1]).read())