diff --git a/disassemblers/ofrak_pyghidra/src/ofrak_pyghidra/standalone/pyghidra_analysis.py b/disassemblers/ofrak_pyghidra/src/ofrak_pyghidra/standalone/pyghidra_analysis.py index 1d3c428dd..e221ee353 100644 --- a/disassemblers/ofrak_pyghidra/src/ofrak_pyghidra/standalone/pyghidra_analysis.py +++ b/disassemblers/ofrak_pyghidra/src/ofrak_pyghidra/standalone/pyghidra_analysis.py @@ -44,19 +44,23 @@ def unpack( program_file = os.path.join(tempdir, "program") with open(program_file, "wb") as f: f.write(b"\x00") - with pyghidra.open_program(program_file, language=language) as flat_api: + with pyghidra.open_program(program_file, language=language, analyze=False) as flat_api: LOGGER.info("Analysis completed. Caching analysis to JSON") # Java packages must be imported after pyghidra.start or pyghidra.open_program from ghidra.app.decompiler import DecompInterface, DecompileOptions from ghidra.util.task import TaskMonitor from ghidra.program.model.block import BasicBlockModel from ghidra.program.model.symbol import RefType + from ghidra.base.project import GhidraProject from java.math import BigInteger from java.io import ByteArrayInputStream + program = flat_api.getCurrentProgram() + program.getOptions("Analyzers").setBoolean("Decompiler Switch Analysis", False) + GhidraProject.analyze(program) + # If memory_regions are provided, delete all data and create new regions: if memory_regions: - program = flat_api.getCurrentProgram() memory = program.getMemory() address_factory = program.getAddressFactory() default_space = address_factory.getDefaultAddressSpace() @@ -103,7 +107,6 @@ def unpack( base_address = int(base_address) # Rebase the program to the specified base address - program = flat_api.getCurrentProgram() address_factory = program.getAddressFactory() new_base_addr = address_factory.getDefaultAddressSpace().getAddress( hex(base_address) @@ -476,12 +479,15 @@ def _decompile(func, decomp_interface, task_monitor): def decompile_all_functions(program_file, language): - with pyghidra.open_program(program_file, language=language) as flat_api: + with pyghidra.open_program(program_file, language=language, analyze=False) as flat_api: from ghidra.app.decompiler import DecompInterface, DecompileOptions from ghidra.util.task import TaskMonitor + from ghidra.base.project import GhidraProject decomp = DecompInterface() program = flat_api.getCurrentProgram() + program.getOptions("Analyzers").setBoolean("Decompiler Switch Analysis", False) + GhidraProject.analyze(program) prog_options = DecompileOptions() prog_options.grabFromProgram(program) decomp.setOptions(prog_options)