想打印hook到的参数


#1

hook了自己写的app的 didSelectRowAtIndexPath 方法,打印indexpath

%hook MessageChatListViewController

  • (void)tableView:(id)arg1 didSelectRowAtIndexPath:(id)arg2{
    Ivar indexPathIvar = class_getInstanceVariable([arg2 class], “indexPath”);
    id indexPath= object_getIvar(arg2, indexPathIvar);
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@“didSelectRowAtIndexPath” message:[NSString stringWithFormat:@“indexpath.row = %ld”,[indexPath row]] delegate:self cancelButtonTitle:@“OK” otherButtonTitles:nil];
    [alert show];

//%orig;
}
%end

但是点击cell后 能hook这方法 但是每次打印出来都是null,
Ivar indexPathIvar = class_getInstanceVariable([arg2 class], “indexPath”);
id indexPath= object_getIvar(arg2, indexPathIvar);
这个方法用的有问题么?


#2

改成
Ivar sectionIvar = class_getInstanceVariable([arg2 class], “section”);
id section = object_getIvar(arg2, sectionIvar);
这样 仔细想想可能应该是这样 还没测试


#3

失败了 还是null


#4

改成

然后你就可以

NSLog(@"%ld", arg2.section)