GO KALI FREE

Ghidra

Reverse Engineering

Advancedlow risk

This hands-on guide shows how to use Ghidra to inspect a program you compile yourself. You'll compare decompiled code with the underlying assembly, follow cross-references, and document what the binary does without executing it.

Installation

sudo apt install ghidra

Basic Syntax

ghidraRun

Quick Facts

Full Name
Ghidra SRE Framework
License
Apache 2.0
Language
Java
Platforms
Linux, macOS, Windows
Category
Reverse Engineering
Created By
NSA

Tool Overview

Ghidra is a free, open-source software reverse engineering framework developed by the U.S. National Security Agency (NSA). It lets you inspect compiled programs without running them: you can read machine instructions, view a C-like approximation of the code, and trace how functions and strings are used across the binary.

Try this tiny C program: #include <stdio.h> static void print_ready(void) { puts("ready"); } int main(int argc, char **argv) { if (argc > 1) print_ready(); return 0; } Compile it on Kali with gcc -O0 -o ready ready.c, then make a stripped copy with cp ready ready-stripped && strip ready-stripped so you can practice working without the original function names. Import the stripped copy, run auto-analysis, and look for main in the Symbol Tree. If main isn't named, start at the entry point and follow the function address passed as the first argument to __libc_start_main. Typical pseudo-C (illustrative, not verbatim): if (1 < param_1) { FUN_...(); } The dots stand for an address suffix. Follow the call, verify that the helper passes "ready" to puts, and rename the FUN_ function to print_ready. Back in main, the call is now readable: an argument count above one means the user supplied at least one argument beyond the program name, which triggers the message.

In CodeBrowser, the Listing shows addresses, assembly instructions, and data. The Decompiler shows C-like logic for the selected function, while the Symbol Tree helps you find functions and imports. The Function Graph draws the blocks and branches inside a function. Defined Strings lists text already defined in the program, and the Byte Viewer lets you inspect the loaded bytes in hex.

The built-in Ghidra decompiler reconstructs expressions, branches, and calls from machine instructions. Its pseudo-C is an approximation, not the original source: comments are generally absent, and names and types may be missing or inferred. Stripped binaries offer fewer naming clues, optimized builds may inline helpers or rearrange branches, and packed binaries may initially reveal only a loader stub. Check the Listing when the pseudo-C is ambiguous.

Use analyzeHeadless to analyze files without opening CodeBrowser. Use -import for new binaries and -process for programs already in a project. Java scripts, or Python scripts (Jython), can collect function names or export selected pseudo-C. Run a script after analysis with -postScript; headless analysis does not export decompiler output on its own.

Learning how to use Ghidra follows one beginner loop: install Ghidra with a compatible JDK, create a project, import a binary you are authorized to analyze, run auto-analysis, then read the decompiler output beside the disassembly — renaming functions, chasing strings and cross-references, and saving your work as you go. This guide walks that loop step by step, so a first-time user can go from download to a decompiled function in a single session.

Ghidra is a software reverse engineering framework developed by the NSA. It includes a suite of tools for analyzing compiled code, including disassembly and decompilation.

The tool supports multiple processor architectures and executable formats. It features a built-in decompiler that converts assembly to pseudo-C code.

Ghidra is widely used for malware analysis, vulnerability research, and software reverse engineering. Its headless mode enables automated batch analysis.

Quick Reference Commands

Verified quick-reference commands for Ghidra
CommandPurpose
ghidraOpen the Ghidra GUI from the installed Kali package.
ghidraRunStart the GUI from an extracted Ghidra release (run ./ghidraRun from the install folder).
analyzeHeadless <project_dir> <project_name> -import <binary_path>Import and analyze a binary without opening the GUI.
analyzeHeadless <project_dir> <project_name> -process <program_name>Process a program already in the project (use its project entry name).
analyzeHeadless <project_dir> <project_name> -process <program_name> -scriptPath <script_dir> -postScript Decompile.javaExport decompiled output with the bundled Decompile.java post-script.
analyzeHeadless <project_dir> <project_name> -import <binary_path> -processor <language_id>Set the processor language explicitly with the full Ghidra language ID for the binary.
Ghidra Installation GuideKali Linux Tools — ghidra

