Ejemplo n.º 1
0
def Functions(start=None, end=None):
    """
    Get a list of functions

    @param start: start address (default: inf.minEA)
    @param end:   end address (default: inf.maxEA)

    @return: list of heads between start and end

    @note: The last function that starts before 'end' is included even
    if it extends beyond 'end'. Any function that has its chunks scattered
    in multiple segments will be reported multiple times, once in each segment
    as they are listed.
    """
    if not start: start = idaapi.cvar.inf.minEA
    if not end: end = idaapi.cvar.inf.maxEA

    # find first function head chunk in the range
    chunk = idaapi.get_fchunk(start)
    if not chunk:
        chunk = idaapi.get_next_fchunk(start)
    while chunk and chunk.startEA < end and (chunk.flags
                                             & idaapi.FUNC_TAIL) != 0:
        chunk = idaapi.get_next_fchunk(chunk.startEA)
    func = chunk

    while func and func.startEA < end:
        startea = func.startEA
        yield startea
        func = idaapi.get_next_func(startea)
Ejemplo n.º 2
0
def Functions(start=None, end=None):
    """
    Get a list of functions

    @param start: start address (default: inf.minEA)
    @param end:   end address (default: inf.maxEA)

    @return: list of heads between start and end

    @note: The last function that starts before 'end' is included even
    if it extends beyond 'end'. Any function that has its chunks scattered
    in multiple segments will be reported multiple times, once in each segment
    as they are listed.
    """
    if not start: start = idaapi.cvar.inf.minEA
    if not end:   end = idaapi.cvar.inf.maxEA

    # find first function head chunk in the range
    chunk = idaapi.get_fchunk(start)
    if not chunk:
        chunk = idaapi.get_next_fchunk(start)
    while chunk and chunk.startEA < end and (chunk.flags & idaapi.FUNC_TAIL) != 0:
        chunk = idaapi.get_next_fchunk(chunk.startEA)
    func = chunk

    while func and func.startEA < end:
        startea = func.startEA
        yield startea
        func = idaapi.get_next_func(startea)
Ejemplo n.º 3
0
def _first_func_addr():
    """
    Get addr of the first function.
    IDA read thread safe.
    """
    logger.debug('_first_func_addr')
    if not start: start = idaapi.cvar.inf.minEA
    if not end:   end = idaapi.cvar.inf.maxEA

    # find first function head chunk in the range
    chunk = idaapi.get_fchunk(start)
    if not chunk:
        chunk = idaapi.get_next_fchunk(start)
    while chunk and chunk.startEA < end and (chunk.flags & idaapi.FUNC_TAIL) != 0:
        chunk = idaapi.get_next_fchunk(chunk.startEA)
    func = chunk
    return int(func.startEA)
Ejemplo n.º 4
0
def FChunks(*args):
    """
    Enumerate array items

    @param <range>: see getrange

    @return: list of all function chunks in an address range.

    For the list of all chunks in a function use idautils.Chunks

    """
    (first, last) = getrange(args)
    chunk = idaapi.get_fchunk(first)
    if not chunk:
        chunk = idaapi.get_next_fchunk(first)
    while chunk and chunk.start_ea < last:
        yield chunk.start_ea
        chunk = idaapi.get_next_fchunk(chunk.start_ea)
Ejemplo n.º 5
0
def _first_func_addr():
    """
    Get addr of the first function.
    IDA read thread safe.
    """
    logger.debug('_first_func_addr')
    if not start: start = idaapi.cvar.inf.minEA
    if not end: end = idaapi.cvar.inf.maxEA

    # find first function head chunk in the range
    chunk = idaapi.get_fchunk(start)
    if not chunk:
        chunk = idaapi.get_next_fchunk(start)
    while chunk and chunk.startEA < end and (chunk.flags
                                             & idaapi.FUNC_TAIL) != 0:
        chunk = idaapi.get_next_fchunk(chunk.startEA)
    func = chunk
    return int(func.startEA)
