Esempio n. 1
0
 def setData(self, index, value, role):
     row, col = index.row(), index.column()
     if role == QtCore.Qt.EditRole and idaapi.isident(str(value)):
         self.items[row].name = str(value)
         self.dataChanged.emit(index, index)
         return True
     return False
Esempio n. 2
0
 def setData(self, column, value):
     if column == 0:
         if idaapi.isident(value) and self.name != value:
             self.name = value
             self.modified = True
             return True
     return False
Esempio n. 3
0
    def rename_regex(self, n, regex_str="", dryrun=False):
        count = 0
        if not regex_str:
            regex_str = idc.AskStr("", "Regex rename rule")

        if regex_str:
            if dryrun:
                print "Testing regex rename rule: '%s'" % regex_str

            regex = re.compile(regex_str)

            # Look at all the profiled functions
            for (function, xrefs) in self.profile.functions.iteritems():
                new_function_name = ""

                # Don't rename functions that have already been renamed
                if not idc.Name(function).startswith("sub_"):
                    continue

                # Look through all the strings referenced by this function
                for string in [x.string for x in xrefs if x.type == str]:

                    # Does the string match the given regex?
                    m = regex.search(string)
                    if m:
                        # Take the last group from the regex match
                        potential_function_name = m.groups()[-1].split(" ")[0]

                        # Replace common bad chars with underscores
                        for c in ['-', '>']:
                            potential_function_name = potential_function_name.replace(
                                c, '_')

                        # Make sure this is a valid name; should not include format strings
                        if idaapi.isident(
                                potential_function_name
                        ) and '%' not in potential_function_name:
                            # Use the longest of the matching strings
                            if len(potential_function_name) > len(
                                    new_function_name):
                                new_function_name = potential_function_name

                if new_function_name:
                    # Append _n to the function name, if it already exists
                    n = 1
                    orig_new_function_name = new_function_name
                    while idc.LocByName(new_function_name) != idc.BADADDR:
                        new_function_name = "%s_%d" % (orig_new_function_name,
                                                       n)
                        n += 1

                    if dryrun:
                        print "%s => %s" % (idc.Name(function),
                                            new_function_name)
                        count += 1
                    else:
                        if idc.MakeName(function, new_function_name):
                            count += 1

            print "Renamed %d functions" % count
Esempio n. 4
0
    def rename_regex(self, n, regex_str="", dryrun=False):
        count = 0
        if not regex_str:
            regex_str = idc.AskStr("", "Regex rename rule")

        if regex_str:
            if dryrun:
                print "Testing regex rename rule: '%s'" % regex_str

            regex = re.compile(regex_str)

            # Look at all the profiled functions
            for (function, xrefs) in self.profile.functions.iteritems():
                new_function_name = ""

                # Don't rename functions that have already been renamed
                if not idc.Name(function).startswith("sub_"):
                    continue

                # Look through all the strings referenced by this function
                for string in [x.string for x in xrefs if x.type == str]:

                    # Does the string match the given regex?
                    m = regex.search(string)
                    if m:
                        # Take the last group from the regex match
                        potential_function_name = m.groups()[-1].split(" ")[0]

                        # Replace common bad chars with underscores
                        for c in ["-", ">"]:
                            potential_function_name = potential_function_name.replace(c, "_")

                        # Make sure this is a valid name; should not include format strings
                        if idaapi.isident(potential_function_name) and "%" not in potential_function_name:
                            # Use the longest of the matching strings
                            if len(potential_function_name) > len(new_function_name):
                                new_function_name = potential_function_name

                if new_function_name:
                    # Append _n to the function name, if it already exists
                    n = 1
                    orig_new_function_name = new_function_name
                    while idc.LocByName(new_function_name) != idc.BADADDR:
                        new_function_name = "%s_%d" % (orig_new_function_name, n)
                        n += 1

                    if dryrun:
                        print "%s => %s" % (idc.Name(function), new_function_name)
                        count += 1
                    else:
                        if idc.MakeName(function, new_function_name):
                            count += 1

            print "Renamed %d functions" % count
Esempio n. 5
0
    def rename_regex(self, n, regex_str="", dryrun=False):
        count = 0
        if not regex_str:
            regex_str = idc.AskStr("", "Regex rename rule")

        if regex_str:
            if dryrun:
                print "Testing regex rename rule: '%s'" % regex_str

            regex = re.compile(regex_str)

            for (function, xrefs) in self.profile.functions.iteritems():
                new_function_name = ""
                if not idc.Name(function).startswith("sub_"):
                    continue

                for string in [x.string for x in xrefs if x.type == str]:
                    m = regex.search(string)
                    if m:
                        potential_function_name = m.groups()[-1].split(" ")[0]
                        for c in ['-', '>']:
                            potential_function_name = \
                                potential_function_name.replace(c, '_')

                        if idaapi.isident(potential_function_name) and \
                                '%' not in potential_function_name:
                            if len(potential_function_name) > len(new_function_name):
                                new_function_name = potential_function_name

                if new_function_name:
                    # Append _n to the function name, if it already exists
                    n = 1
                    orig_new_function_name = new_function_name
                    while idc.LocByName(new_function_name) != idc.BADADDR:
                        new_function_name = "%s_%d" % (orig_new_function_name,
                                                       n)
                        n += 1

                    if dryrun:
                        print "%s => %s" % (idc.Name(function),
                                            new_function_name)
                        count += 1
                    else:
                        if ida_shims.set_name(function, new_function_name):
                            count += 1

            print "Renamed %d functions" % count
Esempio n. 6
0
 def setData(self, column, value):
     if column == 0:
         if idaapi.isident(value) and self.name != value:
             self.name = value
             self.name_modified = True
             for parent in self.parents:
                 parent.modified = True
             return True
     elif column == 1:
         tinfo = idaapi.tinfo_t()
         split = value.split('(')
         if len(split) == 2:
             value = split[0] + ' ' + self.name + '(' + split[1] + ';'
             if idaapi.parse_decl2(idaapi.cvar.idati, value, '', tinfo, idaapi.PT_TYP):
                 if tinfo.is_func():
                     tinfo.create_ptr(tinfo)
                     if tinfo.dstr() != self.tinfo.dstr():
                         self.tinfo = tinfo
                         self.tinfo_modified = True
                         for parent in self.parents:
                             parent.modified = True
                         return True
     return False