mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-29 06:29:30 +08:00
GP-5637: More improvements to the PyGhidra API
This commit is contained in:
+3
-2
@@ -4,9 +4,9 @@
|
|||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
@@ -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()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user