用ApiResolver去hook已触发函数但没日志
- 问题:之前用了
ApiResolver
去写了hook代码,后续调试的函数确保被触发了,但是却没输出我们希望的日志
var resolver = new ApiResolver('objc');
resolver.enumerateMatches('*[AAUISignInViewController *]', {
onMatch: function(match) {
console.log(match['name'] + ":" + match['address']);
},
onComplete: function() {}
});
- 原因:此处
ApiResolver
只是search查找,函数是否存在,只运行一次,后续的确,本身就不会再次触发,所以后续代码被触发时,就不会打印日志
- 解决办法:真正的要实现,hook函数,待函数被运行后触发日志打印,应该改用:
Interceptor
- 具体写法
function hook_specific_method_of_class(className, funcName)
{
var curClass = ObjC.classes[className];
if (typeof(curClass) !== 'undefined') {
var curMethod = curClass[funcName];
if (typeof(curMethod) !== 'undefined') {
Interceptor.attach(curMethod.implementation, {
onEnter: function(args) {
console.log("argSelf=" + args[0] + ", argSel=" + args[1] + ", realArg1=" + args[2]);
}
});
}else{
console.log("Can't find method", funcName);
}
}else{
console.log("Can't find class: ", className);
}
}
hook_specific_method_of_class("NSXPCConnection", "- setExportedObject:")