Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading