示例#1
0
 def activate(self, ctx):
     for idx in ctx.chooser_selection:
         func_ea = idaapi.getn_func(idx - 1).startEA
         cfunc = helper.decompile_function(func_ea)
         obj = api.VariableObject(cfunc.get_lvars()[0], 0)
         if cfunc:
             NewDeepSearchVisitor(cfunc, 0, obj, cache.temporary_structure).process()
示例#2
0
    def activate(self, ctx):
        hx_view = idaapi.get_widget_vdui(ctx.widget)
        ri = self.extract_recast_info(hx_view.cfunc, hx_view.item)
        if not ri:
            return 0

        if isinstance(ri, RecastLocalVariable):
            hx_view.set_lvar_type(ri.local_variable, ri.recast_tinfo)

        elif isinstance(ri, RecastGlobalVariable):
            idaapi.apply_tinfo2(ri.global_variable_ea, ri.recast_tinfo,
                                idaapi.TINFO_DEFINITE)

        elif isinstance(ri, RecastArgument):
            if ri.recast_tinfo.is_array():
                ri.recast_tinfo.convert_array_to_ptr()
            helper.set_func_argument(ri.func_tinfo, ri.arg_idx,
                                     ri.recast_tinfo)
            idaapi.apply_tinfo2(ri.func_ea, ri.func_tinfo,
                                idaapi.TINFO_DEFINITE)

        elif isinstance(ri, RecastReturn):
            cfunc = helper.decompile_function(ri.func_ea)
            if not cfunc:
                return 0

            func_tinfo = idaapi.tinfo_t()
            cfunc.get_func_type(func_tinfo)
            helper.set_func_return(func_tinfo, ri.recast_tinfo)
            idaapi.apply_tinfo2(cfunc.entry_ea, func_tinfo,
                                idaapi.TINFO_DEFINITE)

        elif isinstance(ri, RecastStructure):
            tinfo = idaapi.tinfo_t()
            tinfo.get_named_type(idaapi.cvar.idati, ri.structure_name)
            ordinal = idaapi.get_type_ordinal(idaapi.cvar.idati,
                                              ri.structure_name)
            if ordinal == 0:
                return 0

            udt_member = idaapi.udt_member_t()
            udt_member.offset = ri.field_offset * 8
            idx = tinfo.find_udt_member(idaapi.STRMEM_OFFSET, udt_member)
            if udt_member.offset != ri.field_offset * 8:
                print("[Info] Can't handle with arrays yet")
            elif udt_member.type.get_size() != ri.recast_tinfo.get_size():
                print("[Info] Can't recast different sizes yet")
            else:
                udt_data = idaapi.udt_type_data_t()
                tinfo.get_udt_details(udt_data)
                udt_data[idx].type = ri.recast_tinfo
                tinfo.create_udt(udt_data, idaapi.BTF_STRUCT)
                tinfo.set_numbered_type(idaapi.cvar.idati, ordinal,
                                        idaapi.NTF_REPLACE, ri.structure_name)
        else:
            raise NotImplementedError

        hx_view.refresh_view(True)
        return 0
示例#3
0
    def open_function(self):
        addresses = self.addresses
        if len(addresses) > 1:
            address = helper.choose_virtual_func_address(self.name)
            if not address:
                return
        elif len(addresses) == 1:
            address = addresses[0]
        else:
            return

        if helper.decompile_function(address):
            idaapi.open_pseudocode(address, 0)
        else:
            idaapi.jumpto(address)
示例#4
0
    def activate(self, ctx):
        hx_view = idaapi.get_widget_vdui(ctx.widget)
        if not self.__can_be_part_of_assert(hx_view.cfunc, hx_view.item):
            return

        # So we clicked on function an func argument that is a string. Now we extract
        # argument index and address of assert function
        expr_arg = hx_view.item.it.to_specific_type
        expr_call = hx_view.cfunc.body.find_parent_of(
            expr_arg).to_specific_type
        arg_idx, _ = helper.get_func_argument_info(expr_call, expr_arg)
        assert_func_ea = expr_call.x.obj_ea

        # Iterate through all places where assert function and rename using helper class
        all_callers = helper.get_funcs_calling_address(assert_func_ea)
        for caller_ea in all_callers:
            cfunc = helper.decompile_function(caller_ea)
            if cfunc:
                _RenameUsingAssertVisitor(cfunc, assert_func_ea,
                                          arg_idx).process()

        hx_view.refresh_view(True)