// GhidraScript: FindFunctionCallers.java // Usage (headless): // analyzeHeadless -process -noanalysis -readOnly \ // -scriptPath -postScript FindFunctionCallers.java 0x0063ea70 // // Prints the functions which contain callsites (or any references) to the given function entry. import ghidra.app.script.GhidraScript; import ghidra.program.model.address.Address; import ghidra.program.model.listing.Function; import ghidra.program.model.symbol.Reference; import ghidra.program.model.symbol.ReferenceIterator; import java.util.LinkedHashSet; public class FindFunctionCallers extends GhidraScript { @Override public void run() throws Exception { String[] args = getScriptArgs(); if (args == null || args.length == 0) { printerr("FindFunctionCallers: needs one or more function entry addresses, e.g. 0x613710"); return; } for (String a : args) { long va; try { va = Long.decode(a); } catch (Exception e) { printerr("bad address: " + a); continue; } Address entry = toAddr(va); if (entry == null) { printerr("addr not in program: " + a); continue; } println("=== callers for " + entry + " ==="); LinkedHashSet callers = new LinkedHashSet<>(); ReferenceIterator it = currentProgram.getReferenceManager().getReferencesTo(entry); int n = 0; while (it.hasNext()) { Reference r = it.next(); n++; Function f = getFunctionContaining(r.getFromAddress()); if (f != null) { callers.add(f.getName() + " @ " + f.getEntryPoint() + " (from " + r.getFromAddress() + ")"); } else { callers.add("(no func) from " + r.getFromAddress()); } if (n > 5000) break; } println("refs: " + n); if (callers.isEmpty()) { println("(none)"); } else { for (String s : callers) println(" " + s); } println(""); } } }