Skip to content

Commit

Permalink
Merge pull request #26 from bunny-mod/feat-catch-passkey-attempt
Browse files Browse the repository at this point in the history
feat: catch passkey attempts when sideloaded
  • Loading branch information
castdrian authored Nov 18, 2024
2 parents 172dc71 + f50a15b commit 37d2c39
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
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

0 comments on commit 37d2c39

Please sign in to comment.