Delphi 7 Decompiler High Quality: Borland
Technical Write-Up: Decompiling Borland Delphi 7 Executables
1. Introduction
Borland Delphi 7, released in 2002, remains a popular legacy rapid application development (RAD) tool. It compiles Object Pascal source code into native x86 executables (EXEs) or dynamic link libraries (DLLs). Unlike .NET or Java bytecode, Delphi produces raw machine code, making decompilation significantly more complex. However, due to Delphi’s predictable metadata structures (forms, RTTI, string tables, and method prologues), targeted decompilation tools can recover a high-level approximation of the original source code.
Delphi vs C#: which is better for modern Windows apps? - Cortance borland delphi 7 decompiler
- Load the MAP file generated by IDR. The binary is now annotated.
- Navigate to an event address found in IDR (e.g.,
TForm1.Button1Click). - Use the Hex-Rays decompiler (F5 in IDA). The output will be C-style pseudo-code. You must mentally translate this back to Object Pascal.
6. What Can Be Recovered?
| Element | Recoverable? | Accuracy | |---------|-------------|----------| | Form layout (DFM) | Yes | Exact | | Published event handlers | Yes (names) | High | | Published properties | Yes | High | | Global variables | Partial | Medium | | Local variable names | No | – | | Comments | No | – | | Loops (for, while) | As gotos/ifs | Low | | Inline assembly | Exact | High | | String literals | Exact | High | | Third-party component info | Partial | Low if not registered | Load the MAP file generated by IDR
If the code was compiled with optimizations, the resulting machine instructions may not correspond directly to a single high-level Pascal statement. Incomplete Logic: released in 2002
A more recent entry into the field, Revitalize focuses on modernizing the decompilation process for older binaries.
4. What Can Be Recovered vs. What Is Lost
| Artifact | Recovered? | Fidelity | |----------|-----------|----------| | Form layout (.dfm) | Yes | 100% (exact) | | Published event handlers (names) | Yes | 100% | | Unit/Form class names | Yes | Original | | Component properties (Caption, Color, etc.) | Yes | Exact | | Global variables | Partial | Types recoverable, names lost | | Local variable names | No | Replaced with
var_1,var_2| | Comment lines | No | Permanently lost | | Original if/then/else vs. case statement | Partial | Logic correct, but structure may be flattened | | Loop constructs (for/while/repeat) | Partial | Heuristics applied | | Inline assembly blocks | Yes | Recovered as asm…end |