about summary refs log tree commit diff stats
path: root/example/expression/expr_c.py
diff options
context:
space:
mode:
authorFabrice Desclaux <fabrice.desclaux@cea.fr>2017-05-15 21:25:57 +0200
committerFabrice Desclaux <fabrice.desclaux@cea.fr>2017-05-15 21:29:34 +0200
commit47fb50d611b5ba8eb7e4dc827b522123642ca3b4 (patch)
tree356cc62e4b7bb55b31d4ad82f20dc19d58344410 /example/expression/expr_c.py
parentd67d9ff0742fcf632a5a955c6e36e8b8cc15ec93 (diff)
downloadmiasm-47fb50d611b5ba8eb7e4dc827b522123642ca3b4.tar.gz
miasm-47fb50d611b5ba8eb7e4dc827b522123642ca3b4.zip
Example: clean code
Diffstat (limited to 'example/expression/expr_c.py')
-rw-r--r--example/expression/expr_c.py86
1 files changed, 41 insertions, 45 deletions
diff --git a/example/expression/expr_c.py b/example/expression/expr_c.py
index e2986c55..7adc7b50 100644
--- a/example/expression/expr_c.py
+++ b/example/expression/expr_c.py
@@ -10,57 +10,53 @@ from miasm2.core.objc import CTypesManagerNotPacked, CHandler
 from miasm2.expression.expression import ExprId
 
 
-def test():
-    """
-    C manipulation example
-    """
-
-    # Digest C informations
-    text = """
-    struct line {
-            char color[20];
-            int size;
-    };
-
-    struct rectangle {
-            unsigned int width;
-            unsigned int length;
-            struct line* line;
-    };
-    """
+"""
+C manipulation example
+"""
 
-    # Type manager for x86 64: structures not packed
-    base_types = CTypeAMD64_unk()
-    types_ast = CAstTypes()
+# Digest C informations
+text = """
+struct line {
+        char color[20];
+        int size;
+};
+
+struct rectangle {
+        unsigned int width;
+        unsigned int length;
+        struct line* line;
+};
+"""
 
-    # Add C types definition
-    types_ast.add_c_decl(text)
+# Type manager for x86 64: structures not packed
+base_types = CTypeAMD64_unk()
+types_ast = CAstTypes()
 
-    types_mngr = CTypesManagerNotPacked(types_ast, base_types)
+# Add C types definition
+types_ast.add_c_decl(text)
 
-    # Create the ptr variable with type "struct rectangle*"
-    ptr_rectangle = types_mngr.get_objc(CTypePtr(CTypeStruct('rectangle')))
+types_mngr = CTypesManagerNotPacked(types_ast, base_types)
 
-    ptr = ExprId('ptr', 64)
-    expr_types = {ptr.name: ptr_rectangle}
+# Create the ptr variable with type "struct rectangle*"
+ptr_rectangle = types_mngr.get_objc(CTypePtr(CTypeStruct('rectangle')))
 
-    mychandler = CHandler(types_mngr, expr_types)
+ptr = ExprId('ptr', 64)
+expr_types = {ptr.name: ptr_rectangle}
 
-    # Parse some C accesses
-    c_acceses = ["ptr->width",
-                 "ptr->length",
-                 "ptr->line",
-                 "ptr->line->color",
-                 "ptr->line->color[3]",
-                 "ptr->line->size"
-                ]
+mychandler = CHandler(types_mngr, expr_types)
 
-    for c_str in c_acceses:
-        expr = mychandler.c_to_expr(c_str)
-        c_type = mychandler.c_to_type(c_str)
-        print 'C access:', c_str
-        print '\tExpr:', expr
-        print '\tType:', c_type
+# Parse some C accesses
+c_acceses = ["ptr->width",
+             "ptr->length",
+             "ptr->line",
+             "ptr->line->color",
+             "ptr->line->color[3]",
+             "ptr->line->size"
+            ]
 
-if __name__ == '__main__':
-    test()
+for c_str in c_acceses:
+    expr = mychandler.c_to_expr(c_str)
+    c_type = mychandler.c_to_type(c_str)
+    print 'C access:', c_str
+    print '\tExpr:', expr
+    print '\tType:', c_type