Legacy systems and reverse engineering
Notes on understanding, analysing and safely changing legacy systems by reverse engineering, with definitions, step-by-step processes, commands to remember, worked exam-style examples, common mistakes and practice questions.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Many engineering tasks involve working with old software that must be fixed, extended or moved. Reverse engineering gives a structured way to get models (like UML diagrams and architecture descriptions) from code and binaries so engineers can design safe changes, re-architect, or migrate systems.
Key ideas
Start with plain definitions (I define each term before using it):
Legacy system: a software system that is still in use but suffers from one or more of these properties: outdated technology, poor or missing documentation, original developers absent, or high change cost. Assumption: the system must continue to run while changes are planned.
Reverse engineering: the process of analysing a working system (source code, binaries, data and behaviour) to create higher-level representations (models, diagrams, specifications). Exact statement: reverse engineering produces models that are semantically close to the original system by using static and dynamic analysis, aiming to support comprehension, maintenance or migration.
Re-engineering: making planned changes after reverse engineering, including refactoring, rewriting, or migrating the system. It uses the models extracted by reverse engineering.
Forward engineering: the usual development process that produces software from models and specifications (opposite direction of reverse engineering).
Static analysis: analysing code or binaries without running them to extract structure (files, classes, functions, data definitions). Assumption: you have access to code or binaries and can inspect them safely.
Dynamic analysis: analysing a running system, using logs, traces, or monitoring, to understand runtime behaviour, interactions and performance. Assumption: you can run the system with test inputs or in a controlled environment.
Architecture recovery: process of extracting the architectural structure (components, connectors, layers) from existing artefacts. Exact goal: map low-level elements (files, classes, functions) to architectural components and their interfaces.
Program comprehension: the human task supported by reverse engineering; it consists of reading models, code and traces to form mental models of the system.
Refactoring: behaviour-preserving code transformations that improve design. Exact requirement: after refactoring, externally visible behaviour (APIs, outputs for given inputs) must be unchanged.
Wrapping: leaving legacy code mostly unchanged but adding an adapter or intermediary layer that provides a new interface.
Migration strategies (short definitions): re-hosting (move to new hardware/cloud), re-platforming (move to a new platform with minimal code change), re-architecting (change architecture), rewriting (complete redevelopment). Also know the Strangler Fig pattern (incrementally replace legacy functionality behind a façade while keeping the system running).
Redocumentation: creating or updating documentation (e.g., API, design) from existing code and artifacts without altering behavior.
Design recovery: reconstructing higher-level design/architecture using domain knowledge and external sources beyond mere code analysis (goes beyond redocumentation).
Exact procedural law (commonly asked in university answers): Reverse engineering is performed in these ordered stages (assumption: target system remains available):
- Preparation — collect artefacts: code, binaries, build scripts, configuration, tests, and runtime logs. Document environment.
- Static analysis — parse sources or disassemble binaries; extract call graphs, class and module lists, data schemas, and dependencies.
- Dynamic analysis — generate execution traces; collect logs, profiling data, and sequence traces for key use-cases.
- Model extraction — produce models (UML class diagrams, sequence diagrams, component diagrams) from analyses.
- Architecture recovery — group low-level artifacts into components and map interfaces and connectors; produce an architectural view.
- Assessment and planning — evaluate quality attributes (modularity, coupling, cohesion, performance), decide whether to refactor, wrap, migrate or rewrite.
- Re-engineering — apply controlled changes: refactor stepwise, add tests, validate behaviour.
- Validation — run regression tests and user acceptance tests to ensure external behaviour preserved.
For exams you may be required to draw a diagram. Exactly draw and label this common diagram to explain architecture recovery:
- Draw three horizontal layers: top layer labelled "Presentation / UI", middle labelled "Business / Application", bottom labelled "Data / Persistence".
- Inside each layer, draw boxes representing components (e.g. "UI: Web Frontend", "Service: OrderProcessor", "DB: Orders"), and arrows for connector types: solid arrows for synchronous calls, dashed arrows for asynchronous messaging. Label arrows with interface names (e.g. "REST /orders", "JMS:order.created").
When asked to show a class-diagram recovered from code, draw boxes for classes with three compartments: name, attributes, operations. Draw association lines between classes with multiplicities (1, 0..*, etc.) and show inheritance with a hollow triangle arrow from subclass to superclass.
Formulas
(For this topic we list syntax and commands you should remember.)
javap -c ClassName — disassemble Java bytecode to JVM instructions (add -cp <jar> if the class is inside a JAR). Use to inspect compiled classes when source is missing; for source decompilation, use tools like CFR, Procyon, or JD-GUI.
jdeps -s <jar-file> — list static Java package-level dependencies (use -v for class-level). Note: --list-deps prints module dependencies on JDK 9+, not packages. Verify exact flags for your JDK.
objdump -d <binary> — disassemble ELF binaries (Linux) to assembly; useful in reverse engineering native code.
strings <file> | grep <pattern> — extract printable strings from a binary or file; useful for hints about config or endpoints.
readelf -a <binary> — show ELF file headers and sections (ELF-based systems such as Linux).
nm <object-file> — list symbols in object files or libraries.
strace -f -o trace.txt <command> — trace system calls of a process (Linux); helps dynamic analysis of I/O and file access.
ltrace -f -o trace.txt <command> — trace library calls (Linux).
gdb <binary> — use the GNU debugger to run and inspect program state; use breakpoints and backtraces to observe runtime behaviour.
pycallgraph or trace (Python tools) — generate call graphs for Python programs (tool names depend on environment).
doxygen + Graphviz — generate call graphs and class diagrams from annotated source code (use config file to enable graphs).
PlantUML syntax — remember to write class diagrams as: class A { +op() } and relationships like A --> B to produce quick UML visuals.
Note: exact options for each tool can vary across platforms and versions — verify the flags in your environment.
Worked examples
Example 1 — Recovering UML classes from a small Java legacy project (exam-style answer):
Given: a runnable jar legacy.jar, no source, need class and package structure.
Steps:
- Use
jdeps -s legacy.jarto list package dependencies (use-vfor class-level; on JDK 9+--list-depsshows module dependencies). - Run
jar tf legacy.jarto list contained .class files. (Command:jar tf legacy.jar.) - For a class
com.example.OrderProcessor, runjavap -cp legacy.jar -c com.example.OrderProcessorto view methods and called methods. Record method signatures and the classes they reference. - Build class boxes: for each class, list public methods (from javap) and attributes (inferred from method names like getX/setX). Draw classes and associations: if
OrderProcessorcallsInventoryService, draw an association fromOrderProcessortoInventoryServicelabelled "uses". - Validate by running program with
straceto see which resources are accessed and confirm presence of a DB or files. Final: Provide a UML class diagram with classes, public operations and association arrows. Explain your assumptions (attributes inferred, private fields may be unknown).
Example 2 — Static call graph recovery for a small C program (step-by-step trace):
Given files: main.c, util.c, net.c. Task: draw call graph.
Step 1: Compile with symbols: gcc -g -o app main.c util.c net.c.
Step 2: Use nm app | grep " T " to list text symbols (functions). Suppose output shows main, handle_request, send_packet.
Step 3: Disassemble objdump -d app and find within main: calls to handle_request. Inside handle_request find call to send_packet.
Step 4: Draw nodes: main -> handle_request -> send_packet. Label edges with call frequencies if profiling data available.
Example 3 — Short essay (model answer): Choose a migration strategy for a pay-wall webapp whose PHP 5 codebase has no tests. Answer sketch: First, reverse engineer to extract routes, database schema, and third-party integrations using static analysis (grep, PHP tokenizers) and dynamic tracing (instrumentation on staging). Produce models: component diagram showing Web, DB, PaymentGateway. Because there are no tests, a big-bang rewrite is risky. Recommended strategy: incremental re-engineering — wrap existing app with a new API layer, add automated tests around critical flows (login, payments), and then extract and refactor modules one-by-one, migrating to modern PHP or microservices. Justify by risk: incremental approach keeps system running and reduces regression risk. Include validation plan: side-by-side testing, canary deployments.
Common mistakes
- Not creating or running tests before refactoring. Tests are required to prove behaviour preserved.
- Drawing UML with too much detail from incomplete information; instead mark inferred elements clearly and state assumptions.
- Forgetting to run a system in a safe, isolated environment during dynamic analysis — you may corrupt production data.
For your exam
Kinds of questions:
- Definitions and short notes: define legacy system; difference between reverse engineering and re-engineering.
- Process/derivation: list and explain stages of reverse engineering (preparation, static, dynamic, extraction, recovery, planning, re-engineering, validation). A full-marks answer lists stages and describes input/output of each.
- Diagram questions: draw an architecture recovery diagram or a UML class diagram recovered from given code fragments. A full-marks answer draws boxes, labels layers/components, interfaces and arrow types, and states assumptions.
- Tools/syntax: ask for commands you would use to inspect a jar or binary. Full marks: give correct commands and short purpose for each.
- Case-study / strategy questions: choose migration strategy with pros/cons and validation plan. Full marks: identify risks, propose test strategy, and justify choice.
Tip: always state assumptions (access to source, ability to run the system, test availability) in your answers.
Quick check
- What is the main difference between static and dynamic analysis?
- Give two uses of reverse engineering in software maintenance.
- Name one safe migration strategy when tests are missing.
Answers: 1) Static analysis inspects code/binaries without running them; dynamic analysis observes executing behaviour. 2) Producing UML/architecture models for comprehension; finding interfaces for migration or wrapping. 3) Incremental re-engineering with wrapping and adding tests (not full rewrite).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?