Exemplo n.º 1
0
    def make_function(self, object_version, address):
        #
        # call the architecture dependent plugin  ###########
        #
        self.arch_plugin.make_function_prehook(object_version, address)

        flags = object_version.get_object_flags()
        size = object_version.get_size()
        # create function if not already exist

        current_flags = idc.GetFlags(address)
        # if ea is func
        func = idaapi.get_func(address)
        if not idaapi.isFunc(current_flags) or (func is not None and
                                                (func.startEA != address)):
            logger.debug(
                "MakeFunction at 0x%08X : flags=0x%08X, current_flags=0x%08X" %
                (address, flags, current_flags))

            if func is not None:
                logger.debug(
                    "                                       "
                    "func.startEA[0x%08X]!=address func.endEA[0x%08X]!=(address+size[0x%08X])  "
                    % (func.startEA, func.endEA, size))
            if not idc.MakeFunction(address):
                if not idc.isLoaded(address):
                    logger.error(
                        "Failed at idc.MakeFunction at 0x%08X : data not loaded"
                        % address)
                else:
                    logger.error("Failed at idc.MakeFunction at 0x%08X" %
                                 address)
                    self.clear_function(object_version, address)
                    if not idc.MakeFunction(address):
                        logger.error("Failed at idc.MakeFunction at 0x%08X" %
                                     address)

                        #             idc.MakeUnknown(address, size, DOUNK_SIMPLE)
            if idc.AnalyzeArea(address, address + 1) != 1:
                logger.error("[0x%08X] idc.AnalyzeArea failed" % address)

                #             if(idc.AnalyzeArea(address, address+size) != 1):
                #                 logger.error("[0x%08X] idc.AnalyzeArea failed" % address)
                #             if(address == 0x0000000000411558):
                #                 raise Exception()
        if flags is not None:
            idc.SetFunctionFlags(address, flags)

        self.set_type(object_version, address)

        #
        # call the architecture dependent plugin  ###########
        #
        self.arch_plugin.make_function_posthook(object_version, address)
Exemplo n.º 2
0
def walk_datas():
    for seg_start in idautils.Segments():
        seg_end = idc.SegEnd(seg_start)
        for ea in ya.get_all_items(seg_start, seg_end):
            flags = idc.GetFlags(ea)
            func = idaapi.get_func(ea)
            if idaapi.isFunc(flags) or (func and idc.isCode(flags)):
                # function
                continue
            if not func and idc.isCode(flags):
                # code
                continue
            yield ea
Exemplo n.º 3
0
 def renamed(self, ea, new_name, is_local_name):
     if not shared.PAUSE_HOOK:
         log("Name changed: {0}  = {1} | {2}".format(
             hex(ea), new_name, is_local_name))
         flags_of_address = idc.GetFlags(ea)
         if idaapi.isFunc(flags_of_address):
             pass_to_manager(ChangeFunctionNameEvent(ea, new_name))
         elif flags_of_address != 0:
             if is_local_name:
                 pass_to_manager(ChangeLabelNameEvent(ea, new_name))
             else:
                 pass_to_manager(
                     ChangeGlobalVariableNameEvent(ea, new_name,
                                                   not is_local_name))
     return ida_idp.IDB_Hooks.renamed(self, ea, new_name, is_local_name)
Exemplo n.º 4
0
    idbname = re.sub(r'\.i(db|64)$', '_' + tests + '.i\\1', idc.GetIdbPath())
    if tests == 'yatest':
        YaCo.yaco.commit_cache()
    # save intermediate bases
    if debug:
        idc.SaveBase(idbname)

# save generator as global for all tests
# and prevent potential conflicts
_functions = sorted([k for k in idautils.Functions()])
_not_functions = sorted([j for j in  (set([k for k in idautils.Heads()]) - set(_functions))])
_codes = []
_datas = []
for ea in _not_functions:
    flags = idc.GetFlags(ea)
    if idc.isCode(flags) and not idaapi.isFunc(flags):
        _codes.append(ea)
    elif idc.isData(flags):
        _datas.append(ea)

def _get_next_from_list(list_from, predicate=None):
    for i in xrange(0, len(list_from)):
        ea = list_from[i]
        if not predicate or predicate(ea):
            del list_from[i]
            return ea
    raise BaseException(idaapi.BADADDR)
    

def get_next_function(predicate=None):
    return _get_next_from_list(_functions, predicate)