如何hook私有api

如题 我想hook MobileInstallation.framework的MobileInstallationInstall方法

int (*original_MobileInstallationInstall)(NSString *path, NSDictionary *dict, void *na, NSString *path2_equal_path_maybe_no_use);
int replaced_MobileInstallationInstall(NSString *path, NSDictionary *dict, void *na, NSString *path2_equal_path_maybe_no_use)
{
    int res = original_MobileInstallationInstall(path,dict,na,path2_equal_path_maybe_no_use);
    NSString *bundleid= [NSBundle mainBundle].bundleIdentifier;
    if([LogsUtil isStartMonitor:bundleid])
    {
        NSString *eventInfo = [NSString stringWithFormat:@"安装了应用%@",path];
        NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
        NSString *appName =[infoDict objectForKey:@"CFBundleDisplayName"];
        NSNumber *eventTypeObject=[NSNumber numberWithUnsignedInt:INSTALL_APP];
        NSMutableDictionary *dic1=[NSMutableDictionary dictionaryWithObjectsAndKeys:eventInfo,@"eventInfo",appName,@"processName",eventTypeObject,@"eventTypeObject", nil];
        [LogsUtil sendEventInfoToMonitor:dic1];
    }
    return res;
}
%ctor
{
    MSHookFunction((void *)MobileInstallationInstall,(void *)replaced_MobileInstallationInstall,(void * *)&original_MobileInstallationInstall);
}

结果编译就报错ApplicationInpouring.xm:50:28: Use of undeclared identifier ‘MobileInstallationInstall’
请教大神们 这个该如何破?只是hook不是不需要头文件么

你需要给出这个函数的原型,写在文件开头就可以了;
类似于
extern "C" void Foo(void);

1 个赞

谢谢大神 按你的方法已经解决了 32个赞 :heart_eyes: