Example #1
0
 def populate_function_names(self):
     log_info('Loading functions...')
     with open(self.file_path, "r") as f:
         parsed_json = json.loads(f.read())
         self.tblFunctions.setRowCount(parsed_json['functions_count'])
         index = 0
         for func in parsed_json['functions']:
             self.append_table_item(index, func['address'], func['name'])
             index += 1
     log_info('Finished loading functions.')
Example #2
0
    def populate_function_names(self):
        log_info('Loading functions...')
        total = 0
        for seg in idautils.Segments():
            total += len(list(idautils.Functions(seg, idc.get_segm_end(seg))))

        self.tblFunctions.setRowCount(total)
        index = 0
        for seg in idautils.Segments():
            for func in idautils.Functions(seg, idc.get_segm_end(seg)):
                address = POINTER_FMT.format(func)
                function = idc.get_func_name(func)
                self.append_table_item(index, address, function)
                index += 1
        log_info('Finished loading functions.')
Example #3
0
    def on_start_clicked(self):
        file, ext = os.path.splitext(idc.get_idb_path())
        selected_dir = QFileDialog.getExistingDirectory(
            self, "Select Path to Export Files", os.path.dirname(file))
        if not selected_dir:
            return

        if os.name == 'nt':
            selected_dir = selected_dir.replace('/', '\\')

        file_name = os.path.basename(file)

        datetime = time.strftime("%Y%m%d-%H%M%S")
        file_json = "{}_symbols_{}.json".format(file_name, datetime)
        file_path_json = os.path.join(selected_dir, file_json)
        log_info("Exporting to {}", file_json)
        functions, count = self.process_functions()
        payload = {
            'bpe_info': self.process_pe_info(),
            'functions_count': count,
            'functions': functions
        }
        with open(file_path_json, "w") as f:
            json.dump(payload, f, indent=4, sort_keys=True)

        # NOTE(Gilad): Alternative Solution:
        # Call idc.process_ui_action('ProduceHeader') to produce C header file and then
        # on import idc.process_ui_action('LoadHeaderFile'). Only issue might be with parsing errors.
        # Parsing .IDC file is less error prone in this scenario.
        file_types = "{}_types_{}.idc".format(file_name, datetime)
        file_path_types = os.path.join(selected_dir, file_types)
        if not idc.gen_file(idc.OFILE_IDC, file_types, 0, idc.BADADDR,
                            idc.GENFLG_IDCTYPE):
            QMessageBox.error(self, "FAILED",
                              "Failed to generate type information file.")
        os.rename(file_types, file_path_types)

        QMessageBox.information(
            self, "Successfully Exported", """Exported path:\n{}\n{}
                                \nYou can now use the Importer and select these files to import in another database instance."""
            .format(file_path_json, file_path_types))
Example #4
0
    def on_start_clicked(self):
        count = self.rename_functions()
        log_info("{} functions has been renamed.", count)

        answer = QMessageBox.question(
            self, 'Yes | No',
            """Would you like to import type information as well? (structs, enums)
                \nYou will need to provide the exported IDC file.""",
            QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)

        if answer == QMessageBox.Yes:
            # idc.process_ui_action('Execute')
            dir_path = os.path.dirname(idc.get_idb_path())
            file_path, _ = QFileDialog.getOpenFileName(
                self, "Select File to Import", dir_path, "IDC Script (*.idc)")
            if file_path:
                ida_expr.exec_idc_script(None, str(file_path), "main", None, 0)

        QMessageBox.information(
            self, "Successfully Imported",
            "Successfully renamed {} functions.".format(count))
Example #5
0
    def rename_functions(self):
        row_count = self.tblFunctions.rowCount()
        renamed_count = 0
        for row in range(row_count):
            cbx = self.tblFunctions.item(row, col_CheckBox)
            if not cbx or cbx.checkState() != Qt.Checked:
                continue

            address_str = self.tblFunctions.item(row, col_Address).text()
            address = int(address_str, 16)
            name = self.tblFunctions.item(row, col_Name).text()
            curr_name = idc.get_func_name(address)
            if not name or not curr_name or name == curr_name:
                continue

            if idaapi.set_name(address, str(name), idaapi.SN_NOWARN):
                log_info("{} - Renamed {} to {}", address_str, curr_name, name)
                renamed_count += 1
            else:
                log_info("Failed renaming: {}. Disable SN_NOWARN to see why.",
                         address_str)

        return renamed_count
 def on_start_clicked(self):
     log_info("BASE - on_start_clicked")
 def populate_function_names(self):
     log_info("BASE - populate_function_names")
Example #8
0
 def init(self):
     log_info("Successfully loaded plugin - v{}", VERSION)
     return idaapi.PLUGIN_KEEP