Esempio n. 1
0
    def __init__(self, func):
        self.src = func
        ea = func.startEA
        self.ea = ea
        self.name = idaapi.get_func_name(ea)

        self.elts = []

        if idaapi.is_func_tail(func):
            self.name += "_tail_" + str(ea)

        fr = idaapi.get_frame(func)
        struc_vars = []
        if fr == None:
            self.frame = None
        else:
            self.frame = struct.frame_node(fr, func)
            struc_vars = self.frame.struct_vars

        while ea < func.endEA:
            if idaapi.isData(idaapi.getFlags(ea)):
                self.elts.append(data.data_node(ea, idaapi.next_not_tail(ea)))
            else:
                if ea == func.startEA and not (idaapi.is_func_tail(func)):
                    self.elts.append(insn.insn_node(ea, struc_vars))
                else:
                    self.elts.append(
                        names.name_wrap_insn(ea,
                                             insn.insn_node(ea, struc_vars)))

            ea = idaapi.next_head(ea, func.endEA)
Esempio n. 2
0
    def __init__(self, func):
        self.src = func
        ea = func.startEA
        self.ea = ea
        self.name = idaapi.get_func_name(ea)

        self.elts = []

        if idaapi.is_func_tail(func):
            self.name += "_tail_"+str(ea)

        fr = idaapi.get_frame(func)
        struc_vars = []
        if fr == None:
            self.frame = None
        else:
            self.frame = struct.frame_node(fr, func)
            struc_vars = self.frame.struct_vars

        while ea < func.endEA:
            if idaapi.isData(idaapi.getFlags(ea)):
                self.elts.append(data.data_node(ea, idaapi.next_not_tail(ea)))
            else:
                if ea == func.startEA and not (idaapi.is_func_tail(func)):
                    self.elts.append(insn.insn_node(ea, struc_vars))
                else:
                    self.elts.append(names.name_wrap_insn(ea, insn.insn_node(ea, struc_vars)))

            ea = idaapi.next_head(ea, func.endEA)
Esempio n. 3
0
    def __init__(self, low, high):
        self.elts = []

        ea = low
        while ea < high:
            #if idaapi.isStruct(idaapi.getFlags(ea)):
            #    self.elts.append(struct_instance_node(ea))
            #else:
            self.elts.append(general.verbatim_node(ea))
            ea = idaapi.next_not_tail(ea)
Esempio n. 4
0
def NotTails(*args):
    """
    Enumerate array items

    @param <range>: see getrange

    @return: list of all not-tails

    Note that NotTails includes all Heads plus all undefined bytes

    """
    (first, last) = getrange(args)

    ea = first
    if ea < last and idaapi.is_tail(idaapi.get_full_flags(ea)):
        ea = idaapi.next_not_tail(ea)
    while ea != BADADDR and ea < last:
        yield ea
        ea = idaapi.next_not_tail(ea)
Esempio n. 5
0
 def __init__(self, low, high):
     self.elts = []
     
     ea = low
     while ea < high:
         #if idaapi.isStruct(idaapi.getFlags(ea)):
         #    self.elts.append(struct_instance_node(ea))
         #else:
         self.elts.append(names.name_wrap_data(ea,general.verbatim_node(ea)))
         ea = idaapi.next_not_tail(ea)
Esempio n. 6
0
def NotTails(*args):
    """
    Enumerate array items

    @param <range>: see getrange

    @return: list of all not-tails

    Note that NotTails includes all Heads plus all undefined bytes

    """
    (first, last)= getrange(args)

    ea= first
    if ea<last and idaapi.isTail(idaapi.getFlags(ea)):
        ea= idaapi.next_not_tail(ea)
    while ea!=BADADDR and ea<last:
        yield ea
        ea= idaapi.next_not_tail(ea)
Esempio n. 7
0
    def __init__(self, node, node_id):
        self.address       = node.startEA
        self.size          = node.endEA - node.startEA
        self.id            = node_id
        self.instructions  = 0

        # loop through the node's entire range and count its instructions
        current_address = self.address
        while node.endEA > current_address:
            self.instructions += 1
            current_address = idaapi.next_not_tail(current_address)
Esempio n. 8
0
def color_items(address, size, color):
    """
    Color a region of bytes as specified by address and size.
    """

    # loop through the entire region (address -> address+size) coloring lines
    while size > 0:

        # color the current item
        idaapi.set_item_color(address, color)

        # move forward to the next item
        next_address = idaapi.next_not_tail(address)
        size -= next_address - address
        address = next_address
Esempio n. 9
0
def create_func_signature(start, length):
    """Return function signature in mega format."""
    if length < MIN_SIG_LENGTH:
        return

    ea = start
    end = start + length
    sig = ""
    publics = []
    refs = {}
    v = [False for _ in range(length)]

    while (ea - start < length):
        flags = idaapi.getFlags(ea)
        if idaapi.has_name(flags):
            publics.append(ea)

        ref = idaapi.get_first_dref_from(ea)
        if ref != idaapi.BADADDR:
            ref_loc = ea
            set_v_bytes(v, ref_loc - start)
            refs[ref_loc] = ref

            # Check if there is a second data location ref'd
            ref = idaapi.get_next_dref_from(ea, ref)
            if ref != idaapi.BADADDR:
                ref_loc = ea
                set_v_bytes(v, ref_loc - start)
                refs[ref_loc] = ref
        else:
            # Code ref?
            ref = idaapi.get_first_fcref_from(ea)
            if ref != idaapi.BADADDR:
                if not start <= ref < end:
                    ref_loc = ea
                    set_v_bytes(v, ref_loc - start)
                    refs[ref_loc] = ref

            # Check for r13 and rtoc
            disasm = idaapi.generate_disasm_line(ea)
            if "%r13" in disasm or "%rtoc" in disasm:
                ref_loc = ea
                set_v_bytes(v, ref_loc - start)

        ea = idaapi.next_not_tail(ea)

    line = ""
    for i in range(length):
        if v[i]:
            line += ".."
        else:
            line += "{:02X}".format(idaapi.get_byte(start + i))

    # Write publics
    found = False
    for public in sorted(publics):
        name = idaapi.get_true_name(idaapi.BADADDR, public)
        if name:
            found = True
            if is_skipped(name):
                idaapi.warning("Rename the function {} ({})!".format(
                    name, "it is on the skip list"))
                return
            else:
                line += " :{:04X} {}".format(public - start, name)

    if not found:
        idaapi.warning("The function has autogenerated name, rename it first!")

    # Write refs
    for ref_loc, ref in sorted(refs.items()):
        name = idaapi.get_true_name(idaapi.BADADDR, ref)
        if name:
            if not is_skipped(name) and ref_loc != idaapi.BADADDR:
                line += " ^{:04X} {}".format(ref_loc - start, name)

    return line