dwgx@blog:~$dwgx
> cd ../posts

Forking a Perfect Cherry Blossom decomp to take it apart

// created

To be clear: I didn’t write this, and I didn’t reverse it either. It’s a C++ decompilation of Team Shanghai Alice’s Touhou Youyoumu ~ Perfect Cherry Blossom PCB 1.00b, originally by ZUN. I forked it purely to crack it open and look inside, and to build a working copy of my own along the way.

I’ve always had a thing for reverse engineering old games. PCB is a 2003 title, a Win32 danmaku exe compiled with MSVC 7. The binary is tiny, but it has everything. Fixed-point math, a scripting system, resource packing, the draw loop, all crammed into one exe. A complete game written by a single person is the ideal thing to study, none of the abstractions and dependency piles of modern engineering, you just follow the call chain top to bottom and it makes sense.

This decomp also stands on the shoulders of earlier work. th06, Embodiment of Scarlet Devil, has had a mature decompilation for a while, and it’s cut from almost the same mold as PCB. Types, naming, file layout, you can lift them straight over as reference, which saves a huge amount of guesswork.

Right now it’s at 100% implementation and roughly 97% accuracy. You can play it start to finish and the behavior mostly matches, but it isn’t byte accurate yet and there are occasional bugs. The funny part: a fully matching build will eventually crash itself after 3999 Supervisor cycles, because the checksum still isn’t identical to the original and it fails the integrity check. To run it long, you have to turn that off with --no-matching. It deliberately keeps the original’s self-destruct mechanism, and that’s the fun of a matching decomp. The goal isn’t just “it runs,” it’s producing bytes identical to the 2003 build.

The toolchain is a bit retro. uv manages Python, ninja does the build, and on Linux you also need wine to run MSVC. The first pothole is right there: old wine versions choke completely on the MSVC msi, they just can’t extract it, and only the newest devel version works. The build entry point is a script in the root directory, straight:

uv run scripts/build.py

The output lands in build/th07.exe. To run it longer without the integrity check interrupting, add --no-matching. If you don’t have the original exe on hand (it’s needed to pull the icon), --no-icon will still build an icon-less binary.

For me the value isn’t playing PCB again, it’s watching how someone turns a blob of machine code back into named, structured C++. There’s heavy use of the var_order pragma, ported from EstexNT to MSVC 7, to control the layout order of local variables on the stack. That kind of fine-grained manipulation of the compiler for the sake of byte matching is something you’d never touch in everyday coding, but in reverse engineering it’s the lifeline. The author openly gripes in the Todo that this is an unkempt mess and that proper matching hasn’t really started. For someone like me, half rubbernecking and half learning, that’s perfect, the chaos lets you see the rawest traces of the reconstruction.

The repo is here: https://github.com/dwgx/th07. If you want to go deep, th06 for Embodiment of Scarlet Devil is the real source, and reading it alongside pays off the most.