-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweak.x
182 lines (142 loc) · 4.55 KB
/
Tweak.x
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
#include <stdio.h>
#import <mach-o/ldsyms.h>
#include <Foundation/Foundation.h>
#include <UIKit/UIKit.h>
#include <dlfcn.h>
#include "fishhook.h"
struct os_system_version_s {
unsigned int major;
unsigned int minor;
unsigned int patch;
};
struct _CAFrameRateRange {
float minimum;
float maximum;
float preferred;
};
static const char SystemVersion_plist[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
"<plist version=\"1.0\">\n"
"<dict>\n"
" <key>ProductBuildVersion</key>\n"
" <string>19A346</string>\n"
" <key>ProductCopyright</key>\n"
" <string>1983-2021 Apple Inc.</string>\n"
" <key>ProductName</key>\n"
" <string>iPhone OS</string>\n"
" <key>ProductVersion</key>\n"
" <string>15.0</string>\n"
"</dict>\n"
"</plist>";
// This is in libSystem, so it's OK to refer to it directly here
extern int os_system_version_get_current_version(struct os_system_version_s * _Nonnull);
%group Availability
%hookf(int, os_system_version_get_current_version, struct os_system_version_s * _Nonnull v) {
v->major = 15;
v->minor = 0;
v->patch = 0;
return 0;
}
%hookf(FILE *, fopen, const char * restrict path, const char * restrict mode) {
if (path != NULL && strcmp(mode, "r") == 0 && strcmp(path, "/System/Library/CoreServices/SystemVersion.plist") == 0) {
return fmemopen((void*)SystemVersion_plist, sizeof(SystemVersion_plist), mode);
}
return %orig;
}
%end
%group iOS14_5
%hook NSMutableURLRequest
%property(assign) BOOL assumesHTTP3Capable;
%end
%end
_Thread_local static bool is_in_validate_configuration = false;
%group main_app
%hook QTXDNSServer
- (unsigned long long)serverType {
if (is_in_validate_configuration) {
return 0;
}
return %orig;
}
%end
%hook QTXConfigurationManager
-(bool)validateConfiguration:(id)config withError:(NSError **)error {
is_in_validate_configuration = true;
bool ret = %orig;
is_in_validate_configuration = false;
return ret;
}
%end
%end
%group iOS13
%hook NSProcessInfo
%new
-(BOOL)isiOSAppOnMac {
return false;
}
%end
%hook UIBarButtonItem
%property(nonatomic, copy) id menu;
%end
%hook UIButton
%property(nonatomic, assign) BOOL showsMenuAsPrimaryAction;
%property(nonatomic, copy) id menu;
%end
%end
extern void nw_parameters_create_quic_connection();
extern sec_protocol_options_t _Nullable nw_quic_connection_copy_sec_protocol_options(void *conn);
static void nw_quic_add_tls_application_protocol(void *conn, const char *application_protocol) {
sec_protocol_options_t _Nullable sec_protocol_options = nw_quic_connection_copy_sec_protocol_options(conn);
sec_protocol_options_add_tls_application_protocol(sec_protocol_options, application_protocol);
}
static void (*orig_nw_protocol_udp_finalize_output_frames)(void *arg0, void *arg1);
static void nw_protocol_udp_finalize_output_frames(void *arg0, void *arg1) {
//set_checksum_ptr();
void *ptr = *(void **)(arg0 + 0x28);
uint64_t orig = *(uint64_t *)(ptr + 0x88);
*(uint64_t *)(ptr + 0x88) = 0;
orig_nw_protocol_udp_finalize_output_frames(arg0, arg1);
*(uint64_t *)(ptr + 0x88) = orig;
}
static struct _CAFrameRateRange _CAFrameRateRangeMake(float minimum, float maximum, float preferred) {
return (struct _CAFrameRateRange){minimum, maximum, preferred};
}
%ctor {
if (@available(iOS 15, macOS 12, *)) {
return;
}
void *main_start = dlsym(RTLD_MAIN_ONLY, MH_EXECUTE_SYM);
if (main_start) {
rebind_symbols_image(main_start,
(uint64_t)main_start - 0x100000000,
(struct rebinding[3]){
{"nw_parameters_create_quic", (void *) nw_parameters_create_quic_connection, NULL},
{"nw_quic_add_tls_application_protocol", nw_quic_add_tls_application_protocol, NULL},
{"CAFrameRateRangeMake", _CAFrameRateRangeMake, NULL}
}, 3);
}
if (@available(iOS 13, *)) {
if (@available(iOS 14, *)) {
if (@available(iOS 14.3, *)) {
} else {
MSImageRef libnetwork = MSGetImageByName("/usr/lib/libnetwork.dylib");
if (libnetwork != NULL) {
void *func = MSFindSymbol(libnetwork, "___nw_protocol_udp_finalize_output_frames_block_invoke");
MSHookFunction(func, nw_protocol_udp_finalize_output_frames, (void**)&orig_nw_protocol_udp_finalize_output_frames);
}
}
} else {
%init(iOS13);
}
if (@available(iOS 14.5, *)) {
} else {
%init(iOS14_5);
}
}
NSString *identifier = [[NSBundle mainBundle] bundleIdentifier];
if ([@"com.crossutility.quantumult-x.quantumult-x-tunnel" isEqualToString: identifier]) {
%init(Availability);
} else if ([@"com.crossutility.quantumult-x" isEqualToString: identifier]) {
%init(main_app);
}
}