Common Commands

ghidraLaunch the Ghidra graphical reverse-engineering suite on Kali
ghidraRunAlternative launcher script that starts the Ghidra GUI
analyzeHeadless /path/to/projects MyProject -import /path/to/binaryImport a binary into a project and auto-analyze it without the GUI
analyzeHeadless /path/to/projects MyProject -import /path/to/binary -overwriteRe-import a binary, overwriting any existing program of the same name
analyzeHeadless /path/to/projects MyProject -import /path/to/dir -recursiveRecursively import every file in a directory tree
analyzeHeadless /path/to/projects MyProject -import /path/to/binary -noanalysisImport without running auto-analysis (analyze later)
analyzeHeadless /path/to/projects MyProject -processRe-run analysis/scripts against programs already in the project
analyzeHeadless /path/to/projects MyProject -process binary -postScript Decompile.javaRun a post-analysis script against an existing program
analyzeHeadless /path/to/projects MyProject -import /path/to/binary -postScript MyScript.pyImport, analyze, then run a Python (Jython) post-script
analyzeHeadless /path/to/projects MyProject -import /path/to/binary -preScript Setup.javaRun a script before analysis begins
analyzeHeadless /path/to/projects MyProject -import bin -scriptPath /path/to/scriptsSpecify where Ghidra should look for headless scripts
analyzeHeadless /path/to/projects MyProject -import bin -deleteProjectDelete the project after the headless run completes
analyzeHeadless /path/to/projects MyProject -import bin -processor x86:LE:64:defaultForce a specific processor language ID for analysis
analyzeHeadless /path/to/projects MyProject -import bin -cspec gccSet the compiler specification used during analysis
analyzeHeadless /path/to/projects MyProject -import bin -loader ElfLoaderChoose a specific loader for the imported file
analyzeHeadless /path/to/projects MyProject -import bin -analysisTimeoutPerFile 300Cap per-file analysis time at 300 seconds
analyzeHeadless /path/to/projects MyProject -import bin -max-cpu 4Limit analysis to 4 CPU cores
analyzeHeadless /path/to/projects MyProject -import bin -log analysis.logWrite the analysis log to a file
analyzeHeadless /path/to/projects MyProject -import bin -scriptlog script.logWrite script output to a dedicated log file
analyzeHeadless /path/to/projects MyProject -import bin -readOnlyAnalyze and run scripts without saving changes to the project
analyzeHeadless ghidra://10.10.10.10/SharedProject -connect <USER> -pConnect to a Ghidra Server shared project, prompting for a password
analyzeHeadless ghidra://10.10.10.10/SharedProject -import bin -commit "initial import"Import into a shared project and commit with a message
analyzeHeadless -helpPrint the full analyzeHeadless usage and option list
/usr/share/ghidra/support/analyzeHeadlessInvoke the headless analyzer directly from the Ghidra install path
ghidra_10.4_PUBLIC/support/buildGhidraJarBuild a single Ghidra jar for embedding Ghidra in other Java tools

Step-by-Step Guide

  1. 1Install and verify: Ghidra needs a 64-bit JDK. Ghidra 11 needs JDK 17 or later, and Ghidra 12 needs JDK 21; check your release notes for the exact requirement. Install Ghidra through Kali's package manager and launch it with ghidra, or extract the official ZIP and use its included launcher (ghidraRun on Linux). Confirm that the project window opens.
  2. 2Check authorization before opening a file: Start with a binary you built yourself or have permission to analyze. For malware analysis with Ghidra, work in an isolated lab and inspect the sample without executing it.
  3. 3Create a project: Choose a Non-Shared Project for this local exercise. Give it a name you can recognize later and keep the original binary separately.
  4. 4Import and check the format: Use File > Import File. Compare the detected format and processor language with what you expect, such as ELF for the Kali example. For a raw image, confirm the architecture, bitness, and byte order before choosing a language.
  5. 5Run auto-analysis: Open the imported program in CodeBrowser, accept auto-analysis with the defaults for this exercise, and wait for it to finish before drawing conclusions about missing functions or references.
  6. 6Read both views: Select a function in the Symbol Tree and read it in the Decompiler. Check its calls and branch conditions against the assembly in the Listing.
  7. 7Follow references and refine names: Pick a string in Defined Strings and follow its cross-references (XREFs) to the code that uses it. Rename functions or variables when you can explain their role, and retype a value only when its usage or a known function signature supports the change.
  8. 8Map the flow: Use the Function Graph to follow both sides of a branch inside a function. Use the call tree to see which functions call it and which it calls. Ghidra may not resolve every indirect call.
  9. 9Decompile a batch: Use analyzeHeadless with -import on a folder of authorized binaries. Add -recursive if you also want subfolders. Use -postScript with an export script you supply and -scriptPath for its directory. Test the script on one known binary before processing the batch.
  10. 10Save, export, and hand off: Save the Ghidra project and export the relevant pseudo-C and addresses as a report. To check runtime behavior, debug the same binary in GDB; for a second static view, open it in Radare2. Check for differences in load addresses before matching locations.

