-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnativescript_rasp.h
More file actions
504 lines (434 loc) · 12 KB
/
Copy pathnativescript_rasp.h
File metadata and controls
504 lines (434 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/**
* UNIVERSAL BLACKBOX RASP ENGINE - NativeScript Metadata-Based C++ Headers
*
* This is a "thin" wrapper that calls the native executeAudit(int selector) method.
* All security logic is in the unified C++ core engine.
*
* Security Requirements:
* - NO SENSITIVE STRINGS in framework-level code
* - USE OBFUSCATED SELECTORS (e.g., 0x1A2B instead of "isRooted")
* - SILENT FAILURES with randomized error codes
*
* Platform Support: NativeScript (Android/iOS)
* Architecture: Metadata-based C++ headers for NativeScript
*/
#ifndef NATIVESCRIPT_RASP_H
#define NATIVESCRIPT_RASP_H
// ============================================
// OBFUSCATED SELECTORS
// ============================================
namespace RASPSelectors {
static constexpr int FULL_AUDIT = 0x1A2B;
static constexpr int ROOT_JAILBREAK_ONLY = 0x1A2C;
static constexpr int DEBUGGER_ONLY = 0x1A2D;
static constexpr int FRIDA_ONLY = 0x1A2E;
}
namespace RASPStatusTypes {
static constexpr int ROOT_JAILBREAK = 0x2A2B;
static constexpr int DEBUGGER = 0x2A2C;
static constexpr int FRIDA = 0x2A2D;
}
namespace RASPErrorCodes {
static constexpr int SECURITY_OK = 0x7F3D;
static constexpr int SUSPICIOUS = 0x7F3C;
static constexpr int HIGHLY_SUSPICIOUS = 0x7F3B;
static constexpr int CONFIRMED_TAMPER = 0x7F3A;
}
// ============================================
// NATIVE BRIDGE DECLARATIONS
// ============================================
extern "C" {
// Native bridge functions
int rasp_invoke_audit_c(int selector);
int rasp_get_status_c(int statusType);
void rasp_initialize_c();
void rasp_shutdown_c();
}
// ============================================
// NATIVESCRIPT METADATA
// ============================================
/**
* NativeScript metadata for the RASP module
*
* This metadata is used by NativeScript to generate the JavaScript interface
* All method names are obfuscated to hide from static analysis
*/
#ifdef __OBJC__
// iOS NativeScript metadata
@interface RASPNativeScript : NSObject
/**
* Execute security audit
* @param selector Obfuscated selector value
* @return Randomized error code from native engine
*/
+ (int)a1_impl:(int)selector;
/**
* Get detection status
* @param statusType Obfuscated status type value
* @return Detection status (0 = not detected, 1 = detected)
*/
+ (int)b2_impl:(int)statusType;
/**
* Initialize RASP engine
*/
+ (void)d4_impl;
/**
* Shutdown RASP engine
*/
+ (void)e5_impl;
@end
@implementation RASPNativeScript
+ (int)a1_impl:(int)selector {
try {
return rasp_invoke_audit_c(selector);
} catch (...) {
return RASPErrorCodes::SECURITY_OK;
}
}
+ (int)b2_impl:(int)statusType {
try {
return rasp_get_status_c(statusType);
} catch (...) {
return 0;
}
}
+ (void)d4_impl {
try {
rasp_initialize_c();
} catch (...) {
// Silent failure
}
}
+ (void)e5_impl {
try {
rasp_shutdown_c();
} catch (...) {
// Silent failure
}
}
@end
#elif defined(__ANDROID__)
// Android NativeScript metadata
#include <android/log.h>
#include <jni.h>
/**
* Android NativeScript bridge
*
* This class provides the bridge between NativeScript JavaScript and the native C++ core
*/
class RASPNativeScript {
public:
/**
* Execute security audit
* @param selector Obfuscated selector value
* @return Randomized error code from native engine
*/
static int a1_impl(int selector) {
try {
return rasp_invoke_audit_c(selector);
} catch (...) {
return RASPErrorCodes::SECURITY_OK;
}
}
/**
* Get detection status
* @param statusType Obfuscated status type value
* @return Detection status (0 = not detected, 1 = detected)
*/
static int b2_impl(int statusType) {
try {
return rasp_get_status_c(statusType);
} catch (...) {
return 0;
}
}
/**
* Initialize RASP engine
*/
static void d4_impl() {
try {
rasp_initialize_c();
} catch (...) {
// Silent failure
}
}
/**
* Shutdown RASP engine
*/
static void e5_impl() {
try {
rasp_shutdown_c();
} catch (...) {
// Silent failure
}
}
};
#endif
// ============================================
// NATIVESCRIPT BINDING CODE
// ============================================
/**
* NativeScript binding code
*
* This code is used by NativeScript to bind the native functions to JavaScript
* The binding is done using the NativeScript metadata system
*/
#ifdef __ANDROID__
#include <napi.h>
#include <android/log.h>
#define LOG_TAG "NativeScriptRASP"
/**
* NativeScript N-API binding for Android
*
* This provides the JavaScript interface for NativeScript on Android
*/
namespace RASPNativeScriptBinding {
/**
* Execute security audit
*/
static napi_value a1_impl_wrapper(napi_env env, napi_callback_info info) {
size_t argc = 1;
napi_value args[1];
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
int selector;
napi_get_value_int32(env, args[0], &selector);
int result = RASPNativeScript::a1_impl(selector);
napi_value jsResult;
napi_create_int32(env, result, &jsResult);
return jsResult;
}
/**
* Get detection status
*/
static napi_value b2_impl_wrapper(napi_env env, napi_callback_info info) {
size_t argc = 1;
napi_value args[1];
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
int statusType;
napi_get_value_int32(env, args[0], &statusType);
int result = RASPNativeScript::b2_impl(statusType);
napi_value jsResult;
napi_create_int32(env, result, &jsResult);
return jsResult;
}
/**
* Initialize RASP engine
*/
static napi_value d4_impl_wrapper(napi_env env, napi_callback_info info) {
RASPNativeScript::d4_impl();
return nullptr;
}
/**
* Shutdown RASP engine
*/
static napi_value e5_impl_wrapper(napi_env env, napi_callback_info info) {
RASPNativeScript::e5_impl();
return nullptr;
}
/**
* Initialize the NativeScript module
*/
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor props[] = {
{"a1_impl", nullptr, a1_impl_wrapper, nullptr, nullptr, napi_default, nullptr},
{"b2_impl", nullptr, b2_impl_wrapper, nullptr, nullptr, napi_default, nullptr},
{"d4_impl", nullptr, d4_impl_wrapper, nullptr, nullptr, napi_default, nullptr},
{"e5_impl", nullptr, e5_impl_wrapper, nullptr, nullptr, napi_default, nullptr}
};
napi_define_properties(env, exports, 4, props);
return exports;
}
} // namespace RASPNativeScriptBinding
NAPI_MODULE(NATIVE_RASP, RASPNativeScriptBinding::Init)
#elif defined(__APPLE__)
#include <node_api.h>
/**
* NativeScript N-API binding for iOS
*
* This provides the JavaScript interface for NativeScript on iOS
*/
namespace RASPNativeScriptBinding {
/**
* Execute security audit
*/
static napi_value a1_impl_wrapper(napi_env env, napi_callback_info info) {
size_t argc = 1;
napi_value args[1];
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
int selector;
napi_get_value_int32(env, args[0], &selector);
int result = [RASPNativeScript a1_impl:selector];
napi_value jsResult;
napi_create_int32(env, result, &jsResult);
return jsResult;
}
/**
* Get detection status
*/
static napi_value b2_impl_wrapper(napi_env env, napi_callback_info info) {
size_t argc = 1;
napi_value args[1];
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
int statusType;
napi_get_value_int32(env, args[0], &statusType);
int result = [RASPNativeScript b2_impl:statusType];
napi_value jsResult;
napi_create_int32(env, result, &jsResult);
return jsResult;
}
/**
* Initialize RASP engine
*/
static napi_value d4_impl_wrapper(napi_env env, napi_callback_info info) {
[RASPNativeScript d4_impl];
return nullptr;
}
/**
* Shutdown RASP engine
*/
static napi_value e5_impl_wrapper(napi_env env, napi_callback_info info) {
[RASPNativeScript e5_impl];
return nullptr;
}
/**
* Initialize the NativeScript module
*/
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor props[] = {
{"a1_impl", nullptr, a1_impl_wrapper, nullptr, nullptr, napi_default, nullptr},
{"b2_impl", nullptr, b2_impl_wrapper, nullptr, nullptr, napi_default, nullptr},
{"d4_impl", nullptr, d4_impl_wrapper, nullptr, nullptr, napi_default, nullptr},
{"e5_impl", nullptr, e5_impl_wrapper, nullptr, nullptr, napi_default, nullptr}
};
napi_define_properties(env, exports, 4, props);
return exports;
}
} // namespace RASPNativeScriptBinding
NAPI_MODULE(NATIVE_RASP, RASPNativeScriptBinding::Init)
#endif
// ============================================
// USAGE IN NATIVESCRIPT (TypeScript/JavaScript)
// ============================================
/**
* NativeScript TypeScript/JavaScript usage:
*
* ```typescript
* import { a1_impl, b2_impl, d4_impl, e5_impl } from 'nativescript-rasp';
*
* // Initialize RASP engine
* d4_impl();
*
* // Execute security audit
* const result = a1_impl(0x1A2B);
* console.log('Security result:', result);
*
* // Get detection status
* const rootStatus = b2_impl(0x2A2B);
* const isRooted = rootStatus === 1;
* if (isRooted) {
* console.warn('Root/Jailbreak detected!');
* }
*
* const debuggerStatus = b2_impl(0x2A2C);
* const isDebuggerAttached = debuggerStatus === 1;
* if (isDebuggerAttached) {
* console.warn('Debugger detected!');
* }
*
* const fridaStatus = b2_impl(0x2A2D);
* const isFridaAttached = fridaStatus === 1;
* if (isFridaAttached) {
* console.warn('Frida detected!');
* }
*
* // Shutdown RASP engine
* e5_impl();
* ```
*
* Or create a higher-level TypeScript wrapper:
*
* ```typescript
* // rasp-service.ts
* export class RASPService {
* private static instance: RASPService;
* private initialized: boolean = false;
*
* private constructor() {
* this.initialize();
* }
*
* static getInstance(): RASPService {
* if (!RASPService.instance) {
* RASPService.instance = new RASPService();
* }
* return RASPService.instance;
* }
*
* initialize(): void {
* if (!this.initialized) {
* d4_impl();
* this.initialized = true;
* }
* }
*
* shutdown(): void {
* if (this.initialized) {
* e5_impl();
* this.initialized = false;
* }
* }
*
* executeAudit(selector: number = 0x1A2B): number {
* if (!this.initialized) {
* this.initialize();
* }
* return a1_impl(selector);
* }
*
* getStatus(statusType: number = 0x2A2B): number {
* if (!this.initialized) {
* this.initialize();
* }
* return b2_impl(statusType);
* }
*
* checkSecurity(): number {
* return this.executeAudit(0x1A2B);
* }
*
* isRootJailbroken(): boolean {
* return this.getStatus(0x2A2B) === 1;
* }
*
* isDebuggerAttached(): boolean {
* return this.getStatus(0x2A2C) === 1;
* }
*
* isFridaAttached(): boolean {
* return this.getStatus(0x2A2D) === 1;
* }
*
* getDetailedStatus(): RASPStatus {
* return {
* rootJailbreakDetected: this.isRootJailbroken(),
* debuggerDetected: this.isDebuggerAttached(),
* fridaDetected: this.isFridaAttached(),
* securityResult: this.checkSecurity()
* };
* }
* }
*
* interface RASPStatus {
* rootJailbreakDetected: boolean;
* debuggerDetected: boolean;
* fridaDetected: boolean;
* securityResult: number;
* }
*
* // Usage in NativeScript app
* const raspService = RASPService.getInstance();
* const status = raspService.getDetailedStatus();
* console.log('Status:', status);
* ```
*/
#endif // NATIVESCRIPT_RASP_H