-
Notifications
You must be signed in to change notification settings - Fork 16
/
douyinDylib.m
248 lines (183 loc) · 8.31 KB
/
douyinDylib.m
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
// weibo: http://weibo.com/xiaoqing28
// blog: http://www.alonemonkey.com
//
// douyinDylib.m
// douyinDylib
//
// Created by nododo on 2018/12/18.
// Copyright (c) 2018 nododo. All rights reserved.
//
#import "douyinDylib.h"
#import <CaptainHook/CaptainHook.h>
#import <UIKit/UIKit.h>
#import <Cycript/Cycript.h>
#import <MDCycriptManager.h>
#import "CTBlockDescription.h"
#import "CTObjectiveCRuntimeAdditions.h"
static NSString * const VideoPlayEndedNotiName = @"VideoPlayEndedNotiName";
static NSString * const OpenAutoPlay = @"OpenAutoPlay";
CHConstructor{
printf(INSERT_SUCCESS_WELCOME);
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidFinishLaunchingNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
#ifndef __OPTIMIZE__
CYListenServer(6666);
MDCycriptManager* manager = [MDCycriptManager sharedInstance];
[manager loadCycript:NO];
NSError* error;
NSString* result = [manager evaluateCycript:@"UIApp" error:&error];
NSLog(@"result: %@", result);
if(error.code != 0){
NSLog(@"error: %@", error.localizedDescription);
}
#endif
}];
}
CHDeclareClass(CustomViewController)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wstrict-prototypes"
//add new method
CHDeclareMethod1(void, CustomViewController, newMethod, NSString*, output){
NSLog(@"This is a new method : %@", output);
}
#pragma clang diagnostic pop
CHOptimizedClassMethod0(self, void, CustomViewController, classMethod){
NSLog(@"hook class method");
CHSuper0(CustomViewController, classMethod);
}
CHOptimizedMethod0(self, NSString*, CustomViewController, getMyName){
//get origin value
NSString* originName = CHSuper(0, CustomViewController, getMyName);
NSLog(@"origin name is:%@",originName);
//get property
NSString* password = CHIvar(self,_password,__strong NSString*);
NSLog(@"password is %@",password);
[self newMethod:@"output"];
//set new property
self.newProperty = @"newProperty";
NSLog(@"newProperty : %@", self.newProperty);
//change the value
return @"nododo";
}
#pragma mark - 关闭弹框
CHDeclareClass(UIViewController)
CHOptimizedMethod3(self, void, UIViewController, presentViewController, UIViewController *, viewControllerToPresent, animated, BOOL, flag, completion, id, completion) {
if([viewControllerToPresent isKindOfClass:UIAlertController.class]) {
return;
}
CHSuper3(UIViewController, presentViewController, viewControllerToPresent, animated, flag, completion, completion);
}
#pragma mark - 自动播放相关
CHDeclareClass(AWEFeedTableViewController)
CHOptimizedMethod(0, self, BOOL, AWEFeedTableViewController, pureMode) {
return YES;
}
@interface AWEFeedTableViewController : UIViewController
@property (nonatomic, assign) NSInteger currentPlayIndex;
@end
//- (void)_addNotifications;
CHOptimizedMethod0(self, void, AWEFeedTableViewController, _addNotifications) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playNext) name:VideoPlayEndedNotiName object:nil];
CHSuper0(AWEFeedTableViewController, _addNotifications);
}
CHDeclareMethod0(void, AWEFeedTableViewController, playNext) {
if ([[NSUserDefaults standardUserDefaults] boolForKey:OpenAutoPlay] == NO) {
return;
}
UITableView *tableView = [self valueForKey:@"_tableView"];
NSIndexPath *path = [NSIndexPath indexPathForRow:self.currentPlayIndex +1 inSection:0];
[tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}
CHDeclareClass(AWEVideoPlayerController)
CHOptimizedMethod1(self, void, AWEVideoPlayerController, playerItemDidReachEnd, id, arg1) {
NSLog(@"--------------------------------");
[[NSNotificationCenter defaultCenter] postNotificationName:VideoPlayEndedNotiName object:nil];
CHSuper1(AWEVideoPlayerController, playerItemDidReachEnd, arg1);
}
#pragma mark - 设置界面相关
@interface AWEGeneralSettingViewModel : NSObject
- (id)sectionDataArray;
- (void)setSectionDataArray:(id)arg1;
@end
@interface AWESettingSectionModel : NSObject
@property(retain, nonatomic) NSArray *itemArray;
@end
@interface AWESettingItemModel : NSObject
@property(copy, nonatomic) NSString *title;
@property(nonatomic) long long cellType;
@property(nonatomic) _Bool isSwitchOn;
@property(copy, nonatomic) id switchChangedBlock;
@end
CHDeclareClass(AWESettingsViewModel)
@interface AWESettingsTableViewController : UIViewController
@end
CHDeclareClass(AWESettingsTableViewController)
CHOptimizedMethod0(self, void, AWESettingsTableViewController, refreshView) {
AWEGeneralSettingViewModel *model = [self valueForKey:@"_viewModel"];
NSMutableArray *sectionArr = [NSMutableArray arrayWithArray:model.sectionDataArray];
AWESettingSectionModel *secModel = sectionArr[1];
NSMutableArray *secArr = [NSMutableArray arrayWithArray:secModel.itemArray];
AWESettingItemModel *lastItem = secArr.lastObject;
if(![lastItem.title isEqualToString:@"连续播放"]) {
AWESettingItemModel *item = [[objc_getClass("AWESettingItemModel") alloc] init];
item.title = @"连续播放";
item.cellType = 4;
item.isSwitchOn = [[NSUserDefaults standardUserDefaults] boolForKey:OpenAutoPlay];
item.switchChangedBlock = ^(BOOL ison) {
[[NSUserDefaults standardUserDefaults] setBool:ison forKey:OpenAutoPlay];
};
[secArr addObject:item];
secModel.itemArray = secArr;
[sectionArr replaceObjectAtIndex:1 withObject:secModel];
[model setSectionDataArray:sectionArr];
[self setValue:model forKey:@"_viewModel"];
}
CHSuper0(AWESettingsTableViewController, refreshView);
}
#pragma mark - 获取block参数相关
//CHDeclareClass(AWEGeneralSettingViewController)
//@interface AWEGeneralSettingViewController : UIViewController
////AWEGeneralSettingViewController AWESettingsTableViewController 为并列子类 hook 了 父类的 refreshView 结果代码执行起来优先hook了 堆栈关系优先出现的AWESettingsTableViewController
//@end
//
//CHDeclareMethod0(void, AWEGeneralSettingViewController, testXXX) {
// AWEGeneralSettingViewModel *model = [self valueForKey:@"_viewModel"];
// AWESettingSectionModel *secModel = [(NSArray *)(model.sectionDataArray) firstObject];
// NSMutableArray *secArr = [NSMutableArray arrayWithArray:secModel.itemArray];
//
// NSString *tempStr = @"";
// if (YES) {
// AWESettingItemModel *testItem = secArr[1];
//
// id testBlock = testItem.switchChangedBlock;
// CTBlockDescription *blockDescription = [[CTBlockDescription alloc] initWithBlock:testBlock];
// const char *expectedArguments[] = {@encode(typeof(testBlock)), @encode(BOOL), @encode(id)};
// for (int i = 0; i < blockDescription.blockSignature.numberOfArguments; i++) {
// NSString *argu = [NSString stringWithFormat:@"第%d个参数为 %@", i, [NSString stringWithUTF8String: expectedArguments[i]]];
// tempStr = [[tempStr stringByAppendingString:argu] stringByAppendingString:@"\n"];
// }
// [self performSelector:@selector(showLoadingViewWithTitle:) withObject:tempStr];
// }
//
//}
//
//CHOptimizedMethod0(self, void, AWEGeneralSettingViewController, viewDidLoad) {
// [self performSelector:@selector(testXXX) withObject:nil afterDelay:0.5];
// CHSuper0(AWEGeneralSettingViewController, viewDidLoad);
//}
CHConstructor{
CHLoadLateClass(CustomViewController);
CHClassHook0(CustomViewController, getMyName);
CHClassHook0(CustomViewController, classMethod);
CHLoadLateClass(UIViewController);
CHHook3(UIViewController, presentViewController, animated, completion);
CHLoadLateClass(AWEFeedTableViewController);
CHHook0(AWEFeedTableViewController, pureMode);
CHHook0(AWEFeedTableViewController, _addNotifications);
CHLoadLateClass(AWEVideoPlayerController);
CHHook1(AWEVideoPlayerController, playerItemDidReachEnd);
CHLoadLateClass(AWESettingsTableViewController);
CHHook0(AWESettingsTableViewController, refreshView);
// CHLoadLateClass(AWEGeneralSettingViewController);
// CHHook0(AWEGeneralSettingViewController, viewDidLoad);
// CHHook0(AWEGeneralSettingViewController, testXXX);
}