diff --git a/RedditAPICredentialViewController.h b/RedditAPICredentialViewController.h index 457cc73..bd69a1b 100644 --- a/RedditAPICredentialViewController.h +++ b/RedditAPICredentialViewController.h @@ -1,5 +1,8 @@ -#import #import +#import + +#define RANDSTRING [[NSProcessInfo processInfo] globallyUniqueString] +#define RANDINT (arc4random() % 9) + 1 @interface RedditAPICredentialViewController : UIViewController diff --git a/RedditAPICredentialViewController.m b/RedditAPICredentialViewController.m index 53991c0..61be670 100644 --- a/RedditAPICredentialViewController.m +++ b/RedditAPICredentialViewController.m @@ -132,7 +132,7 @@ - (void)pageDidUpdate:(WKWebView *)webView { Array.from(document.getElementsByName('description')).slice(-1)[0].value = \"i'm a fun reddit app\"; \ Array.from(document.getElementsByName('about_url')).slice(-1)[0].value = \"https://google.com\"; \ document.getElementById('redirect_uri').value = \"apollo://reddit-oauth\"; \ - Array.from(document.getElementsByName('name')).slice(-1)[0].value = \"Some app %@\";", [[NSProcessInfo processInfo] globallyUniqueString]]; + Array.from(document.getElementsByName('name')).slice(-1)[0].value = \"Some app %@\";", RANDSTRING]; [webView evaluateJavaScript:prefillFormJS completionHandler:nil]; }]; diff --git a/Tweak.m b/Tweak.m index ba8c85e..22a7b83 100644 --- a/Tweak.m +++ b/Tweak.m @@ -55,6 +55,7 @@ static OSStatus SecItemUpdate_replacement(CFDictionaryRef query, CFDictionaryRef }); } + // Reddit API Credentials Class _RDKOAuthCredential = objc_getClass("RDKOAuthCredential"); if (_RDKOAuthCredential) { @@ -62,9 +63,29 @@ static OSStatus SecItemUpdate_replacement(CFDictionaryRef query, CFDictionaryRef IMP replacementImp = imp_implementationWithBlock(^NSString *(id _self) { return [[NSUserDefaults standardUserDefaults] valueForKey:@"ApolloRedditAPIClientID"]; }); + method_setImplementation(clientIdMethod, replacementImp); } + // Randomize User-Agent + Class _RDKClient = objc_getClass("RDKClient"); + if (_RDKClient) { + + Method userAgentMethod = class_getInstanceMethod(_RDKClient, sel_registerName("userAgent")); + IMP userAgentReplacementImp = imp_implementationWithBlock(^NSString *(id _self) { + static dispatch_once_t once; + static NSString *newUserAgent; + dispatch_once(&once, ^{ + newUserAgent = [NSString stringWithFormat:@"iOS: com.%@.%@ v%d.%d.%d (by /u/%@)", RANDSTRING, RANDSTRING, RANDINT, RANDINT, RANDINT, RANDSTRING]; + }); + + return newUserAgent; + }); + + method_setImplementation(userAgentMethod, userAgentReplacementImp); + } + + // Imgur API credentials Class _NSURLSessionConfiguration = objc_getClass("NSURLSessionConfiguration"); Method setHeadersMethod = class_getInstanceMethod(_NSURLSessionConfiguration, sel_registerName("setHTTPAdditionalHeaders:")); IMP originalSetHeadersImp = method_getImplementation(setHeadersMethod); @@ -84,7 +105,7 @@ static OSStatus SecItemUpdate_replacement(CFDictionaryRef query, CFDictionaryRef headers = newHeaders; } - ((void (*)(id, SEL, id))originalSetHeadersImp)(_self, NSSelectorFromString(@"setHTTPAdditionalHeaders:"), headers); + ((void (*)(id, SEL, id))originalSetHeadersImp)(_self, sel_registerName("setHTTPAdditionalHeaders:"), headers); }); method_setImplementation(setHeadersMethod, replacementSetHeadersImp);