-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNSClient.m
180 lines (152 loc) · 4.55 KB
/
NSClient.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
//
// NSClient.m
// NoSandX
//
// (Unbox) Created by Árpád Goretity on 07/11/2011
// Licensed under a CreativeCommons Attribution 3.0 Unported License
//
/*
NoSandX Created by Mokhlas Hussein (iMokhles on 29/09/2014)
port of (Arpad Goretity) UnBox to make it work with iOS7 - arm64
*/
#import "NSClient.h"
@implementation NSClient
+ (id)sharedInstance
{
static id shared = nil;
if (shared == nil) {
shared = [[self alloc] init];
}
return shared;
}
- (id)init
{
if ((self = [super init])) {
center = [CPDistributedMessagingCenter centerNamed:@"com.imokhles.nosand"];
rocketbootstrap_distributedmessagingcenter_apply(center);
}
return self;
}
- (NSString *)temporaryFile
{
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
CFStringRef uuid = CFUUIDCreateString(NULL, uuidRef);
CFRelease(uuidRef);
NSString *path = [NSString stringWithFormat:@"/tmp/%@.tmp", uuid];
CFRelease(uuid);
return path;
}
- (void)moveFile:(NSString *)file1 toFile:(NSString *)file2
{
if (file1 == nil || file2 == nil) {
return;
}
NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
[info setObject:file1 forKey:@"NSSourceFile"];
[info setObject:file2 forKey:@"NSTargetFile"];
[center sendMessageAndReceiveReplyName:@"com.imokhles.nosand.move" userInfo:info];
[info release];
}
- (void)copyFile:(NSString *)file1 toFile:(NSString *)file2
{
if (file1 == nil || file2 == nil) {
return;
}
NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
[info setObject:file1 forKey:@"NSSourceFile"];
[info setObject:file2 forKey:@"NSTargetFile"];
[center sendMessageAndReceiveReplyName:@"com.imokhles.nosand.copy" userInfo:info];
[info release];
}
- (void)symlinkFile:(NSString *)file1 toFile:(NSString *)file2
{
if (file1 == nil || file2 == nil) {
return;
}
NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
[info setObject:file1 forKey:@"NSSourceFile"];
[info setObject:file2 forKey:@"NSTargetFile"];
[center sendMessageAndReceiveReplyName:@"com.imokhles.nosand.symlink" userInfo:info];
[info release];
}
- (void)deleteFile:(NSString *)file
{
if (file == nil) {
return;
}
NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
[info setObject:file forKey:@"NSTargetFile"];
[center sendMessageAndReceiveReplyName:@"com.imokhles.nosand.delete" userInfo:info];
[info release];
}
- (NSDictionary *)attributesOfFile:(NSString *)file
{
if (file == nil) {
return nil;
}
NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
[info setObject:file forKey:@"NSTargetFile"];
NSDictionary *reply = [center sendMessageAndReceiveReplyName:@"com.imokhles.nosand.attributes" userInfo:info];
[info release];
return reply;
}
- (NSArray *)contentsOfDirectory:(NSString *)dir
{
if (dir == nil) {
return nil;
}
NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
[info setObject:dir forKey:@"NSTargetFile"];
NSDictionary *reply = [center sendMessageAndReceiveReplyName:@"com.imokhles.nosand.dircontents" userInfo:info];
[info release];
NSArray *result = [reply objectForKey:@"NSDirContents"];
return result;
}
- (void)chmodFile:(NSString *)file mode:(mode_t)mode
{
if (file == nil) {
return;
}
NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
[info setObject:file forKey:@"NSTargetFile"];
NSNumber *modeNumber = [[NSNumber alloc] initWithInt:mode];
[info setObject:modeNumber forKey:@"NSFileMode"];
[modeNumber release];
[center sendMessageAndReceiveReplyName:@"com.imokhles.nosand.chmod" userInfo:info];
[info release];
}
- (BOOL)fileExists:(NSString *)file
{
if (file == nil) {
return NO;
}
NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
[info setObject:file forKey:@"NSTargetFile"];
NSDictionary *reply = [center sendMessageAndReceiveReplyName:@"com.imokhles.nosand.exists" userInfo:info];
[info release];
BOOL result = [(NSNumber *)[reply objectForKey:@"NSFileExists"] boolValue];
return result;
}
- (BOOL)fileIsDirectory:(NSString *)file
{
if (file == nil) {
return NO;
}
NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
[info setObject:file forKey:@"NSTargetFile"];
NSDictionary *reply = [center sendMessageAndReceiveReplyName:@"com.imokhles.nosand.isdir" userInfo:info];
[info release];
BOOL result = [(NSNumber *)[reply objectForKey:@"NSIsDirectory"] boolValue];
return result;
}
- (void)createDirectory:(NSString *)dir
{
if (dir == nil) {
return;
}
NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
[info setObject:dir forKey:@"NSTargetFile"];
[center sendMessageAndReceiveReplyName:@"com.imokhles.nosand.mkdir" userInfo:info];
[info release];
}
@end