是否可调试
- (IBAction)isDebugableBtnClicked:(UIButton *)sender {
_curBtnLbl.text = sender.titleLabel.text;
NSLog(@"is debugable check");
int SYSCTL_OK = 0;
NSString* resultStr = @"";
BOOL isDebugable = FALSE;
int name[4];
name[0] = CTL_KERN;
name[1] = KERN_PROC;
name[2] = KERN_PROC_PID;
int pidToCheck = -1;
int currentPID = getpid();
NSLog(@"currentPID=%d", currentPID);
pidToCheck = currentPID;
NSLog(@"pidToCheck=%d", pidToCheck);
name[3] = pidToCheck;
size_t infoSize = sizeof(struct kinfo_proc);
struct kinfo_proc kernelInfoProc;
memset(&kernelInfoProc, 0, infoSize);
int sysctlRet = sysctl(name, 4, &kernelInfoProc, &infoSize, NULL, 0);
NSLog(@"sysctlRet=%d", sysctlRet);
if(sysctlRet == SYSCTL_OK){
int pFlag = kernelInfoProc.kp_proc.p_flag;
NSLog(@"pFlag=0x%x", pFlag);
isDebugable = ((pFlag & P_TRACED) != 0);
NSLog(@"isDebugable=%s", boolToStr(isDebugable));
if (isDebugable) {
resultStr = @"可被调试 -> 越狱手机";
} else {
resultStr = @"不可被调试 -> 非越狱手机";
}
} else {
NSLog(@"errno=%d\n", errno);
char *errMsg = strerror(errno);
NSLog(@"errMsg=%s\n", errMsg);
resultStr = [NSString stringWithFormat:@"检测失败: %s", errMsg];
}
NSLog(@"resultStr=%@\n", resultStr);
_detectResultTv.text = resultStr;
}