-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathios_objcpp_bridge.mm
More file actions
360 lines (332 loc) · 9.68 KB
/
ios_objcpp_bridge.mm
File metadata and controls
360 lines (332 loc) · 9.68 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
/**
* UNIVERSAL BLACKBOX RASP ENGINE - iOS Objective-C++ Bridge
*
* 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: iOS (Objective-C++)
* Architecture: Objective-C++ with hidden visibility attributes
*/
#import <Foundation/Foundation.h>
#include "universal_rasp_core.cpp"
// ============================================
// OBFUSCATED SELECTORS
// ============================================
namespace RASPSelectors {
static constexpr int fullAudit = 0x1A2B;
static constexpr int rootJailbreakOnly = 0x1A2C;
static constexpr int debuggerOnly = 0x1A2D;
static constexpr int fridaOnly = 0x1A2E;
}
namespace RASPStatusTypes {
static constexpr int rootJailbreak = 0x2A2B;
static constexpr int debugger = 0x2A2C;
static constexpr int frida = 0x2A2D;
}
namespace RASPErrorCodes {
static constexpr int securityOK = 0x7F3D;
static constexpr int suspicious = 0x7F3C;
static constexpr int highlySuspicious = 0x7F3B;
static constexpr int confirmedTamper = 0x7F3A;
}
// ============================================
// OBJECTIVE-C++ BRIDGE CLASS
// ============================================
/**
* RASPCore - Universal RASP Provider
* Single entry point for all frameworks
* Uses hidden visibility to keep out of Mach-O symbol table
*/
__attribute__((visibility("hidden")))
@interface RASPCore : NSObject
+ (NSInteger)invokeAudit:(NSInteger)selector;
+ (NSInteger)getStatus:(NSInteger)statusType;
+ (NSDictionary*)getDetailedStatus;
+ (void)initialize;
+ (void)shutdown;
@end
@implementation RASPCore
/**
* Universal audit invocation
*
* @param selector Obfuscated selector value
* @return Randomized error code from native engine
*/
+ (NSInteger)invokeAudit:(NSInteger)selector {
@try {
return universal_rasp_execute_audit((int)selector);
} @catch (NSException *exception) {
// Silent failure - return randomized error code
return RASPErrorCodes::securityOK;
}
}
/**
* Get detection status
*
* @param statusType Obfuscated status type value
* @return Detection status (0 = not detected, 1 = detected)
*/
+ (NSInteger)getStatus:(NSInteger)statusType {
@try {
return universal_rasp_get_status((int)statusType);
} @catch (NSException *exception) {
// Silent failure - return 0 (not detected)
return 0;
}
}
/**
* Get detailed status
*
* @return Dictionary with all detection statuses
*/
+ (NSDictionary*)getDetailedStatus {
@try {
// Get detection statuses
int rootJailbreak = universal_rasp_get_status(RASPStatusTypes::rootJailbreak);
int debugger = universal_rasp_get_status(RASPStatusTypes::debugger);
int frida = universal_rasp_get_status(RASPStatusTypes::frida);
int securityResult = universal_rasp_execute_audit(RASPSelectors::fullAudit);
return @{
@"rootJailbreakDetected": @(rootJailbreak == 1),
@"debuggerDetected": @(debugger == 1),
@"fridaDetected": @(frida == 1),
@"securityResult": @(securityResult)
};
} @catch (NSException *exception) {
// Silent failure - return empty dictionary
return @{};
}
}
/**
* Initialize RASP engine
*/
+ (void)initialize {
@try {
universal_rasp_initialize();
} @catch (NSException *exception) {
// Silent failure
}
}
/**
* Shutdown RASP engine
*/
+ (void)shutdown {
@try {
universal_rasp_shutdown();
} @catch (NSException *exception) {
// Silent failure
}
}
@end
// ============================================
// EXTERN C INTERFACE FOR FRAMEWORK BRIDGES
// ============================================
extern "C" {
/**
* C-style interface for framework bridges
* Easier to bridge from Swift, Unity, etc.
*/
__attribute__((visibility("hidden")))
int rasp_invoke_audit_c(int selector) {
return [RASPCore invokeAudit:selector];
}
__attribute__((visibility("hidden")))
int rasp_get_status_c(int statusType) {
return [RASPCore getStatus:statusType];
}
__attribute__((visibility("hidden")))
void rasp_initialize_c() {
[RASPCore initialize];
}
__attribute__((visibility("hidden")))
void rasp_shutdown_c() {
[RASPCore shutdown];
}
}
// ============================================
// SWIFT EXTENSION (for reference)
// ============================================
/**
* Swift extension for native iOS applications
*
* ```swift
* import Foundation
*
* // Extension for easy Swift usage
* extension RASPCore {
*
* enum AuditSelector: Int {
* case fullAudit = 0x1A2B
* case rootJailbreakOnly = 0x1A2C
* case debuggerOnly = 0x1A2D
* case fridaOnly = 0x1A2E
* }
*
* enum StatusType: Int {
* case rootJailbreak = 0x2A2B
* case debugger = 0x2A2C
* case frida = 0x2A2D
* }
*
* enum SecurityResult: Int {
* case securityOK = 0x7F3D
* case suspicious = 0x7F3C
* case highlySuspicious = 0x7F3B
* case confirmedTamper = 0x7F3A
* }
*
* static func performAudit(selector: AuditSelector = .fullAudit) -> SecurityResult {
* let result = invokeAudit(selector.rawValue)
* return SecurityResult(rawValue: result) ?? .securityOK
* }
*
* static func getDetectionStatus(statusType: StatusType) -> Bool {
* return getStatus(statusType.rawValue) == 1
* }
*
* static func checkSecurity() -> SecurityResult {
* return performAudit(selector: .fullAudit)
* }
*
* static func isJailbroken() -> Bool {
* return getDetectionStatus(statusType: .rootJailbreak)
* }
*
* static func isDebuggerAttached() -> Bool {
* return getDetectionStatus(statusType: .debugger)
* }
*
* static func isFridaAttached() -> Bool {
* return getDetectionStatus(statusType: .frida)
* }
*
* static func getDetailedStatus() -> [String: Any] {
* return getDetailedStatus() as [String: Any]
* }
* }
* ```
*/
// ============================================
// USAGE IN SWIFT
// ============================================
/**
* Swift usage:
*
* ```swift
* import Foundation
*
* // Direct usage
* let result = RASPCore.invokeAudit(0x1A2B)
* let isJailbroken = RASPCore.getStatus(0x2A2B) == 1
*
* // Using extension (if added)
* let result = RASPCore.performAudit(selector: .fullAudit)
* let isJailbroken = RASPCore.isJailbroken()
*
* // Detailed status
* let status = RASPCore.getDetailedStatus()
* print("Status: \(status)")
* ```
*/
// ============================================
// USAGE IN UNITY (C# P/Invoke)
// ============================================
/**
* Unity C# P/Invoke wrapper (for reference)
*
* ```csharp
* using System.Runtime.InteropServices;
* using UnityEngine;
*
* public class RASPNative {
* #if UNITY_IOS
* [DllImport("__Internal")]
* private static extern int rasp_invoke_audit_c(int selector);
*
* [DllImport("__Internal")]
* private static extern int rasp_get_status_c(int statusType);
*
* [DllImport("__Internal")]
* private static extern void rasp_initialize_c();
*
* [DllImport("__Internal")]
* private static extern void rasp_shutdown_c();
* #elif UNITY_ANDROID
* [DllImport("aran_rasp")]
* private static extern int Java_com_aran_rasp_RASPNativeModule_a1_impl(int selector);
*
* [DllImport("aran_rasp")]
* private static extern int Java_com_aran_rasp_RASPNativeModule_b2_impl(int statusType);
*
* [DllImport("aran_rasp")]
* private static extern void Java_com_aran_rasp_RASPNativeModule_d4_impl();
*
* [DllImport("aran_rasp")]
* private static extern void Java_com_aran_rasp_RASPNativeModule_e5_impl();
* #endif
*
* public static int ExecuteAudit(int selector) {
* #if UNITY_IOS
* return rasp_invoke_audit_c(selector);
* #elif UNITY_ANDROID
* return Java_com_aran_rasp_RASPNativeModule_a1_impl(selector);
* #else
* return 0x7F3D; // SECURITY_OK
* #endif
* }
*
* public static int GetStatus(int statusType) {
* #if UNITY_IOS
* return rasp_get_status_c(statusType);
* #elif UNITY_ANDROID
* return Java_com_aran_rasp_RASPNativeModule_b2_impl(statusType);
* #else
* return 0;
* #endif
* }
*
* public static void Initialize() {
* #if UNITY_IOS
* rasp_initialize_c();
* #elif UNITY_ANDROID
* Java_com_aran_rasp_RASPNativeModule_d4_impl();
* #endif
* }
*
* public static void Shutdown() {
* #if UNITY_IOS
* rasp_shutdown_c();
* #elif UNITY_ANDROID
* Java_com_aran_rasp_RASPNativeModule_e5_impl();
* #endif
* }
*
* public static int CheckSecurity() {
* return ExecuteAudit(0x1A2B);
* }
*
* public static bool IsRootJailbroken() {
* return GetStatus(0x2A2B) == 1;
* }
*
* public static bool IsDebuggerAttached() {
* return GetStatus(0x2A2C) == 1;
* }
*
* public static bool IsFridaAttached() {
* return GetStatus(0x2A2D) == 1;
* }
* }
*
* // Usage in Unity
* RASPNative.Initialize();
* int result = RASPNative.CheckSecurity();
* bool isRooted = RASPNative.IsRootJailbroken();
* Debug.Log($"Security result: {result}");
* ```
*/