You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Flutter应用中检测越狱/ROOT设备及开发者模式?

Flutter 设备越狱/ROOT及开发者模式检测实现方案

一、越狱/ROOT状态检测

1. 使用第三方包快速实现

推荐用flutter_jailbreak_detection包,它封装了iOS和Android的基础越狱/ROOT检测逻辑,还能判断设备是否可伪造位置(越狱/ROOT设备的典型特征)。

  • 安装依赖:在pubspec.yaml中添加

    dependencies:
      flutter_jailbreak_detection: ^1.7.0 # 替换为最新版本
    

    执行flutter pub get完成安装。

  • 代码示例:

    import 'package:flutter_jailbreak_detection/flutter_jailbreak_detection.dart';
    
    Future<bool> isDeviceCompromised() async {
      bool isJailbroken = await FlutterJailbreakDetection.jailbroken;
      bool canMockLocation = await FlutterJailbreakDetection.canMockLocation;
      // 结合两个判断,提升检测准确率
      return isJailbroken || canMockLocation;
    }
    

2. 自定义补充检测逻辑

为避免第三方包的遗漏,可补充以下自定义检测:

  • 检查越狱/ROOT特征路径:
    import 'dart:io';
    
    Future<bool> checkSensitivePaths() async {
      // iOS越狱特征路径 & Android ROOT特征路径
      final List<String> riskyPaths = [
        '/Applications/Cydia.app',
        '/private/var/stash',
        '/system/xbin/su',
        '/system/bin/su',
        '/sbin/su'
      ];
      for (final path in riskyPaths) {
        if (await File(path).exists()) {
          return true;
        }
      }
      return false;
    }
    
  • iOS 额外检测:尝试打开Cydia协议链接,判断是否能唤起越狱商店
    import 'package:url_launcher/url_launcher.dart';
    
    Future<bool> checkCydiaUrl() async {
      final Uri cydiaUrl = Uri.parse('cydia://');
      return await canLaunchUrl(cydiaUrl);
    }
    

二、开发者模式检测

1. iOS 开发者模式检测

iOS 16及以上版本可直接通过device_info_plus包获取开发者模式状态,低版本可通过检查开发者目录判断:

import 'package:device_info_plus/device_info_plus.dart';
import 'dart:io';

Future<bool> isIOSDeveloperModeEnabled() async {
  final iosInfo = await DeviceInfoPlugin().iosInfo;
  // iOS 16+ 原生支持检测
  if (iosInfo.systemVersion.compareTo('16.0') >= 0) {
    return iosInfo.isDeveloperModeEnabled ?? false;
  }
  // iOS 15及以下,检查开发者目录是否存在
  return await Directory('/Library/Developer').exists();
}

2. Android 开发者模式检测

同样使用device_info_plus包快速获取状态:

import 'package:device_info_plus/device_info_plus.dart';

Future<bool> isAndroidDeveloperModeEnabled() async {
  final androidInfo = await DeviceInfoPlugin().androidInfo;
  return androidInfo.isDeveloperModeEnabled ?? false;
}

三、测试方法

越狱/ROOT状态测试

  • 越狱/ROOT设备测试:使用已越狱的iOS真机(安装Cydia)、已ROOT的Android真机,或在模拟器中开启ROOT权限(如Genymotion),调用检测方法验证返回true。
  • 正常设备测试:使用未越狱/ROOT的真机或官方模拟器,确保检测返回false。

开发者模式测试

  • iOS:前往「设置-隐私与安全性-开发者模式」开启/关闭,重启设备后调用检测方法,验证结果是否匹配状态。
  • Android:前往「设置-系统-开发者选项」开启/关闭,直接调用检测方法验证结果。

内容的提问来源于stack exchange,提问作者Shubham Kumar Pandey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 14:21:17