-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTweak.xm
176 lines (140 loc) · 6.3 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
#import <Foundation/Foundation.h>
#import "CustomMenu.h"
#import <Cephei/HBPreferences.h>
//- Opzetten omgeving
//- Vinden bronnen (google dorks)
//- basics
// - Logging
// - Vinden van functies
// - Xcode
// - UIMenu popup
// - Maken preference bundle
// - Communiceren met die bundle
static CustomMenu * menu;
static NSArray * blockedURLs;
static NSArray * blockedDomains;
static NSArray * allowedDomains;
static bool nodialog;
static id tabController;
@interface TabDocument
-(NSString *)URLString;
-(NSURL *)cachedCanonicalURLOrURLForSharing;
@end
@interface TabController
@property(strong) CustomMenu *m; // UIWindow needs strong reference to show on iOS 13
-(id)parentTabDocumentForBackClosesSpawnedTab; //method to get originalTab
@end
void updatePrefs(){
// Getting settings from plist
HBPreferences *preference = [[HBPreferences alloc] initWithIdentifier:@"com.droomone.tabblocker"];
NSString * whitelistdomain = [[preference objectForKey:@"whitelistdomain"] stringValue];
NSString * blacklisturl = [[preference objectForKey:@"blacklisturl"] stringValue];
NSString * blacklistdomain = [[preference objectForKey:@"blacklistdomain"] stringValue];
nodialog = [[preference objectForKey:@"nodialog"] boolValue];
// Converting to array's
blockedURLs = [blacklisturl componentsSeparatedByString:@";"];
blockedDomains = [blacklistdomain componentsSeparatedByString:@";"];
allowedDomains = [whitelistdomain componentsSeparatedByString:@";"];
}
%group iOS12
%hook TabController
- (void)insertNewTabDocument:(id)arg1 openedFromTabDocument:(id)document inBackground:(_Bool)arg3 animated:(_Bool)arg4{
updatePrefs();
TabDocument *originalTab = document;
tabController = self;
if ([originalTab URLString]){
//used to get correctly formatted NSURL; so it's not nil if it contains special characters
//Not tested on iOS 11
NSURL * originURL = [originalTab cachedCanonicalURLOrURLForSharing];
// Cleaning URL from safari!
NSString * cleanDomain = [[originURL host] stringByReplacingOccurrencesOfString:@"www." withString:@""];
NSString * cleanURL = [[originURL resourceSpecifier] stringByReplacingOccurrencesOfString:@"//" withString:@""];
cleanURL = [cleanURL stringByReplacingOccurrencesOfString:@"http://" withString:@""];
cleanURL = [cleanURL stringByReplacingOccurrencesOfString:@"https://" withString:@""];
cleanURL = [cleanURL stringByReplacingOccurrencesOfString:@"www." withString:@""];
if ([allowedDomains containsObject:cleanDomain]){
NSLog(@"Allowed new tab from: [%@] - specified in whitelisted domains", cleanDomain);
return %orig;
}
if ([blockedDomains containsObject:cleanDomain]){
NSLog(@"Blocked new tab from: [%@] - specified in blacklisted domains", cleanDomain);
return;
}
for (id blockedURL in blockedURLs){
// Cleaning URL input by user
NSString * cleanBlockedURL = [blockedURL stringByReplacingOccurrencesOfString:@"http://" withString:@""];
cleanBlockedURL = [cleanBlockedURL stringByReplacingOccurrencesOfString:@"https://" withString:@""];
cleanBlockedURL = [cleanBlockedURL stringByReplacingOccurrencesOfString:@"www." withString:@""];
if ([cleanBlockedURL isEqualToString:cleanURL]){
NSLog(@"Blocked new tab from: [%@] - specified in blacklisted URL's", cleanURL);
return;
}
}
// Nothing happend, must be a new website! Showing userdialog :)
if (!nodialog) {
[menu showMenu:cleanURL domain:cleanDomain];
return;
}
}
return %orig;
}
%end
%end
%group iOS13
%hook TabController
// UIWindow needs strong reference to show on iOS 13
%property(strong) CustomMenu *m;
-(id)initWithBrowserController:(id)arg1{
self.m = [[CustomMenu alloc] init];
return %orig;
}
-(void)insertNewTabDocumentWithDefaultOrdering:(id)arg1 inBackground:(BOOL)arg3 animated:(BOOL)arg4{
updatePrefs();
TabDocument *originalTab = [arg1 parentTabDocumentForBackClosesSpawnedTab];
tabController = self;
if ([originalTab URLString]){
//used to get correctly formatted NSURL; so it's not nil if it contains special characters
NSURL * originURL = [originalTab cachedCanonicalURLOrURLForSharing];
// Cleaning URL from safari!
NSString * cleanDomain = [[originURL host] stringByReplacingOccurrencesOfString:@"www." withString:@""];
NSString * cleanURL = [[originURL resourceSpecifier] stringByReplacingOccurrencesOfString:@"//" withString:@""];
cleanURL = [cleanURL stringByReplacingOccurrencesOfString:@"http://" withString:@""];
cleanURL = [cleanURL stringByReplacingOccurrencesOfString:@"https://" withString:@""];
cleanURL = [cleanURL stringByReplacingOccurrencesOfString:@"www." withString:@""];
if ([allowedDomains containsObject:cleanDomain]){
NSLog(@"Allowed new tab from: [%@] - specified in whitelisted domains", cleanDomain);
return %orig;
}
if ([blockedDomains containsObject:cleanDomain]){
NSLog(@"Blocked new tab from: [%@] - specified in blacklisted domains", cleanDomain);
return;
}
for (id blockedURL in blockedURLs){
// Cleaning URL input by user
NSString * cleanBlockedURL = [blockedURL stringByReplacingOccurrencesOfString:@"http://" withString:@""];
cleanBlockedURL = [cleanBlockedURL stringByReplacingOccurrencesOfString:@"https://" withString:@""];
cleanBlockedURL = [cleanBlockedURL stringByReplacingOccurrencesOfString:@"www." withString:@""];
if ([cleanBlockedURL isEqualToString:cleanURL]){
NSLog(@"Blocked new tab from: [%@] - specified in blacklisted URL's", cleanURL);
return;
}
}
// Nothing happend, must be a new website! Showing userdialog :)
if (!nodialog) {
[self.m showMenu:cleanURL domain:cleanDomain];
return;
}
}
return %orig;
}
%end
%end
%ctor{
updatePrefs();
if(kCFCoreFoundationVersionNumber >= 1665.15){
%init(iOS13);
}else{
menu = [[CustomMenu alloc] init];
%init(iOS12);
}
}