react-native-device-defense 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +236 -0
  3. package/android/build.gradle +90 -0
  4. package/android/proguard-rules.pro +28 -0
  5. package/android/src/main/AndroidManifest.xml +4 -0
  6. package/android/src/main/cpp/CMakeLists.txt +45 -0
  7. package/android/src/main/cpp/device-security.cpp +314 -0
  8. package/android/src/main/java/vn/osp/security/DebugDetection.kt +131 -0
  9. package/android/src/main/java/vn/osp/security/DeviceSecurityModule.kt +277 -0
  10. package/android/src/main/java/vn/osp/security/DeviceSecurityPackage.kt +58 -0
  11. package/android/src/main/java/vn/osp/security/EmulatorDetection.kt +204 -0
  12. package/android/src/main/java/vn/osp/security/HookDetection.kt +270 -0
  13. package/android/src/main/java/vn/osp/security/NativeSecurityCheck.kt +66 -0
  14. package/android/src/main/java/vn/osp/security/RootDetection.kt +349 -0
  15. package/lib/commonjs/NativeDeviceSecurity.js +9 -0
  16. package/lib/commonjs/NativeDeviceSecurity.js.map +1 -0
  17. package/lib/commonjs/api.js +213 -0
  18. package/lib/commonjs/api.js.map +1 -0
  19. package/lib/commonjs/components/SecurityBlockedScreen.js +177 -0
  20. package/lib/commonjs/components/SecurityBlockedScreen.js.map +1 -0
  21. package/lib/commonjs/components/index.js +13 -0
  22. package/lib/commonjs/components/index.js.map +1 -0
  23. package/lib/commonjs/hooks/index.js +13 -0
  24. package/lib/commonjs/hooks/index.js.map +1 -0
  25. package/lib/commonjs/hooks/useDeviceSecurity.js +81 -0
  26. package/lib/commonjs/hooks/useDeviceSecurity.js.map +1 -0
  27. package/lib/commonjs/index.js +48 -0
  28. package/lib/commonjs/index.js.map +1 -0
  29. package/lib/commonjs/types.js +2 -0
  30. package/lib/commonjs/types.js.map +1 -0
  31. package/lib/module/NativeDeviceSecurity.js +3 -0
  32. package/lib/module/NativeDeviceSecurity.js.map +1 -0
  33. package/lib/module/api.js +206 -0
  34. package/lib/module/api.js.map +1 -0
  35. package/lib/module/components/SecurityBlockedScreen.js +169 -0
  36. package/lib/module/components/SecurityBlockedScreen.js.map +1 -0
  37. package/lib/module/components/index.js +2 -0
  38. package/lib/module/components/index.js.map +1 -0
  39. package/lib/module/hooks/index.js +2 -0
  40. package/lib/module/hooks/index.js.map +1 -0
  41. package/lib/module/hooks/useDeviceSecurity.js +73 -0
  42. package/lib/module/hooks/useDeviceSecurity.js.map +1 -0
  43. package/lib/module/index.js +21 -0
  44. package/lib/module/index.js.map +1 -0
  45. package/lib/module/types.js +2 -0
  46. package/lib/module/types.js.map +1 -0
  47. package/lib/typescript/NativeDeviceSecurity.d.ts +16 -0
  48. package/lib/typescript/NativeDeviceSecurity.d.ts.map +1 -0
  49. package/lib/typescript/api.d.ts +55 -0
  50. package/lib/typescript/api.d.ts.map +1 -0
  51. package/lib/typescript/components/SecurityBlockedScreen.d.ts +23 -0
  52. package/lib/typescript/components/SecurityBlockedScreen.d.ts.map +1 -0
  53. package/lib/typescript/components/index.d.ts +2 -0
  54. package/lib/typescript/components/index.d.ts.map +1 -0
  55. package/lib/typescript/hooks/index.d.ts +3 -0
  56. package/lib/typescript/hooks/index.d.ts.map +1 -0
  57. package/lib/typescript/hooks/useDeviceSecurity.d.ts +7 -0
  58. package/lib/typescript/hooks/useDeviceSecurity.d.ts.map +1 -0
  59. package/lib/typescript/index.d.ts +12 -0
  60. package/lib/typescript/index.d.ts.map +1 -0
  61. package/lib/typescript/types.d.ts +81 -0
  62. package/lib/typescript/types.d.ts.map +1 -0
  63. package/package.json +72 -0
  64. package/react-native-device-security.podspec +18 -0
  65. package/src/NativeDeviceSecurity.ts +33 -0
  66. package/src/api.ts +225 -0
  67. package/src/components/SecurityBlockedScreen.tsx +204 -0
  68. package/src/components/index.ts +1 -0
  69. package/src/hooks/index.ts +5 -0
  70. package/src/hooks/useDeviceSecurity.ts +91 -0
  71. package/src/index.ts +27 -0
  72. package/src/types.ts +95 -0
