-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdisplay-mirroring.m
executable file
·63 lines (52 loc) · 1.84 KB
/
display-mirroring.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
#import <Foundation/Foundation.h>
static NSString *plistPath = nil;
static NSAutoreleasePool *pool = nil;
BOOL isEnabled() {
return [[[[NSDictionary dictionaryWithContentsOfFile:plistPath] objectForKey:@"capabilities"] objectForKey:@"display-mirroring"] boolValue];
}
void setEnabled(BOOL enable) {
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
[[dict objectForKey:@"capabilities"] setValue:[NSNumber numberWithBool:enable] forKey:@"display-mirroring"];
[dict writeToFile:plistPath atomically:YES];
}
int main(int argc, char **argv) {
if (!plistPath) {
NSLog(@"This device is not supported!");
exit(-1);
}
if (argv[1] && *argv[1]) {
if (strcmp("yes", argv[1]) == 0 ||
strcmp("YES", argv[1]) == 0 ||
strcmp("true", argv[1]) == 0 ||
strcmp("TRUE", argv[1]) == 0 ||
strcmp("1", argv[1]) == 0) {
setEnabled(YES);
} else if (strcmp("no", argv[1]) == 0 ||
strcmp("NO", argv[1]) == 0 ||
strcmp("false", argv[1]) == 0 ||
strcmp("FALSE", argv[1]) == 0 ||
strcmp("0", argv[1]) == 0) {
setEnabled(NO);
}
}
NSLog(@"Display Mirroring %@", (isEnabled() ? @"Enabled" : @"Disabled"));
}
__attribute__((constructor)) static void initializer() {
pool = [[NSAutoreleasePool alloc] init];
NSArray *plists = [NSArray arrayWithObjects: @"K48AP", // iPad
@"N90AP", // iPhone 4
@"N92AP", // iPhone 4 (Verizon)
@"N81AP", // iPod Touch 4G
nil];
NSFileManager *fileManager = [NSFileManager defaultManager];
for (NSString *plist in plists) {
NSString *path = [NSString stringWithFormat:@"/System/Library/CoreServices/SpringBoard.app/%@.plist", plist];
if ([fileManager fileExistsAtPath:path isDirectory:NO]) {
plistPath = [path copy];
break;
}
}
}
__attribute__((destructor)) static void finalizer() {
[pool release];
}