I have a problem where I try to log NSDictionary content and as soon as the method is called the app crashes.
This is the code I have tried after advice from a talented "hacker":
%hook UserData
-(int)getVariable:(NSDictionary *)fp8 {
for (NSString *key in [fp8 allKeys]) {
%log(@"key: %@, value: %@ \n", key, [fp8 objectForKey:key]);
}
return %orig;
}
%end
also tried:
%hook UserData
-(int)getVariable {
int originalValue = %orig;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSError *error;
[[fp8 description] writeToFile:[NSString stringWithFormat:@"%@/lol_%d.txt",basePath,fp8.count] atomically:NO encoding:NSUTF8StringEncoding error:&error];
return %orig;
}
%end
Both ways result in a crash of the app. This is on a iphone 4 with ios 6.1.3 tethered JB.
DoD EN[1000]: -[__NSCFConstantString allKeys]: unrecognized selector sent to instance 0x2a7a88
DoD EN[1000]: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString allKeys]: unrecognized selector sent to instance 0x2a7a88'
*** First throw call stack:
Does anyone have a suggestion on what may be wrong here?