From f906c2c3550c8cd1f0dbd952f8df1085793b4153 Mon Sep 17 00:00:00 2001 From: jonschz Date: Sat, 24 Aug 2024 09:55:16 +0200 Subject: [PATCH] run linter + formatter --- .../import_functions_and_types_from_pdb.py | 9 ++++++--- tools/ghidra_scripts/lego_util/function_importer.py | 8 ++++++-- tools/ghidra_scripts/lego_util/ghidra_helper.py | 2 ++ tools/ghidra_scripts/lego_util/headers.pyi | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/ghidra_scripts/import_functions_and_types_from_pdb.py b/tools/ghidra_scripts/import_functions_and_types_from_pdb.py index 093b1ebc..54bb7e9f 100644 --- a/tools/ghidra_scripts/import_functions_and_types_from_pdb.py +++ b/tools/ghidra_scripts/import_functions_and_types_from_pdb.py @@ -228,7 +228,6 @@ def log_and_track_failure( def main(): - if GLOBALS.running_from_ghidra: origfile_name = getProgramFile().getName() @@ -237,7 +236,9 @@ def main(): elif origfile_name in ["LEGO1D.DLL", "BETA10.DLL"]: module = SupportedModules.BETA10 else: - raise Lego1Exception(f"Unsupported file name in import script: {origfile_name}") + raise Lego1Exception( + f"Unsupported file name in import script: {origfile_name}" + ) else: module = SupportedModules.LEGO1 @@ -262,7 +263,9 @@ def main(): with Bin(str(origfile_path), find_str=True) as origfile, Bin( str(recompiledfile_path) ) as recompfile: - isle_compare = IsleCompare(origfile, recompfile, str(pdbfile_path), str(repo_root)) + isle_compare = IsleCompare( + origfile, recompfile, str(pdbfile_path), str(repo_root) + ) logger.info("Comparison complete.") diff --git a/tools/ghidra_scripts/lego_util/function_importer.py b/tools/ghidra_scripts/lego_util/function_importer.py index 06b14a4e..379d412f 100644 --- a/tools/ghidra_scripts/lego_util/function_importer.py +++ b/tools/ghidra_scripts/lego_util/function_importer.py @@ -39,6 +39,7 @@ class PdbFunctionImporter(ABC): """A representation of a function from the PDB with each type replaced by a Ghidra type instance.""" + def __init__( self, api: FlatProgramAPI, @@ -71,10 +72,12 @@ def build(api: FlatProgramAPI, func: PdbFunction, type_importer: "PdbTypeImporte ) @abstractmethod - def matches_ghidra_function(self, ghidra_function: Function) -> bool: ... + def matches_ghidra_function(self, ghidra_function: Function) -> bool: + ... @abstractmethod - def overwrite_ghidra_function(self, ghidra_function: Function): ... + def overwrite_ghidra_function(self, ghidra_function: Function): + ... class ThunkPdbFunctionImport(PdbFunctionImporter): @@ -101,6 +104,7 @@ def overwrite_ghidra_function(self, ghidra_function: Function): # pylint: disable=too-many-instance-attributes class FullPdbFunctionImporter(PdbFunctionImporter): """For importing functions into Ghidra where all information are available.""" + def __init__( self, api: FlatProgramAPI, diff --git a/tools/ghidra_scripts/lego_util/ghidra_helper.py b/tools/ghidra_scripts/lego_util/ghidra_helper.py index 8d9ef2c2..24e70c65 100644 --- a/tools/ghidra_scripts/lego_util/ghidra_helper.py +++ b/tools/ghidra_scripts/lego_util/ghidra_helper.py @@ -80,9 +80,11 @@ def create_ghidra_namespace( namespace = api.createNamespace(namespace, part) return namespace + # These appear in debug builds THUNK_OF_RE = re.compile(r"^Thunk of '(.*)'$") + def sanitize_name(name: str) -> str: """ Takes a full class or function name and replaces characters not accepted by Ghidra. diff --git a/tools/ghidra_scripts/lego_util/headers.pyi b/tools/ghidra_scripts/lego_util/headers.pyi index b8926012..b1655437 100644 --- a/tools/ghidra_scripts/lego_util/headers.pyi +++ b/tools/ghidra_scripts/lego_util/headers.pyi @@ -17,4 +17,4 @@ def getFunctionAt( def createFunction( entryPoint: ghidra.program.model.address.Address, name: str ) -> ghidra.program.model.listing.Function: ... -def getProgramFile() -> Any: ... # actually java.io.File +def getProgramFile() -> Any: ... # actually java.io.File