先说两个安全加固的实现
1,增加动态攻击方法防范
main函数中
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import <dlfcn.h>
typedef int (*ptrace_ptr_t)(int _request, pid_t _pid, caddr_t _addr, int _data);
#if !defined(PT_DENY_ATTACH)
#define PT_DENY_ATTACH 31
#endif
void disable_gdb(){
void * handle = dlopen(0, RTLD_GLOBAL | RTLD_NOW); ptrace_ptr_t ptrace_ptr = dlsym(handle, "ptrace"); ptrace_ptr(PT_DENY_ATTACH, 0, 0, 0);
dlclose(handle);
}
int main(int argc, char * argv[]) {
@autoreleasepool {
disable_gdb();
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
2,增加越狱设备运行风险
#import "AppDelegate.h"
if([[NSFileManager defaultManager] fileExistsAtPath:@"/Applications/Cydia.app"]){
return YES;
}
if([[NSFileManager defaultManager] fileExistsAtPath:@"/Library/MobileSubstrate/MobileSubstrate.dylib"]){
return YES;
}
if([[NSFileManager defaultManager] fileExistsAtPath:@"/var/lib/cydia"]){
return YES;
}