Skip to content

Commit

Permalink
Random User-Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanArbuckle committed Jul 4, 2023
1 parent 2ecf3e6 commit dd0b563
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 4 additions & 1 deletion RedditAPICredentialViewController.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>
#import <UIKit/UIKit.h>

#define RANDSTRING [[NSProcessInfo processInfo] globallyUniqueString]
#define RANDINT (arc4random() % 9) + 1

@interface RedditAPICredentialViewController : UIViewController <WKNavigationDelegate>

Expand Down
2 changes: 1 addition & 1 deletion RedditAPICredentialViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}];

Expand Down
23 changes: 22 additions & 1 deletion Tweak.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,37 @@ static OSStatus SecItemUpdate_replacement(CFDictionaryRef query, CFDictionaryRef
});
}

// Reddit API Credentials
Class _RDKOAuthCredential = objc_getClass("RDKOAuthCredential");
if (_RDKOAuthCredential) {

Method clientIdMethod = class_getInstanceMethod(_RDKOAuthCredential, sel_registerName("clientIdentifier"));
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);
Expand All @@ -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);
Expand Down

0 comments on commit dd0b563

Please sign in to comment.