新建工程查看ptrace定义
在iOS App工程下直接#import <sys/ptrace.h>报错,需要新建一个命令行工程,然后#import,主要目的是为了定位到头文件查看信息,找到之后新建一个文件,将内容复制到新建的文件中,为了节约时间这里直接给出该文件
// MyPtrace.h
// Created by apple on 2019/3/4.
// Copyright © 2019 bobo_Ma. All rights reserved.
//
#ifndef _SYS_PTRACE_H_
#define _SYS_PTRACE_H_
#include
#include
enum {
ePtAttachDeprecated__deprecated_enum_msg("PT_ATTACH is deprecated. See PT_ATTACHEXC") = 10
};
#define PT_TRACE_ME 0 /* child declares it's being traced */
#define PT_READ_I 1 /* read word in child's I space */
#define PT_READ_D 2 /* read word in child's D space */
#define PT_READ_U 3 /* read word in child's user structure */
#define PT_WRITE_I 4 /* write word in child's I space */
#define PT_WRITE_D 5 /* write word in child's D space */
#define PT_WRITE_U 6 /* write word in child's user structure */
#define PT_CONTINUE 7 /* continue the child */
#define PT_KILL 8 /* kill the child process */
#define PT_STEP 9 /* single step the child */
#define PT_ATTACH ePtAttachDeprecated /* trace some running process */
#define PT_DETACH 11 /* stop tracing a process */
#define PT_SIGEXC 12 /* signals as exceptions for current_proc */
#define PT_THUPDATE 13 /* signal for thread# */
#define PT_ATTACHEXC 14 /* attach to running process with signal exception */
#define PT_FORCEQUOTA 30 /* Enforce quota for root */
#define PT_DENY_ATTACH 31
#define PT_FIRSTMACH 32 /* for machine-specific requests */
__BEGIN_DECLS
int ptrace(int_request,pid_t_pid,caddr_t_addr,int_data);
__END_DECLS
#endif /* !_SYS_PTRACE_H_ */
解析ptrace函数
函数原型:int ptrace(int _request, pid_t _pid, caddr_t _addr, int _data);
参数1:表明ptrace要做的事情
参数2:进程号PID
参数3:地址
参数4:数据
参数3、4根据参数1决定,具体含义没有深究。
ptrace参数1中的PT_DENY_ATTACH,如果传入这个值,那么就可以中断lldb调试。
反调试代码
-
在main.m文件中 #import "MyPtrace.h"
-
main函数中添加如下代码即可
ptrace(PT_DENY_ATTACH, 0, 0, 0);
网友评论