Skip to content

Instantly share code, notes, and snippets.

@motebaya
Last active March 29, 2025 02:05
Show Gist options
  • Save motebaya/dcfe72af48bd450ae093e9b64c322ae2 to your computer and use it in GitHub Desktop.
Save motebaya/dcfe72af48bd450ae093e9b64c322ae2 to your computer and use it in GitHub Desktop.
python ghidra scripts for batch decompiling
from ghidra.app.decompiler import DecompInterface
from ghidra.util.task import ConsoleTaskMonitor
import os
output_folder = "E:/reversing/output" # set output decompiled
if not os.path.exists(output_folder):
os.makedirs(output_folder)
decomp_interface = DecompInterface()
decomp_interface.openProgram(currentProgram)
functions = list(currentProgram.getFunctionManager().getFunctions(True))
total = str(len(functions))
for index, func in enumerate(functions, 1):
func_name = func.getName()
print(" [{}/{}] Decompiling {}...".format(index, total, func_name))
decompiled = decomp_interface.decompileFunction(func, 60, ConsoleTaskMonitor())
if decompiled.decompileCompleted():
decompiled_code = decompiled.getDecompiledFunction().getC()
with open(os.path.join(output_folder, "{}.c".format(func_name)), "w") as f:
f.write(decompiled_code)
else:
print(" [{}/{}] Decompile failed {}".format(index, total, func_name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment