Skip to content

Commit

Permalink
Merge pull request #46 from cduplantisms/cduplantisms/remove-implicit…
Browse files Browse the repository at this point in the history
…-optional-function-args

Remove implicit Optional function arguments
  • Loading branch information
dc3-tsd authored Oct 29, 2024
2 parents f1c8f2f + 6af564e commit 1b3773a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 34 deletions.
50 changes: 25 additions & 25 deletions pyhidra/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _get_language(id: str) -> "Language":
raise ValueError("Invalid Language ID: "+id)


def _get_compiler_spec(lang: "Language", id: str = None) -> "CompilerSpec":
def _get_compiler_spec(lang: "Language", id: Optional[str] = None) -> "CompilerSpec":
if id is None:
return lang.getDefaultCompilerSpec()
from ghidra.program.model.lang import CompilerSpecID, CompilerSpecNotFoundException
Expand All @@ -98,11 +98,11 @@ def _get_compiler_spec(lang: "Language", id: str = None) -> "CompilerSpec":

def _setup_project(
binary_path: Union[str, Path],
project_location: Union[str, Path] = None,
project_name: str = None,
language: str = None,
compiler: str = None,
loader: Union[str, JClass] = None
project_location: Optional[Union[str, Path]] = None,
project_name: Optional[str] = None,
language: Optional[str] = None,
compiler: Optional[str] = None,
loader: Optional[Union[str, JClass]] = None
) -> Tuple["GhidraProject", "Program"]:
from ghidra.base.project import GhidraProject
from java.lang import ClassLoader
Expand Down Expand Up @@ -213,12 +213,12 @@ def _analyze_program(flat_api, program):
@contextlib.contextmanager
def open_program(
binary_path: Union[str, Path],
project_location: Union[str, Path] = None,
project_name: str = None,
project_location: Optional[Union[str, Path]] = None,
project_name: Optional[str] = None,
analyze=True,
language: str = None,
compiler: str = None,
loader: Union[str, JClass] = None
language: Optional[str] = None,
compiler: Optional[str] = None,
loader: Optional[Union[str, JClass]] = None
) -> ContextManager["FlatProgramAPI"]: # type: ignore
"""
Opens given binary path in Ghidra and returns FlatProgramAPI object.
Expand Down Expand Up @@ -273,16 +273,16 @@ def open_program(

@contextlib.contextmanager
def _flat_api(
binary_path: Union[str, Path] = None,
project_location: Union[str, Path] = None,
project_name: str = None,
binary_path: Optional[Union[str, Path]] = None,
project_location: Optional[Union[str, Path]] = None,
project_name: Optional[str] = None,
verbose=False,
analyze=True,
language: str = None,
compiler: str = None,
loader: Union[str, JClass] = None,
language: Optional[str] = None,
compiler: Optional[str] = None,
loader: Optional[Union[str, JClass]] = None,
*,
install_dir: Path = None
install_dir: Optional[Path] = None
):
"""
Runs a given script on a given binary path.
Expand Down Expand Up @@ -345,16 +345,16 @@ def _flat_api(
def run_script(
binary_path: Optional[Union[str, Path]],
script_path: Union[str, Path],
project_location: Union[str, Path] = None,
project_name: str = None,
script_args: List[str] = None,
project_location: Optional[Union[str, Path]] = None,
project_name: Optional[str] = None,
script_args: Optional[List[str]] = None,
verbose=False,
analyze=True,
lang: str = None,
compiler: str = None,
loader: Union[str, JClass] = None,
lang: Optional[str] = None,
compiler: Optional[str] = None,
loader: Optional[Union[str, JClass]] = None,
*,
install_dir: Path = None
install_dir: Optional[Path] = None
):
"""
Runs a given script on a given binary path.
Expand Down
4 changes: 2 additions & 2 deletions pyhidra/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import platform
import sys
import traceback
from typing import NoReturn
from typing import Optional, NoReturn
import warnings

import pyhidra
Expand Down Expand Up @@ -125,7 +125,7 @@ def _gui():
_gui_default(install_dir)


def gui(install_dir: Path = None):
def gui(install_dir: Optional[Path] = None):
"""
Starts the Ghidra GUI
Expand Down
4 changes: 2 additions & 2 deletions pyhidra/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import threading
from importlib.machinery import ModuleSpec
from pathlib import Path
from typing import List, NoReturn, Tuple, Union
from typing import Optional, List, NoReturn, Tuple, Union

import jpype
from jpype import imports, _jpype
Expand Down Expand Up @@ -129,7 +129,7 @@ class PyhidraLauncher:
Base pyhidra launcher
"""

def __init__(self, verbose=False, *, install_dir: Path = None):
def __init__(self, verbose=False, *, install_dir: Optional[Path] = None):
"""
Initializes a new `PyhidraLauncher`.
Expand Down
3 changes: 2 additions & 1 deletion pyhidra/linux_shortcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import sysconfig
from pathlib import Path
from typing import Optional

desktop_entry = """\
[Desktop Entry]
Expand Down Expand Up @@ -35,7 +36,7 @@ def extract_png(install_dir: Path) -> Path:
return png_path


def create_shortcut(install_dir: Path = None):
def create_shortcut(install_dir: Optional[Path] = None):
"""Install a desktop entry on Linux machine."""
pyhidra_exec = Path(sysconfig.get_path("scripts")) / "pyhidra"
if not pyhidra_exec.exists():
Expand Down
3 changes: 2 additions & 1 deletion pyhidra/mac_shortcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from tempfile import TemporaryDirectory

from pyhidra.linux_shortcut import extract_png
from typing import Optional


applications = Path("~/Applications").expanduser()
Expand Down Expand Up @@ -93,7 +94,7 @@ def __exit__(self, *args):
return self._tmpdir.__exit__(*args)


def create_shortcut(install_dir: Path = None):
def create_shortcut(install_dir: Optional[Path] = None):
"""Install a desktop entry on Mac machine."""
if install_dir is None:
install_dir = os.environ.get("GHIDRA_INSTALL_DIR")
Expand Down
4 changes: 2 additions & 2 deletions pyhidra/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from importlib.machinery import ModuleSpec, SourceFileLoader
from pathlib import Path
from jpype import JClass, JImplementationFor
from typing import List
from typing import Optional, List


from .core import debug_callback
Expand Down Expand Up @@ -213,7 +213,7 @@ def set(self, state, monitor, writer):
"""
self._script.set(state, monitor, writer)

def run(self, script_path: str = None, script_args: List[str] = None):
def run(self, script_path: Optional[str] = None, script_args: Optional[List[str]] = None):
"""
Run this GhidraScript
Expand Down
3 changes: 2 additions & 1 deletion pyhidra/win_shortcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import sysconfig
from pathlib import Path
from pyhidra import DeferredPyhidraLauncher
from typing import Optional


# creating a shortcut with the winapi to have a set app id is trivial right?




def create_shortcut(install_dir: Path = None):
def create_shortcut(install_dir: Optional[Path] = None):
"""Creates a shortcut to Ghidra (with pyhidra) on the desktop."""

link = Path("~/Desktop/Ghidra (pyhidra).lnk").expanduser()
Expand Down

0 comments on commit 1b3773a

Please sign in to comment.