Beispiel #1
0
    def codeify(self, ea=idc.BADADDR):
        func_count = 0
        code_count = 0

        if ea == idc.BADADDR:
            ea = self.get_start_ea(self.CODE)
            if ea == idc.BADADDR:
                ea = ida_shims.get_first_seg()

        print("\nLooking for undefined code starting at: %s:0x%X" % \
              (ida_shims.get_segm_name(ea), ea))

        while ea != idc.BADADDR:
            try:
                if ida_shims.get_segm_attr(ea, idc.SEGATTR_TYPE) == self.CODE:
                    if ida_shims.get_func_name(ea) != '':
                        ea = ida_shims.find_func_end(ea)
                        continue
                    else:
                        if ida_shims.add_func(ea):
                            func_count += 1
                        elif ida_shims.create_insn(ea):
                            code_count += 1
            except:
                pass

            ea = ida_shims.next_addr(ea)

        print("Created %d new functions and %d new code blocks\n" % \
              (func_count, code_count))
Beispiel #2
0
    def __init__(self, ea):
        self.ea = ea
        self.dword = ida_shims.get_wide_dword(self.ea)
        self.type = None
        self.value = None

        string = ida_shims.get_strlit_contents(self.dword)
        name = ida_shims.get_func_name(self.dword)
        if ida_shims.get_name_ea_simple(name) != self.dword:
            name = ''

        if name:
            self.type = int
            self.value = name
        elif string:
            self.type = str
            self.value = string
Beispiel #3
0
    def _profile_function(self):
        current_ea = ida_shims.get_screen_ea()
        current_function = ida_shims.get_func_name(current_ea)
        current_function_ea = ida_shims.get_name_ea_simple(current_function)

        if current_function:
            self.function = current_function

        ea = ida_shims.get_func_attr(current_function_ea, idc.FUNCATTR_START)
        end_ea = ida_shims.get_func_attr(current_function_ea, idc.FUNCATTR_END)

        self.highlighted = ida_shims.get_highlighted_identifier()

        while ea < end_ea and ea != idc.BADADDR and self.highlighted:
            i = 0
            match = False
            optype = self.READ

            insn = ida_shims.decode_insn(ea)

            mnem = ida_shims.print_insn_mnem(ea)

            if self.highlighted in mnem:
                match = True
            elif idaapi.is_call_insn(ea):
                for xref in idautils.XrefsFrom(ea):
                    if xref.type != 21:
                        name = ida_shims.get_name(xref.to)
                        if name and self.highlighted in name:
                            match = True
                            break
            else:
                while True:
                    opnd = ida_shims.print_operand(ea, i)
                    if opnd:
                        if self.highlighted in opnd:
                            canon_feature = ida_shims.get_canon_feature(insn)
                            match = True
                            if canon_feature & self.OPND_WRITE_FLAGS[i]:
                                optype = self.WRITE
                        i += 1
                    else:
                        break

            if not match:
                comment = idc.GetCommentEx(ea, 0)
                if comment and self.highlighted in comment:
                    match = True
                else:
                    comment = idc.GetCommentEx(ea, 1)
                    if comment and self.highlighted in comment:
                        match = True
                    else:
                        comment = None

            if match:
                if ea > current_ea:
                    direction = self.DOWN
                elif ea < current_ea:
                    direction = self.UP
                else:
                    direction = self.THIS

                self.xrefs[ea] = {
                    'offset': ida_shims.get_func_off_str(ea),
                    'mnem': mnem,
                    'type': optype,
                    'direction': direction,
                    'text': idc.GetDisasm(ea),
                }

            ea = ida_shims.next_head(ea)