Last active
March 31, 2024 16:58
-
-
Save MUSTARDTIGERFPV/976f3a0e54ab52431247832bf5ab54b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INPUT_FILENAME = "input.txt" | |
OUTPUT_FILENAME = "out.bin" | |
OUTPUT_DUMP_FILENAME = "out.txt" | |
MAGIC_OFFSET = 0x133 | |
CHECKSUM_OFFSET = 0x143 | |
def print_header(): | |
print(''' | |
_____ _____ __ ______ _ _____ | |
| __ \_ _| /\ \ / / __ \| | |_ _| | |
| | | || | / \ \ / / | | | | | | | |
| | | || | / /\ \ \/ /| | | | | | | | |
| |__| || |_ / ____ \ / | |__| | |____ _| |_ | |
|_____/_____/_/ \_\/ \____/|______|_____| | |
''') | |
def load_file(): | |
hex_contents = "" | |
with open(INPUT_FILENAME, 'r') as f: | |
lines = f.readlines() | |
for line in lines: | |
chunks = line.split(' ') | |
begin = 1 | |
for i in range(begin, begin + 16): | |
hex_contents += chunks[i] | |
return bytearray(bytes.fromhex(hex_contents)) | |
def write_file(data): | |
with open(OUTPUT_FILENAME, 'wb') as f: | |
f.write(data) | |
def print_bytearray(byte_array, outfile=None): | |
# Define the width of each line | |
line_width = 16 | |
# Iterate over the bytearray | |
for i in range(0, len(byte_array), line_width): | |
# Get the current line | |
line = byte_array[i:i + line_width] | |
# Format the offset | |
offset = format(i, '08X') | |
# Format the bytes | |
hex_bytes = ' '.join(f'{byte:02x}' for byte in line) | |
ascii_chars = ''.join(chr(byte) if 32 <= byte < 127 and byte != 0x20 else '.' for byte in line) | |
# Print the formatted output | |
line = f'{offset}: {hex_bytes.ljust(line_width * 3)} {ascii_chars}' | |
if outfile: | |
outfile.write(line + '\n') | |
else: | |
print(line) | |
def get_magic(index): | |
magics = { | |
1: ('MD-DEVILS', 0xDA), | |
2: ('HOGS_SAS', 0xE8), | |
3: ('SC-SURLY', 0xFD), | |
4: ('EQ-PIRATES', 0x84), | |
} | |
index = int(index) | |
if index not in magics: | |
raise ValueError | |
return magics[index] | |
def main(): | |
print_header() | |
print(f'Loading from {INPUT_FILENAME}') | |
f = load_file() | |
print(f'Loaded {len(f)} bytes') | |
print('Chassis types:') | |
print('\t1) MD12XX') | |
print('\t2) MD32XX') | |
print('\t3) SC2XX') | |
print('\t4) PS6200') | |
print('Select desired chassis type: ', end='') | |
chassis_type = get_magic(input()) | |
magic = chassis_type[0] | |
checksum = chassis_type[1] | |
# Clear our magic | |
for i in range(MAGIC_OFFSET, CHECKSUM_OFFSET): | |
f[i] = 0x00 | |
# Write magic | |
for i, b in enumerate(magic.encode('utf-8')): | |
f[MAGIC_OFFSET + i] = b | |
# Set the checksum | |
f[CHECKSUM_OFFSET] = checksum | |
print('Modified file:') | |
print_bytearray(f) | |
with open(OUTPUT_DUMP_FILENAME, 'w') as outfile: | |
print_bytearray(f, outfile) | |
print() | |
write_file(f) | |
print('\n\n\n') | |
print('Wrote:') | |
print(f'\t1. {OUTPUT_FILENAME}') | |
print(f'\t2. {OUTPUT_DUMP_FILENAME}') | |
print() | |
print('You can compare out.txt to your input.txt to see the differences, then use fru_download and xmodem flash out.bin') | |
print('Thank you for using diavoli!') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment