Closed GscheadaHamme closed 2 months ago
When you say "I assume", might I ask how deeply you dug into profiling it? Were you playing with custom builds of Ghidra, or looking at the source and noting that nothing much happens between the prints? A couple of other questions:
analyzeHeadless
in parallel? Thanks!
Thank you for the fast reply, I will provide more information.
Edit: NVM, ~/.ghidra
is not empty, its contents are just hidden files.
analyzeHeadless
in parallel, but I'm planning to do so. My preferred approach is to create a fresh project for each binary I want to analyze to avoid race conditions.ghidra-analyzeHeadless TestProject Test -log Test.log -scriptPath scripts -postScript TestHelloWorld.java -process If
File Contents:
Test.log
: 7 seconds from (HeadlessAnalyzer) REPORT: Analysis succeeded for file: /If
to (HeadlessAnalyzer) SCRIPT: <path>/scripts/TestHelloWorld.java
2024-09-04 12:30:14 INFO (LoggingInitialization) Using log config file: jar:file:/opt/ghidra/Ghidra/Framework/Generic/lib/Generic.jar!/generic.log4j.xml
2024-09-04 12:30:14 INFO (LoggingInitialization) Using log file: Test.log
2024-09-04 12:30:14 INFO (Preferences) Loading user preferences: ~/.ghidra/.ghidra_11.0.3_DEV/preferences
2024-09-04 12:30:14 INFO (Preferences) Loading previous preferences: ~/.ghidra/.ghidra_10.3.2_DEV/preferences
2024-09-04 12:30:14 INFO (ClassSearcher) Searching for classes...
2024-09-04 12:30:14 INFO (ClassSearcher) Class search complete (691 ms)
2024-09-04 12:30:14 INFO (SSLContextInitializer) Initializing SSL Context
2024-09-04 12:30:14 INFO (SecureRandomFactory) Initializing Random Number Generator...
2024-09-04 12:30:14 INFO (SecureRandomFactory) Random Number Generator initialization complete: NativePRNGNonBlocking
2024-09-04 12:30:14 INFO (ApplicationTrustManagerFactory) Trust manager disabled, cacerts have not been set
2024-09-04 12:30:15 INFO (HeadlessAnalyzer) HEADLESS Script Paths:
/opt/ghidra/Ghidra/Features/SystemEmulation/ghidra_scripts
/opt/ghidra/Ghidra/Features/GnuDemangler/ghidra_scripts
/opt/ghidra/Ghidra/Debug/Debugger-agent-frida/ghidra_scripts
/opt/ghidra/Ghidra/Processors/DATA/ghidra_scripts
/opt/ghidra/Ghidra/Processors/JVM/ghidra_scripts
/opt/ghidra/Ghidra/Debug/Debugger-rmi-trace/ghidra_scripts
/opt/ghidra/Ghidra/Features/MicrosoftCodeAnalyzer/ghidra_scripts
/opt/ghidra/Ghidra/Features/Python/ghidra_scripts
/opt/ghidra/Ghidra/Features/VersionTracking/ghidra_scripts
/opt/ghidra/Ghidra/Features/Base/ghidra_scripts
/opt/ghidra/Ghidra/Processors/Atmel/ghidra_scripts
/opt/ghidra/Ghidra/Debug/Debugger/ghidra_scripts
/opt/ghidra/Ghidra/Features/Decompiler/ghidra_scripts
/opt/ghidra/Ghidra/Features/FunctionID/ghidra_scripts
/opt/ghidra/Ghidra/Debug/Debugger-agent-dbgmodel-traceloader/ghidra_scripts
/opt/ghidra/Ghidra/Features/PDB/ghidra_scripts
/opt/ghidra/Ghidra/Processors/8051/ghidra_scripts
/opt/ghidra/Ghidra/Processors/PIC/ghidra_scripts
/opt/ghidra/Ghidra/Features/FileFormats/ghidra_scripts
/opt/ghidra/Ghidra/Features/BSim/ghidra_scripts
<path>/scripts
/opt/ghidra/Ghidra/Features/BytePatterns/ghidra_scripts
2024-09-04 12:30:15 INFO (HeadlessAnalyzer) HEADLESS: execution starts
2024-09-04 12:30:15 INFO (HeadlessAnalyzer) Opening existing project: <path>/TestProject/Test
2024-09-04 12:30:15 INFO (HeadlessProject) Opening project: <path>/TestProject/Test
2024-09-04 12:30:16 INFO (HeadlessAnalyzer) REPORT: Processing project file: /If
2024-09-04 12:30:16 INFO (HeadlessAnalyzer) ANALYZING all memory and code: /If
2024-09-04 12:30:16 INFO (ExternalDebugFilesService) DWARF external debug information found: ExternalDebugInfo [filename=null, crc=0, hash=82a1bc26f22d573ee28b42b4707905ad3700a156]
2024-09-04 12:30:16 INFO (DWARFAnalyzer) Unable to find DWARF information, skipping DWARF analysis
2024-09-04 12:30:16 INFO (PackedDatabaseCache) Packed database cache: /tmp/korbi-Ghidra/packed-db-cache
2024-09-04 12:30:16 DEBUG (PackedDatabaseCache) Using cached packed database: /opt/ghidra/Ghidra/Features/Base/data/typeinfo/generic/generic_clib_64.gdt
2024-09-04 12:30:16 INFO (ApplyDataArchiveAnalyzer) Applied data type archive: generic_clib_64
2024-09-04 12:30:17 INFO (HeadlessAnalyzer) REPORT: Analysis succeeded for file: /If
2024-09-04 12:30:24 INFO (HeadlessAnalyzer) SCRIPT: <path>/scripts/TestHelloWorld.java
2024-09-04 12:30:24 INFO (GhidraScript) TestHelloWorld.java> Hello World
2024-09-04 12:30:24 INFO (HeadlessAnalyzer) ANALYZING changes made by post scripts: /If
2024-09-04 12:30:24 INFO (HeadlessAnalyzer) REPORT: Post-analysis succeeded for file: /If
2024-09-04 12:30:24 INFO (HeadlessAnalyzer) REPORT: Save succeeded for processed file: /If
2024-09-04 12:30:24 DEBUG (DefaultProjectData) Closing ProjectData: <path>/TestProject/Test.rep
2024-09-04 12:30:24 DEBUG (DefaultProjectData) Disposing ProjectData: <path>/TestProject/Test.rep
TestHelloWorld.java
import ghidra.app.script.GhidraScript;
public class TestHelloWorld extends GhidraScript { @Override public void run() throws Exception { println("Hello World"); } }
- `If.c` from which the binary `If` was compiled:
```If.c
int main() {
int x = 0;
int y = 1;
if (x < y) {
return 1;
} else {
return 0;
}
}
Do you see any potential to reduce the time needed for the steps between (HeadlessAnalyzer) REPORT: Analysis succeeded for file: /If
and (HeadlessAnalyzer) SCRIPT: <path>/scripts/TestHelloWorld.java
?
Caveat: this test was performed using a script
directory containing large bin
and build
folders resulting from script development with neovim
.
After removing those folders, performance increased massively. I will test that approach for my export script, too.
Thank you for your patience. After moving the scripts to an individual folder, performance increased drastically (7 seconds reduced to 1 second). More sophisticated profiling exceeds the scope of my work. Thank you once again for the quick response.
Hello there,
I'm planning to analyze large amounts of binary libraries with
analyzeHeadless
and execute a-postScript
for each binary that exports the CFG for every function found by Ghidra to JSON.Currently one of the most resource intensive parts of this process is the step between the outputs
INFO REPORT: Analysis succeeded for file: ...
andINFO SCRIPT: /path/to/script.java (HeadlessAnalyzer)
. I assume, that indicates the recompilation of-postScript
in each run. Is there a way to avoid the recompilation?Many thanks for your support.