def activate(self, ctx): hx_view = idaapi.get_tform_vdui(ctx.form) address = hx_view.cfunc.entry_ea xref_ea = idaapi.get_first_cref_to(address) xrefs = set() while xref_ea != idaapi.BADADDR: xref_func_ea = idc.GetFunctionAttr(xref_ea, idc.FUNCATTR_START) if xref_func_ea != idaapi.BADADDR: xrefs.add(xref_func_ea) else: print "[Warning] Function not found at 0x{0:08X}".format(xref_ea) xref_ea = idaapi.get_next_cref_to(address, xref_ea) for func_ea in xrefs: visitor = VariableLookupVisitor(address) try: cfunc = idaapi.decompile(func_ea) if cfunc: FunctionTouchVisitor(cfunc).process() visitor.apply_to(cfunc.body, None) for idx in visitor.result: scanner = DeepSearchVisitor(cfunc, 0, idx) scanner.process() for field in scanner.candidates: self.temporary_structure.add_row(field) except idaapi.DecompilationFailure: print "[Warning] Failed to decompile function at 0x{0:08X}".format(xref_ea) DeepSearchVisitor.clear()
def activate(self, ctx): hx_view = idaapi.get_tform_vdui(ctx.form) origin = self.temporary_structure.main_offset var_type = ShallowScanVariable.check(hx_view.item) if var_type == "LOCAL": variable = hx_view.item.get_lvar() # lvar_t index = list(hx_view.cfunc.get_lvars()).index(variable) definition_address = None if variable.is_arg_var else variable.defea # index = list(hx_view.cfunc.get_lvars()).index(variable) if FunctionTouchVisitor(hx_view.cfunc).process(): hx_view.refresh_view(True) # Because index of the variable can be changed after touching, we would like to calculate it appropriately lvars = hx_view.cfunc.get_lvars() if definition_address: index = next(x for x in xrange(len(lvars)) if lvars[x].defea == definition_address) scanner = DeepSearchVisitor(hx_view.cfunc, origin, index=index) elif var_type == "GLOBAL": gvar = hx_view.item.it.to_specific_type name = idc.GetTrueName(gvar.obj_ea) tinfo = gvar.type if FunctionTouchVisitor(hx_view.cfunc).process(): hx_view.refresh_view(True) scanner = DeepSearchVisitor(hx_view.cfunc, origin, global_variable=(name, tinfo)) else: return scanner.process() for field in scanner.candidates: self.temporary_structure.add_row(field) scanner.clear()
def scan(self, hx_view, variable): if variable and Helper.is_legal_type(variable.type()): definition_address = None if variable.is_arg_var else variable.defea index = list(hx_view.cfunc.get_lvars()).index(variable) # index = list(hx_view.cfunc.get_lvars()).index(variable) if FunctionTouchVisitor(hx_view.cfunc).process(): hx_view.refresh_view(True) # Because index of the variable can be changed after touching, we would like to calculate it appropriately lvars = hx_view.cfunc.get_lvars() if definition_address: index = next(x for x in xrange(len(lvars)) if lvars[x].defea == definition_address) scanner = DeepSearchVisitor(hx_view.cfunc, self.temporary_structure.main_offset, index) scanner.process() for field in scanner.candidates: self.temporary_structure.add_row(field) scanner.clear()