blob: 86a31b3c27fef0d50b7872da09fa7592c4fd8e2e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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);
}
}
|