@@ -0,0 +1,12 @@
1
+ /**
2
+ * react-native-device-security
3
+ *
4
+ * Main exports for the library
5
+ */
6
+ export { default as DeviceSecurity, DeviceSecurity as DeviceSecurityClass } from './api';
7
+ export { default } from './api';
8
+ export { default as NativeDeviceSecurity } from './NativeDeviceSecurity';
9
+ export { useDeviceSecurity } from './hooks';
10
+ export { SecurityBlockedScreen } from './components';
11
+ export type { SecurityStatus, SecurityThreat, BlockOnSecurityThreatOptions, UseDeviceSecurityOptions, UseDeviceSecurityReturn, } from './types';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,cAAc,IAAI,mBAAmB,EAAE,MAAM,OAAO,CAAC;AACzF,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAGhC,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAGzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAGrD,YAAY,EACV,cAAc,EACd,cAAc,EACd,4BAA4B,EAC5B,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Security threat types
3
+ */
4
+ export type SecurityThreat = 'root_detected' | 'root_beer_detected' | 'native_root_detected' | 'dangerous_bins_detected' | 'root_apps_detected' | 'system_props_modified' | 'frida_detected' | 'xposed_detected' | 'magisk_detected' | 'debugger_detected' | 'emulator_detected';
5
+ /**
6
+ * Detailed security status
7
+ */
8
+ export interface SecurityStatus {
9
+ /** Overall security status */
10
+ isSecure: boolean;
11
+ /** List of detected threats */
12
+ threats: SecurityThreat[];
13
+ /** Device is rooted */
14
+ isRooted: boolean;
15
+ /** RootBeer library detected root */
16
+ hasRootBeerDetected: boolean;
17
+ /** Native C++ detection found root */
18
+ hasNativeRootDetected: boolean;
19
+ /** Dangerous binaries found */
20
+ hasDangerousBins: boolean;
21
+ /** Root management apps found */
22
+ hasRootApps: boolean;
23
+ /** System properties modified */
24
+ hasSystemPropsModified: boolean;
25
+ /** Frida framework detected */
26
+ hasFrida: boolean;
27
+ /** Xposed framework detected */
28
+ hasXposed: boolean;
29
+ /** Magisk detected */
30
+ hasMagisk: boolean;
31
+ /** Debugger is attached */
32
+ isDebuggable: boolean;
33
+ /** Running on emulator */
34
+ isEmulator: boolean;
35
+ /** Additional details about detection */
36
+ details?: Record<string, boolean | string | number>;
37
+ }
38
+ /**
39
+ * Options for blocking on security threat
40
+ */
41
+ export interface BlockOnSecurityThreatOptions {
42
+ /** Show alert to user when blocked */
43
+ showAlert?: boolean;
44
+ /** Custom alert title (default: 'Security Warning') */
45
+ alertTitle?: string;
46
+ /** Custom alert message */
47
+ alertMessage?: string;
48
+ /** Alert button text (default: 'OK') */
49
+ alertButtonText?: string;
50
+ /** Callback when app is blocked */
51
+ onBlocked?: (status: SecurityStatus) => void;
52
+ }
53
+ /**
54
+ * Hook options
55
+ */
56
+ export interface UseDeviceSecurityOptions {
57
+ /** Callback when security threat detected */
58
+ onSecurityThreat?: (threat: SecurityThreat, status: SecurityStatus) => void;
59
+ /** Block app when threat detected */
60
+ blockOnThreat?: boolean;
61
+ /** Custom block options */
62
+ blockOptions?: BlockOnSecurityThreatOptions;
63
+ /** Check interval in ms (default: 0 - check once) */
64
+ checkInterval?: number;
65
+ }
66
+ /**
67
+ * Hook return value
68
+ */
69
+ export interface UseDeviceSecurityReturn {
70
+ /** Device is secure */
71
+ isSecure: boolean | null;
72
+ /** Loading state */
73
+ isLoading: boolean;
74
+ /** Security status details */
75
+ securityStatus: SecurityStatus | null;
76
+ /** Error if any */
77
+ error: Error | null;
78
+ /** Manually re-check security */
79
+ recheck: () => Promise<void>;
80
+ }
81
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,eAAe,GACf,oBAAoB,GACpB,sBAAsB,GACtB,yBAAyB,GACzB,oBAAoB,GACpB,uBAAuB,GACvB,gBAAgB,GAChB,iBAAiB,GACjB,iBAAiB,GACjB,mBAAmB,GACnB,mBAAmB,CAAC;AAExB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,8BAA8B;IAC9B,QAAQ,EAAE,OAAO,CAAC;IAClB,+BAA+B;IAC/B,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,uBAAuB;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,qCAAqC;IACrC,mBAAmB,EAAE,OAAO,CAAC;IAC7B,sCAAsC;IACtC,qBAAqB,EAAE,OAAO,CAAC;IAC/B,+BAA+B;IAC/B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,iCAAiC;IACjC,WAAW,EAAE,OAAO,CAAC;IACrB,iCAAiC;IACjC,sBAAsB,EAAE,OAAO,CAAC;IAChC,+BAA+B;IAC/B,QAAQ,EAAE,OAAO,CAAC;IAClB,gCAAgC;IAChC,SAAS,EAAE,OAAO,CAAC;IACnB,sBAAsB;IACtB,SAAS,EAAE,OAAO,CAAC;IACnB,2BAA2B;IAC3B,YAAY,EAAE,OAAO,CAAC;IACtB,0BAA0B;IAC1B,UAAU,EAAE,OAAO,CAAC;IACpB,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC;CACrD;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,sCAAsC;IACtC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,uDAAuD;IACvD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2BAA2B;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wCAAwC;IACxC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mCAAmC;IACnC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,6CAA6C;IAC7C,gBAAgB,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IAC5E,qCAAqC;IACrC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,2BAA2B;IAC3B,YAAY,CAAC,EAAE,4BAA4B,CAAC;IAC5C,qDAAqD;IACrD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,uBAAuB;IACvB,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;IACzB,oBAAoB;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,8BAA8B;IAC9B,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IACtC,mBAAmB;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,iCAAiC;IACjC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B"}
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "react-native-device-defense",
3
+ "version": "1.0.0",
4
+ "description": "Multi-layer device security detection for React Native (root, hook, debugger, emulator detection)",
5
+ "main": "lib/commonjs/index.js",
6
+ "module": "lib/module/index.js",
7
+ "types": "lib/typescript/index.d.ts",
8
+ "react-native": "src/index.ts",
9
+ "source": "src/index.ts",
10
+ "files": [
11
+ "src",
12
+ "lib",
13
+ "android",
14
+ "ios",
15
+ "react-native-device-security.podspec",
16
+ "!**/__tests__",
17
+ "!**/__fixtures__",
18
+ "!**/__mocks__"
19
+ ],
20
+ "keywords": [
21
+ "react-native",
22
+ "security",
23
+ "root-detection",
24
+ "anti-hook",
25
+ "anti-debug",
26
+ "device-security",
27
+ "android-security"
28
+ ],
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/BuiHung1612/react-native-device-security.git"
32
+ },
33
+ "author": "OSP <dev@osp.vn>",
34
+ "license": "MIT",
35
+ "bugs": {
36
+ "url": "https://github.com/BuiHung1612/react-native-device-security/issues"
37
+ },
38
+ "homepage": "https://github.com/BuiHung1612/react-native-device-security#readme",
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "scripts": {
43
+ "test": "jest",
44
+ "typecheck": "tsc --noEmit",
45
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
46
+ "prepare": "bob build"
47
+ },
48
+ "peerDependencies": {
49
+ "react": "*",
50
+ "react-native": "*"
51
+ },
52
+ "devDependencies": {
53
+ "@types/react": "^18.0.0",
54
+ "@types/react-native": "^0.72.0",
55
+ "react-native-builder-bob": "^0.20.0",
56
+ "typescript": "^5.0.0"
57
+ },
58
+ "react-native-builder-bob": {
59
+ "source": "src",
60
+ "output": "lib",
61
+ "targets": [
62
+ "commonjs",
63
+ "module",
64
+ [
65
+ "typescript",
66
+ {
67
+ "project": "tsconfig.build.json"
68
+ }
69
+ ]
70
+ ]
71
+ }
72
+ }
@@ -0,0 +1,18 @@
1
+ Pod::Spec.new do |s|
2
+ s.name = 'react-native-device-security'
3
+ s.version = '1.0.0'
4
+ s.summary = 'Multi-layer device security detection for React Native'
5
+ s.description = <<-DESC
6
+ React Native library for detecting device security threats including root detection,
7
+ hook detection (Frida, Xposed, Magisk), debugger detection, and emulator detection.
8
+ DESC
9
+ s.homepage = 'https://github.com/your-org/react-native-device-security'
10
+ s.license = { :type => 'MIT', :file => 'LICENSE' }
11
+ s.author = { 'OSP' => 'dev@osp.vn' }
12
+ s.platforms = { :ios => '12.0' }
13
+ s.source = { :git => 'https://github.com/your-org/react-native-device-security.git', :tag => "v#{s.version}" }
14
+ s.source_files = 'ios/**/*.{h,m,mm,swift}'
15
+ s.requires_arc = true
16
+
17
+ s.dependency 'React-Core'
18
+ end
@@ -0,0 +1,33 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import { TurboModuleRegistry } from 'react-native';
3
+
4
+ export interface Spec extends TurboModule {
5
+ // Root detection methods
6
+ isRooted(): boolean;
7
+ isRootedWithDetails(): Promise<string>;
8
+
9
+ // Hook detection methods
10
+ hasFrida(): boolean;
11
+ hasXposed(): boolean;
12
+ hasMagisk(): boolean;
13
+
14
+ // Debug detection
15
+ isDebuggable(): boolean;
16
+
17
+ // Emulator detection
18
+ isEmulator(): boolean;
19
+
20
+ // Comprehensive security check
21
+ getSecurityStatus(): Promise<string>;
22
+ isDeviceSecure(): Promise<boolean>;
23
+
24
+ // Blocking methods
25
+ blockOnSecurityThreat(
26
+ showAlert: boolean,
27
+ alertTitle: string,
28
+ alertMessage: string,
29
+ alertButtonText: string,
30
+ ): void;
31
+ }
32
+
33
+ export default TurboModuleRegistry.getEnforcing<Spec>('DeviceSecurity');
package/src/api.ts ADDED
@@ -0,0 +1,225 @@
1
+ /**
2
+ * DeviceSecurity API
3
+ * Main singleton class for device security checks
4
+ */
5
+
6
+ import { Platform } from 'react-native';
7
+ import NativeDeviceSecurity from './NativeDeviceSecurity';
8
+ import type {
9
+ BlockOnSecurityThreatOptions,
10
+ SecurityStatus,
11
+ SecurityThreat,
12
+ } from './types';
13
+
14
+ /**
15
+ * Main DeviceSecurity API class
16
+ */
17
+ class DeviceSecurity {
18
+ /**
19
+ * Check if device is secure (no security threats)
20
+ */
21
+ async isDeviceSecure(): Promise<boolean> {
22
+ if (Platform.OS !== 'android') {
23
+ // iOS: no-op for now, return true
24
+ return true;
25
+ }
26
+
27
+ try {
28
+ return await NativeDeviceSecurity.isDeviceSecure();
29
+ } catch (error) {
30
+ console.error('DeviceSecurity: Error checking device security', error);
31
+ return false;
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Get detailed security status
37
+ */
38
+ async getSecurityStatus(): Promise<SecurityStatus> {
39
+ if (Platform.OS !== 'android') {
40
+ // iOS: no-op for now, return secure status
41
+ return {
42
+ isSecure: true,
43
+ threats: [],
44
+ isRooted: false,
45
+ hasRootBeerDetected: false,
46
+ hasNativeRootDetected: false,
47
+ hasDangerousBins: false,
48
+ hasRootApps: false,
49
+ hasSystemPropsModified: false,
50
+ hasFrida: false,
51
+ hasXposed: false,
52
+ hasMagisk: false,
53
+ isDebuggable: false,
54
+ isEmulator: false,
55
+ };
56
+ }
57
+
58
+ try {
59
+ const statusJson = await NativeDeviceSecurity.getSecurityStatus();
60
+ return JSON.parse(statusJson) as SecurityStatus;
61
+ } catch (error) {
62
+ console.error('DeviceSecurity: Error getting security status', error);
63
+ return this.getDefaultSecurityStatus();
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Check if device is rooted (synchronous, Android only)
69
+ */
70
+ isRooted(): boolean {
71
+ if (Platform.OS !== 'android') {
72
+ return false;
73
+ }
74
+
75
+ try {
76
+ return NativeDeviceSecurity.isRooted();
77
+ } catch (error) {
78
+ console.error('DeviceSecurity: Error checking root status', error);
79
+ return false;
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Check if Frida is present
85
+ */
86
+ hasFrida(): boolean {
87
+ if (Platform.OS !== 'android') {
88
+ return false;
89
+ }
90
+
91
+ try {
92
+ return NativeDeviceSecurity.hasFrida();
93
+ } catch (error) {
94
+ console.error('DeviceSecurity: Error checking Frida', error);
95
+ return false;
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Check if Xposed framework is present
101
+ */
102
+ hasXposed(): boolean {
103
+ if (Platform.OS !== 'android') {
104
+ return false;
105
+ }
106
+
107
+ try {
108
+ return NativeDeviceSecurity.hasXposed();
109
+ } catch (error) {
110
+ console.error('DeviceSecurity: Error checking Xposed', error);
111
+ return false;
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Check if Magisk is present
117
+ */
118
+ hasMagisk(): boolean {
119
+ if (Platform.OS !== 'android') {
120
+ return false;
121
+ }
122
+
123
+ try {
124
+ return NativeDeviceSecurity.hasMagisk();
125
+ } catch (error) {
126
+ console.error('DeviceSecurity: Error checking Magisk', error);
127
+ return false;
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Check if app is debuggable
133
+ */
134
+ isDebuggable(): boolean {
135
+ if (Platform.OS !== 'android') {
136
+ return false;
137
+ }
138
+
139
+ try {
140
+ return NativeDeviceSecurity.isDebuggable();
141
+ } catch (error) {
142
+ console.error('DeviceSecurity: Error checking debuggable', error);
143
+ return false;
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Check if running on emulator
149
+ */
150
+ isEmulator(): boolean {
151
+ if (Platform.OS !== 'android') {
152
+ return false;
153
+ }
154
+
155
+ try {
156
+ return NativeDeviceSecurity.isEmulator();
157
+ } catch (error) {
158
+ console.error('DeviceSecurity: Error checking emulator', error);
159
+ return false;
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Block app when security threat detected
165
+ * This will show an alert and potentially exit the app
166
+ */
167
+ blockOnSecurityThreat(options: BlockOnSecurityThreatOptions = {}): void {
168
+ if (Platform.OS !== 'android') {
169
+ return;
170
+ }
171
+
172
+ const {
173
+ showAlert = true,
174
+ alertTitle = 'Security Warning',
175
+ alertMessage = 'This device is not secure. The app cannot run on rooted or modified devices.',
176
+ alertButtonText = 'OK',
177
+ onBlocked,
178
+ } = options;
179
+
180
+ try {
181
+ NativeDeviceSecurity.blockOnSecurityThreat(
182
+ showAlert,
183
+ alertTitle,
184
+ alertMessage,
185
+ alertButtonText,
186
+ );
187
+
188
+ // Call callback if provided
189
+ if (onBlocked) {
190
+ // Get status for callback
191
+ this.getSecurityStatus().then(status => {
192
+ onBlocked(status);
193
+ });
194
+ }
195
+ } catch (error) {
196
+ console.error('DeviceSecurity: Error blocking on security threat', error);
197
+ }
198
+ }
199
+
200
+ /**
201
+ * Get default security status (error case)
202
+ */
203
+ private getDefaultSecurityStatus(): SecurityStatus {
204
+ return {
205
+ isSecure: false,
206
+ threats: ['emulator_detected'], // Mark as threat on error to be safe
207
+ isRooted: false,
208
+ hasRootBeerDetected: false,
209
+ hasNativeRootDetected: false,
210
+ hasDangerousBins: false,
211
+ hasRootApps: false,
212
+ hasSystemPropsModified: false,
213
+ hasFrida: false,
214
+ hasXposed: false,
215
+ hasMagisk: false,
216
+ isDebuggable: false,
217
+ isEmulator: false,
218
+ };
219
+ }
220
+ }
221
+
222
+ // Export singleton instance
223
+ const deviceSecurityInstance = new DeviceSecurity();
224
+ export default deviceSecurityInstance;
225
+ export { DeviceSecurity };
@@ -0,0 +1,204 @@
1
+ /**
2
+ * SecurityBlockedScreen.tsx
3
+ *
4
+ * Screen to display when app is blocked due to security threats
5
+ */
6
+
7
+ import React from 'react';
8
+ import {
9
+ View,
10
+ Text,
11
+ StyleSheet,
12
+ ScrollView,
13
+ SafeAreaView,
14
+ Platform,
15
+ } from 'react-native';
16
+ import type { SecurityStatus, SecurityThreat } from '../types';
17
+
18
+ interface SecurityBlockedScreenProps {
19
+ /** Security status details */
20
+ threats?: SecurityThreat[];
21
+ /** Custom title */
22
+ title?: string;
23
+ /** Custom message */
24
+ message?: string;
25
+ /** Custom icon component */
26
+ icon?: React.ReactNode;
27
+ }
28
+
29
+ const THREAT_TITLES: Record<SecurityThreat, string> = {
30
+ root_detected: 'Thiết bị đã root',
31
+ root_beer_detected: 'Phát hiện root (RootBeer)',
32
+ native_root_detected: 'Phát hiện root (Native)',
33
+ dangerous_bins_detected: 'Phát hiện binary nguy hiểm',
34
+ root_apps_detected: 'Phát hiện ứng dụng root',
35
+ system_props_modified: 'Thuộc tính hệ thống đã sửa đổi',
36
+ frida_detected: 'Phát hiện Frida (Hooking)',
37
+ xposed_detected: 'Phát hiện Xposed Framework',
38
+ magisk_detected: 'Phát hiện Magisk',
39
+ debugger_detected: 'Phát hiện Debugger',
40
+ emulator_detected: 'Phát hiện Bộ giả lập',
41
+ };
42
+
43
+ const THREAT_DESCRIPTIONS: Record<SecurityThreat, string> = {
44
+ root_detected: 'Thiết bị của bạn đã được root, làm giảm tính bảo mật của ứng dụng.',
45
+ root_beer_detected: 'Công cụ phát hiện root đã phát hiện thiết bị đã bị can thiệp.',
46
+ native_root_detected: 'Phát hiện native root - thiết bị có thể đã bị sửa đổi.',
47
+ dangerous_bins_detected: 'Phát hiện các file thực thi nguy hiểm trên thiết bị.',
48
+ root_apps_detected: 'Phát hiện ứng dụng quản lý root trên thiết bị.',
49
+ system_props_modified: 'Các thuộc tính hệ thống quan trọng đã bị sửa đổi.',
50
+ frida_detected: 'Phát hiện công cụ Frida - thường dùng để can thiệp vào ứng dụng.',
51
+ xposed_detected: 'Phát hiện Xposed Framework - có thể can thiệp vào ứng dụng.',
52
+ magisk_detected: 'Phát hiện Magisk - công cụ root ẩn danh.',
53
+ debugger_detected: 'Phát hiện debugger đang gắn vào ứng dụng.',
54
+ emulator_detected: 'Ứng dụng đang chạy trên bộ giả lập, không an toàn cho môi trường production.',
55
+ };
56
+
57
+ /**
58
+ * Default security blocked screen component
59
+ */
60
+ export const SecurityBlockedScreen: React.FC<SecurityBlockedScreenProps> = ({
61
+ threats = [],
62
+ title = 'Cảnh báo bảo mật',
63
+ message = 'Thiết bị của bạn không đáp ứng yêu cầu bảo mật. Ứng dụng không thể tiếp tục chạy.',
64
+ icon,
65
+ }) => {
66
+ return (
67
+ <SafeAreaView style={styles.container}>
68
+ <ScrollView
69
+ contentContainerStyle={styles.scrollContent}
70
+ bounces={false}
71
+ >
72
+ {icon || (
73
+ <View style={styles.iconContainer}>
74
+ <Text style={styles.icon}>🔒</Text>
75
+ </View>
76
+ )}
77
+
78
+ <Text style={styles.title}>{title}</Text>
79
+
80
+ <Text style={styles.message}>{message}</Text>
81
+
82
+ {threats.length > 0 && (
83
+ <>
84
+ <Text style={styles.threatsTitle}>Vấn đề phát hiện:</Text>
85
+
86
+ <View style={styles.threatsList}>
87
+ {threats.map((threat) => (
88
+ <View key={threat} style={styles.threatItem}>
89
+ <View style={styles.bullet} />
90
+ <View style={styles.threatContent}>
91
+ <Text style={styles.threatTitle}>
92
+ {THREAT_TITLES[threat] || threat}
93
+ </Text>
94
+ <Text style={styles.threatDescription}>
95
+ {THREAT_DESCRIPTIONS[threat] || 'Vấn đề bảo mật không xác định.'}
96
+ </Text>
97
+ </View>
98
+ </View>
99
+ ))}
100
+ </View>
101
+ </>
102
+ )}
103
+
104
+ <View style={styles.footer}>
105
+ <Text style={styles.footerText}>
106
+ Nếu bạn cho rằng đây là sự nhầm lẫn, vui lòng liên hệ với bộ phận hỗ trợ.
107
+ </Text>
108
+ </View>
109
+ </ScrollView>
110
+ </SafeAreaView>
111
+ );
112
+ };
113
+
114
+ const styles = StyleSheet.create({
115
+ container: {
116
+ flex: 1,
117
+ backgroundColor: '#f5f5f5',
118
+ },
119
+ scrollContent: {
120
+ padding: 24,
121
+ alignItems: 'center',
122
+ },
123
+ iconContainer: {
124
+ width: 100,
125
+ height: 100,
126
+ borderRadius: 50,
127
+ backgroundColor: '#ffebee',
128
+ justifyContent: 'center',
129
+ alignItems: 'center',
130
+ marginBottom: 24,
131
+ },
132
+ icon: {
133
+ fontSize: 48,
134
+ },
135
+ title: {
136
+ fontSize: 24,
137
+ fontWeight: '700',
138
+ color: '#d32f2f',
139
+ textAlign: 'center',
140
+ marginBottom: 12,
141
+ },
142
+ message: {
143
+ fontSize: 16,
144
+ color: '#424242',
145
+ textAlign: 'center',
146
+ marginBottom: 24,
147
+ lineHeight: 24,
148
+ },
149
+ threatsTitle: {
150
+ fontSize: 18,
151
+ fontWeight: '600',
152
+ color: '#212121',
153
+ alignSelf: 'flex-start',
154
+ marginBottom: 16,
155
+ },
156
+ threatsList: {
157
+ width: '100%',
158
+ marginBottom: 24,
159
+ },
160
+ threatItem: {
161
+ flexDirection: 'row',
162
+ backgroundColor: '#ffffff',
163
+ borderRadius: 8,
164
+ padding: 16,
165
+ marginBottom: 12,
166
+ borderLeftWidth: 4,
167
+ borderLeftColor: '#d32f2f',
168
+ },
169
+ bullet: {
170
+ width: 8,
171
+ height: 8,
172
+ borderRadius: 4,
173
+ backgroundColor: '#d32f2f',
174
+ marginTop: 6,
175
+ marginRight: 12,
176
+ },
177
+ threatContent: {
178
+ flex: 1,
179
+ },
180
+ threatTitle: {
181
+ fontSize: 16,
182
+ fontWeight: '600',
183
+ color: '#212121',
184
+ marginBottom: 4,
185
+ },
186
+ threatDescription: {
187
+ fontSize: 14,
188
+ color: '#757575',
189
+ lineHeight: 20,
190
+ },
191
+ footer: {
192
+ marginTop: 24,
193
+ paddingTop: 24,
194
+ borderTopWidth: 1,
195
+ borderTopColor: '#e0e0e0',
196
+ },
197
+ footerText: {
198
+ fontSize: 14,
199
+ color: '#9e9e9e',
200
+ textAlign: 'center',
201
+ },
202
+ });
203
+
204
+ export default SecurityBlockedScreen;
@@ -0,0 +1 @@
1
+ export { SecurityBlockedScreen } from './SecurityBlockedScreen';
@@ -0,0 +1,5 @@
1
+ export { useDeviceSecurity } from './useDeviceSecurity';
2
+ export type {
3
+ UseDeviceSecurityOptions,
4
+ UseDeviceSecurityReturn,
5
+ } from '../types';