越狱的iPhone让我很恼火,因为它使用MobileSubstrate污染了iOS上的一些基本API。
http://www.iphonedevwiki.net/index.php/MobileSubstrate
我相信许多应用程序使用UDID作为验证设备和/或用户的手段,因为它是半自动和方便的,但您应该意识到这个问题:UIDevice不像应该那样防篡改。有一个叫做UDID Faker的应用程序,在运行时轻松地使您可以欺骗别人的UDID。
http://www.iphone-network.net/how-to-fake-udid-on-ios-4/
这是它的源代码:
//
// UDIDFaker.m
// UDIDFaker
//
#include "substrate.h"
#define ALog(...) NSLog(@"*** udidfaker: %@", [NSString stringWithFormat:__VA_ARGS__]);
#define kConfigPath @"/var/mobile/Library/Preferences/com.Reilly.UDIDFaker.plist"
@protocol Hook
- (NSString *)orig_uniqueIdentifier;
@end
NSString *fakeUDID = nil;
static NSString *$UIDevice$uniqueIdentifier(UIDevice<Hook> *self, SEL sel) {
if(fakeUDID != nil) {
ALog(@"fakeUDID %@", fakeUDID);
/* if it's a set value, make sure it's sane, and return it; else return the default one */
return ([fakeUDID length] == 40) ? fakeUDID : [self orig_uniqueIdentifier];
}
/* ... if it doesn't then return the original UDID */
else {
return [self orig_uniqueIdentifier];
}
}
__attribute__((constructor)) static void udidfakerInitialize() {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *appsBundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
ALog(@"Loading UDID Faker into %@", appsBundleIdentifier);
NSDictionary *config = [NSDictionary dictionaryWithContentsOfFile: kConfigPath];
fakeUDID = [config objectForKey: appsBundleIdentifier];
[fakeUDID retain];
if(fakeUDID != nil) {
ALog(@"Hooking UDID Faker into %@", appsBundleIdentifier);
MSHookMessage(objc_getClass("UIDevice"), @selector(uniqueIdentifier), (IMP)&$UIDevice$uniqueIdentifier, "orig_");
}
[pool release];
}
如您所见,在UIDevice类中的uniqueIdentifier方法现在会在任何应用程序中返回fakeUDID。
似乎Skype和其他一些应用程序可以检测到这种污染,但我不知道该如何做到。
我的想法是:当检测到被污染的UIDevice时,启动警报并退出(0)。
有什么好的建议吗?