This repository has been archived by the owner on Aug 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logdefaults.m
155 lines (143 loc) · 4.87 KB
/
logdefaults.m
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
154
155
// clang -fmodules -dynamiclib -I ../non-metal-common/Utils logdefaults.m -o /tmp/defaults.dylib && codesign -fs - /tmp/defaults.dylib && DYLD_INSERT_LIBRARIES=/tmp/defaults.dylib /S*/A*/T*/C*/M*/TextEdit
#define showBacktrace false
#import "Utils.h"
NSMutableSet<NSString*>* seen=nil;
void takeKey(NSString* key)
{
if(!seen)
{
seen=NSMutableSet.alloc.init;
}
if(![seen containsObject:key])
{
if(showBacktrace)
{
trace(@"%@ %@",key,NSThread.callStackSymbols);
}
else
{
trace(@"%@",key);
}
[seen addObject:key];
}
}
id (*realValue)(NSUserDefaults*,SEL,NSString*);
id fakeValue(NSUserDefaults* self,SEL sel,NSString* key)
{
takeKey(key);
return realValue(self,sel,key);
}
id (*realObject)(NSUserDefaults*,SEL,NSString*);
id fakeObject(NSUserDefaults* self,SEL sel,NSString* key)
{
takeKey(key);
return realObject(self,sel,key);
}
NSURL* (*realURL)(NSUserDefaults*,SEL,NSString*);
NSURL* fakeURL(NSUserDefaults* self,SEL sel,NSString* key)
{
takeKey(key);
return realURL(self,sel,key);
}
NSArray* (*realArray)(NSUserDefaults*,SEL,NSString*);
NSArray* fakeArray(NSUserDefaults* self,SEL sel,NSString* key)
{
takeKey(key);
return realArray(self,sel,key);
}
NSDictionary* (*realDictionary)(NSUserDefaults*,SEL,NSString*);
NSDictionary* fakeDictionary(NSUserDefaults* self,SEL sel,NSString* key)
{
takeKey(key);
return realDictionary(self,sel,key);
}
NSString* (*realString)(NSUserDefaults*,SEL,NSString*);
NSString* fakeString(NSUserDefaults* self,SEL sel,NSString* key)
{
takeKey(key);
return realString(self,sel,key);
}
NSArray* (*realStringArray)(NSUserDefaults*,SEL,NSString*);
NSArray* fakeStringArray(NSUserDefaults* self,SEL sel,NSString* key)
{
takeKey(key);
return realStringArray(self,sel,key);
}
NSData* (*realData)(NSUserDefaults*,SEL,NSString*);
NSData* fakeData(NSUserDefaults* self,SEL sel,NSString* key)
{
takeKey(key);
return realData(self,sel,key);
}
BOOL (*realBool)(NSUserDefaults*,SEL,NSString*);
BOOL fakeBool(NSUserDefaults* self,SEL sel,NSString* key)
{
takeKey(key);
return realBool(self,sel,key);
}
NSInteger (*realInteger)(NSUserDefaults*,SEL,NSString*);
NSInteger fakeInteger(NSUserDefaults* self,SEL sel,NSString* key)
{
takeKey(key);
return realInteger(self,sel,key);
}
float (*realFloat)(NSUserDefaults*,SEL,NSString*);
float fakeFloat(NSUserDefaults* self,SEL sel,NSString* key)
{
takeKey(key);
return realFloat(self,sel,key);
}
double (*realDouble)(NSUserDefaults*,SEL,NSString*);
double fakeDouble(NSUserDefaults* self,SEL sel,NSString* key)
{
takeKey(key);
return realDouble(self,sel,key);
}
__attribute__((constructor)) void l()
{
swizzleImp(@"NSUserDefaults",@"valueForKey:",true,fakeValue,&realValue);
swizzleImp(@"NSUserDefaults",@"objectForKey:",true,fakeObject,&realObject);
swizzleImp(@"NSUserDefaults",@"URLForKey:",true,fakeURL,&realURL);
swizzleImp(@"NSUserDefaults",@"arrayForKey:",true,fakeArray,&realArray);
swizzleImp(@"NSUserDefaults",@"dictionaryForKey:",true,fakeDictionary,&realDictionary);
swizzleImp(@"NSUserDefaults",@"stringForKey:",true,fakeString,&realString);
swizzleImp(@"NSUserDefaults",@"stringArrayForKey:",true,fakeStringArray,&realStringArray);
swizzleImp(@"NSUserDefaults",@"dataForKey:",true,fakeData,&realData);
swizzleImp(@"NSUserDefaults",@"boolForKey:",true,fakeBool,&realBool);
swizzleImp(@"NSUserDefaults",@"integerForKey:",true,fakeInteger,&realInteger);
swizzleImp(@"NSUserDefaults",@"floatForKey:",true,fakeFloat,&realFloat);
swizzleImp(@"NSUserDefaults",@"doubleForKey:",true,fakeDouble,&realDouble);
}
CFPropertyListRef fakeCFPreferencesCopyAppValue(CFStringRef key,CFStringRef application)
{
takeKey(key);
return CFPreferencesCopyAppValue(key,application);
}
DYLD_INTERPOSE(fakeCFPreferencesCopyAppValue,CFPreferencesCopyAppValue)
CFDictionaryRef fakeCFPreferencesCopyMultiple(CFArrayRef keys,CFStringRef application,CFStringRef user,CFStringRef host)
{
for(NSString* key in (NSArray*)keys)
{
takeKey(key);
}
return CFPreferencesCopyMultiple(keys,application,user,host);
}
DYLD_INTERPOSE(fakeCFPreferencesCopyMultiple,CFPreferencesCopyMultiple)
CFPropertyListRef fakeCFPreferencesCopyValue(CFStringRef key,CFStringRef application,CFStringRef user,CFStringRef host)
{
takeKey(key);
return CFPreferencesCopyValue(key,application,user,host);
}
DYLD_INTERPOSE(fakeCFPreferencesCopyValue,CFPreferencesCopyValue)
Boolean fakeCFPreferencesGetAppBooleanValue(CFStringRef key,CFStringRef application,Boolean* keyExistsAndHasValidFormat)
{
takeKey(key);
return CFPreferencesGetAppBooleanValue(key,application,keyExistsAndHasValidFormat);
}
DYLD_INTERPOSE(fakeCFPreferencesGetAppBooleanValue,CFPreferencesGetAppBooleanValue)
CFIndex fakeCFPreferencesGetAppIntegerValue(CFStringRef key,CFStringRef application,Boolean* keyExistsAndHasValidFormat)
{
takeKey(key);
return CFPreferencesGetAppIntegerValue(key,application,keyExistsAndHasValidFormat);
}
DYLD_INTERPOSE(fakeCFPreferencesGetAppIntegerValue,CFPreferencesGetAppIntegerValue)