#!/usr/bin/env python3 """Redirect the verified 7.25.1 ARM/ARM64 RouterOS updater host. The two references are ELF32 absolute literal words. The second string has four trailing NUL bytes, enough for mikrotik.brunner.ninja without moving a section. The first reference is redirected to that second string. """ import argparse import hashlib from pathlib import Path import struct LAYOUTS = { "6fa7c71d0ff6014d3d65f3e696893bd87a4b3635b9a06d51de8619524aee9512": (0x37ce9, 0xfed4, 0x4200c, 0x359c4), "237ccca17a91d06a52b91d24b4cda60b2a5aca83a47fa1c38719b8b2bba47bea": (0x384bf, 0x118a8, 0x4286c, 0x35b1c), } OLD = b"upgrade.mikrotik.com\0" SLOT_SIZE = 24 def patch(data: bytes, host: str) -> bytes: if host != "mikrotik.brunner.ninja": raise ValueError("Only the verified project hostname is supported") layout = LAYOUTS.get(hashlib.sha256(data).hexdigest()) if layout is None: raise ValueError("Unsupported sys2 build; updater host was not changed") first, first_ref, second, second_ref = layout if (data[first:first + len(OLD)] != OLD or data[second:second + SLOT_SIZE] != OLD + b"\0" * (SLOT_SIZE - len(OLD))): raise ValueError("Unexpected updater string layout") if (data[first_ref:first_ref + 4] != struct.pack("