Search code examples
uitextfielduitextviewjailbreakcydiatweak

Unable to hooking UITextfield Class via theos


I want to develop simple tweak for hooking uitextfield or uitextview. My have code as below

%hook UITextView

-(id)initWithFrame:(CGRect)frame webView:(id)view
{
    UIAlertView *keyAlert = [[UIAlertView alloc] initWithTitle:@"testApp" message:@"Test" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
    [keyAlert show];
    [keyAlert release];

    return %orig;
}
%end

its execute successfully but i am unable to get any output. please check this tweak and help me and please suggest me if i am going in any wrong direction.

Thanks.


Solution

  • There are 2 things you could be doing wrong here:

    1) UITextView doesn't necessarily call that method on init; It might be calling -initWithFrame: , -initWithFrame:font: or -initWithFrame:webView: (or even just -init, and be setting the frame later on) . You should hook all cases and see if you get any results and on which one of them.

    %hook UITextView
    -(id)initWithFrame:(CGRect)frame
    {
        %log; // conveniently NSLogs self,selector,arguments
        return %orig;
    }
    -(id)initWithFrame:(CGRect)frame font:(UIFont *)font
    {
        %log; 
        return %orig;
    }
    -(id)initWithFrame:(CGRect)frame webView:(UIWebView *)webView
    {
        %log; 
        return %orig;
    }
    %end
    

    2) Make sure the process you're hooking onto is the one calling the method. If your project's plist filters "com.apple.springboard" and you're testing this into another app, e.g. "com.apple.mobilesafari", it won't work.