搜尋套件、儲存庫與 APP 分類

safe_device 封面
套件詳情v1.4.1

safe_device

此套件可幫助檢測 iOS 模擬器、Android 模擬器與除錯模式。此套件亦可檢測 Android 設備上的模擬位置/偽造 GPS 位置。同時檢查裝置是否為真實裝置。

AndroidiOS
近 30 天下載
14.7萬
喜歡數
386
Pub 分數
140

安裝套件

flutter pub add safe_device

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

safe_device 套件幫助開發者檢測應用程式是否在模擬環境(例如 iOS 模擬器、Android 模擬器)或除錯模式下執行。它也能識別 Android 裝置上的偽造 GPS 位置,並判斷裝置是否為真實裝置。透過防止來自模擬或偽造環境的未授權存取,增強了安全性。此套件對於需要強大的裝置完整性檢查之應用程式非常有用,特別是在金融或敏感資料情境中。

適用情境

  • 防止應用在模擬器中執行
  • 檢測偽造GPS位置
  • 防止調試模式被利用
  • 驗證真實設備的存在
  • 增強欺詐檢測
  • 保護敏感資料存取

主要特色

  • 檢測 iOS 模擬器
  • 識別 Android 模擬器
  • 檢查除錯模式
  • 檢測偽造位置/偽裝GPS
  • 驗證設備真實性
  • 輕量且平台無關

適合對象

  • 注重安全的應用程式
  • 金融或銀行應用
  • 欺詐預防系統
  • 需要設備完整性
  • 開發人員優先考慮執行時安全
  • 具有高安全要求的移動應用

使用建議

  • 僅限 Android 和 iOS 平台
  • 無法防止所有形式的偽造
  • 依賴於設備特定的指標
  • 可能在已root的設備上觸發誤報
  • Android 上需要正確的權限處理

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

safe_device (Null-Safety)

Safe Device Safe Device Flutter (Null-Safety) Jailbroken, root, emulator and mock location detection.

Getting Started

In your flutter project add the dependency:

dependencies:
...
  safe_device: ^1.4.1

Usage

Importing package
import 'package:safe_device/safe_device.dart';
Configuration

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

Using it

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;

Enhanced iOS Jailbreak Detection

The plugin includes enhanced jailbreak detection for iOS with comprehensive path checking. The custom detection method checks for:

Jailbreak Tool Paths
  • Cydia and package managers (/Applications/Cydia.app, /private/var/lib/apt, etc.)
  • System binaries commonly found on jailbroken devices (/bin/bash, /usr/sbin/sshd, etc.)
  • MobileSubstrate files (/Library/MobileSubstrate/MobileSubstrate.dylib)
  • APT package manager files (/etc/apt, /var/lib/dpkg/status)
  • Launch daemons (/System/Library/LaunchDaemons/com.saurik.Cydia.Startup.plist)
  • Palera1n rootless jailbreak indicators (/var/jb/.installed_palera1n, etc.)
Detection Methods
  • Path Existence: Checks for files and directories commonly present on jailbroken devices
  • URL Scheme Detection: Tests if jailbreak-related URL schemes can be opened (cydia://, sileo://, zebra://, etc.)
  • Sandbox Violation: Attempts to write outside the app sandbox
  • Environment Variables: Checks for jailbreak-related environment variables
  • Symbolic Link Detection: Looks for suspicious symbolic links
  • Process Detection: Checks for running jailbreak-related processes
Platform Notes
  • Simulator: Always returns false — no jailbreak detection runs on simulator
  • Mac Catalyst: Always returns false — macOS filesystem structure differs from iOS
Usage Example
// 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
// }

Android Emulator Detection

Detects a wide range of Android emulators including:

  • Android SDK Emulator, Genymotion
  • LDPlayer, MEmu, BlueStacks, MuMu Player (NetEase), Nox, Droid4X

Known Limitations

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.

Notes

Mock location detection
  • Android — Location permission is required to detect mock location. The check can be disabled at runtime via config.
  • iOS — Mock location detection is based on jailbreak/emulator status.
Development Mode
  • Development Options in emulator is always true by default.

❗Since emulators are usually rooted, you might want to bypass these checks during development. Unless you're keen on constant false alarms ⏰

所屬分類

原始碼儲存庫

使用此套件的專案