This repository has been archived by the owner on Dec 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathASCommon.mm
executable file
·76 lines (62 loc) · 3.34 KB
/
ASCommon.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#import "ASCommon.h"
#include <sys/sysctl.h>
#import <objc/runtime.h>
#import <AudioToolbox/AudioServices.h>
#import "NSTimer+Blocks.h"
#import "ASPreferences.h"
#import "ASPasscodeHandler.h"
#import "ASAuthenticationController.h"
#import <RocketBootstrap/RocketBootstrap.h>
#import <AppSupport/CPDistributedMessagingCenter.h>
@interface ASCommon ()
- (void)authenticated:(BOOL)wasCancelled;
@end
void authenticationSuccessful(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
[[ASCommon sharedInstance] authenticated:NO];
}
void authenticationCancelled(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
[[ASCommon sharedInstance] authenticated:YES];
}
@implementation ASCommon
static ASCommon *sharedCommonObj;
+ (instancetype)sharedInstance {
static dispatch_once_t token = 0;
dispatch_once(&token, ^{
sharedCommonObj = [[ASCommon alloc] init];
addObserver(authenticationSuccessful, "com.a3tweaks.asphaleia.xpc/AuthSucceeded");
addObserver(authenticationCancelled, "com.a3tweaks.asphaleia.xpc/AuthCancelled");
});
return sharedCommonObj;
}
- (BOOL)displayingAuthAlert {
CPDistributedMessagingCenter *centre = [objc_getClass("CPDistributedMessagingCenter") centerNamed:@"com.a3tweaks.asphaleia.xpc"];
rocketbootstrap_distributedmessagingcenter_apply(centre);
NSDictionary *reply = [centre sendMessageAndReceiveReplyName:@"com.a3tweaks.asphaleia.xpc/GetCurrentAuthAlert" userInfo:nil];
return [reply[@"displayingAuthAlert"] boolValue];
}
- (BOOL)authenticateAppWithDisplayIdentifier:(NSString *)appIdentifier customMessage:(NSString *)customMessage dismissedHandler:(ASCommonAuthenticationHandler)handler {
if (objc_getClass("ASAuthenticationController")) {
return [[objc_getClass("ASAuthenticationController") sharedInstance] authenticateAppWithDisplayIdentifier:appIdentifier customMessage:customMessage dismissedHandler:handler];
}
CPDistributedMessagingCenter *centre = [objc_getClass("CPDistributedMessagingCenter") centerNamed:@"com.a3tweaks.asphaleia.xpc"];
rocketbootstrap_distributedmessagingcenter_apply(centre);
NSDictionary *reply = [centre sendMessageAndReceiveReplyName:@"com.a3tweaks.asphaleia.xpc/AuthenticateApp" userInfo:@{ @"appIdentifier" : appIdentifier, @"customMessage" : customMessage }];
return [reply[@"isProtected"] boolValue];
}
- (BOOL)authenticateFunction:(ASAuthenticationAlertType)alertType dismissedHandler:(ASCommonAuthenticationHandler)handler {
if (objc_getClass("ASAuthenticationController")) {
return [[objc_getClass("ASAuthenticationController") sharedInstance] authenticateFunction:alertType dismissedHandler:handler];
}
authHandler = [handler copy];
CPDistributedMessagingCenter *centre = [objc_getClass("CPDistributedMessagingCenter") centerNamed:@"com.a3tweaks.asphaleia.xpc"];
rocketbootstrap_distributedmessagingcenter_apply(centre);
NSDictionary *reply = [centre sendMessageAndReceiveReplyName:@"com.a3tweaks.asphaleia.xpc/AuthenticateFunction" userInfo:@{ @"alertType" : [NSNumber numberWithInt:alertType] }];
return [reply[@"isProtected"] boolValue];
}
- (void)authenticated:(BOOL)wasCancelled {
if (authHandler) {
authHandler(wasCancelled);
authHandler = nil;
}
}
@end