Skip to content

Headless Analysis

Everything the CodeBrowser does can be driven without the window, by a command-line program that ships in the installation: support/analyzeHeadless. Server rooms, scheduled jobs, and batch work over a folder of firmware images all live here — and so does this guide's evidence, because a command line is what the build sandbox can run. Every command in this chapter ran for real.

The shape of the command

analyzeHeadless <project folder> <project name> \
    -import <binary> \
    -scriptPath <folder holding scripts> \
    -postScript SurveyProgram.java check_code

Read it left to right: keep the project in this folder under this name; import this binary into it (copying it, as always — the original is untouched); after importing, analyse it; then run this script over the result. The arguments that matter most:

Argument What it does
-import <file> Import and analyse a new program
-process <name> Re-open a program already in the project — no re-import
-postScript <script> [args] Run a script after analysis
-preScript <script> [args] Run a script before analysis
-scriptPath <folder> Add a folder to the script search path
-deleteProject Throw the project away when done
-noanalysis Import without analysing (rare, deliberate)
-log <file> Send the log to a file instead of the console

The guide's second lab pass used -process gatekeeper to decompile two more functions from the project the first pass had saved — proof that a headless project is a real project, reusable by later runs and by the CodeBrowser alike. The whole first invocation, JVM start and all, took about 26 seconds on the build machine; the analysis inside it reported Total Time 3 secs for this 16 KB specimen. Both numbers are this machine and this binary only — startup dominates tiny jobs, analysis dominates real ones.

Two traps, both caught by this guide

Headless work is scripted work, and two of its sharp edges drew blood during this guide's own lab. They are recorded here rather than smoothed over, because you will meet them:

  • Script arguments are separate words. Writing -postScript "SurveyProgram.java check_code" — the script and its argument quoted as one lump — fails with Script not found: SurveyProgram.java check_code. The script name is one word; its arguments follow as their own words.
  • One -scriptPath survives. Repeating the flag did not add folders in the lab's runs: only the last folder given was searched, and a single flag carrying two folders joined by a colon was ignored outright. The reliable pattern is one folder per invocation — gather the scripts a job needs into a single folder and point -scriptPath at it. (Observed on 12.2; the bundled analyzeHeadlessREADME in support/ is the reference to argue with if a future release behaves better.)

A third, slower trap deserves naming before chapter 11 tells its story: headless resolves a script by name across every script folder on its path, including the hundreds Ghidra bundles. A name they already use is a name yours can lose to. Choose names of your own.

When headless is the right door

  • Batches. A folder of a hundred firmware images gets identical, tireless treatment: import, analyse, run the survey script, write the report, next.
  • Repeatability. A result a colleague can re-run is a result that can be checked. The commands above are the guide's whole lab in three lines — that is not an accident, it is the method.
  • Machines without desktops. Servers and build agents have no CodeBrowser to open; headless analysis fits where they live.

And when it isn't: interactive reading — renaming as you learn, following a hunch through the references — is window work, and headless can't follow a hunch.

Check: headless has done its job when the console ends with the analyser's own words — REPORT: Import succeeded — and, when you asked for a script, its output is in the log with the answers you sent it for. The transcripts in examples/ are exactly that output, trimmed of the log's timestamps and prefixes and otherwise untouched.