Rebuilding Legacy Systems with Lost Source Code: An LLM-Driven Reverse Engineering and Rewriting Pipeline
Losing the source code of a legacy system leaves enterprises with only binaries, outdated dependencies, and undocumented business logic. This article explores how large language models can take on the most expensive part of reverse engineering—inferring original design from disassembled code—and lays out a four-stage pipeline (static asset analysis, behavioral reverse engineering, architecture rebuilding, and consistency verification), along with real-world challenges such as semantic drift, legal compliance, and engineering cost. The approach is illustrated through the idea of rewriting a classic game whose source code is long gone into a behaviorally equivalent modern version.
1. The Problem: Legacy Systems with Lost Source Code
In the software industry, “lost source code” is far more common than one might expect. Development environments from early projects have been retired, teams have disbanded, and storage media have degraded. What remains for enterprises is often just an executable file and scattered documentation. Such systems typically share these characteristics:
- Binary artifacts only: executables, dynamic libraries, and resource packs, with no source code anywhere;
- Outdated dependency stacks: running on old platforms or runtimes that are no longer maintained;
- Implicit business logic: countless rules embedded in code behavior, with no documentation to reconstruct them;
- Extremely high modification costs: adding a feature often requires high-risk binary patching.
The traditional solution is manual reverse engineering: reading assembly with disassemblers and decompilers, gradually reconstructing data structures and control flow, then rewriting by hand. This path demands rare expertise and takes enormous amounts of time, so most enterprises simply keep the system running untouched.
2. A New Approach: Let LLMs Handle Reverse Engineering and Rewriting
New-generation large language models exhibit two key capabilities in code tasks that open a way out of this dilemma:
1. Strong code semantic inference. Given decompiler output, assembly fragments, or runtime logs, models can reasonably accurately infer the original data structures, function intent, and call relationships—translating “machine-view” code back into “human-view” design.
2. Cross-language rewriting and migration. Models can migrate logic to a modern tech stack while preserving behavioral semantics—for example, rewriting archaic graphics API calls into modern graphics library calls, or converting fixed-point arithmetic to floating-point.
This leads to a bold hypothesis: for a classic game whose source code is long lost, could an LLM reverse engineer the executable and resource formats and completely rewrite it into a behaviorally equivalent, modernized version?
In engineering terms, this hypothesis can be decomposed into a clear pipeline.
3. The Technical Route: A Four-Stage Reverse-and-Rebuild Pipeline
Stage 1: Asset and Structure Analysis
First, perform static analysis on the binary to extract the executable’s section layout, import symbol tables, and resource pack formats. The goal here is not “reading code” but building a static map of the system:
- Identify functional modules (rendering, pathfinding, AI, network synchronization, etc.);
- Reverse engineer resource file formats (images, audio, unit stat tables);
- Locate key data structures through strings and constant tables.
Stage 2: Behavioral Reverse Engineering
Use dynamic debugging tools to record runtime behavior: memory layouts, object lifecycles, state machine transitions. Feed the decompiler output together with dynamic traces to the LLM, and have it produce structured conclusions, for example:
Input: decompiled function fragment + runtime logsOutput:- Inferred data structure: Unit { hp, armor, speed, weapon_id }- Damage formula: damage = max(weapon_power - armor, min_damage)- State machine: Idle -> Attacking -> Reloading -> Idle
Model inferences must be validated with behavioral comparison tests: implement the inferred formula in an independent script and diff its output against the original program’s actual output.
Stage 3: Architecture Rebuilding and Rewriting
Once semantics are recovered, design the new target architecture, then have the model rewrite module by module. Several practical lessons:
- Rewrite one module at a time to control context size and prevent the model from drifting semantically in overly long tasks;
- Write interfaces and data structures first, then implementations, giving each module a clear contract;
- Build a regression test suite for every rewritten module, using input/output pairs recorded from the original system as the baseline.
Stage 4: Consistency Verification
The rewritten version must be behaviorally equivalent to the original. Viable verification methods include:
- Deterministic replay: record the original system’s input sequences, replay them in the new system, and compare state frame by frame;
- Fuzz testing: randomly generate operation sequences and compare key state differences between the two systems;
- Performance stress testing: confirm the rewritten version achieves acceptable frame rates and latency on modern hardware.
4. Real Challenges That Must Be Faced
Semantic drift is the core risk. LLM inference is probabilistic. A misplaced percentage sign in a damage formula can completely distort unit balance, and such errors are extremely hard to catch in code review. An automated differential testing loop is the essential safety net.
Compliance and copyright red lines. It must be emphasized: reverse engineering commercial software is generally constrained by copyright law and end-user license agreements; unauthorized reverse engineering and rewriting may constitute infringement. Legitimate scenarios include rebuilding legacy systems for which you hold full rights, developing parsers for openly documented formats, and analyzing legally obtained samples for teaching and research. Any idea of “bypassing a model’s safety policies to reverse engineer someone else’s work” violates platform norms and carries legal risk.
Engineering cost must not be underestimated. Even with model assistance, rebuilding a medium-sized legacy system still takes months of human-machine collaboration. The model’s role is an accelerator, not a one-click button.
5. Extension: Applying the Approach to Enterprise Scenarios
The same pipeline applies to more common enterprise needs: when an old system’s code repository is corrupted or has version gaps, partial reconstruction can be done by combining backed-up build artifacts with operational logs. Combined with general cloud capabilities—code hosting, continuous integration, and log monitoring—you can quickly set up an automated “rewrite–verify–release” loop and safely launch the rebuilt version with modern operations practices.
Conclusion
“Rebuilding legacy systems with LLMs” is not a joke—it is a technically feasible route, provided there is a rigorous pipeline design, automated behavioral verification, and a clear-eyed awareness of copyright boundaries. What AI fills in is the most expensive talent gap—inferring design from binaries. The rest of the engineering discipline still has to be upheld by developers themselves.
