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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
// SPDX-License-Identifier: BSD-3-Clause
//
// ConfigureAnalysis.java - Ghidra pre-script used by the Open-IOV CUDA
// tooling to make headless auto-analysis of a large stripped vendor library
// tractable and reproducible.
//
// The CUDA userspace driver is a ~70 MB, fully stripped x86-64 shared object
// with roughly a hundred thousand functions. The default analyzer set spends
// the majority of its time in the two optional "identifier" analyzers, which
// are not needed to obtain readable decompilation:
//
// * Decompiler Parameter ID - decompiles every function to recover
// parameter types (very expensive, no value
// for a stripped binary where we have no
// type definitions for internal structs)
// * Function ID (FID) - matches function bodies against .fidb
// signature databases (liberal, and we have
// no curated database for this toolchain)
//
// Everything else (disassembly, function start search, aggressive instruction
// finder, exception handling, stack analysis, reference analyzers, ...) is
// kept, because function discovery quality on a stripped binary depends on
// them.
//
// Usage (analyzeHeadless):
// -preScript ConfigureAnalysis.java [verbose]
//
// Re-runnable: the same settings are applied on every analysis of a program.
import ghidra.app.script.GhidraScript;
import ghidra.framework.options.Options;
public class ConfigureAnalysis extends GhidraScript {
private static final String[] DISABLE = {
"Decompiler Parameter ID",
"Function ID",
};
private static final String[] ENABLE = {
"Aggressive Instruction Finder",
"GCC Exception Handlers",
"Function Start Search",
"Shared Return Calls",
"Non-Returning Functions - Known",
"Non-Returning Functions - Discovered",
};
@Override
public void run() throws Exception {
boolean verbose = getScriptArgs().length > 0;
Options opts = currentProgram.getOptions("Analyzers");
if (verbose) {
println("[ConfigureAnalysis] analyzer options before:");
for (String name : opts.getOptionNames()) {
println(" " + name + " = " + opts.getObject(name, null));
}
}
for (String name : DISABLE) {
if (opts.contains(name)) {
opts.setBoolean(name, false);
println("[ConfigureAnalysis] disabled: " + name);
} else {
println("[ConfigureAnalysis] WARN not found: " + name);
}
}
for (String name : ENABLE) {
if (opts.contains(name)) {
opts.setBoolean(name, true);
println("[ConfigureAnalysis] enabled: " + name);
}
}
if (verbose) {
println("[ConfigureAnalysis] analyzer options after:");
for (String name : opts.getOptionNames()) {
println(" " + name + " = " + opts.getObject(name, null));
}
}
}
}
|