版权归作者所有,如有转发,请注明文章出处:https://cyrus-studio.github.io/blog/
反调试检测
反调试检测的几种方式。
1. TrackerId
首先,通过 IDA Pro 的调试器附加到当前 app 进程
关于IDA Pro调试android app的详细教程可以参考这篇文章【使用IDA Pro动态调试Android APP】
使用 top 命令查看进程状态
top | grep com.cyrus.example
17305 u0_a137 10 -10 4.8G 104M 42M t 0.0 1.8 0:02.02 com.cyrus.example
在输出中,S 表示进程状态,17305 是 PID。
通过head /proc/[pid]/status 可以查看详细的进程状态。
head -n 6 /proc/17305/status
Name: m.cyrus.example
State: S (sleeping)
Tgid: 17305
Pid: 17305
PPid: 728
TracerPid: 16208
TracerPid: 16208 说明当前的进程正在被进程 16208 调试或跟踪,否则没有被调试值应该为0。
2. stat
这时我们断点调试 app
再通过 head /proc/[pid]/status 可以查看详细的进程状态,包括是否被调试等信息。
head -n 6 /proc/17305/status
Name: m.cyrus.example
State: t (tracing stop)
Tgid: 17305
Pid: 17305
PPid: 728
TracerPid: 16208
在输出中,t (tracing stop) 表示 app 停止(被调试或其他暂停)
3. wchan
使用 cat 命令查看 /proc/[pid]/wchan 文件,该文件显示进程当前正在等待的内核函数。
cat /proc/17305/wchan
ptrace_stop
在输出中,ptrace_stop 表示进程 17305 当前正在被调试器暂停,等待调试器发出的命令。
4. android app 反调试检测
在 Android app 中实现反调试检测
package com.cyrus.example.antidebug
import android.os.Bundle
import android.os.Debug
import android.util.Log
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.cyrus.example.R
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispat