v1.4.1safe_device
该包有助于检测 iOS 模拟器、Android 模拟器和调试模式。该包还可检测 Android 设备上的模拟位置/虚假 GPS 位置。同时检查设备是否为真实设备。
ufukhawk/safe_device open-source repository details.
{"sdk":"flutter"}{"sdk":"flutter"}以下为英文项目原文快照,最新内容请访问 GitHub。
Safe Device Safe Device Flutter (Null-Safety) Jailbroken, root, emulator and mock location detection.
In your flutter project add the dependency:
dependencies:
...
safe_device: ^1.4.1
import 'package:safe_device/safe_device.dart';
You can configure the plugin at startup using SafeDevice.init and SafeDeviceConfig. This is useful if you want to disable automatic check such as the mock location detection.
import 'package:safe_device/safe_device.dart';
import 'package:safe_device/safe_device_config.dart';
void main() async {
SafeDevice.init(
SafeDeviceConfig(mockLocationCheckEnabled: false), // disables mock location check on Android
);
// ...rest of your app
}
It's not mandatory to configure the plugin at the start, if not provided a default configuration with everything enable is provided automatically
Checks whether device JailBroken on iOS/Android?
bool isJailBroken = await SafeDevice.isJailBroken;
(iOS ONLY) Enhanced jailbreak detection with custom path checking
bool isJailBrokenCustom = await SafeDevice.isJailBrokenCustom;
(iOS ONLY) Get detailed breakdown of jailbreak detection methods
Map<String, bool> details = await SafeDevice.jailbreakDetails;
Checks whether device is real or emulator
bool isRealDevice = await SafeDevice.isRealDevice;
bool isMockLocation = await SafeDevice.isMockLocation;
bool isMockLocation = await SafeDevice.isMockLocation;
Android: If mock location check is disabled via config, the check always returns false and no location updates are started. If enabled (default), the check is active.
iOS: The config is stored for future use but does not affect current detection logic. Mock location detection on iOS is based on jailbreak/emulator status.
(ANDROID ONLY) Check if application is running on external storage
bool isOnExternalStorage = await SafeDevice.isOnExternalStorage;
Check if device violates any of the above
bool isSafeDevice = await SafeDevice.isSafeDevice;
(ANDROID ONLY) Check if development Options is enable on device
bool isDevelopmentModeEnable = await SafeDevice.isDevelopmentModeEnable;
(ANDROID ONLY) Get detailed breakdown of root detection methods for debugging
Map<String, dynamic> rootDetails = await SafeDevice.rootDetectionDetails;
The plugin includes enhanced jailbreak detection for iOS with comprehensive path checking. The custom detection method checks for:
/Applications/Cydia.app, /private/var/lib/apt, etc.)/bin/bash, /usr/sbin/sshd, etc.)/Library/MobileSubstrate/MobileSubstrate.dylib)/etc/apt, /var/lib/dpkg/status)/System/Library/LaunchDaemons/com.saurik.Cydia.Startup.plist)/var/jb/.installed_palera1n, etc.)cydia://, sileo://, zebra://, etc.)false — no jailbreak detection runs on simulatorfalse — macOS filesystem structure differs from iOS// Basic jailbreak detection (uses both DTTJailbreakDetection and custom detection)
bool isJailbroken = await SafeDevice.isJailBroken;
// Custom detection only (comprehensive path checking)
bool isJailbrokenCustom = await SafeDevice.isJailBrokenCustom;
// Detailed breakdown of detection methods
Map<String, dynamic> details = await SafeDevice.jailbreakDetails;
// Returns:
// {
// "isSimulator": false,
// "isDevelopmentEnvironment": false,
// "hasObviousJailbreakSigns": false,
// "dttResult": false,
// "customResult": false,
// "finalResult": false
// }
Detects a wide range of Android emulators including:
Root and jailbreak detection is a best-effort approach. A determined attacker using tools such as Magisk Hide or Zygisk can bypass detection. This plugin is intended as a security layer — not a guarantee.
Device-specific handling: Some manufacturers (Samsung, Xiaomi, Vivo) ship with system properties or Knox security components that can cause false positives. The plugin applies conservative multi-indicator checks for these brands to balance accuracy and reliability.
true by default.