forked from p0358/bfdecrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbfdecrypt.m
More file actions
executable file
·201 lines (168 loc) · 10.1 KB
/
bfdecrypt.m
File metadata and controls
executable file
·201 lines (168 loc) · 10.1 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
/*
BF Decryptor - Decrypt iOS apps and repack them into an .ipa
https://github.com/BishopFox/bfinject
Carl Livitt @ Bishop Fox
*/
#include <stdio.h>
#include <unistd.h>
#include <mach/mach.h>
#include <mach-o/dyld.h>
#include <stdlib.h>
#include <dlfcn.h>
#import <UIKit/UIKit.h>
#include <stdint.h>
#include "DumpDecrypted.h"
#include <TargetConditionals.h>
#import "SparkAppList.h"
//#import <Cephei/HBPreferences.h>
@interface UIWindow (private)
- (void)orderOut:(id)sender;
@end
UIWindow *alertWindow = NULL;
UIWindow *kw = NULL;
UIWindow *originalWindow;
UIViewController *root = NULL;
UIAlertController *alertController = NULL;
UIAlertController *ncController = NULL;
UIAlertController *errorController = NULL;
// The dylib constructor sets decryptedIPAPath, spawns a thread to do the app decryption, then exits.
__attribute__ ((constructor)) static void bfinject_rocknroll() {
NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
if (bundleID && ([SparkAppList doesIdentifier:@"com.level3tjg.bfdecrypt" andKey:@"includedApps" containBundleIdentifier:bundleID]) ){
NSLog(@"[bfdecrypt] Spawning thread to do decryption in the background...");
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"[bfdecrypt] Inside decryption thread");
// traversal all images
uint32_t count = _dyld_image_count();
const char *fullPathStr;
for(uint32_t i = 0; i < count; i++) {
fullPathStr = _dyld_get_image_name(i);
NSLog(@"tried image[%d] => %s", i, fullPathStr);
if(! strstr(fullPathStr, ".dylib") ) break;//set dyld to the first non-lib image
}
//const char *fullPathStr = _dyld_get_image_name(1);// [0] is /usr/lib/substitute-loader.dylib in my enviroment
DumpDecrypted *dd = [[DumpDecrypted alloc] initWithPathToBinary:[NSString stringWithUTF8String:fullPathStr]];
if(!dd) {
NSLog(@"[bfdecrypt] ERROR: failed to get DumpDecrypted instance");
return;
}
NSLog(@"[bfdecrypt] Full path to app: %s /// IPA File: %@", fullPathStr, [dd IPAPath]);
dispatch_async(dispatch_get_main_queue(), ^{
//UIWindow *originalWindow = [[UIApplication sharedApplication] keyWindow];
UIWindow *originalWindow = [[[UIApplication sharedApplication] delegate] window];
alertWindow = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];
alertWindow.rootViewController = [UIViewController new];
alertWindow.windowLevel = UIWindowLevelAlert + 1;
[alertWindow makeKeyAndVisible];
// Show a "Decrypting!" alert on the device and block the UI
alertController = [UIAlertController
alertControllerWithTitle:@"Decrypting"
message:@"Please wait, this will take a few seconds..."
preferredStyle:UIAlertControllerStyleAlert];
kw = alertWindow;
if([kw respondsToSelector:@selector(topmostPresentedViewController)])
root = [kw performSelector:@selector(topmostPresentedViewController)];
else
root = [kw rootViewController];
root.modalPresentationStyle = UIModalPresentationFullScreen;
[root presentViewController:alertController animated:YES completion:nil];
});
// Do the decryption
NSString *outputFile = [dd createIPAFile];
//[dd show]
// Dismiss the alert box
dispatch_async(dispatch_get_main_queue(), ^{
[alertController dismissViewControllerAnimated:NO completion:^{
ncController = [UIAlertController
alertControllerWithTitle:@"Decryption complete!"
message:[NSString stringWithFormat:@"Saved decrypted IPA to:\n%@", outputFile]
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Done" style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {
NSLog(@"Cancel action");
[ncController dismissViewControllerAnimated:NO completion:nil];
kw.hidden = true;
[originalWindow makeKeyAndVisible];
[kw removeFromSuperview];
kw = nil;
ncController = nil;
}];
UIAlertAction *copyAction = [UIAlertAction actionWithTitle:@"Copy path" style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
NSLog(@"Copy action");
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = outputFile;
[ncController dismissViewControllerAnimated:NO completion:nil];
kw.hidden = true;
[originalWindow makeKeyAndVisible];
[kw removeFromSuperview];
kw = nil;
ncController = nil;
}];
UIAlertAction *shareAction = [UIAlertAction actionWithTitle:@"Share file" style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
NSLog(@"Share action");
[ncController dismissViewControllerAnimated:NO completion:nil];
NSURL *fileURL = [NSURL fileURLWithPath:outputFile];
NSArray *activityItems = @[fileURL];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[root presentViewController:activityViewController animated:YES completion:nil];
activityViewController.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
kw.hidden = true;
[originalWindow makeKeyAndVisible];
[kw removeFromSuperview];
kw = nil;
ncController = nil;
};
}];
bool canOpenInFilza = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"filza://"]];
bool canOpenIniFile = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"ifile://"]];
UIAlertAction *showInFileExplorerAction = [UIAlertAction actionWithTitle:(canOpenInFilza ? @"Show in Filza" : @"Show in iFile") style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
NSLog(@"Show in file explorer action");
[ncController dismissViewControllerAnimated:NO completion:nil];
if (canOpenInFilza) {
NSURL *filzaURL = [NSURL URLWithString:[@"filza://view" stringByAppendingString:outputFile]];
[[UIApplication sharedApplication] openURL:filzaURL options:@{} completionHandler:nil];
} else if (canOpenIniFile) {
NSURL *ifileURL = [NSURL URLWithString:[@"ifile://file://" stringByAppendingString:outputFile]];
[[UIApplication sharedApplication] openURL:ifileURL options:@{} completionHandler:nil];
}
kw.hidden = true;
[originalWindow makeKeyAndVisible];
[kw removeFromSuperview];
kw = nil;
ncController = nil;
}];
/*UIAlertAction *removePrefAction = [UIAlertAction actionWithTitle:@"Finish"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
NSLog(@"Remove pref (finish) action");
// it's crashing, meh
HBPreferences *preferences = [HBPreferences preferencesForIdentifier:@"com.level3tjg.bfdecrypt"];
[preferences removeObjectForKey:[[NSBundle mainBundle] bundleIdentifier]];
[preferences synchronize];
kw.hidden = true;
[originalWindow makeKeyAndVisible];
[kw removeFromSuperview];
kw = nil;
ncController = nil;
}];*/
[ncController addAction:copyAction];
[ncController addAction:shareAction];
if (canOpenInFilza || canOpenIniFile)
[ncController addAction:showInFileExplorerAction];
//[ncController addAction:removePrefAction];
[ncController addAction:cancelAction];
[root presentViewController:ncController animated:YES completion:nil];
alertController = nil;
}];
}); // dispatch on main
NSLog(@"[bfdecrypt] Over and out.");
while(1)
sleep(9999999);
}); // dispatch in background
NSLog(@"[bfdecrypt] All done, exiting constructor.");
}
}