A decompiler tries to reconstruct readable logic from compiled instructions. Ghidra is a reverse-engineering tool that combines a byte listing, disassembly and decompiler views. Disassembly represents machine instructions; decompilation presents a higher-level interpretation, often resembling C.
The original source may contain names, comments and structure that compilation does not preserve. A reconstructed view therefore needs evidence and review. This lesson compares compare.c with an author-written sketch. The sketch demonstrates a possible naming difference; it was not produced by Ghidra and is not a screenshot or decompiler export.
Before you begin
- Recommended first
- An editor that works under pressure, Processes, How to read a script someone else wrote, Where practice is allowed, file, strings, and strace
- Estimated time
- 16 min reading, 16 min activity. Setup and optional practice may take longer.
- Where you work
- Read the supplied C/Python source and clearly labeled conceptual models in any current desktop or mobile browser. No compiler, binary execution, debugger, tracer or Ghidra installation is required. Function-only C sources are not standalone programs.
- Without a lab
- Trace the source or model on paper and record the condition, chosen branch and evidence limit. No matched lesson ELF, disassembly, debugger session or Ghidra export is supplied. Historical observations retain their separate context. Reading works without JavaScript. Checking requires JavaScript and a secure context; saving also requires usable storage.
After this lesson you can:
- State what the decompiler window shows, from the help page.
- Name one difference between compare.c and the author sketch.
- Leave main unfound while no project exists.
01Example
This fresh pair is hand-written to illustrate reconstruction. It is unrelated to the guided mark/recovered files, and neither line is decompiler output.
Hypothetical source: int add_one(int n) { return n + 1; }
Hypothetical sketch: int recovered_step(int value) { return value + 1; }
Both describe adding one, with different names.
A shared operation does not make the texts identical.
No binary or decompiler produced this pair.02What the tool is for
In an actual Ghidra project, importing a binary establishes the bytes to analyze and the chosen machine-language interpretation. Analysis can identify functions, references and candidate types. The decompiler window follows the selected function and uses labels and types applied during analysis. Changing a label changes the analysis presentation, not the original source file.
A symbol is a name associated with a location, such as a function name retained in a binary. Stripping can remove some names, so failure to find a main symbol does not prove that a program lacks a main function. The operating-system entry location and the C main function are distinct. No project is open here, so no symbol or address has been found.
The navigation card describes a candidate tool setup, not a required installation. It states its Ghidra/JDK documentation snapshot and architecture limits. A live import, matched binary, analysis settings and decompiler export remain missing. Use the source/sketch comparison to practice reading while keeping those practical gaps explicit.
Read a decompiler view as an analysis of a function, and keep it separate from the author's source.Model. A teaching model drawn by hand. It shows the idea, not real tool output.
Read the full explanation below.
| Field | Hypothetical source | Hypothetical sketch |
|---|---|---|
| Function name | add_one | recovered_step |
| Parameter role/name | n | value |
| Return operation | return n + 1; | return value + 1; |
| Provenance | Hand-written; no binary | Hand-written; no decompiler |
n and value occupy equivalent input roles, but the texts are not identical.
n and value occupy equivalent input roles, but the texts are not identical.
Follow the explanation
- n and value occupy equivalent input roles, but the texts are not identical.
- Both sketches describe adding one. No Ghidra project, binary or recovered output produced the pair.
Read every state and value
1. n and value occupy equivalent input roles, but the texts are not identical.
- Selected Comparison
- names
- Highlighted Field
- Function name · Parameter role/name
2. Both sketches describe adding one. No Ghidra project, binary or recovered output produced the pair.
- Selected Comparison
- operation
- Highlighted Field
- operation · Provenance
Ghidra navigation card. Not a screenshot. You do not need Ghidra for this page.
From Getting Started, effective as of Ghidra 12.2 and subject to change:
Linux is a supported platform.
The stated software requirement is a Java 25 64-bit JDK.
Install by extracting the distribution. Do not extract it on top of an existing copy.
GUI launch is ghidraRun from the install directory.
An official public release includes native binaries for Linux x86-64.
Linux ARM 64-bit is listed as needing user-built native components. Building them is not part of this lesson.
From the Decompiler window help:
The window shows one function at a time.
It follows the current address in the Code Browser.
Decompilation is done on the fly and picks up labels, data types, and comments the user has applied.
Finding main, without a project:
If a later owned project shows a function named main, that name is a symbol in that file.
A missing name does not prove where main is.
The program entry and the C function named main are different ideas.
The GDB manual says that for C the main procedure is named main.
This course has no Ghidra project, so no symbol was looked up.
/* Original teaching source. Not compiled. */
int mark(int x) {
if (x == 7) {
return 1;
}
return 0;
}
Author sketch of a decompiler-style view.
Not produced by Ghidra. Not the original source. Not a disassembly.
int recovered(int value) {
if (value == 7) {
return 1;
}
return 0;
}
Compare this sketch with compare.c.
The source function is named mark and its parameter is named x.
This sketch uses recovered and value.
The decision has the same shape. The text is not the source file.
No address from a Ghidra listing belongs on this card.
03Compare the sketch with the source
Use the two downloads. The question asks a yes-or-no about a guarantee. This activity asks for a name that differs.
- Place the mark function and the recovered function in your notes.
- Underline one name that differs. Check: mark versus recovered, or x versus value.
- Write the shared decision in one line: equal to 7 returns 1, and the other path returns 0.
- Stop. Do not open Ghidra and do not invent an address to make the sketch look official.
04Optional challenge
Suppose a later project let you rename recovered back to mark. Explain why that rename would be an analysis label, and why it still would not create the missing binary. About ten minutes.
05Fresh cases for the checks
Use these fictional cases for the checks below. They have different inputs from the worked examples. Read them here or make notes; no installation or external service is needed.
Reconstruction case A: help descriptionOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.
A decompiler window reconstructs a high-level C-like representation from a program.
It is not a recovery guarantee for original names or exact original source text.
A function must first be located in an actual imported/analyzed project.
Reconstruction case B: fresh hand-written pairOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.
Source: int lower(int amount) { if (amount == 6) return 1; return 0; }
Author sketch: int function_1(int value) { return value == 6; }
For this model, a true comparison produces 1 and false produces 0.
Both lines are hand-written, not Ghidra output. No binary or project is supplied.
06Explain your evidence
Optional written self-check: explain one decision using the supplied case. No tool run is required.
Check your explanation: describe reconstruction accurately; compare names, control structure and predicted values independently; identify the missing project and avoid attributing the hand-written sketch to a tool.
07Common mistakes
If the sketch is described as Ghidra's listing, the header line was skipped. The file says it was typed for the lesson.
If main is declared found, a symbol was invented. The navigation card says no project was opened.
If Java or Ghidra is installed to finish the page, stop. The check uses the printed source and the sketch. You do not need those install steps for this page.
References
- Ghidra: Getting Started
Describes the tool's setup requirements and architecture limits. The navigation card labels its documentation snapshot; installation is deferred.
- Ghidra help: Decompiler window
Explains function decompilation and how labels/types affect the reconstructed view. It does not promise the original source text.
- Debugging with GDB: Starting your Program
Defines run and start, including program selection and temporary stopping at main.