Warnings

Use Cases

Malware Analysis

Analyze malware samples and understand behavior.

Vulnerability Research

Find vulnerabilities in compiled software.

Binary Analysis

Understand compiled code without source.

CTF Challenges

Solve reverse engineering CTF problems.

Firmware Analysis

Inspect authorized firmware images to trace startup code and find references to version strings.

Legacy Code Recovery

Recover the logic of old binaries whose source code is lost, so they can be documented or replaced.

Key Features

Related Tools

Radare2

Reverse Engineering

Radare2 (r2) is a complete open-source framework for reverse engineering and binary analysis. It bundles a disassembler, debugger, hex editor, and scripting engine into a single lightweight command-line toolkit that supports dozens of architectures and executable formats.

GDB

Reverse Engineering

Learn how to use GDB, the GNU Debugger, by building a small C program with debug symbols and following it from the first breakpoint to a crash. Use the same steps to inspect variables, read a backtrace, and tell when a core dump or a look at the assembly would help.

Objection

Reverse Engineering

Objection is a runtime mobile exploration toolkit, powered by Frida, built to help you assess the security of your mobile applications without needing a jailbroken or rooted device.

Frida

Reverse Engineering

Frida is a dynamic instrumentation toolkit for developers, reverse-engineers, and security researchers. It allows you to inject snippets of JavaScript or your own library into native apps on various platforms — making it the industry standard for runtime analysis and mobile app security testing.

objdump

Reverse Engineering

objdump displays information about object files. It can disassemble executables, show headers, symbols, and more.

strings

Reverse Engineering

strings prints the sequences of printable characters in files. Useful for finding hidden text, URLs, and clues in binaries.

Related Cybersecurity Guides

Ethical Hacking · Intermediate

Reverse Engineering for Beginners: Learn to Analyze Binaries with Ghidra & GDB

Learn reverse engineering from scratch: analyze binaries with Ghidra and GDB, read assembly, crack a practice binary, and build a starter toolkit.

Maltego · Beginner

Maltego Community Edition: Free OSINT Tool Guide

A comprehensive guide to Maltego Community Edition — the free version of Maltego. Learn what you get, what you don't, and how to maximize your OSINT capabilities without spending a dime.

Web Security · Intermediate

What Is CSRF? Cross-Site Request Forgery Examples & How to Prevent CSRF Attacks

What is CSRF? Learn how cross-site request forgery tricks your browser into unwanted actions, see real examples and a DVWA worked test, and follow 7 steps to prevent CSRF attacks with tokens, SameSite cookies and framework protection.

OSINT · Intermediate

Google Dorking: How to Use Google Dorks for OSINT & Security Research

Learn Google dorking: advanced search operators, a worked OSINT example on a domain you own, GHDB dorks, a cheat sheet, and how to protect your site.

Frequently Asked Questions

What is Ghidra used for?

Ghidra is used for reverse engineering and binary analysis. It provides disassembly, decompilation, and scripting capabilities for analyzing compiled code.

Is Ghidra free?

Yes, Ghidra is completely free and open source, developed by the NSA.

Is Ghidra as good as IDA Pro?

