Skip to content

Searching

A real program is far too big to read. Even the specimen, at 20 functions, is mostly library machinery you will never open. The craft is mostly finding: getting from a question to the dozen instructions that answer it. Ghidra offers three searches, each matched to a kind of question, and the specimen can demonstrate the thinking behind all three — its strings and references are real lab output, while the window steps are (documented).

Strings: what the program says

Programs talk, and their text is indexed. The Defined Strings window lists every string the analysers identified, with its address. The specimen's list (79 strings in all, most of them the machinery of an ELF file) contains four the program's author wrote, and the lab's script printed them verbatim:

00102008  "The lighthouse keeper winds the clock at midnight."
0010203b  "usage: gatekeeper <code>"
00102054  "The gate swings open."
0010206a  "The gate stays shut."

Strings are the fastest first survey of any program: menus, error messages, URLs, and file paths announce what a program does before a single function is read. The command line has a poor relation of this window — strings gatekeeper prints the same text with no addresses and no analysis (chapter 13 runs it) — useful for a first look, blind to everything this chapter does next.

References: who uses it

Knowing a string exists is half the fact; knowing who uses it is the other half. A reference (or xref, cross-reference) is a recorded link: this instruction reads that address. Ask Ghidra for the references to the lighthouse string and it will point you at main, the only code that touches it — in the decompiled main the connection is already drawn for you as puts(keeper_note), the string's data symbol carrying the name.

References run in both directions and come in kinds: code calls a function, code reads or writes data, a jump lands on an instruction. The working moves are:

  • References to a function — everything that calls it; the fastest way to learn what a function is for, since callers reveal context the function hides.
  • References from an instruction — where this jump can go, what this call reaches.
  • The call graph — references drawn as a map, for when the question is shape rather than detail.

In a big program this is the whole game: start from a string you recognise (an error message is ideal), follow references to the function that prints it, and you are standing in the middle of the behaviour you wanted — with the other ten thousand functions politely ignored.

Program text and memory

Two heavier searches complete the set. Search Program Text scans the Listing itself — mnemonics, operands, comments — for patterns, which finds instructions ("every CALL to this register") rather than things. Search Memory scans the raw bytes for a pattern you supply, hex or text, which is how you hunt a value the analysers never labelled: a constant like the specimen's 0x191b2, say — searching memory for it lands on the comparison in check_code even in a binary whose functions were never found.

The Program Trees window deserves a mention here too: it shows the program's memory as named fragments (the sections of the file — .text for code, .rodata for read-only data like the specimen's strings), and lets you carve the tree into your own modules as your understanding firms up — the geography on which all the searches run.

Check: searching has succeeded when the question "where does X happen" takes seconds rather than a reading of the whole program — a string found, its references followed, and you are reading the dozen lines that matter. Everything in chapters 5 and 6 worked because the specimen is tiny; this chapter is how the same reading is reached when it isn't.