-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcrawler.h
200 lines (142 loc) · 5.42 KB
/
crawler.h
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
/*
* Copyright (c) YungRaj
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <objc/message.h>
#include <objc/objc.h>
#include <objc/runtime.h>
#include <CoreFoundation/CoreFoundation.h>
#include <Foundation/Foundation.h>
#include <SpriteKit/SpriteKit.h>
#include <UIKit/UIKit.h>
/* iOS App Crawler */
extern NSString* kNSDarwinAppCrawlerCrawledViews;
namespace NSDarwin {
namespace AppCrawler {
class CrawlManager;
}
} // namespace NSDarwin
using namespace NSDarwin::AppCrawler;
@interface NSViewCrawlData : NSObject
@property(strong, nonatomic) NSString* name;
@property(strong, nonatomic) NSString* parent;
@property(assign, nonatomic) CGRect frame;
@property(assign, nonatomic) CGPoint position; // position in window
@property(assign, nonatomic) CGPoint center;
@property(assign, nonatomic) CGPoint anchorPoint;
@end
@interface NSDarwinAppCrawler : NSObject
@property(atomic) CrawlManager* crawlManager;
@property(strong, atomic) NSTimer* crawlingTimer;
@property(strong, atomic) NSTimer* idleTimer;
@property(strong, atomic) NSMutableDictionary* crawlData;
@property(strong, atomic) NSMutableArray* viewControllerStack;
@property(assign, atomic) CFAbsoluteTime timeSinceLastUserInteraction;
@property(assign, atomic) BOOL spriteKitCrawlCondition;
@property(assign, atomic) BOOL crawlerTimerDidFire;
- (instancetype)initWithCrawlingManager:(CrawlManager*)crawlManager;
- (NSMutableDictionary*)crawlData;
- (NSViewCrawlData*)setupCrawlDataForView:(UIView*)view;
- (UIViewController*)topViewController;
- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController;
- (BOOL)hasViewBeenCrawled:(UIView*)view inViewController:(UIViewController*)vc;
- (void)crawlingTimerDidFire:(NSTimer*)timer;
- (void)idlingTimerDidFire:(NSTimer*)timer;
- (void)simulateTouchEventAtPoint:(CGPoint)point;
- (void)simulateTouchesOnSpriteKitView:(SKView*)view;
- (bool)bypassInterstitialAds:(UIViewController*)vc;
- (void)pushViewControllerToStack:(UIViewController*)vc;
- (BOOL)simulatedTouchesHasHadNoEffect;
@end
namespace NSDarwin {
namespace AppCrawler {
class CrawlManager {
public:
explicit CrawlManager(UIApplication *application, id<UIApplicationDelegate> delegate) : application(application), delegate(delegate) {
SetupAppCrawler();
}
~CrawlManager() = default;
NSDarwinAppCrawler* GetCrawler() {
return crawler;
}
NSTimer* GetCrawlingTimer() {
return crawler.crawlingTimer;
}
NSTimer* GetIdleTimer() {
return crawler.idleTimer;
}
NSString* GetBundleID() {
return bundleIdentifier;
}
UIApplication* GetApplication() {
return application;
}
id<UIApplicationDelegate> GetAppDelegate() {
return delegate;
}
UIViewController* GetCurrentViewController() {
return currentViewController;
}
NSArray* GetViews() {
return [currentViewController.view subviews];
}
void SetCurrentViewController(UIViewController* viewController) {
currentViewController = viewController;
}
void SetupAppCrawler();
inline void SetupCrawlingTimer() {
InvalidateCrawlingTimer();
crawler.crawlingTimer =
[NSTimer scheduledTimerWithTimeInterval:1.25f
target:crawler
selector:@selector(crawlingTimerDidFire:)
userInfo:nil
repeats:NO];
}
inline void SetupIdleTimer() {
InvalidateIdleTimer();
crawler.idleTimer =
[NSTimer scheduledTimerWithTimeInterval:3.5f
target:crawler
selector:@selector(idlingTimerDidFire:)
userInfo:nil
repeats:NO];
}
void InvalidateCrawlingTimer() {
if (crawler.crawlingTimer && [crawler.crawlingTimer isValid]) {
[crawler.crawlingTimer invalidate];
crawler.crawlingTimer = nullptr;
}
}
void InvalidateIdleTimer() {
if (crawler.idleTimer && [crawler.idleTimer isValid]) {
[crawler.idleTimer invalidate];
crawler.idleTimer = nullptr;
}
}
NSMutableArray* GetViewsForUserInteraction(UIViewController* viewController);
NSMutableArray* GetViewsForUserInteractionFromRootView(UIView* view);
NSMutableArray* GetViewsWithKindOfClass(NSMutableArray* views, Class cls);
void OnViewControllerViewDidAppear(UIViewController* viewController);
private:
NSDarwinAppCrawler* crawler;
NSDictionary* crawlData;
NSString* bundleIdentifier;
UIApplication* application;
id<UIApplicationDelegate> delegate;
UIViewController* currentViewController;
};
} // namespace AppCrawler
} // namespace NSDarwin