-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathSwizzlingDetector.py
38 lines (30 loc) · 1.48 KB
/
SwizzlingDetector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#Detects whether an app is using swizzling and prints all references
#@author LaurieWired
#@category iOS
from ghidra.program.model.symbol import SymbolType
def find_swizzling():
# List of potential swizzling related methods
swizzling_methods = [
"method_exchangeImplementations",
"class_getInstanceMethod",
"class_getClassMethod",
"method_setImplementation"
]
# Find the addresses of all functions containing the substrings from swizzling_methods
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:
# Enumerate all references to this function
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()