From ce4acec8d9d67f1c03ec8b55e1b2453503069cee Mon Sep 17 00:00:00 2001 From: Sigma-Ohio Date: Mon, 9 Jun 2025 03:35:52 +0200 Subject: went insane --- research/bad-bruteforcing/inspecto.py | 77 +++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 research/bad-bruteforcing/inspecto.py (limited to 'research/bad-bruteforcing/inspecto.py') diff --git a/research/bad-bruteforcing/inspecto.py b/research/bad-bruteforcing/inspecto.py new file mode 100644 index 0000000..37dc3d6 --- /dev/null +++ b/research/bad-bruteforcing/inspecto.py @@ -0,0 +1,77 @@ +import os +from binascii import unhexlify, hexlify +import csv + +def load_samples(folder): + msgs, crcs, rawhex = [], [], [] + for fn in os.listdir(folder): + path = os.path.join(folder, fn) + with open(path, 'r') as f: + for line in f: + if '=' not in line: + continue + try: + h, c = line.strip().split('=') + data = list(unhexlify(h)) + chk = int(c, 16) + msgs.append(data) + crcs.append(chk) + rawhex.append(h.upper()) + except Exception: + continue + return msgs, crcs, rawhex + +def bit_diff(a, b): + return ''.join(['↑' if (a ^ b) & (1 << i) else '.' for i in reversed(range(8))]) + +def analyze(msgs, crcs, rawhex): + base_msg, base_crc = msgs[0], crcs[0] + base_hex = rawhex[0] + rows = [] + for idx, (msg, crc, raw) in enumerate(zip(msgs[1:], crcs[1:], rawhex[1:]), start=1): + maxlen = max(len(base_msg), len(msg)) + for i in range(maxlen): + b0 = base_msg[i] if i < len(base_msg) else None + b1 = msg[i] if i < len(msg) else None + if b0 != b1: + delta_crc = (crc - base_crc) & 0xFF + xor_crc = crc ^ base_crc + b0_str = f"{b0:02X}" if b0 is not None else "--" + b1_str = f"{b1:02X}" if b1 is not None else "--" + bitdiff = bit_diff(b0 or 0, b1 or 0) + print(f"Sample {idx} | Byte {i} | {b0_str} → {b1_str} | ΔCRC={crc:02X} | BitDiff={bitdiff}") + rows.append([ + idx, + i, + b0_str, + b1_str, + bitdiff, + f"{base_crc:02X}", + f"{crc:02X}", + f"{delta_crc:02X}", + f"{xor_crc:02X}", + raw, + f"{crc:02X}" + ]) + return rows + +# 📂 Point this to your folder +input_folder = "C:/Users/crt/Documents/bodeting/research/bad-bruteforcing/reveng-formatted" + +# 🧠 Do the work +msgs, crcs, rawhex = load_samples(input_folder) +rows = analyze(msgs, crcs, rawhex) + +# 📝 Save CSV +out_path = os.path.join(os.getcwd(), "crc_analysis_output.csv") +with open(out_path, 'w', newline='', encoding='utf-8') as f: + writer = csv.writer(f) + writer.writerow([ + "Sample", "Byte Index", "Base Byte", "Other Byte", "Bit Diff", + "Base CRC", "Other CRC", "CRC_DIFF", "CRC_XOR", + "HEX Input", "Original CRC" + ]) + writer.writerows(rows) + +print(f"\n✅ Analysis saved to: {out_path}") +os.system(f'start notepad "{out_path}"') -- cgit v1.2.3-70-g09d2