Back to Home

Reverse 9S12HY64: patching without disassembler

The article describes reverse engineering of 9S12HY64 firmware without disassembler: I²C sniffing, signature search in Ghidra, SREC patching to change the display. Achieved working result of indicator emulation. The approach is applicable to similar tasks.

Patching 9S12HY64 firmware: from I²C to result
Advertisement 728x90

Patching Static Data in 9S12HY64 Firmware Without Disassembling

Changing how indicators appear on an automotive instrument cluster built around the MC9S12HY64 microcontroller is achieved by analyzing I²C traffic and patching the SREC firmware file. This method avoids disassembling code entirely, instead focusing on identifying signatures in static data using Ghidra. The goal is to replace characters A with P and M with D, while eliminating digit artifacts.

Hardware Analysis and Protocol

The 9S12HY64 microcontroller connects to the display via a 6-pin interface without an external driver. Circuit tracing and reference manuals confirm the I²C protocol. A Saleae logic analyzer captures traffic between the MCU and display across all gear selector modes.

A summary table of the traffic reveals changing bytes that serve as potential signatures:

Google AdInline article slot
  • Mode A1: 5A C9 9A 8D...
  • Mode M1: 5A C9 9A 8D... (variations in first bytes)

Red-highlighted bytes are targeted for search in the firmware, presumed to represent a 2D array of static message payloads.

Locating Signatures in the Firmware

Ghidra is used for hex searching without HCS12 disassembly. The signature 0x5A, 0xC9, 0x9A, 0x8D pinpoints a memory region. Message format: display byte number + data.

Matching traffic to memory:

Google AdInline article slot
  • First byte identifies the segment (A/M).
  • Subsequent bytes define character patterns.

From a new cluster’s firmware, messages for P and D were extracted:

  • P: one-byte replacement.
  • D: two-byte correction.

Message Comparison:

| Mode | Original Message | Target Message |

Google AdInline article slot

|------|------------------|----------------|

| A1 | 5A C9 9A 8D... | 5A XX XX 8D... (P) |

| M1 | 5A C9 9A 8D... | 5A YY ZZ 8D... (D) |

Patching the SREC File

SREC structure: header, address, data, checksum. Byte changes require recalculating the checksum (KS).

Python script for KS calculation:

# Example script (adapted from GitHub)
def calc_srec_checksum(line):
    # Sum of bytes with inversion
    s = sum(bytes.fromhex(line[1:-1]))  # Exclude S and KS
    return format((~s + 1) & 0xFF, '02X')

Changes:

  • For P: modify the 1st byte in one line.
  • For D: adjust the 1st and 2nd bytes in two lines.

Recalculate KS; resulting firmware shows partial replacement with digit artifacts.

Eliminating Digit Artifacts

Digits (1–5) are generated as: 00th byte + nibble from the 12th byte (base 0x80 + value). Signature search in firmware for digits, zeroing data for '4' (keeping 1, 2, 3).

  • Format: byte number – data.
  • Recalculate KS for modified lines.

Final firmware delivers full P/D emulation without digits.

Key Takeaways

  • I²C traffic sniffing enables locating static data without code analysis.
  • Ghidra hex search works effectively even for unknown architectures like HCS12.
  • SREC patching demands precise checksum handling for validity.
  • Approach is scalable to other embedded systems using serial protocols.
  • Method reduces risk by avoiding execution of modified code.

— Editorial Team

Advertisement 728x90

Read Next