From 7c80833fdddd3df49d6b083bdca0996bfb0990a6 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sat, 28 Sep 2013 17:37:32 -0700 Subject: [PATCH] Use MobileGestalt to get device uniqueIdentifier. --- CyteKit/WebViewController.mm | 13 ++++++++++++- MobileCydia.mm | 18 +++++++++++++++--- makefile | 1 - 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/CyteKit/WebViewController.mm b/CyteKit/WebViewController.mm index 643c2b8b..5846a66f 100644 --- a/CyteKit/WebViewController.mm +++ b/CyteKit/WebViewController.mm @@ -38,6 +38,8 @@ extern NSString * const kCAFilterNearest; #define lprintf(args...) fprintf(stderr, args) +JSValueRef (*$JSObjectCallAsFunction)(JSContextRef, JSObjectRef, JSObjectRef, size_t, const JSValueRef[], JSValueRef *); + // XXX: centralize these special class things to some file or mechanism? static Class $MFMailComposeViewController; @@ -138,6 +140,14 @@ float CYScrollViewDecelerationRateNormal; + (void) _initialize { [WebPreferences _setInitialDefaultTextEncodingToSystemEncoding]; + void *js(NULL); + if (js == NULL) + js = dlopen("/System/Library/Frameworks/JavaScriptCore.framework/JavaScriptCore", RTLD_GLOBAL | RTLD_LAZY); + if (js == NULL) + js = dlopen("/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore", RTLD_GLOBAL | RTLD_LAZY); + if (js != NULL) + $JSObjectCallAsFunction = reinterpret_cast(dlsym(js, "JSObjectCallAsFunction")); + dlopen("/System/Library/Frameworks/MessageUI.framework/MessageUI", RTLD_GLOBAL | RTLD_LAZY); $MFMailComposeViewController = objc_getClass("MFMailComposeViewController"); @@ -994,7 +1004,8 @@ float CYScrollViewDecelerationRateNormal; JSGlobalContextRef context([frame globalContext]); JSObjectRef object([function JSObject]); - JSObjectCallAsFunction(context, object, NULL, 0, NULL, NULL); + if ($JSObjectCallAsFunction != NULL) + ($JSObjectCallAsFunction)(context, object, NULL, 0, NULL, NULL); } - (void) reloadButtonClicked { diff --git a/MobileCydia.mm b/MobileCydia.mm index c1fbddc9..bdc5b7ae 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -267,6 +267,15 @@ static bool AprilFools_; static void (*$SBSSetInterceptsMenuButtonForever)(bool); +static CFStringRef (*$MGCopyAnswer)(CFStringRef); + +static NSString *UniqueIdentifier(UIDevice *device = nil) { + if (kCFCoreFoundationVersionNumber < 800) // iOS 7.x + return [device ?: [UIDevice currentDevice] uniqueIdentifier]; + else + return [(id)$MGCopyAnswer(CFSTR("UniqueDeviceID")) autorelease]; +} + static bool IsReachable(const char *name) { SCNetworkReachabilityFlags flags; { SCNetworkReachabilityRef reachability(SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, name)); @@ -725,7 +734,7 @@ static NSString *SerialNumber_ = nil; static NSString *ChipID_ = nil; static NSString *BBSNum_ = nil; static _H Token_; -static NSString *UniqueID_ = nil; +static _H UniqueID_; static _H UserAgent_; static _H Product_; static _H Safari_; @@ -4059,7 +4068,7 @@ static _H Diversions_; } - (NSString *) device { - return [[UIDevice currentDevice] uniqueIdentifier]; + return UniqueIdentifier(); } - (NSString *) firmware { @@ -10657,6 +10666,9 @@ int main(int argc, char *argv[]) { dealloc_ = dealloc->method_imp; dealloc->method_imp = (IMP) &Dealloc_;*/ + void *gestalt(dlopen("/usr/lib/libMobileGestalt.dylib", RTLD_GLOBAL | RTLD_LAZY)); + $MGCopyAnswer = reinterpret_cast(dlsym(gestalt, "MGCopyAnswer")); + /* System Information {{{ */ size_t size; @@ -10688,7 +10700,7 @@ int main(int argc, char *argv[]) { ChipID_ = [CYHex((NSData *) CYIOGetValue("IODeviceTree:/chosen", @"unique-chip-id"), true) uppercaseString]; BBSNum_ = CYHex((NSData *) CYIOGetValue("IOService:/AppleARMPE/baseband", @"snum"), false); - UniqueID_ = [device uniqueIdentifier]; + UniqueID_ = UniqueIdentifier(device); if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:@"/Applications/MobileSafari.app/Info.plist"]) { Product_ = [info objectForKey:@"SafariProductVersion"]; diff --git a/makefile b/makefile index d167f4ed..bcd811c5 100644 --- a/makefile +++ b/makefile @@ -62,7 +62,6 @@ libs += -framework CoreGraphics libs += -framework Foundation libs += -framework GraphicsServices libs += -framework IOKit -libs += -framework JavaScriptCore libs += -framework QuartzCore libs += -framework SpringBoardServices libs += -framework SystemConfiguration -- 2.45.2