forked from Baw-Appie/A-Bypass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweak.xm
executable file
·342 lines (310 loc) · 14.9 KB
/
Tweak.xm
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
#import <UIKit/UIKit.h>
#import <MRYIPCCenter.h>
#import <dlfcn.h>
#import <AppList/AppList.h>
#include <unistd.h>
#include <CommonCrypto/CommonDigest.h>
#include <spawn.h>
#include <errno.h>
#import <mach-o/getsect.h>
#import <mach/mach.h>
#import <mach-o/dyld.h>
#import <substrate.h>
#import <Foundation/Foundation.h>
#import <sys/types.h>
#import <sys/syscall.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
#include <sys/mount.h>
#import <APToast.h>
#import "header.h"
#import "ABWindow.h"
// NSFileManager *fileManager = [NSFileManager defaultManager];
#define fileManager [NSFileManager defaultManager]
BOOL isSubstitute = ([fileManager fileExistsAtPath:@"/usr/lib/libsubstitute.dylib"] && ![fileManager fileExistsAtPath:@"/usr/lib/substrate"]) && ![fileManager fileExistsAtPath:@"/usr/lib/libhooker.dylib"];
BOOL isXinaA12 = [fileManager fileExistsAtPath:@"/var/LIY/"];
NSString *ABLoaderPath = isXinaA12 ? @"/var/LIY/BawAppie/ABypass/ABLicense" : @"/Library/BawAppie/ABypass/ABLicense";
const char *DisableLocation = "/var/tmp/.substitute_disable_loader";
const char *ABKVDLockPath = "/var/tmp/.abkvd.lock";
static BBServer *bbServer = nil;
static MRYIPCCenter* center;
NSArray *disableIdentifiers;
NSArray *subloader;
NSArray *vnodeBypassIdentifiers;
NSArray *vnodeHidePath;
float iosVersion;
static void easy_spawn(const char* args[]){
pid_t pid;
int status;
posix_spawn(&pid, args[0], NULL, NULL, (char* const*)args, NULL);
waitpid(pid, &status, WEXITED);
}
static dispatch_queue_t getBBServerQueue() {
static dispatch_queue_t queue;
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
void *handle = dlopen(NULL, RTLD_GLOBAL);
if (handle) {
dispatch_queue_t *pointer = (dispatch_queue_t *) dlsym(handle, "__BBServerQueue");
if (pointer) {
queue = *pointer;
}
dlclose(handle);
}
});
return queue;
}
static void fakeNotification(NSString *sectionID, NSString *title, NSString *message) {
BBBulletin *bulletin = [[%c(BBBulletin) alloc] init];
NSDate *date = [NSDate date];
bulletin.title = title;
bulletin.message = message;
bulletin.sectionID = sectionID;
bulletin.bulletinID = [[NSProcessInfo processInfo] globallyUniqueString];
bulletin.recordID = [[NSProcessInfo processInfo] globallyUniqueString];
bulletin.publisherBulletinID = [[NSProcessInfo processInfo] globallyUniqueString];
bulletin.date = date;
bulletin.defaultAction = [%c(BBAction) actionWithLaunchBundleID:sectionID callblock:nil];
bulletin.clearable = YES;
bulletin.showsMessagePreview = YES;
bulletin.publicationDate = date;
bulletin.lastInterruptDate = date;
if ([bbServer respondsToSelector:@selector(publishBulletin:destinations:)]) {
dispatch_sync(getBBServerQueue(), ^{
[bbServer publishBulletin:bulletin destinations:15];
});
}
}
%group SpringBoard
%hook BBServer
-(id)initWithQueue:(id)arg1 {
bbServer = %orig;
return bbServer;
}
-(id)initWithQueue:(id)arg1 dataProviderManager:(id)arg2 syncService:(id)arg3 dismissalSyncCache:(id)arg4 observerListener:(id)arg5 utilitiesListener:(id)arg6 conduitListener:(id)arg7 systemStateListener:(id)arg8 settingsListener:(id)arg9 {
bbServer = %orig;
return bbServer;
}
- (void)dealloc {
if (bbServer == self) bbServer = nil;
%orig;
}
%end
extern "C" CFPropertyListRef MGCopyAnswer(CFStringRef property);
@interface SpringBoard
@property (nonatomic, strong) MRYIPCCenter *centerForABypass;
@property (nonatomic, strong) APLoadingToast *loadingToastForABypass;
-(SBApplication *)_accessibilityFrontMostApplication;
@end
%hook SpringBoard
%property (strong) MRYIPCCenter *centerForABypass;
%property (strong) APLoadingToast *loadingToastForABypass;
-(void)applicationDidFinishLaunching:(id)application {
%orig;
self.centerForABypass = [MRYIPCCenter centerNamed:@"com.rpgfarm.a-bypass"];
[self.centerForABypass addTarget:self action:@selector(handleShowNotification:)];
[self.centerForABypass addTarget:self action:@selector(handleUpdateLicense:)];
self.loadingToastForABypass = [[objc_getClass("APLoadingToast") alloc] initWithView:[[ABWindow sharedInstance] rootViewController].view];
}
%new
-(void)handleShowNotification:(NSDictionary *)userInfo {
fakeNotification(userInfo[@"identifier"], userInfo[@"title"], userInfo[@"message"]);
}
%new
-(NSDictionary *)handleUpdateLicense:(NSDictionary *)userInfo {
NSError *error = nil;
if([userInfo[@"type"] isEqual:@3]) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^() {
dispatch_async(dispatch_get_main_queue(), ^() {
[self.loadingToastForABypass showToast:@"Loading A-Bypass" withMessage:[NSString stringWithFormat:@"0/%@ Completed", userInfo[@"max"]]];
});
});
} else if([userInfo[@"type"] isEqual:@4]) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^() {
dispatch_async(dispatch_get_main_queue(), ^() {
[self.loadingToastForABypass setPercent:[userInfo[@"per"] doubleValue]/[userInfo[@"max"] doubleValue]];
self.loadingToastForABypass.subtitleLabel.text = [NSString stringWithFormat:@"%@/%@ Completed", userInfo[@"per"], userInfo[@"max"]];
});
});
} else if([userInfo[@"type"] isEqual:@5]) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^() {
dispatch_async(dispatch_get_main_queue(), ^() {
[self.loadingToastForABypass hideToast];
});
});
} else if([userInfo[@"type"] isEqual:@6]) {
[fileManager removeItemAtPath:@"/var/mobile/Library/Preferences/ABLivePatch" error:&error];
}
if(error) return @{@"success": @0, @"message": [error localizedDescription]};
return @{@"success": @1};
}
%end
%hook _SBApplicationLaunchAlertInfo
-(NSString *)bundleID {
if (isSubstitute && access(DisableLocation, F_OK) != -1) remove(DisableLocation);
return %orig;
}
%end
%hook SBMainWorkspace
-(void)applicationProcessDidLaunch:(FBProcess *)arg1 {
if (isSubstitute && access(DisableLocation, F_OK) != -1) remove(DisableLocation);
// if([vnodeBypassIdentifiers containsObject:arg1.bundleIdentifier]) {
// // [NSThread sleepForTimeInterval:2];
// }
return %orig;
}
%end
#define ABKVD_IS_AVAILABLE access(ABKVDLockPath, F_OK) != -1
void saveAndHideVnode() {
if (ABKVD_IS_AVAILABLE) {
MRYIPCCenter *ABKVDCenter = [MRYIPCCenter centerNamed:@"com.rpgfarm.abkvd"];
[ABKVDCenter callExternalMethod:@selector(handleABKVDRequest:) withArguments:@{ @"type" : @"updateVnodeHidePath", @"vnodeHidePath": vnodeHidePath }];
[ABKVDCenter callExternalMethod:@selector(handleABKVDRequest:) withArguments:@{ @"type" : @"saveAndHideVnode" }];
// HBLogError(@"[ABKVD] saveAndHideVnode");
}
}
void revertAndRecoveryVnode() {
if (ABKVD_IS_AVAILABLE) {
MRYIPCCenter *ABKVDCenter = [MRYIPCCenter centerNamed:@"com.rpgfarm.abkvd"];
[ABKVDCenter callExternalMethod:@selector(handleABKVDRequest:) withArguments:@{ @"type" : @"revertAndRecoveryVnode" }];
// HBLogError(@"[ABKVD] revertAndRecoveryVnode");
}
}
%hook FBProcessManager
-(void)noteProcess:(FBApplicationProcess *)process didUpdateState:(FBProcessState *)state {
if(process.executionContext.identity.embeddedApplicationIdentifier) {
dispatch_async(dispatch_get_main_queue(), ^{
SpringBoard *springBoardInstance = (SpringBoard *)[UIApplication sharedApplication];
if(!springBoardInstance) return;
SBApplication *frontApplication = [springBoardInstance _accessibilityFrontMostApplication];
if(!frontApplication) {
revertAndRecoveryVnode();
return;
}
NSString *bundleID = [frontApplication bundleIdentifier];
if([vnodeBypassIdentifiers containsObject:bundleID]) saveAndHideVnode();
else revertAndRecoveryVnode();
});
}
%orig;
}
- (id)_createProcessWithExecutionContext:(FBProcessExecutionContext *)executionContext {
NSString *bundleID = executionContext.identity.embeddedApplicationIdentifier;
NSMutableDictionary* environmentM = [executionContext.environment mutableCopy];
NSMutableDictionary *plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.rpgfarm.abypassprefs.plist"];
if(![plistDict[bundleID] isEqual:@1]) return %orig;
if([subloader containsObject:bundleID]) [environmentM setObject:@"/usr/lib/ABSubLoader.dylib" forKey:@"DYLD_INSERT_LIBRARIES"];
if([disableIdentifiers containsObject:bundleID]) [environmentM setObject:@"/usr/lib/ABDYLD.dylib" forKey:@"DYLD_INSERT_LIBRARIES"];
if([vnodeBypassIdentifiers containsObject:bundleID]) saveAndHideVnode();
if([disableIdentifiers containsObject:bundleID] || [subloader containsObject:bundleID] || ([vnodeBypassIdentifiers containsObject:bundleID] && ABKVD_IS_AVAILABLE)) {
if(isSubstitute) {
fopen(DisableLocation, "w");
} else {
[environmentM setObject:@(1) forKey:@"_MSSafeMode"];
[environmentM setObject:@(1) forKey:@"_SafeMode"];
}
}
executionContext.environment = [environmentM copy];
return %orig(executionContext);
}
-(id)createApplicationProcessForBundleID:(NSString *)bundleID withExecutionContext:(FBProcessExecutionContext*)executionContext {
NSMutableDictionary* environmentM = [executionContext.environment mutableCopy];
NSMutableDictionary *plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.rpgfarm.abypassprefs.plist"];
if(![plistDict[bundleID] isEqual:@1]) return %orig;
if([subloader containsObject:bundleID]) [environmentM setObject:@"/usr/lib/ABSubLoader.dylib" forKey:@"DYLD_INSERT_LIBRARIES"];
if([disableIdentifiers containsObject:bundleID]) [environmentM setObject:@"/usr/lib/ABDYLD.dylib" forKey:@"DYLD_INSERT_LIBRARIES"];
if([vnodeBypassIdentifiers containsObject:bundleID]) saveAndHideVnode();
if([disableIdentifiers containsObject:bundleID] || [subloader containsObject:bundleID] || ([vnodeBypassIdentifiers containsObject:bundleID] && ABKVD_IS_AVAILABLE)) {
if(isSubstitute) {
fopen(DisableLocation, "w");
} else {
[environmentM setObject:@(1) forKey:@"_MSSafeMode"];
[environmentM setObject:@(1) forKey:@"_SafeMode"];
}
}
executionContext.environment = [environmentM copy];
return %orig(bundleID, executionContext);
}
%end
%end
%ctor {
HBLogError(@"Hello! Jailbreak Detection! A-Bypass is Loading...");
HBLogError(@"A-Bypass by Baw Appie <[email protected]>");
NSString *identifier = [NSBundle mainBundle].bundleIdentifier;
NSMutableDictionary *plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.rpgfarm.abypassprefs.plist"];
center = [MRYIPCCenter centerNamed:@"com.rpgfarm.a-bypass"];
isXinaA12 = [fileManager fileExistsAtPath:@"/var/LIY/"];
ABLoaderPath = isXinaA12 ? @"/var/LIY/BawAppie/ABypass/ABLicense" : @"/Library/BawAppie/ABypass/ABLicense";
if([identifier isEqualToString:@"com.apple.springboard"]) {
dlopen("/usr/local/lib/libAPToast.dylib", RTLD_NOW);
NSData *data = [NSData dataWithContentsOfFile:@"/var/mobile/Library/Preferences/ABPattern" options:0 error:nil];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
iosVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
disableIdentifiers = [dic[@"disableIdentifiers"] copy];
subloader = [dic[@"subloader"] copy];
vnodeBypassIdentifiers = [dic[@"vnodeBypassIdentifiers"] copy];
vnodeHidePath = [dic[@"vnodeHidePath"] copy];
if([fileManager fileExistsAtPath:@"/usr/bin/ABKVD"]) easy_spawn((const char *[]){"/usr/bin/ABKVD", NULL});
%init(SpringBoard);
return;
}
if([plistDict[identifier] isEqual:@1]) {
if(plistDict[@"stopABLivePatch"] && ![fileManager fileExistsAtPath:ABLoaderPath]) {
[center callExternalVoidMethod:@selector(handleShowNotification:) withArguments:@{
@"title" : @"A-Bypass Live Patch",
@"message" : @"A-Bypass Live Patch is not available. Starting Live Patch Update..",
@"identifier": @"com.apple.Preferences"
}];
plistDict[@"stopABLivePatch"] = nil;
}
if(!plistDict[@"stopABLivePatch"]) {
if([fileManager fileExistsAtPath:@"/var/mobile/Library/Preferences/ABLivePatch"]) {
[center callExternalMethod:@selector(handleUpdateLicense:) withArguments:@{ @"type": @6, @"identifier": identifier }];
}
NSDictionary *result = [center callExternalMethod:@selector(handleUpdateLicense:) withArguments:@{
@"type": @1,
@"identifier": identifier
}];
if([result[@"success"] isEqual:@0]) {
if([result[@"errno"] isEqual:@1] && [fileManager fileExistsAtPath:ABLoaderPath]) {
[center callExternalVoidMethod:@selector(handleShowNotification:) withArguments:@{
@"title" : @"A-Bypass Live Patch",
@"message" : [NSString stringWithFormat:@"ABLoader is unable to update A-Bypass. (A network error has occurred: %@)", result[@"message"]],
@"identifier": @"com.apple.Preferences"
}];
} else {
[center callExternalVoidMethod:@selector(handleShowNotification:) withArguments:@{
@"title" : @"A-Bypass License Manager Error",
@"message" : [NSString stringWithFormat:@"ABLoader is unable to update A-Bypass. (A storage error has occurred: %@)", result[@"message"]],
@"identifier": @"com.apple.Preferences"
}];
exit(0);
return;
}
}
if(![fileManager fileExistsAtPath:ABLoaderPath]) {
[center callExternalVoidMethod:@selector(handleShowNotification:) withArguments:@{
@"title" : @"ABLoader Exception",
@"message" : @"ABLoader is unable to load A-Bypass. Please report this error to @BawAppie (License is not verified)",
@"identifier": @"com.apple.Preferences"
}];
exit(0);
return;
}
}
// HBLogError(@"[ABLoader] Start Loading!");
void *loader = dlopen([ABLoaderPath UTF8String], RTLD_NOW);
if(loader == nil) {
// easy_spawn((const char *[]){"/usr/bin/cynject", [[NSString stringWithFormat:@"%d", getpid()] UTF8String], "/Library/BawAppie/ABypass/ABLicense", NULL});
[[NSString stringWithFormat:@"ABLOADER EXCEPTION\n\n%s", dlerror()] writeToFile:[NSString stringWithFormat:@"%@/Documents/ABLoaderError.log", NSHomeDirectory()] atomically:true encoding:NSUTF8StringEncoding error:nil];
[center callExternalVoidMethod:@selector(handleShowNotification:) withArguments:@{
@"title" : @"ABLoader Exception",
@"message" : @"ABLoader is unable to load A-Bypass. Please report this error to @BawAppie (A-Bypass injection failed)",
@"identifier": @"com.apple.Preferences"
}];
exit(0);
}
NSLog(@"A-Bypass V2 Initialize complete!");
}
return;
}