For many static analysis tasks, yes. Ghidra is free and open source and includes a decompiler. IDA Pro is paid, and Hex-Rays decompiler coverage depends on the license. Both can produce readable pseudo-C; compare them on the architectures and builds you work with. Ghidra has community extensions and supports shared, versioned projects through Ghidra Server. IDA has a long-established plugin ecosystem, and team options depend on the products you license. IDA Pro can be the better choice if you rely on an IDA-only plugin or it produces clearer output for your binaries.

Can Ghidra analyze malware?

Yes, Ghidra is widely used for malware analysis with its decompiler and scripting capabilities.

How do I use Ghidra on Kali Linux?

Install it with sudo apt install ghidra, or download the ZIP and run ./ghidraRun from the extracted folder. Then create a Non-Shared Project, import a binary you are authorized to analyze with File > Import File, accept auto-analysis, and open the program in the CodeBrowser to read the decompiler output.

How do I install Ghidra on Windows?

Install a compatible 64-bit JDK first, download the Ghidra ZIP from the official releases page, extract it, and double-click ghidraRun.bat. On first launch, point Ghidra to your JDK location if it asks, then create a Non-Shared Project and import your first binary.

How do I decompile a binary with Ghidra?

Import the binary into a project, open it, and accept auto-analysis. Then click a function in the Symbol Tree: the Decompiler pane shows C-like pseudo-C for that function, while the Listing pane shows the matching assembly. Rename generic FUN_ functions with L as you identify them, and retype variables with Ctrl+L to make the pseudo-C readable.

How do I use Ghidra for malware analysis?

Analyze the sample statically in an isolated lab — never run it on your main machine. Import it, run auto-analysis, search for strings, imports, and suspicious API calls, and read the decompiler to understand what the sample does without executing it. Pair Ghidra with a dynamic-analysis environment when you need runtime behavior.

Is Ghidra good for beginners?

Yes — Ghidra is one of the best free tools for learning reverse engineering because its decompiler turns assembly into readable pseudo-C. Start with a small program you wrote yourself, follow the import, analyze, and decompile loop, and practice renaming functions and chasing strings before tackling larger binaries.

Can Ghidra decompile EXE files?

Yes. Ghidra imports Windows PE executables as well as Linux ELF binaries and macOS Mach-O files, and its decompiler produces pseudo-C for the functions it recovers. Decompilation is an approximation, not the original source code: names, comments, and some type information are lost during compilation.

How do I decompile a file with Ghidra?

Import a supported binary, open it in CodeBrowser, and let auto-analysis finish. Select a function in the Symbol Tree to see its pseudo-C in the Decompiler. Use the Listing to verify important calls and branches.

Does Ghidra have a decompiler?

Yes. The Ghidra decompiler is built in and shows C-like code for functions on supported processors. It works with many native-code Windows EXE and Linux ELF files, but it does not recover the original source.

Is it illegal to decompile code?

It depends on the law, license terms, and what you're authorized to do. For learning, start with binaries you wrote and compiled yourself. For someone else's code, confirm permission and check the applicable rules; owning a copy does not necessarily authorize decompilation. Laws and exceptions vary by jurisdiction. This is not legal advice.

How do I use AI with Ghidra?

Ghidra has no built-in AI assistant. A community MCP server such as ghidra-mcp can expose decompiler output, function lists, string search, and cross-references to a compatible assistant. Ask it to explain a function or summarize where a string is used, then verify its claims against the Listing. Check what data the integration shares before connecting a project.

How do I import a file into Ghidra?

Open your project, choose File > Import File, and select the binary. Review the proposed format and processor language before confirming. Then open the imported program in CodeBrowser and accept auto-analysis.

Tags

#reverse-engineering#sre#framework#decompiler

Output Explanation

Start at the entry point in the Listing. In this glibc-linked example, startup code passes the address of main to __libc_start_main. Follow that address if main isn't listed by name in the Symbol Tree. Read main in the Decompiler, checking the argument-count comparison and conditional call against the Listing. Find "ready" in Defined Strings and follow its cross-reference to the helper. Trace the helper's call to the puts import in the Symbol Tree. That connects the string to standard output, not just to bytes stored in the file. Rename the helper print_ready and return to main. Verdict: at least one extra command-line argument triggers the message, and both paths return zero.

Ethical Usage Notice

This tool is designed for authorized security testing, educational purposes, and legitimate network administration only. Unauthorized access to computer systems is illegal.