From 6aaa4de1b3af99d0dc9c74a57d61a67f421049da Mon Sep 17 00:00:00 2001 From: William Bruneau Date: Tue, 24 Apr 2018 14:41:25 +0200 Subject: Fix typo --- example/ida/ctype_propagation.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'example') diff --git a/example/ida/ctype_propagation.py b/example/ida/ctype_propagation.py index b2c7d5ab..84d9d4bd 100644 --- a/example/ida/ctype_propagation.py +++ b/example/ida/ctype_propagation.py @@ -1,6 +1,3 @@ -import os -import tempfile - import ida_kernwin import idc import ida_funcs @@ -8,17 +5,14 @@ import ida_funcs from miasm2.core.bin_stream_ida import bin_stream_ida from miasm2.expression import expression as m2_expr 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 -from miasm2.expression.expression import ExprMem, ExprId, ExprInt, ExprOp, ExprAff +from miasm2.expression.expression import ExprId, ExprInt, ExprOp, ExprAff from miasm2.ir.symbexec_types import SymbExecCType from miasm2.expression.parser import str_to_expr -from miasm2.ir.symbexec import SymbolicExecutionEngine, SymbolicState from miasm2.analysis.cst_propag import add_state, propagate_cst_expr from utils import guess_machine @@ -35,9 +29,9 @@ class TypePropagationForm(ida_kernwin.Form): ida_kernwin.Form.__init__(self, r"""BUTTON YES* Launch BUTTON CANCEL NONE -Dependency Graph Settings +Type Propagation Settings <##Header file :{headerFile}> - + {cUnalias}> """, { -- cgit 1.4.1 From 4f0c4d1ea1c96c8546ccb6cf4f1d4a603bb18872 Mon Sep 17 00:00:00 2001 From: William Bruneau Date: Tue, 24 Apr 2018 16:07:59 +0200 Subject: Add some graphical options --- example/ida/ctype_propagation.py | 110 +++++++++++++++++++++++++++++++++------ 1 file changed, 95 insertions(+), 15 deletions(-) (limited to 'example') diff --git a/example/ida/ctype_propagation.py b/example/ida/ctype_propagation.py index 84d9d4bd..9b9c2e95 100644 --- a/example/ida/ctype_propagation.py +++ b/example/ida/ctype_propagation.py @@ -26,27 +26,96 @@ class TypePropagationForm(ida_kernwin.Form): default_types_info = r"""ExprId("RDX", 64): char *""" archs = ["AMD64_unk", "X86_32_unk", "msp430_unk"] + func = ida_funcs.get_func(idc.ScreenEA()) + func_addr = func.startEA + + start_addr = idc.SelStart() + if start_addr == idc.BADADDR: + start_addr = idc.ScreenEA() + end_addr = idc.SelEnd() + ida_kernwin.Form.__init__(self, r"""BUTTON YES* Launch BUTTON CANCEL NONE Type Propagation Settings -<##Header file :{headerFile}> - - + +{FormChangeCb} +Analysis scope: + + +{cScope}> + + + + + + + +<##Header file :{headerFile}> +{cTypeFile}> +<##Types informations :{typeFile}> + + {cUnalias}> """, { - 'headerFile': ida_kernwin.Form.FileInput(swidth=20, open=True), + 'FormChangeCb': ida_kernwin.Form.FormChangeCb(self.OnFormChange), + 'cScope': ida_kernwin.Form.RadGroupControl( + ("rFunction", "rAddr", "r2Addr")), + 'functionAddr': ida_kernwin.Form.NumericInput( + tp=ida_kernwin.Form.FT_RAWHEX, + value=func_addr), + 'startAddr': ida_kernwin.Form.NumericInput( + tp=ida_kernwin.Form.FT_RAWHEX, + value=start_addr), + 'endAddr': ida_kernwin.Form.NumericInput( + tp=ida_kernwin.Form.FT_RAWHEX, + value=end_addr), 'arch': ida_kernwin.Form.DropdownListControl( items=archs, readonly=False, selval=archs[0]), + 'headerFile': ida_kernwin.Form.FileInput(swidth=20, open=True), + 'cTypeFile': ida_kernwin.Form.ChkGroupControl(("rTypeFile",)), + 'typeFile': ida_kernwin.Form.FileInput(swidth=20, open=True), 'strTypesInfo': ida_kernwin.Form.MultiLineTextControl(text=default_types_info, flags=ida_kernwin.Form.MultiLineTextControl.TXTF_FIXEDFONT), 'cUnalias': ida_kernwin.Form.ChkGroupControl(("rUnaliasStack",)), }) form, args = self.Compile() form.rUnaliasStack.checked = True - + form.rTypeFile.checked = True + + def OnFormChange(self, fid): + if fid == -1: # INIT + self.EnableField(self.functionAddr, True) + self.EnableField(self.startAddr, False) + self.EnableField(self.endAddr, False) + self.EnableField(self.strTypesInfo, False) + self.EnableField(self.typeFile, True) + elif fid == self.cTypeFile.id: + if self.GetControlValue(self.cTypeFile) == 0: + self.EnableField(self.strTypesInfo, True) + self.EnableField(self.typeFile, False) + elif self.GetControlValue(self.cTypeFile) == 1: + self.EnableField(self.strTypesInfo, False) + self.EnableField(self.typeFile, True) + elif fid == self.cScope.id: + # "Whole function" scope + if self.GetControlValue(self.cScope) == 0: + self.EnableField(self.functionAddr, True) + self.EnableField(self.startAddr, False) + self.EnableField(self.endAddr, False) + # "From an address" scope + elif self.GetControlValue(self.cScope) == 1: + self.EnableField(self.functionAddr, False) + self.EnableField(self.startAddr, True) + self.EnableField(self.endAddr, False) + # "Between two addresses" scope + elif self.GetControlValue(self.cScope) == 2: + self.EnableField(self.functionAddr, False) + self.EnableField(self.startAddr, True) + self.EnableField(self.endAddr, True) + return 1 def get_types_mngr(headerFile, arch): text = open(headerFile).read() @@ -187,21 +256,25 @@ def analyse_function(): ir_arch = iraCallStackFixer(mdis.symbol_pool) - # Get the current function - func = ida_funcs.get_func(idc.ScreenEA()) - addr = func.startEA - blocks = mdis.dis_multiblock(addr) - # Generate IR - for block in blocks: - ir_arch.add_block(block) - - # Get settings settings = TypePropagationForm(ir_arch) ret = settings.Execute() if not ret: return + if settings.cScope.value == 0: + addr = settings.functionAddr.value + else: + addr = settings.startAddr.value + if settings.cScope.value == 2: + end = settings.endAddr + mdis.dont_dis = [end] + + blocks = mdis.dis_multiblock(addr) + # Generate IR + for block in blocks: + ir_arch.add_block(block) + cst_propag_link = {} if settings.cUnalias.value: init_infos = {ir_arch.sp: ir_arch.arch.regs.regs_init[ir_arch.sp] } @@ -211,7 +284,14 @@ def analyse_function(): types_mngr = get_types_mngr(settings.headerFile.value, settings.arch.value) mychandler = MyCHandler(types_mngr, {}) infos_types = {} - for line in settings.strTypesInfo.value.split('\n'): + infos_types_raw = [] + + if settings.cTypeFile.value: + infos_types_raw = open(settings.typeFile.value).read().split('\n') + else: + infos_types_raw = settings.strTypesInfo.value.split('\n') + + for line in infos_types_raw: if not line: continue expr_str, ctype_str = line.split(':') -- cgit 1.4.1