d4rkm0n r3d patched Pokemon Red credits

rev
flag d4rk{l3t_th3_cr3d1ts_r0ll_HELLLL_Y3AHHHH}

d4rk{l3t_th3_cr3d1ts_r0ll_HELLLL_Y3AHHHH}

Summary

game.gbc is a rebuilt Pokemon Red (UE) — the pret/pokered disassembly with a single addition buried in the credits code. Diffing the shipped ROM against a clean reference build shows one 0xDF-byte insert in bank 0x1D, inside Credits.showTheEnd, right after "THE END" is drawn. The injected routine loads three custom font tiles (_, {, } — not in the stock charset), copies a 32-byte key, then decrypts 44 bytes with

output
out[i] = enc[i] ^ key[i & 31] ^ i        for i = 0..43

and prints the result with the game's own PlaceString. Because the plaintext is stored in the game's text charset (not ASCII), plain strings and single-byte xor/add searches for d4rk find nothing — you have to decode the charset to read the flag. Static decryption recovers the flag; the ROM was never played to the credits in an emulator.

Solution / Exploit

1. Initial string searches come up empty

Plain strings game.gbc, charset-decoded text dumps, and single-byte xor/add searches for d4rk all find nothing. The payload is not stored as ASCII and is encrypted on top.

2. Build a clean reference and diff

Build an unmodified reference from pret/pokered with rgbds 1.0.4. Its SHA-1 is the known-good Red ROM:

output
ea9bcae617fdf159b045185467ae58b2e4a48b9a

Byte-diffing the shipped game.gbc against that reference gives 24 differing ranges. All but one are pointer fix-ups caused by a single 0xDF-byte insert in bank 0x1D, inside Credits.showTheEnd — TheEndTextString moved from 1d:4229 to 1d:4308.

3. The injected routine

The insert adds a routine at 1d:4232 (file offset 0x74232), called right after "THE END" is drawn. It does four things:

  • CopyVideoData 3 tiles from 1d:42d8 to $97A0 — custom glyphs for tile ids 0x7A = _, 0x7B = {, 0x7C = } (none of which exist in the stock charset).
  • Copies a 32-byte key from 1d:42b8 to $D002.
  • Loops c = 0..43: [$D030+c] = [$428C+c] ^ [$D002 + (c & 31)] ^ c.
  • FillMiddleOfScreenWithWhite, then PlaceString of $D030 at $C405.

So the ciphertext lives at 1d:428C (44 bytes) and the key at 1d:42b8 (32 bytes), and the decrypted text is written to $D030 and drawn as the "THE END" screen.

4. Reproduce the loop offline

solve_lattice.py is the lattice solver for a different challenge; the ROM decryptor is d4rkm0n-r3d-solve.py. It reads the ROM at the two offsets and applies the loop, then maps the resulting bytes through the Pokemon Red text charset:

python
1rom = open(sys.argv[1] if len(sys.argv) > 1 else "game.gbc", "rb").read()
2enc = rom[0x7428C:0x7428C + 44]
3key = rom[0x742B8:0x742B8 + 32]
4out = bytes(enc[i] ^ key[i & 31] ^ i for i in range(44))
5
6cs = {0x7A: "_", 0x7B: "{", 0x7C: "}", 0x4E: "", 0x50: ""}
7for i in range(26):
8    cs[0x80 + i] = chr(65 + i)   # 'A'..'Z'
9    cs[0xA0 + i] = chr(97 + i)   # 'a'..'z'
10for i in range(10):
11    cs[0xF6 + i] = str(i)        # '0'..'9'
12
13print("raw :", out.hex())
14print("flag:", "".join(cs[b] for b in out))

Run:

output
$ python3 -I d4rkm0n-r3d-solve.py game.gbc
raw : a3fab1aa7babf9b37ab3a7f97aa2b1f9a3f74eb3b27ab1f6abab7a87848b8b8b8b7a98f9804e878787877c50
flag: d4rk{l3t_th3_cr3d1ts_r0ll_HELLLL_Y3AHHHH}

The two 0x4E bytes (after cr3d1 and after Y3A) are on-screen line breaks and 0x50 is the string terminator; both are dropped from the flag. The 0x7A/0x7B/0x7C bytes are the custom _, {, } glyphs.

Flag(s)

output
d4rk{l3t_th3_cr3d1ts_r0ll_HELLLL_Y3AHHHH}

Notes / Pitfalls

  • Static decryption only. The ROM was not played to the credits in an emulator; the flag is proven by the offline decrypt, not by beating the Elite Four.
  • The plaintext is not ASCII. It is in the Pokemon Red text charset, which is exactly why strings and naive d4rk searches fail — d4rk is stored as bytes 0xA4 0xF6 0xB2 0xAB, not 64 34 72 6B.
  • Most of the 24 diffs are noise. 23 of the 24 differing ranges are pointer fix-ups (caused by the one insert shifting TheEndTextString); only one range is the actual payload. Do not chase the pointer diffs.
  • The three custom glyphs are the tell. Tiles 0x7A/0x7B/0x7C do not exist in the stock charset — they were added purely so the flag's _, {, } can be drawn.
  • Reference build is not kept. The pret/pokered checkout, rgbds, and pokered.gbc lived in a session scratchpad and are not preserved; re-clone pret/pokered and make to redo the diff. The shipped d4rkm0n-r3d-solve.py needs only game.gbc.