-
Notifications
You must be signed in to change notification settings - Fork 12
/
SMFCommonTools.m
163 lines (152 loc) · 5.13 KB
/
SMFCommonTools.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
//
// SMFCommonTools.m
// SMFramework
//
// Created by Thomas Cool on 11/4/10.
// Copyright 2010 tomcool.org. All rights reserved.
//
#import "SMFCommonTools.h"
#import "SMFPhotoMethods.h"
#import "SynthesizeSingleton.h"
#import <CoreGraphics/CoreGraphics.h>
#import "Backrow/AppleTV.h"
static void daemonRunCode(int type, NSString *codeString){
//
// CFMessagePortRef daemonPort = 0;
// NSMutableDictionary *d = [[NSMutableDictionary alloc]init];
//
// [d setObject:codeString forKey:@"command"];
// CFDataRef data= CFPropertyListCreateData (
// NULL,
// (CFDictionaryRef)d,
// kCFPropertyListXMLFormat_v1_0,
// 0,
// NULL);
// NSLog(@"sending info");
// if (!daemonPort || !CFMessagePortIsValid(daemonPort)) {
// NSLog(@"searching for port");
// daemonPort = CFMessagePortCreateRemote(NULL, CFSTR("org.tomcool.lowtide.daemon"));
// }
// if (!daemonPort) return;
// NSLog(@"found port");
// // create and send message
// CFMessagePortSendRequest(daemonPort, type, data, 1, 1, NULL, NULL);
// CFMessagePor
// if (data) {
// CFRelease(data);
// }
}
@implementation SMFCommonTools
SYNTHESIZE_SINGLETON_FOR_CLASS(SMFCommonTools,sharedInstance)
-(void)test
{
// NSLog(@"facade singleton: %@",[ATVSettingsFacade singleton]);
// [[ATVSettingsFacade singleton] setScreenSaverPhotoCollection:[SMFPhotoMethods photoCollectionForPath:@"/var/root/pf"]];
}
+(id)popupControlWithLines:(NSArray *)array andImage:(BRImage *)image
{
if (image==nil)
return nil;
id ctrl =[[NSClassFromString(@"SMFPopupInfo") alloc] init];
NSDictionary *dict;
if (array==nil) {
dict = [NSDictionary dictionaryWithObjectsAndKeys:
image,@"Image",
nil];
}
else {
dict = [NSDictionary dictionaryWithObjectsAndKeys:
image,@"Image",
array,@"Lines",nil];
}
[ctrl setObject:dict];
return [ctrl autorelease];
}
+(id)popupControlWithDictionary:(NSDictionary *)dict
{
id ctrl =[[NSClassFromString(@"SMFPopupInfo") alloc] init];
[ctrl setObject:dict];
return [ctrl autorelease];
}
+(void)showPopup:(id)popup withTimeout:(int)timeout withPosition:(PopupPosition)position withWidth:(float)width withHeight:(float)height
{
if (width<=0.0f)
width=0.9;
if (height<=0.0f)
height=0.15;
[SMFCommonTools showPopup:popup withTimeout:timeout withPosition:position withSize:CGSizeMake(width, height)];
}
+(void)showPopup:(id)popup withTimeout:(int)timeout withPosition:(PopupPosition)position withSize:(CGSize)size
{
if (popup==nil)
return;
// if (size==nil)
// size=CGSizeMake(0.9,0.15);
if (position <0)
position=6;
if (timeout<=0)
timeout=8;
id manager = [BRPopUpManager sharedInstance];
if (manager==nil) {
[BRPopUpManager setSingleton:[[[BRPopUpManager alloc]init]autorelease]];
}
[[BRPopUpManager sharedInstance] postPopUpWithControl:popup
identifier:@"SMFPopup"
position:(int)position
size:size
options:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:1],@"BRPopUpPostImmediately",
[NSNumber numberWithInt:timeout],@"BRPopUpTimeoutValueKey",nil]];
}
+(void)showPopup:(id)popup
{
[SMFCommonTools showPopup:popup withTimeout:8 withPosition:6 withSize:CGSizeMake(0.9,0.15)];
}
-(NSArray *)returnForProcess:(NSString *)call
{
if (call==nil)
return 0;
char line[200];
FILE* fp = popen([call UTF8String], "r");
NSMutableArray *lines = [[NSMutableArray alloc]init];
if (fp)
{
while (fgets(line, sizeof line, fp))
{
NSString *s = [NSString stringWithCString:line encoding:NSUTF8StringEncoding];
[lines addObject:s];
}
}
pclose(fp);
return [lines autorelease];
}
-(int)syscallSeatbeltEnabled
{
NSArray *lines = [self returnForProcess:@"sysctl security.mac.vnode_enforce"];
if ([lines count]>0) {
for (NSString *line in lines) {
NSArray *parts = [line componentsSeparatedByString:@": "];
if ([parts count]>1) {
if ([(NSString *)[parts objectAtIndex:0] isEqualToString:@"security.mac.vnode_enforce"]) {
int r = [(NSString *)[parts objectAtIndex:1] intValue];
return r;
}
}
}
}
return -1;
}
-(int)disableSeatbelt
{
daemonRunCode(0, @"SMFHelper security.mac.vnode_enforce 0");
return 0;
//return system("SMFHelper security.mac.vnode_enforce 0");
}
-(int)enableSeatbelt
{
return system("SMFHelper security.mac.vnode_enforce 1");
}
-(void)restartLowtide
{
[[BRApplication sharedApplication]terminate];
}
@end