-2

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?

  • 5
    On what line does the app crash? What is the error reason given for the crash (EXEC_BAD_ACCESS? Something else?) Also, what are the "%" signs in your code supposed to represent? I've never seen that before in this context. – user1118321 Nov 29 '13 at 19:26
  • You say it crashes but don't provide any error message. – Hot Licks Nov 29 '13 at 22:22
  • And note that you're not logging an NSDictionary, but rather an entry from one. – Hot Licks Nov 29 '13 at 22:23
  • The app crash after the dylib that is compiled with this hook of the getVariable function is loaded. The % signs is from theos – user2700999 Nov 30 '13 at 09:25
  • http://iphonedevwiki.net/index.php/Logos – user2700999 Nov 30 '13 at 09:45
  • just some good-natured advice: you dabble in things you don't get .. very basic things. before trying stuff like hooking into other apps Id ask you to start with the basics – Daij-Djan Nov 30 '13 at 12:22

2 Answers2

2

The crash log provide quite an explanation

-[__NSCFConstantString allKeys]: unrecognized selector sent to instance 0x2a7a88

I guess this is the crash log associated with the first piece of code you posted :

%hook UserData
-(int)getVariable:(NSDictionary *)fp8 {

    for (NSString *key in [fp8 allKeys]) {
        %log(@"key: %@, value: %@ \n", key, [fp8 objectForKey:key]);
    }
    return %orig;
}
%end

It crashes at the execution of [fp8 allKeys], claiming that allKeys is not a valid selector for objects of class __NSCFConstantString What it tells you is that fp8 is not an NSDictionary* but rather a __NSCFConstantString* (that is, a pointer to a constant instance of NSString such as one defined like NSString* foo = @"bar").

If that is true, then the second code you posted would crash also because count is not a valid selector for class NSString.

Why don't you just try the following, see what it gives you :

%hook UserData
-(int)getVariable:(id)fp8 {

    %log(@"fp8: %@ : %@\n", NSStringFromClass([fp8 class]), [fp8 description]);

    return %orig;
}
%end
Olotiar
  • 3,225
  • 1
  • 18
  • 37
0

If you print the description it should work. Following Way :

NSLog(@"%@", [dictionary description]);
Divya Bhaloidiya
  • 5,018
  • 2
  • 25
  • 45
Raphael Oliveira
  • 7,751
  • 5
  • 47
  • 55
  • Not sure how to use this info, sorry for being unclear. The code above is a hook into a function of a app I dont have the sourcecode for. Its reverse engineering so to speak. – user2700999 Nov 30 '13 at 09:35