Last active
June 8, 2021 11:50
-
-
Save joswr1ght/4480de9862284fc74f6e to your computer and use it in GitHub Desktop.
Demonstration code to detect runtime method swizzling with Cydia Substrate/Cycript.
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
// Compile with: | |
// clang catchredir.m -o catchredir -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/ -miphoneos-version-min=7 -framework Foundation | |
#import <Foundation/Foundation.h> | |
#import <stdio.h> | |
#import <objc/runtime.h> | |
@interface UrlConnection : NSObject | |
@property (strong) NSString *url; | |
- (void)connect; | |
@end | |
@implementation UrlConnection | |
- (void)connect { | |
// Connect to a server, or other behavior the attacker wants to change | |
} | |
@end | |
int main() { | |
Class ucclass = objc_getClass("UrlConnection"); | |
SEL sel = sel_getUid("connect"); | |
IMP runtimeimp, ucconnectimp = class_getMethodImplementation(ucclass, sel); | |
while(1) { | |
[NSThread sleepForTimeInterval:10.0f]; | |
ucclass = objc_getClass("UrlConnection"); | |
sel = sel_getUid("connect"); | |
runtimeimp = class_getMethodImplementation(ucclass, sel); | |
printf("pointer %p and %p\n", ucconnectimp, runtimeimp); | |
if (runtimeimp != ucconnectimp) printf("Modification Detected\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, how to detect 3rd party lib using method swizzle .
I used your code, but can not detect the following swizzle method.
`
`
the detector code
`
`
the output logs
`
`