Rewriting a Legacy System with LLMs: A Practical Review of Reverse Engineering and Code Generation

    As large language models (LLMs) continue to advance, debate persists over whether their code generation abilities are truly ready for industrial use. This article reviews an experiment that used an LLM to completely rewrite a classic real-time strategy (RTS) game whose original source code had been lost. It covers how the work was broken into milestones, how the model handled undocumented binary formats and "magic constants" under license constraints, how high-frequency commits were validated, and where the model showed unexpected behavior. Readers will see a concrete workflow for reconstructing legacy binaries with AI, along with the limits of automation and the shifting role of human experts.

    As deep learning and LLM technology iterate at a rapid pace, the discussion around whether their “code generation ability is industrially viable” has never stopped. A common argument is this: LLMs perform impressively when generating standalone functions or solving algorithm problems, but can they still lead a refactoring effort when facing a “legacy system” burdened with complex history, tightly coupled dependencies, and specific binary formats?

    Recently, an experiment that used an LLM to thoroughly rewrite a classic real-time strategy (RTS) game offered a highly instructive answer. The starting point was a harsh reality: the original game’s source code had long been lost. This meant the so-called “rewrite” was not a simple module replacement, but a full-stack effort built from scratch on black-box reverse engineering.

    1. Project Setup and Planning: Breaking a Grand Goal into Executable AI Tasks

    The initial phase did not jump straight into coding, but focused on decomposing the goal. Facing complex game logic that existed only inside an executable, the team (in this scenario, humans acted only as architecture supervisors) laid out a phased “battle plan” for the LLM. The plan was not a vague “complete the task,” but was divided into three milestones:

    1. Pre-Alpha (Interface and Basic Framework): Handle window rendering, the event loop, resource loading, and user interface (UI) drawing. This required deriving control layout and interaction logic through reverse analysis, since the original UI libraries could not be called directly.
    2. Alpha (Core Gameplay Logic): Implement combat resolution, unit pathfinding, AI behavior trees, and map pathfinding algorithms. This phase demanded extreme logical rigor and was the key test of the LLM’s ability to understand complex state machines.
    3. Beta (Networking and Multiplayer): Abstract the network synchronization protocol and implement online matchmaking, which required solving distributed-systems problems such as latency compensation and state synchronization.

    2. Tackling the Hard Parts: Not Simple “Generation,” but Complex “Reverse Derivation”

    The most challenging part of the project was not “writing new code” but “reading old data.” The original game used many long-aged proprietary封装 formats, meaning existing parsing libraries could barely cover the requirements.

    The “Magic Constant” Trap in Format Reverse Engineering

    When handling the game’s built-in video and audio resources, the team found a core technical pain point: the binary formats were full of mysterious “magic constants” (undocumented hardcoded values). Using a general-purpose multimedia decoding solution directly would run into strict license compatibility conflicts. The LLM’s behavior under such constraints was interesting—rather than trying to brute-force the problem through enumeration, it displayed a kind of “avoidance-style learning.”

    At first, it tried to find inspiration by reading related open-source decoding logic, but promptly abandoned that path due to incompatible license terms. It then changed strategy: instead of scanning code globally, it focused on extracting the core “magic constants” and bitwise logic from the decoder. By abstracting large blocks of algorithmic logic into describable mathematical steps, and then reimplementing based on that abstract description, it produced a brand-new decoding module in a very short time—one that met the project’s license requirements with no loss of performance. This shows that LLMs are highly sensitive to intellectual property risk and are good at turning “reference” into an “independent implementation.”

    Adapting to Engineering with High-Frequency Commits

    Once the project entered a stable phase, the LLM advanced at a pace of hundreds of code commits per day. Facing such high-frequency iteration, manual code review clearly could not cover every detail. The experiment adopted a strategy of “black-box verification as the main approach, spot-checking of critical logic as a supplement.” That is, the human supervisor focused more on “whether the game runs as expected” than on “whether every line of code is elegant.”

    This workflow forced the LLM to have strong self-generated unit testing ability. In each round of commits, it had to submit not only functional code but also assertion tests for scenarios such as map boundaries and unit health changes. This test-driven generation pattern effectively ensured functional stability under extreme development speed.

    3. The Boundaries of LLM Collaboration and Observations of “Sneaky” Behavior

    Although the LLM performed well, the experiment also exposed some peculiar “temperaments” in engineering collaboration.

    • Implicit reuse of inspiration: The LLM was extremely conservative about open-source license compliance. When told that “a certain algorithm has already been implemented in the industry,” it would show a strong research spirit to search for the algorithm’s paper or description, and then reproduce it in a “dictation” style using completely different syntax and variable names. This can be seen as a uniquely AI-era form of “rewriting” programming; while effective, it requires the engineering supervisor to understand the algorithm’s principles deeply enough to correct the model when it goes off track.
    • Dependence on multimodal input: For restoring UI layout, pure text prompts (such as “the button is in the bottom-right corner of the window”) were far less efficient than “screenshot + prompt” multimodal input. In the early phase, the LLM frequently produced coordinate offsets, because its abstract understanding of “bottom-right” deviated from pixel-level coordinates. Introducing screenshots as visual context significantly improved this precision problem.

    4. Takeaways and Summary: A Paradigm Shift from “Tool” to “Collaborator”

    This two-week sprint experiment concluded with a “playable game” and “partial online functionality.” While still short of a perfect replica, it clearly outlined a branch scenario for the future of software engineering: when a legacy system cannot be migrated, AI can leverage its strong pattern-recognition ability to “excavate” and “reconstruct” a binary legacy in a very short time.

    Of course, this process was not fully automated. The human expert’s role became that of “architect” and “interrogator”—responsible for setting the solution approach, defining license boundaries, and providing key clues when the AI got stuck in the “magic constant” swamp. If you are facing the nightmare of refactoring an old system, you might try building a similar closed loop: define the rules → validate at high frequency → tolerate the AI’s “inspirational” path.

    This may be the most practical path for LLM technology to move from “toy” to “productivity.”