Last active
March 29, 2025 02:05
-
-
Save motebaya/dcfe72af48bd450ae093e9b64c322ae2 to your computer and use it in GitHub Desktop.
python ghidra scripts for batch decompiling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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