import sqlite3 import os, time import subprocess # для работы с ida from i64tosqlite import create_sqlite_from_i64 # для работы с excel import pandas as pd from openpyxl.styles import PatternFill from openpyxl import load_workbook # def main(): # эти пути необходимо задавать вручную ida_executable = r"C:\tools\IDA\ida.exe" diaphora_dir = r"C:\tools\diaphora" i64_1_path = r"C:\tools\ilya.exe.i64" i64_2_path = r"C:\tools\my.exe.i64" # # генерация sqlite базы из i64 start = time.perf_counter() diaphora_script_path = diaphora_dir + r"\diaphora_ida.py" diaphora_path = diaphora_dir + r"\diaphora.py" sqlite1_path = i64_1_path+'.sqlite' sqlite2_path = i64_2_path+'.sqlite' create_sqlite_from_i64(ida_executable, i64_1_path, diaphora_script_path, sqlite1_path) create_sqlite_from_i64(ida_executable, i64_2_path, diaphora_script_path, sqlite2_path) # # создание выходного файла sql_output_path = r'result.sqlite' excel_output_path = r'output.xlsx' generate_output_db(diaphora_path, sqlite1_path, sqlite2_path, sql_output_path) result_data = read_results_table(sql_output_path) elapsed = time.perf_counter() - start # # удаляю ненужное os.remove(sqlite1_path) os.remove(sqlite2_path) os.remove(sql_output_path) # export_to_excel(result_data, excel_output_path, elapsed) print(f"\033[92mResults exported to\033[0m {excel_output_path}") print(f'\033[92mAnalysis time\033[0m {elapsed} sec') os.startfile(excel_output_path) def generate_output_db(diaphora_path, sqlite1_path, sqlite2_path, output_path): cmd = f'py {diaphora_path} {sqlite1_path} {sqlite2_path} -o {output_path}' try: # capture_output=True подавляет вывод сообщений от субпроцесса subprocess.run(cmd, check=True, capture_output=True) print(f"\033[92mSuccess subprocess run\033[0m") except subprocess.CalledProcessError as e: print(f"\033[31mError subprocess run: {e.stderr}\033[0m") def read_results_table(output_path): conn = sqlite3.connect(output_path) cursor = conn.cursor() cursor.execute("SELECT * FROM results") rows = cursor.fetchall() columns = [description[0] for description in cursor.description] result_list = [] for row in rows: result_list.append(dict(zip(columns, row))) conn.close() return result_list def export_to_excel(result_data, excel_output_path, elapsed_time): df = pd.DataFrame(result_data) df = df[['type', 'name', 'name2', 'description']] df['matches'] = ' ' df['elapsed'] = ' ' df.at[0, 'matches'] = len(result_data) df.at[0, 'elapsed'] = f'{elapsed_time:.2f} sec' df.to_excel(excel_output_path, index=False) wb = load_workbook(excel_output_path) ws = wb.active green_fill = PatternFill(start_color="90EE00", end_color="90EE00", fill_type="solid") light_green_fill = PatternFill(start_color="90EE90", end_color="90EE90", fill_type="solid") ws['E2'].fill = green_fill ws['F2'].fill = light_green_fill wb.save(excel_output_path) if __name__ == "__main__": main()