Android安全防护/检查root/检查Xposed/反调试/应用多开/模拟器检测(持续更新)

本文详细介绍了Android应用的安全防护措施,包括检查root权限、检测Xposed框架、多开软件的检测、反调试方案以及模拟器检测。通过一系列的技术手段,确保应用在安全环境中运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载请注明出处,转载时请不要抹去原始链接。

代码已上传git,欢迎star/fork/issue
https://github.com/lamster2018/EasyProtector
复制代码

文章目录

  • 食用方法
  • root权限检查
  • Xposed框架检查
  • 应用多开检查
  • 反调试方案
  • 模拟器检测
  • TODO

使用方法

implementation 'com.lahm.library:easy-protector-release:latest.release'

https://github.com/lamster2018/EasyProtector


root权限检查

开发者会使用诸如xposed,cydiasubstrate的框架进行hook操作,前提是拥有root权限。

关于root的原理,请参考《Android Root原理分析及防Root新思路》 blog.csdn.net/hsluoyc/art…

简单来说就是去拿『ro.secure』的值做判断, ro.secure值为1,adb权限降为shell,则认为没有root权限。 但是单纯的判断该值是没法检查userdebug版本的root权限

结合《Android判断设备是User版本还是Eng版本》 https://www.jianshu.com/p/7407cf6c34bd 其实还有一个值ro.debuggable

ro.secure=0 ro.secure=1
ro.debuggable=0 / user
ro.debuggable=1 eng/userdebug* /

*暂无userdebug的机器,不知道ro.secure是否为1,埋坑 userdebug 的debuggable值未知,secure为0.

实际上通过『ro.debuggable』值判断更准确 直接读取ro.secure值足够了

下一步再检验是否存在su文件 方案来自《Android检查手机是否被root》 www.jianshu.com/p/f9f39704e…

通过检查su是否存在,su是否可执行,综合判断root权限。

*EasyProtectorLib.checkIsRoot()*的内部实现

    public boolean isRoot() {
        int secureProp = getroSecureProp();
        if (secureProp == 0)//eng/userdebug版本,自带root权限
            return true;
        else return isSUExist();//user版本,继续查su文件
    }

    private int getroSecureProp() {
        int secureProp;
        String roSecureObj = CommandUtil.getSingleInstance().getProperty("ro.secure");
        if (roSecureObj == null) secureProp = 1;
        else {
            if ("0".equals(roSecureObj)) secureProp = 0;
            else secureProp = 1;
        }
        return secureProp;
    }

    private boolean isSUExist() {
        File file = null;
        String[] paths = {
   
   "/sbin/su",
                "/system/bin/su",
                "/system/xbin/su",
                "/data/local/xbin/su",
                "/data/local/bin/su",
                "/system/sd/xbin/su",
                "/system/bin/failsafe/su",
                "/data/local/su"};
        for (String path : paths) {
            file = new File(path);
            if (file.exists()) return true;//可以继续做可执行判断
        }
        return false;
    }
复制代码

Xposed框架检查

原理请参考我的《反Xposed方案学习笔记》 www.jianshu.com/p/ee0062468…

所有的方案回归到一点:判断xposed的包是否存在。 1.是通过主动抛出异常查栈信息; 2.是主动反射调用。

当检测到xp框架存在时,我们先行调用xp方法,关闭xp框架达到反制的目的。

EasyProtectorLib.checkIsXposedExist()_内部实现

    private static final String XPOSED_HELPERS = "de.robv.android.xposed.XposedHelpers";
    private static final String XPOSED_BRIDGE = "de.robv.android.xposed.XposedBridge";

    //手动抛出异常,检查堆栈信息是否有xp框架包
    public boolean isEposedExistByThrow() {
        try {
            throw new Exception("gg");
        } catch (Exception e) {
            for (StackTraceElement stackTraceElement : e.getStackTrace()) {
                if (stackTraceElement.getClassName().contains(XPOSED_BRIDGE)) return true;
            }
            return false;
        }
    }

    //检查xposed包是否存在
    public boolean isXposedExists() {
        try {
            Object xpHelperObj = ClassLoader
                    .getSystemClassLoader()
                    .loadClass(XPOSED_HELPERS)
                    .newInstance();
        } catch (InstantiationException e) {
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值