This repository was archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTweak.xm
More file actions
153 lines (131 loc) · 4.26 KB
/
Tweak.xm
File metadata and controls
153 lines (131 loc) · 4.26 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#import "Headers/NFBackgroundTagReadingManager.h"
#import "Headers/NFDriverWrapper.h"
#import "Headers/NFTimer.h"
#import "Headers/NFTag.h"
#import "NBETagLockProvider/NBETagLockProvider.h"
#import "NBETagLockProvider/NBETagRemovalProtocol.h"
float protectionTime = 2;
float debounceTime = 1;
bool airplaneOverride = false;
bool tagLockEnable = YES;
%hook NFHardwareControllerInfo
- (bool)hasLPCDSupport {
// Enables background tag detection.
return YES;
}
%end
%hook NFTimer
- (void)startTimer:(double)time leeway:(double)leeway {
/**
* _readermodeBurnoutProtectionDebounceTimer
* The timer that dictates how long to wait before a new session can start.
* Originally set for 5 seconds.
*/
const double originalDebounceTimerTime = 5;
if (time == originalDebounceTimerTime) {
%orig(debounceTime, leeway);
HBLogInfo(@"DebounceTimer fired with: %f and: %f", debounceTime, leeway);
}
else {
%orig();
}
}
%end
%hook NFBackgroundTagReadingManager
%property(nonatomic, retain) NBETagLockProvider *tagLockProvider;
- (id)initWithQueue:(id)queue driverWrapper:(NFDriverWrapper *)driverWrapper lpcdHWSupport:(bool)arg3 {
id orig = %orig;
if (orig) {
self.tagLockProvider = [[NBETagLockProvider alloc] initWithDriver:driverWrapper];
self.tagLockProvider.tagRemovalDelegate = self;
}
return orig;
}
- (void)didScreenStateChange:(bool)state {
[self.tagLockProvider screenStateChanged:state];
%orig;
}
- (void)handleDetectedTags:(NSMutableArray <NSObject<NFTag> *> *)tags {
HBLogInfo(@"Detected tags, count: %lu", [tags count]);
/**
* _readermodeBurnoutProtectionTimer
* The timer that dictates how long a session can last.
* Modified here because it also affects app sessions.
*/
NFDriverWrapper *driverWrapper = MSHookIvar<NFDriverWrapper *>(self, "_driverWrapper");
NFTimer *protectionTimer = MSHookIvar<NFTimer *>(driverWrapper, "_readermodeBurnoutProtectionTimer");
if (!tagLockEnable) {
HBLogInfo(@"Restarting Timer to: %f", protectionTime);
[protectionTimer stopTimer];
[protectionTimer startTimer:protectionTime leeway:0.1];
}
if (tagLockEnable) {
self.tagLockProvider.debounceTime = debounceTime;
if (![self.tagLockProvider shouldSkipTag:tags[0]]) {
%orig;
}
}
else {
%orig;
}
}
- (bool)updateAirplaneMode {
bool orig = %orig;
if (airplaneOverride) {
MSHookIvar<bool>(self, "_airplaneMode") = NO;
}
return orig;
}
%new
- (void)tagPresenceRemoved {
NFDriverWrapper *driverWrapper = MSHookIvar<NFDriverWrapper *>(self, "_driverWrapper");
// A lock is used whenever the _burnoutProtectionState is accessed
NSLock *lock = MSHookIvar<NSLock *>(driverWrapper, "_burnoutStateLock");
[lock lock];
// If the state is 1, the protection timer has not finished yet
if (MSHookIvar<unsigned int>(driverWrapper, "_burnoutProtectionState") == 1) {
HBLogInfo(@"End Session now");
NFTimer *protectionTimer = MSHookIvar<NFTimer *>(driverWrapper, "_readermodeBurnoutProtectionTimer");
[protectionTimer stopTimer];
[protectionTimer startTimer:0 leeway:0];
}
[lock unlock];
}
%end
static void reloadPreferences() {
NSString *preferencesFilePath = [NSString stringWithFormat:@"/User/Library/Preferences/com.haotestlabs.nfcbackgroundenablerpreferences.plist"];
NSData *fileData = [NSData dataWithContentsOfFile:preferencesFilePath];
if (fileData) {
NSError *error = nil;
NSDictionary *preferences = [NSPropertyListSerialization propertyListWithData:fileData options:NSPropertyListImmutable format:nil error:&error];
if (error) {
HBLogError(@"Unable to read preference file, Error: %@", error);
}
else {
if (preferences[@"ProtectionTime"]) {
protectionTime = [preferences[@"ProtectionTime"] floatValue];
}
if (preferences[@"DebounceTime"]) {
debounceTime = [preferences[@"DebounceTime"] floatValue];
}
if (preferences[@"AirplaneOverride"]) {
airplaneOverride = [preferences[@"AirplaneOverride"] boolValue];
}
if (preferences[@"TagLockEnable"]) {
tagLockEnable = [preferences[@"TagLockEnable"] boolValue];
}
}
}
}
%ctor {
HBLogDebug(@"Hooked");
reloadPreferences();
CFNotificationCenterAddObserver(
CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
(CFNotificationCallback)reloadPreferences,
CFSTR("com.haotestlabs.nfcbackgroundenablerpreferences.reload"),
NULL,
CFNotificationSuspensionBehaviorCoalesce
);
}