Skip to content

Commit

Permalink
renamed target_opts
Browse files Browse the repository at this point in the history
  • Loading branch information
burhanr13 committed May 29, 2024
1 parent a33d44d commit 52ae3d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/advanced_usages/add_new_target_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_assembler(self, assembler):
You can select the assembler like this:

```python
p = Patcherex("/path/to/binary", target_opts={"assembler": "gas"})
p = Patcherex("/path/to/binary", components={"assembler": "gas"})
```

This will use the `Gas` assembler instead of the default `Keystone` assembler.
Expand Down
15 changes: 7 additions & 8 deletions src/patcherex2/patcherex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import logging

from .components.binary_analyzers.ghidra import Ghidra
from .patches import *
from .patches import __all__ as all_patches
from .targets import Target
from .components.binary_analyzers.ghidra import Ghidra

logger = logging.getLogger(__name__)

Expand All @@ -20,19 +20,19 @@ def __init__(
self,
binary_path: str,
target_cls: type[Target] | None = None,
target_opts: dict[str, str] | None = None,
components: dict[str, str] | None = None,
components_opts: dict[str, dict[str, str]] | None = None,
) -> None:
"""
Constructor.
:param binary_path: The path of the binary to patch.
:param target_cls: Specified architecture class to use, otherwise it is automatically detected, defaults to None
:param target_opts: Options to specify components for the target, defaults to None
:param components: Options to specify components for the target, defaults to None
:param components_opts: Options for configuring each component for the target, defaults to None
"""
if target_opts is None:
target_opts = {}
if components is None:
components = {}
if components_opts is None:
components_opts = {}
self.binary_path = binary_path
Expand Down Expand Up @@ -62,7 +62,7 @@ def __init__(
component,
self.target.get_component(
component,
target_opts.get(component),
components.get(component),
components_opts.get(component),
),
)
Expand All @@ -85,15 +85,14 @@ def __init__(
)
assert len(self.patch_order) == len(all_patches)

def shutdown(self):
def shutdown(self) -> None:
"""
Shuts down any resources used by Patcherex2.
This needs to be called when using Ghidra as the binary analyzer when done patching.
"""
if isinstance(self.binary_analyzer, Ghidra):
self.binary_analyzer.shutdown()


def apply_patches(self) -> None:
"""
Applies all added patches to the binary. Call this when you have added all the patches you want.
Expand Down

0 comments on commit 52ae3d9

Please sign in to comment.