#!/usr/bin/env python3 import sys import struct import re def convert_txt_to_bin(txt_file, bin_file): with open(txt_file, 'r', encoding='utf-8') as f: lines = f.readlines() with open(bin_file, 'wb') as f: count = 0 for line in lines: line = line.strip() if line == 'start' or line == 'end' or not line: continue # Check if line contains only hex digits (8 characters) if re.match(r'^[0-9A-Fa-f]{8}$', line): hex_value = line # Convert hex string to integer int_value = int(hex_value, 16) count += 1 # Write first 63 complete 4-byte integers if count <= 63: f.write(struct.pack(' ") sys.exit(1) txt_file = sys.argv[1] bin_file = sys.argv[2] try: convert_txt_to_bin(txt_file, bin_file) print(f"Successfully converted {txt_file} to {bin_file}") except Exception as e: print(f"Error: {e}") sys.exit(1)