mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 01:39:21 +02:00
GP-5637: More improvements to the PyGhidra API
This commit is contained in:
parent
5fbb052b28
commit
657ec39201
3 changed files with 19 additions and 9 deletions
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package ghidra.app.plugin.core.analysis;
|
package ghidra.app.plugin.core.analysis;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
public interface AutoAnalysisManagerListener {
|
public interface AutoAnalysisManagerListener {
|
||||||
|
|
||||||
public void analysisEnded(AutoAnalysisManager manager, boolean isCancelled);
|
public void analysisEnded(AutoAnalysisManager manager, boolean isCancelled);
|
||||||
|
|
|
@ -141,11 +141,15 @@ def program_context(
|
||||||
|
|
||||||
### pyghidra.analyze()
|
### pyghidra.analyze()
|
||||||
```python
|
```python
|
||||||
def analyze(program: "Program"):
|
def analyze(
|
||||||
|
program: "Program",
|
||||||
|
monitor: Optional["TaskMonitor"] = None
|
||||||
|
) -> str:
|
||||||
"""
|
"""
|
||||||
Analyzes the given program.
|
Analyzes the given program.
|
||||||
|
|
||||||
:param program: The Ghidra program to analyze.
|
:param program: The Ghidra program to analyze.
|
||||||
|
:return: The analysis log.
|
||||||
"""
|
"""
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -162,11 +162,12 @@ def program_context(
|
||||||
def analyze(
|
def analyze(
|
||||||
program: "Program",
|
program: "Program",
|
||||||
monitor: Optional["TaskMonitor"] = None
|
monitor: Optional["TaskMonitor"] = None
|
||||||
):
|
) -> str:
|
||||||
"""
|
"""
|
||||||
Analyzes the given program.
|
Analyzes the given program.
|
||||||
|
|
||||||
:param program: The Ghidra program to analyze.
|
:param program: The Ghidra program to analyze.
|
||||||
|
:return: The analysis log.
|
||||||
"""
|
"""
|
||||||
from ghidra.app.script import GhidraScriptUtil
|
from ghidra.app.script import GhidraScriptUtil
|
||||||
from ghidra.program.util import GhidraProgramUtilities
|
from ghidra.program.util import GhidraProgramUtilities
|
||||||
|
@ -181,12 +182,16 @@ def analyze(
|
||||||
mgr: AutoAnalysisManager = AutoAnalysisManager.getAnalysisManager(program);
|
mgr: AutoAnalysisManager = AutoAnalysisManager.getAnalysisManager(program);
|
||||||
mgr.initializeOptions();
|
mgr.initializeOptions();
|
||||||
mgr.reAnalyzeAll(None);
|
mgr.reAnalyzeAll(None);
|
||||||
analysisTool = mgr.getAnalysisTool();
|
mgr_log = ""
|
||||||
if analysisTool is None or analysisTool.threadIsBackgroundTaskThread():
|
def get_log(manager, _is_cancelled):
|
||||||
mgr.startAnalysis(monitor, True); # yields to analysis
|
nonlocal mgr_log
|
||||||
else:
|
mgr_log += manager.getMessageLog().toString()
|
||||||
mgr.waitForAnalysis(None, monitor); # waits for all analysis to complete
|
mgr.addListener(get_log)
|
||||||
|
mgr.startAnalysis(monitor, True); # yields to analysis
|
||||||
|
if not monitor.isCancelled():
|
||||||
|
monitor.cancel()
|
||||||
GhidraProgramUtilities.markProgramAnalyzed(program)
|
GhidraProgramUtilities.markProgramAnalyzed(program)
|
||||||
|
return mgr_log
|
||||||
finally:
|
finally:
|
||||||
GhidraScriptUtil.releaseBundleHostReference()
|
GhidraScriptUtil.releaseBundleHostReference()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue