main
serr 2025-03-16 17:20:45 +03:00
commit b0b7c7b140
5 changed files with 137 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
venv
.xlsx

Binary file not shown.

89
comp.py Normal file
View File

@ -0,0 +1,89 @@
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()

46
i64tosqlite.py Normal file
View File

@ -0,0 +1,46 @@
import os
import subprocess
def create_sqlite_from_i64(ida_executable, i64_path, diaphora_script_path, output_sqlite_path):
"""
Создаёт SQLite базу данных из .i64 базы данных с использованием Diaphora.
Пример использования в блоке if __name__ == "__main__"
"""
if not os.path.exists(ida_executable):
raise FileNotFoundError(f"IDA executable not found: {ida_executable}")
if not os.path.exists(i64_path):
raise FileNotFoundError(f".i64 file not found: {i64_path}")
if not os.path.exists(diaphora_script_path):
raise FileNotFoundError(f"Diaphora script not found: {diaphora_script_path}")
# Формируем команду для запуска IDA Pro с Diaphora
cmd = [
ida_executable,
"-A", # Автоматический режим (без GUI)
f"-S{diaphora_script_path}", # Скрипт Diaphora
i64_path # Входной .i64 файл
]
# Устанавливаем переменные окружения для Diaphora
env = {
"DIAPHORA_AUTO": "1", # Автоматический режим
"DIAPHORA_USE_DECOMPILER": "1", # Использовать декомпилятор (если доступен)
"DIAPHORA_EXPORT_FILE": output_sqlite_path, # Путь для сохранения SQLite
}
try:
subprocess.run(cmd, env=env, check=True)
print(f"SQLite database successfully created: {output_sqlite_path}")
except subprocess.CalledProcessError as e:
print(f"Error creating SQLite database: {e}")
except Exception as e:
print(f"Unknown error: {e}")
if __name__ == "__main__":
ida_executable = r"C:\tools\IDA\ida.exe" # Путь к IDA Pro
i64_path = r"C:\tools\ilya.exe.i64" # Путь к .i64 файлу
diaphora_script_path = r"C:\tools\diaphora\diaphora_ida.py" # Путь к скрипту Diaphora
output_sqlite_path = r"C:\tools\123.exe.sqlite" # Путь для сохранения SQLite
create_sqlite_from_i64(ida_executable, i64_path, diaphora_script_path, output_sqlite_path)

BIN
output.xlsx Normal file

Binary file not shown.