blob: 29cc1cdee1a3cb0d77f9387768e338f83995b58d (
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
39
40
41
42
43
44
45
46
|
// Export functions as a green-eye-compatible symbol TSV.
//
// Usage (Ghidra headless):
// analyzeHeadless <proj> <name> -process <program> -noanalysis \
// -scriptPath debug/risc-v-gsp-rm-vm/ghidra \
// -postScript ExportForGreenEye.java /abs/path/ghidra-symbols.tsv
//
// Columns: addr (program address) <TAB> name <TAB> size.
// green-eye's `symbols export --index` accepts this form directly.
//
//@category OpenIOV
//@menupath Tools.OpenIOV.Export for green-eye
import java.io.File;
import java.io.PrintWriter;
import ghidra.app.script.GhidraScript;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.FunctionIterator;
public class ExportForGreenEye extends GhidraScript {
@Override
public void run() throws Exception {
String[] args = getScriptArgs();
if (args.length < 1) {
println("usage: ExportForGreenEye.java <out.tsv>");
return;
}
File out = new File(args[0]);
int count = 0;
try (PrintWriter pw = new PrintWriter(out, "UTF-8")) {
pw.println("addr\tname\tsize");
FunctionIterator functions =
currentProgram.getFunctionManager().getFunctions(true);
while (functions.hasNext()) {
Function function = functions.next();
long addr = function.getEntryPoint().getOffset();
long size = function.getBody().getNumAddresses();
pw.printf("0x%08x\t%s\t%d%n", addr, function.getName(), size);
count++;
}
}
println("green-eye: exported " + count + " functions to " + out.getAbsolutePath());
}
}
|