about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--example/ida/ctype_propagation.py5
-rw-r--r--miasm2/arch/msp430/ctype.py68
2 files changed, 72 insertions, 1 deletions
diff --git a/example/ida/ctype_propagation.py b/example/ida/ctype_propagation.py
index 76d4fa2d..8c64c6d2 100644
--- a/example/ida/ctype_propagation.py
+++ b/example/ida/ctype_propagation.py
@@ -11,6 +11,7 @@ from miasm2.expression.simplifications import expr_simp
 from miasm2.analysis.depgraph import DependencyGraph
 from miasm2.ir.ir import IRBlock, AssignBlock
 from miasm2.arch.x86.ctype import CTypeAMD64_unk, CTypeX86_unk
+from miasm2.arch.msp430.ctype import CTypeMSP430_unk
 from miasm2.expression.expression import ExprId
 from miasm2.core.objc import CTypesManagerNotPacked, ExprToAccessC, CHandler
 from miasm2.core.ctypesmngr import CAstTypes
@@ -29,7 +30,7 @@ class TypePropagationForm(ida_kernwin.Form):
         self.ira = ira
 
         default_types_info = r"""ExprId("RDX", 64): char *"""
-        archs = ["AMD64_unk", "X86_32_unk"]
+        archs = ["AMD64_unk", "X86_32_unk", "msp430_unk"]
 
         ida_kernwin.Form.__init__(self,
                       r"""BUTTON YES* Launch
@@ -59,6 +60,8 @@ def get_types_mngr(headerFile, arch):
         base_types = CTypeAMD64_unk()
     elif arch =="X86_32_unk":
         base_types = CTypeX86_unk()
+    elif arch =="msp430_unk":
+        base_types = CTypeMSP430_unk()
     else:
         raise NotImplementedError("Unsupported arch")
     types_ast = CAstTypes()
diff --git a/miasm2/arch/msp430/ctype.py b/miasm2/arch/msp430/ctype.py
new file mode 100644
index 00000000..adb0a953
--- /dev/null
+++ b/miasm2/arch/msp430/ctype.py
@@ -0,0 +1,68 @@
+from miasm2.core.objc import CLeafTypes, ObjCDecl, PADDING_TYPE_NAME
+from miasm2.core.ctypesmngr import CTypeId, CTypePtr
+
+
+class CTypeMSP430_unk(CLeafTypes):
+    """Define C types sizes/alignement for msp430 architecture"""
+
+    obj_pad = ObjCDecl(PADDING_TYPE_NAME, 1, 1) # __padding__ is size 1/align 1
+
+    obj_char = ObjCDecl("char", 1, 1)
+    obj_short = ObjCDecl("short", 2, 2)
+    obj_int = ObjCDecl("int", 2, 2)
+    obj_long = ObjCDecl("long", 2, 2)
+
+    obj_uchar = ObjCDecl("uchar", 1, 1)
+    obj_ushort = ObjCDecl("ushort", 2, 2)
+    obj_uint = ObjCDecl("uint", 2, 2)
+    obj_ulong = ObjCDecl("ulong", 2, 2)
+
+    obj_void = ObjCDecl("void", 1, 1)
+
+    obj_enum = ObjCDecl("enum", 2, 2)
+
+    obj_float = ObjCDecl("float", 4, 4)
+    obj_double = ObjCDecl("double", 8, 8)
+    obj_ldouble = ObjCDecl("ldouble", 16, 16)
+
+    def __init__(self):
+        self.types = {
+            CTypeId(PADDING_TYPE_NAME): self.obj_pad,
+
+            CTypeId('char'): self.obj_char,
+            CTypeId('short'): self.obj_short,
+            CTypeId('int'): self.obj_int,
+            CTypeId('void'): self.obj_void,
+            CTypeId('long',): self.obj_long,
+            CTypeId('float'): self.obj_float,
+            CTypeId('double'): self.obj_double,
+
+            CTypeId('signed', 'char'): self.obj_char,
+            CTypeId('unsigned', 'char'): self.obj_uchar,
+
+            CTypeId('short', 'int'): self.obj_short,
+            CTypeId('signed', 'short'): self.obj_short,
+            CTypeId('signed', 'short', 'int'): self.obj_short,
+            CTypeId('unsigned', 'short'): self.obj_ushort,
+            CTypeId('unsigned', 'short', 'int'): self.obj_ushort,
+
+            CTypeId('unsigned', ): self.obj_uint,
+            CTypeId('unsigned', 'int'): self.obj_uint,
+            CTypeId('signed', 'int'): self.obj_int,
+
+            CTypeId('long', 'int'): self.obj_long,
+            CTypeId('long', 'long'): self.obj_long,
+            CTypeId('long', 'long', 'int'): self.obj_long,
+            CTypeId('signed', 'long', 'long'): self.obj_long,
+            CTypeId('unsigned', 'long', 'long'): self.obj_ulong,
+            CTypeId('signed', 'long', 'long', 'int'): self.obj_long,
+            CTypeId('unsigned', 'long', 'long', 'int'): self.obj_ulong,
+
+            CTypeId('signed', 'long'): self.obj_long,
+            CTypeId('unsigned', 'long'): self.obj_ulong,
+            CTypeId('signed', 'long', 'int'): self.obj_long,
+            CTypeId('unsigned', 'long', 'int'): self.obj_ulong,
+
+            CTypeId('long', 'double'): self.obj_ldouble,
+            CTypePtr(CTypeId('void')): self.obj_uint,
+        }