This repository has been archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
RAAppKiller.xm
96 lines (85 loc) · 2.68 KB
/
RAAppKiller.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
#import "RAAppKiller.h"
#import "RARunningAppsProvider.h"
extern "C" void BKSTerminateApplicationForReasonAndReportWithDescription(NSString *app, int a, int b, NSString *description);
@interface RAAppKiller () {
NSMutableDictionary *completionDictionary;
}
@end
@implementation RAAppKiller : NSObject
+(instancetype) sharedInstance
{
SHARED_INSTANCE2(RAAppKiller,
[sharedInstance initialize];
);
}
+(void) killAppWithIdentifier:(NSString*)identifier
{
return [RAAppKiller killAppWithIdentifier:identifier completion:nil];
}
+(void) killAppWithIdentifier:(NSString*)identifier completion:(void(^)())handler
{
return [RAAppKiller killAppWithSBApplication:[[%c(SBApplicationController) sharedInstance] RA_applicationWithBundleIdentifier:identifier] completion:handler];
}
+(void) killAppWithSBApplication:(SBApplication*)app
{
return [RAAppKiller killAppWithSBApplication:app completion:nil];
}
+(void) killAppWithSBApplication:(SBApplication*)app completion:(void(^)())handler
{
return [RAAppKiller checkAppDead:app withTries:0 andCompletion:handler];
}
+(void) checkAppDead:(SBApplication*)app withTries:(int)tries andCompletion:(void(^)())handler
{
/*
BOOL isDeadOrMaxed = (app.pid == 0 || app.isRunning == NO) && tries < 5;
if (isDeadOrMaxed)
{
if (handler)
{
handler();
}
}
else
{
if (tries == 0)
{
// Try nicely
FBApplicationProcess *process = [[%c(FBProcessManager) sharedInstance] createApplicationProcessForBundleID:app.bundleIdentifier];
[process killForReason:1 andReport:NO withDescription:@"PSY SLAYED" completion:nil];
}
/*else if (tries == 1)
{
BKSTerminateApplicationForReasonAndReportWithDescription(app.bundleIdentifier, 5, 1, @"PSY SLAYED");
}
else if (tries == 2)
{
kill(app.pid, SIGTERM);
}
else
{
// Attempt force
kill(app.pid, SIGKILL);
}* /
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.25 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[RAAppKiller checkAppDead:app withTries:tries + 1 andCompletion:handler];
});
}
*/
[RAAppKiller.sharedInstance->completionDictionary setObject:[handler copy] forKey:app.bundleIdentifier];
BKSTerminateApplicationForReasonAndReportWithDescription(app.bundleIdentifier, 5, 1, @"Multiplexer requested this process to be slayed.");
}
-(void) initialize
{
completionDictionary = [NSMutableDictionary dictionary];
[RARunningAppsProvider.sharedInstance addTarget:self];
}
-(void) appDidDie:(__unsafe_unretained SBApplication*)app
{
if (completionDictionary && [completionDictionary objectForKey:app.bundleIdentifier] != nil)
{
dispatch_block_t block = completionDictionary[app.bundleIdentifier];
block();
[completionDictionary removeObjectForKey:app.bundleIdentifier];
}
}
@end