-
Notifications
You must be signed in to change notification settings - Fork 13
/
Sharing_Tweak.x
63 lines (54 loc) · 1.54 KB
/
Sharing_Tweak.x
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
#import <Foundation/Foundation.h>
#include <mach-o/dyld.h>
#include "general.h"
static struct podsgrant_settings *settings;
%group sharing_hook_grp
%hook SFBLEScanner
- (id)pairingParsePayload:(NSData *)payload identifier:(id)idf bleDevice:(id)bleDev peerInfo:(id)peerInfo {
uint16_t patched=PGS_patchProductId(settings, *(uint16_t*)(payload.bytes+5));
if(patched) {
char *newPayload=malloc(payload.length);
memcpy(newPayload, payload.bytes, payload.length);
*(uint16_t*)(newPayload+5)=patched;
id ret=%orig([NSData dataWithBytes:newPayload length:payload.length], idf, bleDev, peerInfo);
free(newPayload);
return ret;
}
return %orig;
}
- (id)pairingParsePayload:(NSData *)payload identifier:(id)idf bleDevice:(id)bleDev {
uint16_t patched=PGS_patchProductId(settings, *(uint16_t*)(payload.bytes+5));
if(patched) {
char *newPayload=malloc(payload.length);
memcpy(newPayload, payload.bytes, payload.length);
*(uint16_t*)(newPayload+5)=patched;
id ret=%orig([NSData dataWithBytes:newPayload length:payload.length], idf, bleDev);
free(newPayload);
return ret;
}
return %orig;
}
%end
%end
%dtor {
if(settings) {
PGS_freeSettings(settings);
}
}
%ctor {
char exec_path[512]={0};
uint32_t len=512;
_NSGetExecutablePath(exec_path, &len);
//if(strcmp(exec_path, "/usr/libexec/sharingd")==0)
if(memcmp(exec_path, "/usr/sbin/bluetoothd", 21)!=0) {
settings=PGS_readSettings(0);
if(!settings->is_tweak_enabled) {
PGS_freeSettings(settings);
settings=NULL;
return;
}
%init(sharing_hook_grp);
}else{
settings=NULL;
}
}