Authorized Reverse Engineering and Rewrite of Legacy Software with AI Coding Assistants

    This article explains how teams with legal rights can use an AI coding assistant to reconstruct legacy software when only binaries and resource packs remain. It covers authorization checks, a practical toolchain, staged milestones, clean-room format analysis, magic-constant records, black-box hash comparison, three reference issues, a reuse checklist, and cases where the method does not apply.

    1. Confirm authorization and compliance first

    Many classic programs no longer have source code. Only executables and resource packs remain. Reverse analysis and a rewrite are appropriate only when you have a lawful basis, such as being the copyright owner or holding written permission from the rights holder, and when the applicable jurisdiction and license terms allow that analysis. Before work starts, the project owner should confirm the scope of authorization, the origin of the samples, and the intended use, and should obtain a legal opinion. This article is not legal advice.

    Some teams assume that if an AI coding assistant “writes it again,” the result is unrelated to the original work. That assumption is unreliable. A model may have seen related open-source implementations during training, so generated code is not automatically an independent expression. Compliance should not depend on how the model phrases its output. It should depend on a traceable record: who performed the analysis, which materials they used, and whether implementers ever saw protected code. Keep a record of each step.

    2. Toolchain and prerequisites

    An assistant cannot read a binary directly. Tools must turn the binary into information that people can review, and people must check the assistant’s conclusions. Common tools include:

    • A disassembler and decompiler, such as Ghidra or IDA, to inspect function structure and cross-references
    • A hex editor, to locate magic bytes, frame headers, and fixed offsets
    • A debugger, to observe memory layout and function arguments on an authorized sample
    • A black-box comparison framework, to compare outputs of the original program and the new program
    • Version control and a sample inventory that records each file’s version and SHA-256 hash

    Use a debugger only on a copy of software you are allowed to run. Do not use it to bypass digital rights protection.

    3. Method: move in stages

    3.1 Set verifiable milestones

    Split the rewrite into stages, each with a clear acceptance criterion. In the reference case, the project had three steps. The first stage loaded the interface and resources so the program could start and show the main menu. The second stage implemented combat logic and map rendering. The third stage handled networked matches and synchronization. At the end of each stage, save progress and the decisions made. This reduces risk and helps the assistant keep a consistent context over a long task.

    3.2 Private formats and a clean-room process

    Private formats are the main obstacle. A video container, for example, may be an unpublished variant. Open implementations are scarce, and licenses across projects may conflict. If the project uses the MIT license, you cannot simply import GPL or LGPL code, and dynamic linking can also be disputed.

    A clean-room process is the safer approach. The analysis group records only the format specification: frame-header layout, field meanings, and statistics from samples. It does not produce protected code. The implementation group writes code only from that specification and does not see the original decoder source. Keep the full handoff between the two groups so it can be audited later.

    3.3 Register and extract magic constants

    Values that cannot be derived from logic—encryption keys, compression tables, and specific offsets—are often called magic constants. They can be taken only from the binary. Extract them with static analysis on a lawfully authorized sample, and debug in a controlled environment only when needed. For each constant, record four items: source file and version, address or offset, extraction method, and how it was checked.

    Do not run unauthorized software to obtain a constant, and do not bypass encryption or other protection.

    3.4 Black-box comparison tests

    Code from an assistant is rarely correct on the first try. For each input file, run both the original program and the new program, then compare output hashes. When results differ, reduce the gap to a minimal test case and give that case to the assistant. Automate this loop and keep it running. Merge a version into the main branch only after it passes regression tests.

    4. Three issues from the reference case

    4.1 Video decoder

    The team first extracted macroblock types, quantization tables, and motion vectors from samples. From those, they inferred that the encoder was roughly based on the discrete cosine transform and used a custom code table. The assistant’s first decoder showed color blocks. After several comparison rounds, the team found that one symbol in the code table had the wrong bit width. After that correction, video played normally.

    The reference case did not state how many samples were used or how hashes were compared. In your own project, record the sample count, format versions, and the output comparison method so others can reproduce the result.

    4.2 Map data and pathfinding

    Maps were made of several planes, including terrain height, unit spawn points, and resource placement, stored with RLE compression. By watching the two-dimensional arrays in memory after the program loaded a map, the team inferred the decompression algorithm. After pathfinding was implemented from the public A* principle, units still took long routes. The coefficient on Manhattan distance in the heuristic differed from the old version. That coefficient sat at a fixed offset in the map file and was read only after the file was analyzed.

    4.3 Network synchronization

    The old game used a lockstep model. Each client ran the same logic and exchanged only player commands. Tests showed small differences in floating-point results across machines, which split game state. The team replaced floating-point math with fixed-point math and made the order of operations the same everywhere. In that case, the change removed the divergence that had been observed. It is not a general guarantee. Multi-platform regression tests and hash comparison are still required.

    5. Reusable checklist

    • Authorization review: scope, sample origin, and legal opinion are archived
    • Format analysis: the specification was written independently by the analysis group, and the implementation group did not see original code
    • Magic constants: every constant has a source, version, and verification record
    • Black-box comparison: old and new output hashes match, and every difference found has been added to the test set
    • Cross-platform regression: all tests pass on every target platform combination
    • License compatibility matrix: every dependency license is listed and confirmed compatible with the others

    6. Where this applies, and where it does not

    This method fits older business systems, device firmware, and proprietary file formats, provided the binary still has recognizable features and the target logic can be described by explicit rules.

    It does not fit heavily obfuscated or packed code, programs that depend on a specific hardware state, software that runs only if a protection mechanism is bypassed, or samples you are not authorized to use. Even when the conditions are met, the migration timeline depends on sample complexity and test coverage. Expecting maintainable source code within a few days from a single executable is not realistic.

    An AI coding assistant can cut a large amount of repetitive analysis and coding work. It cannot replace an authorization review, legal judgment, or strict verification.