mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-01-06 20:53:55 -05:00
Merge remote-tracking branch 'origin/patch'
This commit is contained in:
@@ -120,7 +120,7 @@ def consume_program(
|
|||||||
object was provided, the same consumer object is returned. Otherwise, a new consumer object
|
object was provided, the same consumer object is returned. Otherwise, a new consumer object
|
||||||
is created and returned.
|
is created and returned.
|
||||||
:raises FileNotFoundError: If the path does not exist in the project.
|
:raises FileNotFoundError: If the path does not exist in the project.
|
||||||
:raises TypeError: If the path in the project exists but is not a Program.
|
:raises pyghidra.ProgramTypeError: If the path in the project exists but is not a Program.
|
||||||
"""
|
"""
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ def program_context(
|
|||||||
:param path: The project path of the program (should start with "/").
|
:param path: The project path of the program (should start with "/").
|
||||||
:return: The Ghidra program.
|
:return: The Ghidra program.
|
||||||
:raises FileNotFoundError: If the path does not exist in the project.
|
:raises FileNotFoundError: If the path does not exist in the project.
|
||||||
:raises TypeError: If the path in the project exists but is not a Program.
|
:raises pyghidra.ProgramTypeError: If the path in the project exists but is not a Program.
|
||||||
"""
|
"""
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -277,6 +277,12 @@ def walk_programs(
|
|||||||
"""
|
"""
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### pyghidra.ProgramTypeError
|
||||||
|
```python
|
||||||
|
class ProgramTypeError(TypeError):
|
||||||
|
"""Custom exception for when a Program was expected but not received."""
|
||||||
|
```
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
The following example, while not very useful, showcases much of the API:
|
The following example, while not very useful, showcases much of the API:
|
||||||
```python
|
```python
|
||||||
@@ -564,6 +570,7 @@ import pdb_ # imports Ghidra's pdb
|
|||||||
__3.0.2__
|
__3.0.2__
|
||||||
* Fixed an issue that prevented [`pyghidra.analysis_properties()`](#pyghidraanalysis_properties)
|
* Fixed an issue that prevented [`pyghidra.analysis_properties()`](#pyghidraanalysis_properties)
|
||||||
from having access to all of the analysis properties.
|
from having access to all of the analysis properties.
|
||||||
|
* Fixed issues related to the PyGhidra API inadvertently squashing exceptions
|
||||||
|
|
||||||
__3.0.1__
|
__3.0.1__
|
||||||
* Fixed `AttributeError: module 'pyghidra' has no attribute 'program_conext'` when performing a
|
* Fixed `AttributeError: module 'pyghidra' has no attribute 'program_conext'` when performing a
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ from pyghidra.api import start, started
|
|||||||
from pyghidra.api import open_project, open_filesystem, consume_program, program_context, analyze
|
from pyghidra.api import open_project, open_filesystem, consume_program, program_context, analyze
|
||||||
from pyghidra.api import ghidra_script, transaction, analysis_properties, program_info
|
from pyghidra.api import ghidra_script, transaction, analysis_properties, program_info
|
||||||
from pyghidra.api import program_loader, task_monitor, walk_project, walk_programs
|
from pyghidra.api import program_loader, task_monitor, walk_project, walk_programs
|
||||||
|
from pyghidra.api import ProgramTypeError
|
||||||
from pyghidra.launcher import DeferredPyGhidraLauncher, GuiPyGhidraLauncher, HeadlessPyGhidraLauncher
|
from pyghidra.launcher import DeferredPyGhidraLauncher, GuiPyGhidraLauncher, HeadlessPyGhidraLauncher
|
||||||
from pyghidra.script import get_current_interpreter
|
from pyghidra.script import get_current_interpreter
|
||||||
from pyghidra.version import ApplicationInfo, ExtensionDetails
|
from pyghidra.version import ApplicationInfo, ExtensionDetails
|
||||||
@@ -70,5 +71,5 @@ __all__ = [
|
|||||||
"HeadlessPyGhidraLauncher", "start", "started", "open_project", "open_filesystem",
|
"HeadlessPyGhidraLauncher", "start", "started", "open_project", "open_filesystem",
|
||||||
"consume_program", "program_context", "analyze", "ghidra_script", "transaction",
|
"consume_program", "program_context", "analyze", "ghidra_script", "transaction",
|
||||||
"analysis_properties", "program_info", "program_loader", "task_monitor", "walk_project",
|
"analysis_properties", "program_info", "program_loader", "task_monitor", "walk_project",
|
||||||
"walk_programs"
|
"walk_programs", "ProgramTypeError"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ def consume_program(
|
|||||||
object was provided, the same consumer object is returned. Otherwise, a new consumer object
|
object was provided, the same consumer object is returned. Otherwise, a new consumer object
|
||||||
is created and returned.
|
is created and returned.
|
||||||
:raises FileNotFoundError: If the path does not exist in the project.
|
:raises FileNotFoundError: If the path does not exist in the project.
|
||||||
:raises TypeError: If the path in the project exists but is not a Program.
|
:raises pyghidra.ProgramTypeError: If the path in the project exists but is not a Program.
|
||||||
"""
|
"""
|
||||||
from ghidra.program.model.listing import Program
|
from ghidra.program.model.listing import Program
|
||||||
from java.lang import Object # type:ignore @UnresolvedImport
|
from java.lang import Object # type:ignore @UnresolvedImport
|
||||||
@@ -135,7 +135,7 @@ def consume_program(
|
|||||||
program_cls = Program.class_
|
program_cls = Program.class_
|
||||||
if not program_cls.isAssignableFrom(dobj.getClass()):
|
if not program_cls.isAssignableFrom(dobj.getClass()):
|
||||||
dobj.release(consumer)
|
dobj.release(consumer)
|
||||||
raise TypeError(f'"{path}" exists but is not a Program')
|
raise ProgramTypeError(f'"{path}" exists but is not a Program')
|
||||||
return dobj, consumer
|
return dobj, consumer
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
@@ -151,7 +151,7 @@ def program_context(
|
|||||||
:param path: The project path of the program (should start with "/").
|
:param path: The project path of the program (should start with "/").
|
||||||
:return: The Ghidra program.
|
:return: The Ghidra program.
|
||||||
:raises FileNotFoundError: If the path does not exist in the project.
|
:raises FileNotFoundError: If the path does not exist in the project.
|
||||||
:raises TypeError: If the path in the project exists but is not a Program.
|
:raises pyghidra.ProgramTypeError: If the path in the project exists but is not a Program.
|
||||||
"""
|
"""
|
||||||
program, consumer = consume_program(project, path)
|
program, consumer = consume_program(project, path)
|
||||||
try:
|
try:
|
||||||
@@ -270,6 +270,7 @@ def transaction(
|
|||||||
yield transaction_id
|
yield transaction_id
|
||||||
except:
|
except:
|
||||||
success = False
|
success = False
|
||||||
|
raise
|
||||||
finally:
|
finally:
|
||||||
program.endTransaction(transaction_id, success)
|
program.endTransaction(transaction_id, success)
|
||||||
|
|
||||||
@@ -361,7 +362,11 @@ def walk_programs(
|
|||||||
with program_context(project, file.getPathname()) as program:
|
with program_context(project, file.getPathname()) as program:
|
||||||
if program_filter(file, program):
|
if program_filter(file, program):
|
||||||
callback(file, program)
|
callback(file, program)
|
||||||
except TypeError:
|
except ProgramTypeError:
|
||||||
pass # skip over non-programs
|
pass # skip over non-programs
|
||||||
|
|
||||||
walk_project(project, process, start=start)
|
walk_project(project, process, start=start)
|
||||||
|
|
||||||
|
class ProgramTypeError(TypeError):
|
||||||
|
"""Custom exception for when a Program was expected but not received."""
|
||||||
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user