Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Open
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
4 changes: 3 additions & 1 deletion Headers/NFBackgroundTagReadingManager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "NBETagLockProvider/NBETagLockProvider.h"
#import "NBETagLockProvider/NBETagRemovalProtocol.h"
#import "NFTagInternal.h"

@interface NFBackgroundTagReadingManager <NBETagRemovalProtocol> {
NFDriverWrapper *_driverWrapper;
Expand All @@ -9,7 +10,8 @@
- (id)initWithQueue:(id)arg1 driverWrapper:(id)arg2 lpcdHWSupport:(bool)arg3;
- (void)didScreenStateChange:(bool)arg1;
- (bool)updateAirplaneMode;
- (id)_readNDEFFromTag:(NFTagInternal *)tag;

#pragma mark NBETagRemovalProtocol
- (void)tagPresenceRemoved;
@end
@end
4 changes: 4 additions & 0 deletions Headers/NFCNDEFMessage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@interface NFCNDEFMessage : NSObject
@property (nonatomic,copy) NSArray *records;
-(id)initWithNFNdefMessage:(id)message;
@end
5 changes: 5 additions & 0 deletions Headers/NFCNDEFPayload.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@interface NFCNDEFPayload : NSObject
@property (nonatomic,copy) NSData *type; //@synthesize type=_type - In the implementation block
@property (nonatomic,copy) NSData *identifier; //@synthesize identifier=_identifier - In the implementation block
@property (nonatomic,copy) NSData *payload; //@synthesize payload=_payload - In the implementation block
@end
3 changes: 3 additions & 0 deletions Headers/NFTagInternal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@interface NFTagInternal
@property (nonatomic,copy,readonly) NSData *tagID;
@end
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export DEBUG = 0
export FINALPACKAGE = 1

export TARGET = iphone:clang:11.2:latest
Expand All @@ -9,8 +10,9 @@ include $(THEOS)/makefiles/common.mk

TWEAK_NAME = NFCBackgroundEnabler

NFCBackgroundEnabler_FILES = Tweak.xm NBETagLockProvider/NBETagLockProvider.mm
NFCBackgroundEnabler_FILES = Tweak.xm NBETagLockProvider/NBETagLockProvider.mm NSData+Conversion.m
NFCBackgroundEnabler_CFLAGS = -fobjc-arc
NFCBackgroundEnabler_FRAMEWORKS = CoreNFC

include $(THEOS_MAKE_PATH)/tweak.mk
SUBPROJECTS += nfcbackgroundenablerpreferences
Expand Down
8 changes: 8 additions & 0 deletions NSData+Conversion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import <Foundation/Foundation.h>

@interface NSData (NSData_Conversion)

#pragma mark - String Conversion
- (NSString *)hexadecimalString;

@end
23 changes: 23 additions & 0 deletions NSData+Conversion.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#import "NSData+Conversion.h"

@implementation NSData (NSData_Conversion)

#pragma mark - String Conversion
- (NSString *)hexadecimalString {
/* Returns hexadecimal string of NSData. Empty string if data is empty. */

const unsigned char *dataBuffer = (const unsigned char *)[self bytes];

if (!dataBuffer)
return [NSString string];

NSUInteger dataLength = [self length];
NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)];

for (int i = 0; i < dataLength; ++i)
[hexString appendString:[NSString stringWithFormat:@"%02lx", (unsigned long)dataBuffer[i]]];

return [NSString stringWithString:hexString];
}

@end
43 changes: 35 additions & 8 deletions Tweak.xm
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
#import "Headers/NFDriverWrapper.h"
#import "Headers/NFTimer.h"
#import "Headers/NFTag.h"
#import "Headers/NFTagInternal.h"
#import "Headers/NFCNDEFMessage.h"
#import "Headers/NFCNDEFPayload.h"
#import "NBETagLockProvider/NBETagLockProvider.h"
#import "NBETagLockProvider/NBETagRemovalProtocol.h"
#import "NSData+Conversion.h"

extern "C" CFNotificationCenterRef CFNotificationCenterGetDistributedCenter(void);

float protectionTime = 2;
float debounceTime = 1;
Expand Down Expand Up @@ -72,14 +78,35 @@ bool tagLockEnable = YES;

if (tagLockEnable) {
self.tagLockProvider.debounceTime = debounceTime;
if (![self.tagLockProvider shouldSkipTag:tags[0]]) {
%orig;
}
}
else {
%orig;
if ([self.tagLockProvider shouldSkipTag:tags[0]]) return;
}


%orig;

if ([[NSFileManager defaultManager] fileExistsAtPath:@"/Library/MobileSubstrate/DynamicLibraries/NFCActivator.dylib"]){
NSMutableArray *compiledData = [[NSMutableArray alloc] init];
for (NFTagInternal *tag in tags) {
NSString *uid = [tag.tagID hexadecimalString];

NSMutableArray *records = [[NSMutableArray alloc] init];
[self _readNDEFFromTag:tag];
id messageInternal = [self _readNDEFFromTag:tag];
NFCNDEFMessage *ndefMessage = [[NFCNDEFMessage alloc] initWithNFNdefMessage: messageInternal];
for(NFCNDEFPayload *payload in ndefMessage.records) {
NSString *payloadData = [[NSString alloc] initWithData:payload.payload encoding:NSUTF8StringEncoding];
NSString *type = [[NSString alloc] initWithData:payload.type encoding:NSUTF8StringEncoding];
[records addObject:@{@"payload" : payloadData, @"type" : type}];
}

[compiledData addObject:@{@"uid" : uid, @"records" : [records copy]}];
}

dispatch_async(dispatch_get_main_queue(), ^{
CFDictionaryRef userInfo = (__bridge CFDictionaryRef)@{@"data" : [compiledData copy]};
CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
CFNotificationCenterPostNotification(center, CFSTR("nfcbackground.newtag"), NULL, userInfo, TRUE);
});
}
}

- (bool)updateAirplaneMode {
Expand Down Expand Up @@ -150,4 +177,4 @@ static void reloadPreferences() {
NULL,
CFNotificationSuspensionBehaviorCoalesce
);
}
}
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: com.haotestlabs.nfcbackgroundenabler
Name: NFCBackgroundEnabler
Depends: mobilesubstrate
Version: 1.2.0.0
Version: 1.2.0.1
Architecture: iphoneos-arm
Description: Enables native background NFC detection on iPhones.
Maintainer: ArandomDev <Haow6449@gmail.com>
Expand Down