예제 #1
0
    def add_item(self, current_root, ea):
        name = idaapi.get_true_name(int(ea), int(ea))
        new_item = QtWidgets.QTreeWidgetItem(current_root)
        new_item.setText(0, "%s" % name)
        new_item.setText(1, "%x" % ea)

        return new_item
예제 #2
0
def name(fn, name=None):
    fn = by(fn)
    if name is None:
        res = idaapi.get_func_name(fn.startEA)
        if not res: res = idaapi.get_name(-1, fn.startEA)
        if not res: res = idaapi.get_true_name(fn.startEA, fn.startEA)
        return res
    return idaapi.set_name(fn.startEA, name, idaapi.SN_PUBLIC)
예제 #3
0
def name(fn, name=None):
    fn = by(fn)
    if name is None:
        res = idaapi.get_func_name(fn.startEA)
        if not res: res = idaapi.get_name(-1, fn.startEA)
        if not res: res = idaapi.get_true_name(fn.startEA, fn.startEA)
        return res
    return idaapi.set_name(fn.startEA, name, idaapi.SN_PUBLIC)
예제 #4
0
    def getName(ea):
        '''fetches the function name, or the global name'''
        res = idaapi.get_func_name(ea)
        if res is None:
            res = idaapi.get_name(-1, ea)
        if res is None:
            res = idaapi.get_true_name(ea, ea)

        # if name is mangled...  and version <= 6.4
        if res and res.startswith('@'):
            return '$'+res
        return res
예제 #5
0
    def getName(ea):
        '''fetches the function name, or the global name'''
        res = idaapi.get_func_name(ea)
        if res is None:
            res = idaapi.get_name(-1, ea)
        if res is None:
            res = idaapi.get_true_name(ea, ea)

        # if name is mangled...  and version <= 6.4
        if res and res.startswith('@'):
            return '$' + res
        return res
예제 #6
0
def main():
    address = idaapi.askaddr(idaapi.get_imagebase() + 0x19000,
                             "Enter address of table: ")
    if (address != None):
        idx = 0
        while (address != BADADDR):
            name = idaapi.get_true_name(BADADDR, Qword(address))
            if not name:
                break
            printf("[%04d] %s = %X\n", idx, name, Qword(address))
            address += 8 if idaapi.get_inf_structure().is_64bit() else 4
            idx += 1
예제 #7
0
def get_function_name(function_address):
    """
    Get a function's true name.
    """

    # get the original function name from the database
    if using_ida7api:
        original_name = idaapi.get_name(function_address)
    else:
        original_name = idaapi.get_true_name(idaapi.BADADDR, function_address)

    # sanity check
    if original_name == None:
        raise ValueError("Invalid function address")

    # return the function name
    return original_name
예제 #8
0
def name(key=None, name=None):
    '''Returns the name of the function or import identified by key.'''
    rt,ea = __addressOfRtOrSt(ui.current.address() if key is None else key)
    if rt:   
        if name is None:
            res = idaapi.get_name(-1, ea)
            return internal.declaration.extract.fullname(internal.declaration.demangle(res)) if res.startswith('?') else res
        # FIXME: shuffle the new name into the prototype and then re-mangle it
        return database.name(ea, name)

    if name is None:
        res = idaapi.get_func_name(ea)
        if not res: res = idaapi.get_name(-1, ea)
        if not res: res = idaapi.get_true_name(ea, ea)
        return internal.declaration.extract.fullname(internal.declaration.demangle(res)) if res.startswith('?') else res
        #return internal.declaration.extract.name(internal.declaration.demangle(res)) if res.startswith('?') else res
    return idaapi.set_name(ea, name, idaapi.SN_PUBLIC)
예제 #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
예제 #10
0
 def get_function_raw_name_at(self, function_address):
     if self.USING_IDA7API:
         return idaapi.get_name(function_address)
     return idaapi.get_true_name(idaapi.BADADDR, function_address)
예제 #11
0
 def tag_read(ea, key=None, repeatable=0):
     res = idaapi.get_cmt(ea, int(bool(repeatable)))
     dict = internal.comment.toDict(res)
     name = idaapi.get_true_name(-1, ea)
     if name is not None: dict.setdefault('name', name)
     return dict if key is None else dict[key]