Ejemplo n.º 6
0
def FChunks(*args):
    """
    Enumerate array items

    @param <range>: see getrange

    @return: list of all function chunks in an address range.

    For the list of all chunks in a function use idautils.Chunks

    """
    (first, last)= getrange(args)
    chunk = idaapi.get_fchunk(first)
    if not chunk:
        chunk = idaapi.get_next_fchunk(first)
    while chunk and chunk.startEA < last:
        yield chunk.startEA
        chunk = idaapi.get_next_fchunk(chunk.startEA)
Ejemplo n.º 7
0
def Funcs(*args):
    """
    Enumerate array items

    @param <range>: see getrange

    @return: list of all function starts

    """
    (first, last)= getrange(args)
    # find first function head chunk in the range
    chunk = idaapi.get_fchunk(first)
    if not chunk:
        chunk = idaapi.get_next_fchunk(first)
    while chunk and chunk.startEA < last and (chunk.flags & idaapi.FUNC_TAIL) != 0:
        chunk = idaapi.get_next_fchunk(chunk.startEA)
    func = chunk

    while func and func.startEA < last:
        yield func.startEA
        func = idaapi.get_next_func(func.startEA)
Ejemplo n.º 8
0
def Funcs(*args):
    """
    Enumerate array items

    @param <range>: see getrange

    @return: list of all function starts

    """
    (first, last) = getrange(args)
    # find first function head chunk in the range
    chunk = idaapi.get_fchunk(first)
    if not chunk:
        chunk = idaapi.get_next_fchunk(first)
    while chunk and chunk.start_ea < last and (chunk.flags
                                               & idaapi.FUNC_TAIL) != 0:
        chunk = idaapi.get_next_fchunk(chunk.start_ea)
    func = chunk

    while func and func.start_ea < last:
        yield func.start_ea
        func = idaapi.get_next_func(func.start_ea)
Ejemplo n.º 9
0
def NonFuncs(*args):
    """
    Enumerate code which is not in a function

    @param <range>: see getrange

    @return: list of addresses containing code, but not in a function

    Example::

        for ea in NonFuncs((FirstSeg(), BADADDR)):
            if not MakeFunction(ea):
                Jump(ea)
                break
            Wait()

    Will try to change non-function code to function
    until MakeFunction fails
    """

    (first, last) = getrange(args)

    ea = first
    while ea != idaapi.BADADDR and ea < last:
        nextcode = idaapi.find_code(ea,
                                    idaapi.SEARCH_NEXT | idaapi.SEARCH_DOWN)
        thischunk = idaapi.get_fchunk(ea)
        nextchunk = idaapi.get_next_fchunk(ea)
        if thischunk:
            ea = thischunk.end_ea
        elif idaapi.is_code(idaapi.get_full_flags(ea)):
            yield ea
            ea = idaapi.next_head(ea, last)
        elif nextchunk is None:
            return
        elif nextcode < nextchunk.start_ea:
            yield nextcode
            ea = nextcode
        else:
            ea = nextchunk.end_ea
Ejemplo n.º 10
0
def NonFuncs(*args):
    """
    Enumerate code which is not in a function

    @param ea:    where to start
    @param endea: BADADDR, or end address

    @return: list of addresses containing code, but not in a function

    Example::

        for ea in NonFuncs(FirstSeg(), BADADDR):
            if not MakeFunction(ea):
                Jump(ea)
                break
            Wait()

    Will try to change non-function code to function
    until MakeFunction fails
    """

    (first, last)= getrange(args)

    ea = first
    while ea!=idaapi.BADADDR and ea<last:
        nextcode= idaapi.find_code(ea, idaapi.SEARCH_NEXT|idaapi.SEARCH_DOWN)
        thischunk= idaapi.get_fchunk(ea)
        nextchunk= idaapi.get_next_fchunk(ea)
        if thischunk:
            ea= thischunk.endEA
        elif idaapi.isCode(idaapi.getFlags(ea)):
            yield ea
            ea= idaapi.next_head(ea, last)
        elif nextchunk is None:
            return
        elif nextcode<nextchunk.startEA:
            yield nextcode
            ea= nextcode
        else:
            ea= nextchunk.endEA