forked from dayanch96/YTMusicUltimate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sideloading.xm
290 lines (243 loc) · 7.99 KB
/
Sideloading.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
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <dlfcn.h>
#import <rootless.h>
#import "Source/Headers/YTAlertView.h"
#import "Source/Headers/Localization.h"
#define YT_BUNDLE_ID @"com.google.ios.youtubemusic"
#define YT_BUNDLE_NAME @"YouTubeMusic"
#define YT_NAME @"YouTube Music"
#define YTMULoginAlert @"YTMULoginAlert"
@interface SSOConfiguration : NSObject
@end
static NSString *accessGroupID() {
NSDictionary *query = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge NSString *)kSecClassGenericPassword, (__bridge NSString *)kSecClass,
@"bundleSeedID", kSecAttrAccount,
@"", kSecAttrService,
(id)kCFBooleanTrue, kSecReturnAttributes,
nil];
CFDictionaryRef result = nil;
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, (CFTypeRef *)&result);
if (status == errSecItemNotFound) {
status = SecItemAdd((__bridge CFDictionaryRef)query, (CFTypeRef *)&result);
if (status != errSecSuccess) {
return nil;
}
}
NSString *accessGroup = [(__bridge NSDictionary *)result objectForKey:(__bridge NSString *)kSecAttrAccessGroup];
return accessGroup;
}
%group SideloadingFixes
//Fix login (2) - Ginsu & AhmedBakfir
// %hook SSOSafariSignIn
// - (void)signInWithURL:(id)arg1 presentationAnchor:(id)arg2 completionHandler:(id)arg3 {
// NSURL *origURL = arg1;
// NSURLComponents *urlComponents = [[NSURLComponents alloc] initWithURL:origURL resolvingAgainstBaseURL:NO];
// NSMutableArray *newQueryItems = [urlComponents.queryItems mutableCopy];
// for (NSURLQueryItem *queryItem in urlComponents.queryItems) {
// if ([queryItem.name isEqualToString:@"system_version"]
// || [queryItem.name isEqualToString:@"app_version"]
// || [queryItem.name isEqualToString:@"kdlc"]
// || [queryItem.name isEqualToString:@"kss"]
// || [queryItem.name isEqualToString:@"lib_ver"]
// || [queryItem.name isEqualToString:@"device_model"]) {
// [newQueryItems removeObject:queryItem];
// }
// }
// urlComponents.queryItems = [newQueryItems copy];
// %orig(urlComponents.URL, arg2, arg3);
// }
// %end
//Force enable safari sign-in
%hook SSOConfiguration
- (BOOL)shouldEnableSafariSignIn { return YES; }
- (BOOL)temporarilyDisableSafariSignIn { return NO; }
- (void)setTemporarilyDisableSafariSignIn:(BOOL)arg1 { return %orig(NO); }
%end
%hook SSOKeychainHelper
+ (id)accessGroup {
return accessGroupID();
}
+ (id)sharedAccessGroup {
return accessGroupID();
}
%end
%hook SSOKeychainCore
//Thanks to jawshoeadan for this hook.
+ (id)accessGroup {
return accessGroupID();
}
+ (id)sharedAccessGroup {
return accessGroupID();
}
%end
%hook NSFileManager
- (NSURL *)containerURLForSecurityApplicationGroupIdentifier:(NSString *)groupIdentifier {
if (groupIdentifier != nil) {
NSArray *paths = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
NSURL *documentsURL = [paths lastObject];
return [documentsURL URLByAppendingPathComponent:@"AppGroup"];
}
return %orig(groupIdentifier);
}
%end
#pragma mark - Thanks PoomSmart for the following hooks
/* IAmYouTube + Extra hooks for ytmusic */
%hook YTVersionUtils
+ (NSString *)appName {
return YT_NAME;
}
+ (NSString *)appID {
return YT_BUNDLE_ID;
}
%end
%hook GCKBUtils
+ (NSString *)appIdentifier {
return YT_BUNDLE_ID;
}
%end
%hook GPCDeviceInfo
+ (NSString *)bundleId {
return YT_BUNDLE_ID;
}
%end
%hook OGLBundle
+ (NSString *)shortAppName {
return YT_NAME;
}
%end
%hook GVROverlayView
+ (NSString *)appName {
return YT_NAME;
}
%end
%hook OGLPhenotypeFlagServiceImpl
- (NSString *)bundleId {
return YT_BUNDLE_ID;
}
%end
%hook APMAEU
+ (BOOL)isFAS {
return YES;
}
%end
%hook GULAppEnvironmentUtil
+ (BOOL)isFromAppStore {
return YES;
}
%end
%hook SSOConfiguration
- (id)initWithClientID:(id)clientID supportedAccountServices:(id)supportedAccountServices {
self = %orig;
[self setValue:YT_NAME forKey:@"_shortAppName"];
[self setValue:YT_BUNDLE_ID forKey:@"_applicationIdentifier"];
return self;
}
%end
%hook NSBundle
- (NSString *)bundleIdentifier {
NSArray *address = [NSThread callStackReturnAddresses];
Dl_info info = {0};
if (dladdr((void *)[address[2] longLongValue], &info) == 0)
return %orig;
NSString *path = [NSString stringWithUTF8String:info.dli_fname];
if ([path hasPrefix:NSBundle.mainBundle.bundlePath])
return YT_BUNDLE_ID;
return %orig;
}
- (id)objectForInfoDictionaryKey:(NSString *)key {
if ([key isEqualToString:@"CFBundleIdentifier"])
return YT_BUNDLE_ID;
if ([key isEqualToString:@"CFBundleDisplayName"])
return YT_NAME;
if ([key isEqualToString:@"CFBundleName"])
return YT_BUNDLE_NAME;
return %orig;
}
%end
/*IAmYouTube end */
%hook ASWUtilities
+ (NSString *)productionBundleIdentifier {
return YT_BUNDLE_ID;
}
+ (NSString *)lowercaseProductionBundleIdentifier {
return YT_BUNDLE_ID;
}
%end
%hook GAZAppInfo
- (NSString *)currentBundleIdentifier {
return YT_BUNDLE_ID;
}
%end
%end
NSDictionary *(*orig_infoDictionary)(id self, SEL _cmd);
NSDictionary *replaceInfoDict(id self, SEL _cmd) {
NSDictionary *originalInfoDictionary = orig_infoDictionary(self, _cmd);
NSString *bundleIdentifier = originalInfoDictionary[@"CFBundleIdentifier"];
if (![bundleIdentifier isEqualToString:YT_BUNDLE_ID]) {
NSMutableDictionary *newInfoDictionary = [NSMutableDictionary dictionaryWithDictionary:originalInfoDictionary];
[newInfoDictionary setValue:YT_BUNDLE_ID forKey:@"CFBundleIdentifier"];
return newInfoDictionary;
}
return originalInfoDictionary;
}
BOOL isFirstTime = YES;
@interface InitWorkaround : UIViewController
@property (nonatomic, copy) void (^completion)(void);
@end
@implementation InitWorkaround
- (void)viewDidLoad {
[super viewDidLoad];
isFirstTime = NO;
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
activityIndicator.color = [UIColor whiteColor];
activityIndicator.center = self.view.center;
[self.view addSubview:activityIndicator];
[activityIndicator startAnimating];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
MSHookMessageEx(objc_getClass("NSBundle"), @selector(infoDictionary), (IMP)replaceInfoDict, (IMP *)&orig_infoDictionary);
[self dismissViewControllerAnimated:YES completion:^{
if (self.completion) {
self.completion();
}
}];
});
}
@end
@interface SFAuthenticationViewController : UIViewController
- (void)remoteViewControllerWillDismiss:(id)remoteVC;
@end
%hook SFAuthenticationViewController
- (void)viewDidAppear:(BOOL)animated {
%orig;
if (isFirstTime) {
InitWorkaround *workaround = [[InitWorkaround alloc] init];
workaround.completion = ^{
[self dismissViewControllerAnimated:YES completion:^{
if ([self respondsToSelector:@selector(remoteViewControllerWillDismiss:)]) {
[self performSelector:@selector(remoteViewControllerWillDismiss:)];
}
YTAlertView *alertView = [%c(YTAlertView) infoDialog];
alertView.title = LOC(@"WARNING");
alertView.subtitle = LOC(@"RETRY_LOGIN");
[alertView show];
}];
};
[self presentViewController:workaround animated:YES completion:nil];
}
}
%end
%hook YTMFirstTimeSignInViewController
- (void)viewDidDisappear:(bool)arg1 {
%orig;
YTAlertView *alertView = [%c(YTAlertView) infoDialog];
alertView.title = LOC(@"WARNING");
alertView.subtitle = LOC(@"LOGIN_INFO");
[alertView show];
}
%end
%ctor {
%init;
%init(SideloadingFixes);
}