Created
April 10, 2024 07:24
-
-
Save shepgoba/379eaa69cb1fc81bb675c69a8c71cda9 to your computer and use it in GitHub Desktop.
Batch script to decompile an extracted dyld_shared_cache with IDA Pro
This file contains 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
import os | |
from multiprocessing.pool import ThreadPool | |
IDA_DIR_PATH = "C:/Users/user/Desktop/ida77" | |
FILES_PATH = "C:/Users/user/Desktop/dsc_extract_16.6.1" | |
class Context: | |
def __init__(self, command, dir): | |
self.command = command | |
self.dir = dir | |
analysis_contexts = [] | |
decompile_contexts = [] | |
macho64_magic = bytes([0xcf, 0xfa, 0xed, 0xfe]) | |
for dirpath, dirnames, filenames in sorted(os.walk(FILES_PATH)): | |
for filename in filenames: | |
os.chdir(dirpath) | |
# Analyze files without an extension | |
with open(filename, 'rb') as fd: | |
first_4_bytes = fd.read(4) | |
is_macho64 = first_4_bytes == macho64_magic | |
if is_macho64: | |
analyze_cmd = f"{IDA_DIR_PATH}/idat64 -B {filename}" | |
analysis_contexts.append(Context(analyze_cmd, dirpath)) | |
decompile_cmd = f"{IDA_DIR_PATH}/idat64 -Ohexrays:{filename}.c:ALL -A {filename}" | |
decompile_contexts.append(Context(decompile_cmd, dirpath)) | |
def analyze(ctx): | |
os.chdir(ctx.dir) | |
print("Analyzing", ctx.command, end="\n\n") | |
os.system(ctx.command) | |
def decompile(ctx): | |
os.chdir(ctx.dir) | |
print(f"Decompiling {ctx.command}", end="\n\n") | |
os.system(ctx.command) | |
# Create max amount of threads | |
pool = ThreadPool(None) | |
pool.map(analyze, analysis_contexts) | |
pool.map(decompile, decompile_contexts) | |
print("Batch decompile complete") | |
wait = input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment