Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: catch passkey attempts when sideloaded #26

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Headers/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

NSURL *getPyoncordDirectory(void);
UIColor *hexToUIColor(NSString *hex);
void showErrorAlert(NSString *title, NSString *message);
void showErrorAlert(NSString *title, NSString *message, void (^completion)(void));
36 changes: 31 additions & 5 deletions Sources/Sideloading.x
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "Logger.h"
#import "Utils.h"
#import <AuthenticationServices/AuthenticationServices.h>
#import <Foundation/Foundation.h>
#import <Security/Security.h>
#import <UIKit/UIKit.h>
Expand All @@ -18,14 +19,31 @@ extern OSStatus CMSDecoderCopyContent(CMSDecoderRef cmsDecoder, CFDataRef *conte

typedef NS_ENUM(NSInteger, BundleIDError) {
BundleIDErrorFiles,
BundleIDErrorIcon
BundleIDErrorIcon,
BundleIDErrorPasskey
};

static void showBundleIDError(BundleIDError error) {
NSString *message = @"For this to work change the Bundle ID so that it matches your "
@"provisioning profile's App ID (excluding the Team ID prefix).";
NSString *title = error == BundleIDErrorFiles ? @"Cannot Access Files" : @"Cannot Change Icon";
showErrorAlert(title, message);
NSString *message;
NSString *title;
void (^completion)(void) = nil;

switch (error) {
case BundleIDErrorFiles:
case BundleIDErrorIcon:
message = @"For this to work change the Bundle ID so that it matches your "
@"provisioning profile's App ID (excluding the Team ID prefix).";
title = error == BundleIDErrorFiles ? @"Cannot Access Files" : @"Cannot Change Icon";
break;
case BundleIDErrorPasskey:
message = @"Passkeys are not supported when sideloading Discord. "
@"Please use a different login method.";
title = @"Cannot Use Passkey";
completion = ^{ exit(0); };
break;
}

showErrorAlert(title, message, completion);
}

static NSString *getProvisioningAppID(void) {
Expand Down Expand Up @@ -180,6 +198,14 @@ static BOOL isSelfCall(void) {
}
%end

%hook ASAuthorizationController

- (void)performRequests {
showBundleIDError(BundleIDErrorPasskey);
}

%end

%end

%ctor {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Tweak.x
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ static LoaderConfig *loaderConfig;
if (!bunnyPatchesBundle) {
BunnyLog(@"Failed to load BunnyPatches bundle from path: %@", bunnyPatchesBundlePath);
showErrorAlert(@"Loader Error",
@"Failed to initialize mod loader. Please reinstall the tweak.");
@"Failed to initialize mod loader. Please reinstall the tweak.", nil);
return %orig;
}

NSURL *patchPath = [bunnyPatchesBundle URLForResource:@"payload-base" withExtension:@"js"];
if (!patchPath) {
BunnyLog(@"Failed to find payload-base.js in bundle");
showErrorAlert(@"Loader Error",
@"Failed to initialize mod loader. Please reinstall the tweak.");
@"Failed to initialize mod loader. Please reinstall the tweak.", nil);
return %orig;
}

Expand Down
8 changes: 6 additions & 2 deletions Sources/Utils.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
return nil;
}

void showErrorAlert(NSString *title, NSString *message) {
void showErrorAlert(NSString *title, NSString *message, void (^completion)(void)) {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alert =
[UIAlertController alertControllerWithTitle:title
Expand All @@ -52,7 +52,11 @@ void showErrorAlert(NSString *title, NSString *message) {

UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:nil];
handler:^(UIAlertAction *action) {
if (completion) {
completion();
}
}];

[alert addAction:okAction];

Expand Down