diff options
Diffstat (limited to 'userspace/cuda/tools/ghidra/PrintProgramInfo.java')
| -rw-r--r-- | userspace/cuda/tools/ghidra/PrintProgramInfo.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/userspace/cuda/tools/ghidra/PrintProgramInfo.java b/userspace/cuda/tools/ghidra/PrintProgramInfo.java new file mode 100644 index 0000000..86a31b3 --- /dev/null +++ b/userspace/cuda/tools/ghidra/PrintProgramInfo.java @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// PrintProgramInfo.java - Ghidra post-script: print the program's image base, +// executable block ranges and function count. Used to establish the address +// convention of a project before running decompilation tools. +// +// Usage: +// analyzeHeadless <proj> <name> -process <program> -readOnly -noanalysis \ +// -postScript PrintProgramInfo.java +import ghidra.app.script.GhidraScript; +import ghidra.program.model.address.Address; +import ghidra.program.model.listing.Function; +import ghidra.program.model.listing.FunctionIterator; +import ghidra.program.model.mem.MemoryBlock; + +public class PrintProgramInfo extends GhidraScript { + @Override + public void run() throws Exception { + println("program = " + currentProgram.getName()); + println("language = " + currentProgram.getLanguageID()); + println("image base = 0x" + Long.toHexString(currentProgram.getImageBase().getOffset())); + println("executable blocks:"); + for (MemoryBlock b : currentProgram.getMemory().getBlocks()) { + if (b.isExecute()) { + println(" 0x" + Long.toHexString(b.getStart().getOffset()) + + " - 0x" + Long.toHexString(b.getEnd().getOffset()) + + " " + b.getName()); + } + } + int n = 0; + FunctionIterator fit = currentProgram.getListing().getFunctions(true); + while (fit.hasNext() && !monitor.isCancelled()) { + Function f = fit.next(); + if (!f.isExternal()) n++; + } + println("functions = " + n); + } +} |
