Overview
DecompInterface is a self-contained interface to the Ghidra decompiler process. It provides a persistent connection suitable for an open-ended number of function decompilations for a single program. The interface automatically handles process crashes by respawning and reinitializing as needed.Interface
Package:ghidra.app.decompilerLocation:
Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/DecompInterface.java
Constructor
DecompInterface()
Creates a new decompiler interface instance.Initialization Methods
openProgram()
Initializes the decompiler process for a specific program. This method only needs to be called once per program.prog- The program on which to perform decompilations
true if the decompiler process is successfully initialized
Even if the underlying decompiler process crashes, the interface will automatically restart and reinitialize when needed. You do not need to call openProgram again.
closeProgram()
Shutdown the decompiler process and free resources. The interface cannot be used again until openProgram is called.Configuration Methods
setOptions()
Sets the global options used by the decompiler.options- The new (or changed) option object
true if the decompiler process accepted the new options
This method does NOT need to be called repeatedly if options don’t change. Even after recovering from a process crash, the interface keeps the options and automatically sends them to the new process.
setSimplificationStyle()
Sets the type of analysis performed by the decompiler.actionstring- Analysis style name (see below)
true if the decompiler process was successfully configured
Available Styles:
"decompile"- Default style, performs all analysis steps suitable for producing C code"normalize"- Omits type recovery and some final clean-up steps, suitable for normalized pcode syntax trees"firstpass"- No analysis, produces unmodified syntax tree of dataflow from raw pcode"register"- Register-focused analysis"paramid"- Required decompilation followed by parameter measure analysis
toggleSyntaxTree()
Toggles whether the decompiler produces a syntax tree.val-trueto produce a syntax tree,falseotherwise
true if the decompiler process accepted the change
toggleCCode()
Toggles whether the decompiler produces C code.val-trueto produce C code,falseotherwise
true if the decompiler process accepted the change
toggleParamMeasures()
Toggles whether the decompiler produces parameter measures.val-trueto produce parameter measures,falseotherwise
true if the decompiler process accepted the change
toggleJumpLoads()
Toggles whether the decompiler returns information about jump tables used for switch statements.val-trueto return jump table info,falseotherwise
true if the decompiler process accepted the change
Decompilation Methods
decompileFunction()
Decompiles a function and returns the results.func- Function to be decompiledtimeoutSecs- Timeout in seconds (returns null if exceeded)monitor- Optional task monitor for cancellation (may be null)
DecompileResults object containing decompiled function information
flushCache()
Clears cached function and symbol information.It’s recommended to call this after each decompileFunction call, as the decompiler caches and reuses data without explicit synchronization with the database.
Information Methods
getProgram()
Returns the currently open program.getLastMessage()
Returns the last message produced by the decompiler process.If the message is non-null, it’s probably an error message. Use DecompileResults.getErrorMessage() instead.
getSimplificationStyle()
Returns the current simplification style identifier.getMajorVersion()
Returns the major version number of the decompiler.getMinorVersion()
Returns the minor version number of the decompiler.Advanced Methods
generateSignatures()
Generates a signature for a function using current signature settings.func- The function to generate signatures forkeepcalllist-trueif direct call addresses should be collectedtimeoutSecs- Maximum time to spend decompilingmonitor- TaskMonitor for cancellation
stopProcess()
Stops the decompiler process immediately.resetDecompiler()
Resets the native decompiler process. Call this when the decompiler’s view of a program has been invalidated.dispose()
Cleans up resources and terminates the decompiler process.Usage Example
Here’s a complete example of using the DecompInterface:See Also
- Function Manager - Managing functions in a program
- Analyzers - Creating custom analyzers
