diff --git a/Preferences/Resources/Root.plist b/Preferences/Resources/Root.plist index 0d14873..56b53a0 100644 --- a/Preferences/Resources/Root.plist +++ b/Preferences/Resources/Root.plist @@ -48,6 +48,14 @@ PostNotification cafe.kirameki.iosdiscordpresencepreferences/PreferencesChanged + + cell + PSButtonCell + label + Get Discord Token + action + getDiscordToken + cell PSGroupCell @@ -58,7 +66,7 @@ cell PSButtonCell label - GitHub + GitHub Repository action openGitHubLink @@ -66,7 +74,7 @@ cell PSGroupCell label - YuzuZensai + Made with ❤️ by YuzuZensai title diff --git a/Preferences/iOSDiscordPresenceRootListController.m b/Preferences/iOSDiscordPresenceRootListController.m index 4ede6d3..d065df4 100644 --- a/Preferences/iOSDiscordPresenceRootListController.m +++ b/Preferences/iOSDiscordPresenceRootListController.m @@ -17,7 +17,7 @@ return [specifier.properties objectForKey:@"default"]; } return [prefs objectForKey:[specifier.properties objectForKey:@"key"]]; - } +} -(void)setPreferenceValue:(id)value specifier:(PSSpecifier*)specifier { NSMutableDictionary * prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/var/mobile/Library/Preferences/%@.plist", [specifier.properties objectForKey:@"defaults"]]]; @@ -33,4 +33,49 @@ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://github.com/YuzuZensai/iOS-DiscordPresence"]]; } + +// Please don't use this to make something malicious +// The world is already cruel enough +- (void)getDiscordToken { + NSFileManager *fileManager = [NSFileManager defaultManager]; + + NSString *sharedDirectoryPath = [[NSURL fileURLWithPath:@"/var/mobile/Containers/Shared/AppGroup/"] path]; + NSArray *contents = [fileManager contentsOfDirectoryAtPath:sharedDirectoryPath error:NULL]; + + // Loop all folders in sharedDirectoryPath + for (NSString *path in contents) { + NSString *containerPath = [sharedDirectoryPath stringByAppendingPathComponent:path]; + NSString *metadataPlistPath = [containerPath stringByAppendingPathComponent:@".com.apple.mobile_container_manager.metadata.plist"]; + + if (![fileManager fileExistsAtPath:metadataPlistPath]) continue; + + // Load the metadata plist + NSDictionary *metadataDict = [NSDictionary dictionaryWithContentsOfFile:metadataPlistPath]; + NSString *metadataIdentifier = [metadataDict objectForKey:@"MCMMetadataIdentifier"]; + + // Check if the bundleID is Discord + if ([metadataIdentifier isEqualToString:@"group.com.hammerandchisel.discord"]) { + NSString *discordPlistPath = [containerPath stringByAppendingPathComponent:@"/Library/Preferences/group.com.hammerandchisel.discord.plist"]; + NSDictionary *discordDict = [NSDictionary dictionaryWithContentsOfFile:discordPlistPath]; + + // Read the token + NSString *authenticationTokenKey = [discordDict objectForKey:@"_authenticationTokenKey"]; + + // Copy to clipboard + UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; + pasteboard.string = authenticationTokenKey; + + // Show alert box + UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Discord Presence" message:@"Discord token copied to clipboard." preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + [alert dismissViewControllerAnimated:YES completion:nil]; + }]; + [alert addAction:okAction]; + [self presentViewController:alert animated:YES completion:nil]; + + break; + } + } +} + @end