Flutter越狱与Root检测插件jailbreak_root_detection的使用
Flutter越狱与Root检测插件jailbreak_root_detection的使用
jailbreak_root_detection
此插件利用 RootBeer + DetectFrida 用于Android设备的root检测,以及 IOSSecuritySuite 用于iOS设备的越狱检测。
Getting started
在你的Flutter项目中添加依赖:
dependencies:
jailbreak_root_detection: "^1.1.4"
然后运行flutter pub get
来安装插件。
Usage
Android
以下是一些可以在Android设备上使用的属性和方法:
final isNotTrust = await JailbreakRootDetection.instance.isNotTrust;
final isJailBroken = await JailbreakRootDetection.instance.isJailBroken;
final isRealDevice = await JailbreakRootDetection.instance.isRealDevice;
final isOnExternalStorage = await JailbreakRootDetection.instance.isOnExternalStorage;
final checkForIssues = await JailbreakRootDetection.instance.checkForIssues;
final isDevMode = await JailbreakRootDetection.instance.isDevMode;
iOS
对于iOS,你需要更新你的 Info.plist
文件以包含特定的URL Scheme:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>undecimus</string>
<string>sileo</string>
<string>zbra</string>
<string>filza</string>
<string>activator</string>
<string>cydia</string>
</array>
然后你可以使用如下代码进行检测:
final isNotTrust = await JailbreakRootDetection.instance.isNotTrust;
final isJailBroken = await JailbreakRootDetection.instance.isJailBroken;
final isRealDevice = await JailbreakRootDetection.instance.isRealDevice;
final checkForIssues = await JailbreakRootDetection.instance.checkForIssues;
final bundleId = 'my-bundle-id'; // Ex: final bundleId = 'com.w3conext.jailbreakRootDetectionExample'
final isTampered = await JailbreakRootDetection.instance.isTampered(bundleId);
示例demo
下面是一个完整的示例应用,展示了如何使用 jailbreak_root_detection
插件来检查设备是否被越狱或Root:
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:jailbreak_root_detection/jailbreak_root_detection.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _result = '';
@override
void initState() {
super.initState();
_processCheckJailbreakRoot();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: [
Text(_result),
ElevatedButton(
onPressed: () => _processCheckJailbreakRoot(),
child: const Text('Check'),
),
],
),
),
),
);
}
void _processCheckJailbreakRoot() async {
_result = '';
final isNotTrust = await JailbreakRootDetection.instance.isNotTrust;
final isRealDevice = await JailbreakRootDetection.instance.isRealDevice;
print('isNotTrust: $isNotTrust');
print('isRealDevice: $isRealDevice');
_result += 'isNotTrust: $isNotTrust\n';
_result += 'isRealDevice: $isRealDevice\n';
if (Platform.isAndroid) {
try {
bool isOnExternalStorage =
await JailbreakRootDetection.instance.isOnExternalStorage;
print('isOnExternalStorage: $isOnExternalStorage');
_result += 'isOnExternalStorage: $isOnExternalStorage\n';
} catch (e) {
print(e);
}
}
if (Platform.isIOS) {
const bundleId = 'com.w3conext.jailbreakRootDetectionExample';
final isTampered =
await JailbreakRootDetection.instance.isTampered(bundleId);
print('isTampered: $isTampered');
_result += 'isTampered: $isTampered\n';
}
final checkForIssues = await JailbreakRootDetection.instance.checkForIssues;
print('checkForIssues: $checkForIssues');
for (final issue in checkForIssues) {
print('issue: ${issue.toString()}');
_result += '$issue\n';
}
setState(() {});
}
}
这个示例创建了一个简单的Flutter应用程序,它会在启动时自动检查设备的安全状态,并允许用户通过点击按钮再次执行检查。所有检查结果将显示在屏幕上并打印到控制台。
Reference
希望这篇指南能帮助你理解如何在Flutter项目中使用 jailbreak_root_detection
插件。如果你有任何问题或需要进一步的帮助,请随时提问!
更多关于Flutter越狱与Root检测插件jailbreak_root_detection的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter越狱与Root检测插件jailbreak_root_detection的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
当然,以下是如何在Flutter项目中集成和使用jailbreak_root_detection
插件的示例代码。jailbreak_root_detection
插件可以帮助你检测Android设备是否已被Root以及iOS设备是否已越狱。
1. 添加依赖
首先,你需要在你的pubspec.yaml
文件中添加jailbreak_root_detection
依赖:
dependencies:
flutter:
sdk: flutter
jailbreak_root_detection: ^x.y.z # 请替换为最新版本号
然后运行以下命令来安装依赖:
flutter pub get
2. 导入插件
在你需要使用该插件的Dart文件中导入它:
import 'package:jailbreak_root_detection/jailbreak_root_detection.dart';
3. 使用插件
你可以在你的Flutter应用中通过调用JailbreakRootDetection
类的方法来检测设备状态。以下是一个完整的示例代码,展示如何在Flutter应用中检测设备是否已被Root或越狱,并在UI中显示结果。
import 'package:flutter/material.dart';
import 'package:jailbreak_root_detection/jailbreak_root_detection.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Jailbreak & Root Detection Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomeScreen(),
);
}
}
class HomeScreen extends StatefulWidget {
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
String deviceStatus = "Checking...";
@override
void initState() {
super.initState();
_checkDeviceStatus();
}
Future<void> _checkDeviceStatus() async {
bool isJailbrokenOrRooted = await JailbreakRootDetection.isJailbrokenOrRooted;
setState(() {
deviceStatus = isJailbrokenOrRooted ? "Device is jailbroken or rooted" : "Device is not jailbroken or rooted";
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Jailbreak & Root Detection'),
),
body: Center(
child: Text(
deviceStatus,
style: TextStyle(fontSize: 24),
),
),
);
}
}
4. 运行应用
确保你的开发环境已经正确设置,并且连接了一个可以运行的设备或模拟器。然后运行以下命令来启动你的Flutter应用:
flutter run
应用启动后,它将自动检测设备是否已被Root或越狱,并在屏幕上显示结果。
这个示例代码展示了如何使用jailbreak_root_detection
插件来检测设备的Root或越狱状态,并在UI中显示检测结果。根据你的具体需求,你可以进一步扩展这个示例。