iOS逆向与安全4.2:利用fishhook做防护

利用注入framework防护

#import "fishhook.h"
#import 

+(void)load{
    
    
    //基本防护
    struct rebinding bd;
    bd.name = "method_exchangeImplementations";
    bd.replacement = myExchange;
    bd.replaced = (void *)&exhangeP;
    
    //setIMP
    struct rebinding gt;
    gt.name = "method_getImplementation";
    gt.replacement = my_getIMP;
    gt.replaced = (void *)&getIMP;
    
    //getIMP
    struct rebinding st;
    st.name = "method_setImplementation";
    st.replacement = my_setIMP;
    st.replaced = (void *)&setIMP;
    
    struct rebinding rebs[3] = {bd,gt,st};
    rebind_symbols(rebs, 3);
    
}
//保存原来的交换函数
IMP  (*getIMP)(Method _Nonnull m);
IMP  (*setIMP)(Method _Nonnull m, IMP _Nonnull imp);

IMP  my_getIMP(Method _Nonnull m){
    exit(0);
    return nil;
}
IMP  my_setIMP(Method _Nonnull m, IMP _Nonnull imp){
    exit(0);
    return nil;
}


void(*exhangeP)(Method _Nonnull m1, Method _Nonnull m2);


void myExchange(Method _Nonnull m1, Method _Nonnull m2){
    NSLog(@"检测到HOOK");
}

你可能感兴趣的:(iOS逆向与安全4.2:利用fishhook做防护)