diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2017-07-22 15:08:45 +0200 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2017-07-22 15:08:45 +0200 |
| commit | 1ed1d12f081819a1e85a1c142393f60d0ba6285f (patch) | |
| tree | dd0116e19baea93fa5426b322f2a3fcf066474fd /miasm2/core/objc.py | |
| parent | 19084a5729fd2ba5a0a13e19a82f12760d1861c9 (diff) | |
| download | miasm-1ed1d12f081819a1e85a1c142393f60d0ba6285f.tar.gz miasm-1ed1d12f081819a1e85a1c142393f60d0ba6285f.zip | |
Objc: warn on non defined structures
Diffstat (limited to 'miasm2/core/objc.py')
| -rw-r--r-- | miasm2/core/objc.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/miasm2/core/objc.py b/miasm2/core/objc.py index 917d0ea9..afc4334f 100644 --- a/miasm2/core/objc.py +++ b/miasm2/core/objc.py @@ -6,6 +6,7 @@ C helper for Miasm: """ +import warnings from pycparser import c_parser, c_ast from miasm2.expression.expression_reduce import ExprReducer @@ -17,6 +18,10 @@ from miasm2.core.ctypesmngr import CTypeUnion, CTypeStruct, CTypeId, CTypePtr,\ PADDING_TYPE_NAME = "___padding___" +def missing_definition(objtype): + warnings.warn("Null size type: Missing definition? %r" % objtype) + + class ObjC(object): """Generic ObjC""" @@ -672,6 +677,10 @@ class CTypeAnalyzer(ExprReducer): else: raise RuntimeError('cannot find struct field') elif isinstance(base_type, ObjCArray): + if base_type.objtype.size == 0: + missing_definition(base_type.objtype) + return [] + sub_offset = offset % (base_type.objtype.size) element_num = offset / (base_type.objtype.size) if element_num >= base_type.elems: @@ -747,6 +756,9 @@ class CTypeAnalyzer(ExprReducer): ptr_offset = int(arg1.expr) for info in arg0.info: ptr_basetype = info.objtype + if ptr_basetype.size == 0: + missing_definition(ptr_basetype) + continue # Array-like: int* ptr; ptr[1] = X out += self.get_typeof(ptr_basetype, ptr_offset % ptr_basetype.size, @@ -898,6 +910,10 @@ class ExprToAccessC(ExprReducer): OUT: - CGenArray(CGenField(toto, b), 1) """ + if base_type.size == 0: + missing_definition(base_type) + return [] + void_type = self.types_mngr.void_ptr if isinstance(base_type, ObjCStruct): @@ -922,6 +938,9 @@ class ExprToAccessC(ExprReducer): else: raise RuntimeError('Cannot find struct field') elif isinstance(base_type, ObjCArray): + if base_type.objtype.size == 0: + missing_definition(base_type.objtype) + return [] element_num = offset / (base_type.objtype.size) assert element_num < base_type.elems f_offset = offset % base_type.objtype.size |