Ghidra is a free and open-source reverse engineering tool developed by the NSA. It provides excellent support for analyzing iOS Mach-O binaries and includes powerful scripting capabilities for automation.
# Extract the IPA fileunzip YourApp.ipa# Locate the binarycd Payload/YourApp.app/file YourApp # Verify it's a Mach-O binary
Import Payload/YourApp.app/YourApp into Ghidra via File → Import File.
# SSH into jailbroken devicessh root@<device-ip># Locate the app binarycd /var/containers/Bundle/Application/<app-guid>/YourApp.app/# Copy to your machinescp root@<device-ip>:/path/to/binary ~/Desktop/
3
Analyze the Binary
Double-click the imported file in the project window
When prompted, click “Yes” to analyze
In the Analysis Options dialog:
Enable “Objective-C” analyzer
Enable “Decompiler Parameter ID” for better decompilation
Click “Analyze”
Initial analysis may take several minutes for large iOS applications.
The SwizzlingDetector.py script identifies potential method swizzling, a common technique used in iOS malware and some legitimate apps for runtime method modification.
The script searches for calls to these Objective-C runtime functions:
method_exchangeImplementations - Swaps two method implementations
class_getInstanceMethod - Retrieves an instance method (often used before swizzling)
class_getClassMethod - Retrieves a class method
method_setImplementation - Directly sets a method’s implementation
# Detects whether an app is using swizzling and prints all references# @author LaurieWired# @category iOSfrom ghidra.program.model.symbol import SymbolTypedef find_swizzling(): swizzling_methods = [ "method_exchangeImplementations", "class_getInstanceMethod", "class_getClassMethod", "method_setImplementation" ] swizzling_symbols = [] for symbol in currentProgram.getSymbolTable().getAllSymbols(True): if symbol.getSymbolType() == SymbolType.FUNCTION and \ any(method in symbol.getName() for method in swizzling_methods): swizzling_symbols.append(symbol) if not swizzling_symbols: print("No swizzling found") return for swizzling_symbol in swizzling_symbols: references = list(currentProgram.getReferenceManager() .getReferencesTo(swizzling_symbol.getAddress())) if not references: print("Swizzling method {} located at address {}, but had no references" .format(swizzling_symbol.getName(), swizzling_symbol.getAddress())) continue print("Swizzling method {} located at address {}, with references:" .format(swizzling_symbol.getName(), swizzling_symbol.getAddress())) for ref in references: print("Address: {}".format(ref.getFromAddress()))find_swizzling()
Swizzling method _method_exchangeImplementations located at address 001a2f40, with references:Address: 001b3c88Address: 001b4120Swizzling method _class_getInstanceMethod located at address 001a2f60, with references:Address: 001b3c80Address: 001b4118
Method swizzling isn’t inherently malicious. Many legitimate apps and frameworks (like analytics SDKs) use it for hooking and monitoring. Always analyze the context.