Search code examples
iosjailbreakcydia

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.


Solution

  • 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