-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevice.m
More file actions
319 lines (244 loc) · 8.55 KB
/
Device.m
File metadata and controls
319 lines (244 loc) · 8.55 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
/*
* Copyright (C) 10/01/2020 VX STATS <sales@vxstats.com>
*
* This document is property of VX STATS. It is strictly prohibited
* to modify, sell or publish it in any way. In case you have access
* to this document, you are obligated to ensure its nondisclosure.
* Noncompliances will be prosecuted.
*
* Diese Datei ist Eigentum der VX STATS. Jegliche Änderung, Verkauf
* oder andere Verbreitung und Veröffentlichung ist strikt untersagt.
* Falls Sie Zugang zu dieser Datei haben, sind Sie verpflichtet,
* alles in Ihrer Macht stehende für deren Geheimhaltung zu tun.
* Zuwiderhandlungen werden strafrechtlich verfolgt.
*/
/* sys header */
#include <sys/sysctl.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/if_dl.h>
/* objc header */
#import <CommonCrypto/CommonDigest.h>
/* local header */
#import "Device.h"
/* modules */
@import Foundation;
#if TARGET_OS_IPHONE
@import UIKit;
#endif
static Device *m_deviceInstance;
@interface Device (PrivateMethods)
- (NSString *)firstMacAddress;
@end
@implementation Device
- (id)init {
if ( ( self = [super init] ) ) {
/* check for system */
size_t size;
sysctlbyname("hw.machine", nil, &size, nil, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, nil, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine);
m_platform = platform;
/* calculate unique id or read from settings */
NSString *address = [self firstMacAddress];
if ( address.length <= 0 || address.length > 17 || [address isEqualToString:@"00:00:00:00:00:00"] || [address isEqualToString:@"02:00:00:00:00:00"] ) {
NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.vxstat.statistics"];
NSString *uuid = [userDefaults objectForKey:@"uuid"];
if ( uuid == nil ) {
uuid = [[NSUUID UUID] UUIDString];
[userDefaults setObject:uuid forKey:@"uuid"];
[userDefaults synchronize];
}
m_uniqueIdentifier = uuid;
}
else {
/* Create pointer to the string as UTF8 */
const char *ptr = [address UTF8String];
/* Create byte array of unsigned chars */
unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];
/* Create 16 byte MD5 hash value, store in buffer */
CC_MD5(ptr, ( unsigned int )strlen(ptr), md5Buffer);
/* Convert MD5 value in the buffer to NSString of hex values */
NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
for ( int i = 0; i < CC_MD5_DIGEST_LENGTH; i++ ) {
[output appendFormat:@"%02x", md5Buffer[i]];
}
m_uniqueIdentifier = [NSString stringWithFormat:@"%@-%@-%@-%@-%@", [output substringWithRange:NSMakeRange(0, 8)], [output substringWithRange:NSMakeRange(8, 4)], [output substringWithRange:NSMakeRange(12, 4)], [output substringWithRange:NSMakeRange(16, 4)], [output substringWithRange:NSMakeRange(20, 12)]];
}
}
return self;
}
+ (BOOL)useDarkMode {
return [[[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"] length] > 0;
}
#pragma mark - Hacked
+ (BOOL)isJailbroken {
#if TARGET_OS_IPHONE && !(TARGET_IPHONE_SIMULATOR)
if ( [[NSFileManager defaultManager] fileExistsAtPath:@"/Applications/Cydia.app"] ) {
return YES;
}
else if ( [[NSFileManager defaultManager] fileExistsAtPath:@"/Library/MobileSubstrate/MobileSubstrate.dylib"] ) {
return YES;
}
else if ([[NSFileManager defaultManager] fileExistsAtPath:@"/bin/bash"] ) {
return YES;
}
else if ([[NSFileManager defaultManager] fileExistsAtPath:@"/usr/sbin/sshd"] ) {
return YES;
}
else if ( [[NSFileManager defaultManager] fileExistsAtPath:@"/etc/apt"] ) {
return YES;
}
NSError *error = nil;
NSString *stringToBeWritten = @"This is a test.";
[stringToBeWritten writeToFile:@"/private/jailbreak.txt" atomically:YES encoding:NSUTF8StringEncoding error:&error];
if ( error == nil ) {
/* Device is jailbroken */
return YES;
}
else {
[[NSFileManager defaultManager] removeItemAtPath:@"/private/jailbreak.txt" error:nil];
}
#endif
/* All checks have failed. Most probably, the device is not jailbroken */
return NO;
}
#pragma mark - Info
- (NSString *)platformString { return m_platform; }
#pragma mark - Global info
- (NSString *)model {
#if TARGET_IPHONE_SIMULATOR
return @"iOS Simulator";
#else
NSString *platform = m_platform;
NSRange range = [platform rangeOfString:@","];
NSInteger versionBegin = range.location;
if ( versionBegin > 1 ) {
unichar chr = [platform characterAtIndex:versionBegin - 1];
if ( chr >= '0' && chr <= '9' )
--versionBegin;
}
if ( versionBegin > 1 ) {
unichar chr = [platform characterAtIndex:versionBegin - 1];
if ( chr >= '0' && chr <= '9' )
--versionBegin;
}
return [platform substringWithRange:NSMakeRange(0, versionBegin)];
#endif
}
- (NSString *)version {
NSString *platform = m_platform;
#if TARGET_IPHONE_SIMULATOR
return platform;
#else
NSRange range = [platform rangeOfString:@","];
NSInteger versionBegin = range.location;
if ( versionBegin > 1 ) {
unichar chr = [platform characterAtIndex:versionBegin - 1];
if ( chr >= '0' && chr <= '9' )
--versionBegin;
}
if ( versionBegin > 1 ) {
unichar chr = [platform characterAtIndex:versionBegin - 1];
if ( chr >= '0' && chr <= '9' )
--versionBegin;
}
return [platform substringWithRange:NSMakeRange(versionBegin, [platform length] - versionBegin)];
#endif
}
+ (NSString *)osName {
#if TARGET_OS_MAC && !(TARGET_OS_IPHONE)
return @"macOS";
#endif
#if TARGET_OS_IPHONE
return @"iOS";
#endif
#if TARGET_OS_WATCH
return @"watchOS";
#endif
#if TARGET_OS_TV
return @"tvOS";
#endif
}
+ (NSString *)osVersion {
NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
return [NSString stringWithFormat:@"%zd.%zd.%zd", version.majorVersion, version.minorVersion, version.patchVersion];
}
- (NSString *)firstMacAddress {
int mgmtInfoBase[6];
char *msgBuffer = nil;
size_t length;
unsigned char macAddress[6];
struct if_msghdr *interfaceMsgStruct = nil;
struct sockaddr_dl *socketStruct = nil;
NSString *errorFlag = nil;
/* Setup the management Information Base (mib) */
mgmtInfoBase[0] = CTL_NET; /* Request network subsystem */
mgmtInfoBase[1] = AF_ROUTE; /* Routing table info */
mgmtInfoBase[2] = 0;
mgmtInfoBase[3] = AF_LINK; /* Request link layer information */
mgmtInfoBase[4] = NET_RT_IFLIST; /* Request all configured interfaces */
/* With all configured interfaces requested, get handle index */
if ( ( mgmtInfoBase[5] = if_nametoindex( "en0" ) ) == 0) {
errorFlag = @"if_nametoindex failure";
}
else {
/* Get the size of the data available (store in len) */
if ( sysctl( mgmtInfoBase, 6, nil, &length, nil, 0 ) < 0 ) {
errorFlag = @"sysctl mgmtInfoBase failure";
}
else {
/* Alloc memory based on above call */
if ( ( msgBuffer = malloc( length ) ) == nil ) {
errorFlag = @"buffer allocation failure";
}
else {
/* Get system information, store in buffer */
if ( sysctl( mgmtInfoBase, 6, msgBuffer, &length, nil, 0 ) < 0 ) {
errorFlag = @"sysctl msgBuffer failure";
}
}
}
}
/* Befor going any further... */
if ( errorFlag.length > 0 ) {
#ifdef DEBUG
NSLog(@"Error: %@", errorFlag);
#endif
return nil;
}
/* Map msgbuffer to interface message structure */
interfaceMsgStruct = (struct if_msghdr *) msgBuffer;
/* Map to link-level socket structure */
socketStruct = (struct sockaddr_dl *) (interfaceMsgStruct + 1);
/* nil check */
if ( socketStruct == nil ) {
return nil;
}
/* Copy link layer address data in socket structure to an array */
memcpy(&macAddress, socketStruct->sdl_data + socketStruct->sdl_nlen, 6);
/* Read from char array into a string object, into traditional Mac address format */
NSString *macAddressString = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X", macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4], macAddress[5]];
macAddressString = [macAddressString lowercaseString];
#ifdef DEBUG
NSLog(@"Mac Address: %@", macAddressString);
#endif
/* Release the buffer memory */
free(msgBuffer);
return macAddressString;
}
- (NSString *)uniqueIdentifier {
return m_uniqueIdentifier;
}
#pragma mark - Instance
+ (Device *)currentDevice {
if ( m_deviceInstance == nil ) {
m_deviceInstance = [[Device alloc] init];
}
return m_deviceInstance;
}
@end