diff --git a/tools/ghidra_scripts/import_functions_from_pdb.py b/tools/ghidra_scripts/import_functions_from_pdb.py index 717f849c..481697f4 100644 --- a/tools/ghidra_scripts/import_functions_from_pdb.py +++ b/tools/ghidra_scripts/import_functions_from_pdb.py @@ -109,11 +109,9 @@ def add_python_path(path: str): sys.path.insert(1, str(venv_path)) - +# We need to quote the types here because they might not exist when running without Ghidra def migrate_function_to_ghidra( - api: "FlatProgramAPI", - match_info: "MatchInfo", - signature: "FunctionSignature" + api: "FlatProgramAPI", match_info: "MatchInfo", signature: "FunctionSignature" ): hex_original_address = f"{match_info.orig_addr:x}" @@ -157,7 +155,11 @@ def migrate_function_to_ghidra( logger.critical("User quit, terminating") raise SystemExit(1) - logger.debug("Modifying function %s at 0x%s", typed_pdb_function.get_full_name(), hex_original_address) + logger.debug( + "Modifying function %s at 0x%s", + typed_pdb_function.get_full_name(), + hex_original_address, + ) typed_pdb_function.overwrite_ghidra_function(ghidra_function) @@ -243,15 +245,19 @@ def main(): add_python_path("tools/isledecomp") import setuptools # pylint: disable=unused-import # required to fix a distutils issue in Python 3.12 + reload_module("isledecomp") from isledecomp import Bin + reload_module("isledecomp.compare") from isledecomp.compare import Compare as IsleCompare + reload_module("isledecomp.compare.db") from isledecomp.compare.db import MatchInfo reload_module("lego_util.exceptions") from lego_util.exceptions import Lego1Exception + reload_module("lego_util.pdb_extraction") from lego_util.pdb_extraction import ( PdbExtractionForGhidraMigration, @@ -262,7 +268,6 @@ def main(): reload_module("lego_util.pdb_to_ghidra") from lego_util.pdb_to_ghidra import PdbFunctionWithGhidraObjects - if __name__ == "__main__": main() finally: diff --git a/tools/ghidra_scripts/lego_util/ghidra_helper.py b/tools/ghidra_scripts/lego_util/ghidra_helper.py index 00a8e394..20132ea3 100644 --- a/tools/ghidra_scripts/lego_util/ghidra_helper.py +++ b/tools/ghidra_scripts/lego_util/ghidra_helper.py @@ -54,7 +54,9 @@ def add_pointer_type(api: FlatProgramAPI, pointee: DataType): return data_type -def get_ghidra_namespace(api: FlatProgramAPI, namespace_hierachy: list[str]) -> Namespace: +def get_ghidra_namespace( + api: FlatProgramAPI, namespace_hierachy: list[str] +) -> Namespace: namespace = api.getCurrentProgram().getGlobalNamespace() for part in namespace_hierachy: namespace = api.getNamespace(namespace, part) diff --git a/tools/ghidra_scripts/lego_util/pdb_to_ghidra.py b/tools/ghidra_scripts/lego_util/pdb_to_ghidra.py index cbb67fbd..d312b004 100644 --- a/tools/ghidra_scripts/lego_util/pdb_to_ghidra.py +++ b/tools/ghidra_scripts/lego_util/pdb_to_ghidra.py @@ -25,7 +25,6 @@ from lego_util.exceptions import StackOffsetMismatchError - logger = logging.getLogger(__name__) @@ -220,7 +219,9 @@ def get_matching_stack_symbol(self, stack_offset: int) -> Optional[CppStackSymbo None, ) - def get_matching_register_symbol(self, register: str) -> Optional[CppRegisterSymbol]: + def get_matching_register_symbol( + self, register: str + ) -> Optional[CppRegisterSymbol]: return next( ( symbol diff --git a/tools/isledecomp/isledecomp/types.py b/tools/isledecomp/isledecomp/types.py index 31829c65..e047109e 100644 --- a/tools/isledecomp/isledecomp/types.py +++ b/tools/isledecomp/isledecomp/types.py @@ -1,4 +1,5 @@ """Types shared by other modules""" + from enum import Enum