user5893829
user5893829

Reputation: 15

Logging Function Arguments for iOS App

I've been trying to figure out how one of the functions in an app I downloaded works, but I can't seem to get it. So far I managed to get the function code but it's unreadable. All I really need is to see what one of the arguments is, but I'm not sure how I can do that.

My phone is jailbroken so I installed Flex but it doesn't seem to offer anything except making tweaks to the return and argument values, which is helpful for other things.

I tried making a MobileSubstrate tweak but I just get errors whenever I compile it with make.

*** first argument to word function must be greater than 0. Stop.

%hook TestClass

- (id)function {
    return "test";
}
%end

Is there another way to override a function and log its argument? Or maybe there is some debug tool that will log every single thing for me and I can find what I'm looking for? Any help is appreciated. Thanks.

Upvotes: 0

Views: 834

Answers (3)

Fouad
Fouad

Reputation: 409

As far as i remember, "theos" error you are getting means that you don't have SDK in your sdks folder.

If you are trying to find the type of an argument you can check it with a UIAlertView inside that method.

%hook HookedClass

- (void)someMethod:(id)arg1 {

    // call original method
    %orig;

    // whenever the method is called show type and value using UIAlertView
    UIAlertView *className = [[UIAlertView alloc] 
        initWithTitle:[NSString stringWithFormat:@"arg1 is a %@",[arg1 class]] 
        message:[NSString stringWithFormat:@"value: %@",arg1] 
        delegate:nil 
        cancelButtonTitle:@"Okay" 
        otherButtonTitles:nil];
    [className show];
    [className release];
}

%end

Or you can simply use one of logos directives %log to log it (you need to have syslog installed to check the log):

%hook HookedClass

- (void)someMethod:(id)arg1 {
     %log;
     %orig;
}
%end

you can learn more about logos directives here

And what Ben Gerard said is wrong, you can't log a bool with %@

For NSString you use %@
For int  you use %i
For float you use %f
For double you use %lf

Upvotes: 0

ienthach
ienthach

Reputation: 1

i use this %log in my tweak to view in console log.

%hook TestClass

-(void)functionName:(BOOL)isFunction {
     %log;
     %orig;
}
%end

Upvotes: 0

Ben Gerard
Ben Gerard

Reputation: 64

You can print the argument given to a function to the console. (syslog).

%hook TestClass

-(void)functionName:(BOOL)isFunction {
     %orig;
    NSLog(@"%@",isFunction);
}
%end

The (BOOL)isFunction but may not be known. But by dumping the headers you can get something similar to -(void)functionName:(id)arg1;. You can then simply print arg1 to the console like I have shown above.

Upvotes: 1

Related Questions