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
|
@ -4,9 +4,9 @@
|
|||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package ghidra.app.plugin.core.analysis;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface AutoAnalysisManagerListener {
|
||||
|
||||
public void analysisEnded(AutoAnalysisManager manager, boolean isCancelled);
|
||||
|
|
|
@ -141,11 +141,15 @@ def program_context(
|
|||
|
||||
### pyghidra.analyze()
|
||||
```python
|
||||
def analyze(program: "Program"):
|
||||
def analyze(
|
||||
program: "Program",
|
||||
monitor: Optional["TaskMonitor"] = None
|
||||
) -> str:
|
||||
"""
|
||||
Analyzes the given program.
|
||||
|
||||
:param program: The Ghidra program to analyze.
|
||||
:return: The analysis log.
|
||||
"""
|
||||
```
|
||||
|
||||
|
|
|
@ -162,11 +162,12 @@ def program_context(
|
|||
def analyze(
|
||||
program: "Program",
|
||||
monitor: Optional["TaskMonitor"] = None
|
||||
):
|
||||
) -> str:
|
||||
"""
|
||||
Analyzes the given program.
|
||||
|
||||
:param program: The Ghidra program to analyze.
|
||||
:return: The analysis log.
|
||||
"""
|
||||
from ghidra.app.script import GhidraScriptUtil
|
||||
from ghidra.program.util import GhidraProgramUtilities
|
||||
|
@ -181,12 +182,16 @@ def analyze(
|
|||
mgr: AutoAnalysisManager = AutoAnalysisManager.getAnalysisManager(program);
|
||||
mgr.initializeOptions();
|
||||
mgr.reAnalyzeAll(None);
|
||||
analysisTool = mgr.getAnalysisTool();
|
||||
if analysisTool is None or analysisTool.threadIsBackgroundTaskThread():
|
||||
mgr.startAnalysis(monitor, True); # yields to analysis
|
||||
else:
|
||||
mgr.waitForAnalysis(None, monitor); # waits for all analysis to complete
|
||||
mgr_log = ""
|
||||
def get_log(manager, _is_cancelled):
|
||||
nonlocal mgr_log
|
||||
mgr_log += manager.getMessageLog().toString()
|
||||
mgr.addListener(get_log)
|
||||
mgr.startAnalysis(monitor, True); # yields to analysis
|
||||
if not monitor.isCancelled():
|
||||
monitor.cancel()
|
||||
GhidraProgramUtilities.markProgramAnalyzed(program)
|
||||
return mgr_log
|
||||
finally:
|
||||
GhidraScriptUtil.releaseBundleHostReference()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue