diff options
| author | Camille Mougey <commial@gmail.com> | 2017-07-05 11:19:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-05 11:19:55 +0200 |
| commit | c7718a8d0c1263771ca8e0a31b3717c7063d50e4 (patch) | |
| tree | fa9a4eb6269d7a16f5f7bc1de03df1f49e31b2ad | |
| parent | f2980aef62b4328b702517862e79636a83dab359 (diff) | |
| parent | 29fde45b617412f74c3ff73c813a1df4166235ee (diff) | |
| download | miasm-c7718a8d0c1263771ca8e0a31b3717c7063d50e4.tar.gz miasm-c7718a8d0c1263771ca8e0a31b3717c7063d50e4.zip | |
Merge pull request #575 from serpilliere/fix_ida_example
Fix ida example
| -rw-r--r-- | example/ida/ctype_propagation.py | 16 | ||||
| -rw-r--r-- | miasm2/ir/symbexec_types.py | 35 |
2 files changed, 17 insertions, 34 deletions
diff --git a/example/ida/ctype_propagation.py b/example/ida/ctype_propagation.py index 95fef75f..b086ef3e 100644 --- a/example/ida/ctype_propagation.py +++ b/example/ida/ctype_propagation.py @@ -96,11 +96,10 @@ class MyCHandler(CHandler): class TypePropagationEngine(SymbExecCType): - def __init__(self, ir_arch, state): - mychandler = MyCHandler(types_mngr, state.infos_types) + def __init__(self, ir_arch, types_mngr, state): + mychandler = MyCHandler(types_mngr, state.symbols) super(TypePropagationEngine, self).__init__(ir_arch, state.symbols, - state.infos_types, mychandler) @@ -137,11 +136,10 @@ class SymbExecCTypeFix(SymbExecCType): class CTypeEngineFixer(SymbExecCTypeFix): - def __init__(self, ir_arch, state): - mychandler = MyCHandler(types_mngr, state.infos_types) + def __init__(self, ir_arch, types_mngr, state): + mychandler = MyCHandler(types_mngr, state.symbols) super(CTypeEngineFixer, self).__init__(ir_arch, state.symbols, - state.infos_types, mychandler) @@ -211,7 +209,7 @@ def analyse_function(): ir_arch.blocks[lbl_head] = irb_head ir_arch.graph.add_uniq_edge(lbl_head, lbl_real_start) - state = TypePropagationEngine.StateEngine(infos_types, infos_types) + state = TypePropagationEngine.StateEngine(infos_types) states = {lbl_head: state} todo = set([lbl_head]) done = set() @@ -222,7 +220,7 @@ def analyse_function(): if (lbl, state) in done: continue done.add((lbl, state)) - symbexec_engine = TypePropagationEngine(ir_arch, state) + symbexec_engine = TypePropagationEngine(ir_arch, types_mngr, state) get_block(ir_arch, mdis, lbl) @@ -238,7 +236,7 @@ def analyse_function(): symbexec_engine.get_state()) for lbl, state in states.iteritems(): - symbexec_engine = CTypeEngineFixer(ir_arch, state) + symbexec_engine = CTypeEngineFixer(ir_arch, types_mngr, state) addr = symbexec_engine.emul_ir_block(lbl) symbexec_engine.del_mem_above_stack(ir_arch.sp) diff --git a/miasm2/ir/symbexec_types.py b/miasm2/ir/symbexec_types.py index df159939..297c0c9e 100644 --- a/miasm2/ir/symbexec_types.py +++ b/miasm2/ir/symbexec_types.py @@ -9,12 +9,11 @@ from miasm2.core.ctypesmngr import CTypeId class SymbolicStateCTypes(StateEngine): """Store C types of symbols""" - def __init__(self, dct, infos_types): - self._symbols = frozenset(dct.items()) - self._infos_types = frozenset(infos_types.items()) + def __init__(self, symbols): + self._symbols = frozenset(symbols.items()) def __hash__(self): - return hash((self.__class__, self._symbols, self._infos_types)) + return hash((self.__class__, self._symbols)) def __str__(self): out = [] @@ -27,8 +26,7 @@ class SymbolicStateCTypes(StateEngine): return True if self.__class__ != other.__class__: return False - return (self.symbols == other.symbols and - self.infos_types == other.infos_types) + return self.symbols == other.symbols def __iter__(self): for dst, src in self._symbols: @@ -39,28 +37,16 @@ class SymbolicStateCTypes(StateEngine): Only expressions with equal C types in both states are kept. @other: second symbolic state """ - symb_a = self.symbols - symb_b = other.symbols - types_a = set(self.infos_types.items()) - types_b = set(other.infos_types.items()) - intersection = set(symb_a.keys()).intersection(symb_b.keys()) - symbols = {} - infos_types = dict(types_a.intersection(types_b)) - for dst in intersection: - if symb_a[dst] == symb_b[dst]: - symbols[dst] = symb_a[dst] - return self.__class__(symbols, infos_types) + symb_a = self.symbols.items() + symb_b = other.symbols.items() + symbols = dict(set(symb_a).intersection(symb_b)) + return self.__class__(symbols) @property def symbols(self): """Return the dictionnary of known symbols'types""" return dict(self._symbols) - @property - def infos_types(self): - """Return known types of the state""" - return dict(self._infos_types) - class SymbExecCType(SymbolicExecutionEngine): """Engine of C types propagation @@ -71,13 +57,12 @@ class SymbExecCType(SymbolicExecutionEngine): OBJC_INTERNAL = "___OBJC___" def __init__(self, ir_arch, - symbols, infos_types, + symbols, chandler, func_read=None, func_write=None, sb_expr_simp=expr_simp): self.chandler = chandler - self.infos_types = dict(infos_types) super(SymbExecCType, self).__init__(ir_arch, {}, func_read, @@ -212,7 +197,7 @@ class SymbExecCType(SymbolicExecutionEngine): def get_state(self): """Return the current state of the SymbolicEngine""" - return self.StateEngine(self.symbols, self.infos_types) + return self.StateEngine(self.symbols) def eval_ir_expr(self, assignblk): """ |