Skip to content

Commit c44e00b

Browse files
committed
init project
1 parent fbd4499 commit c44e00b

File tree

115 files changed

+2843
-780
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+2843
-780
lines changed

HelpTool/HelpTool-Info.plist

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleIdentifier</key>
6+
<string>com.cxy.PPTPVPN.HelpTool</string>
7+
<key>CFBundleInfoDictionaryVersion</key>
8+
<string>6.0</string>
9+
<key>CFBundleName</key>
10+
<string>HelpTool</string>
11+
<key>CFBundleShortVersionString</key>
12+
<string>1.0</string>
13+
<key>CFBundleVersion</key>
14+
<string>1.0</string>
15+
<key>SMAuthorizedClients</key>
16+
<array>
17+
<string>identifier &quot;com.cxy.PPTPVPN&quot; and anchor apple generic and certificate leaf[subject.CN] = &quot;Mac Developer: [email protected] (A6N22GWPU9)&quot; and certificate 1[field.1.2.840.113635.100.6.2.1] /* exists */</string>
18+
</array>
19+
</dict>
20+
</plist>

HelpTool/HelpTool-Launchd.plist

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>Label</key>
6+
<string>com.cxy.PPTPVPN.HelpTool</string>
7+
<key>MachServices</key>
8+
<dict>
9+
<key>com.cxy.PPTPVPN.HelpTool</key>
10+
<true/>
11+
</dict>
12+
</dict>
13+
</plist>

HelpTool/HelperTool.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// HelperTool.h
3+
// com.cxy.PPTPVPN.HelpTool
4+
//
5+
// Created by chen on 2018/8/5.
6+
// Copyright © 2018年 ___CXY___. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
@protocol HelperToolProtocol
11+
- (void)executeShellCommand:(NSString*)command withReply:(void(^)(NSDictionary * errorInfo))reply;
12+
@end
13+
14+
@interface HelperTool : NSObject
15+
- (void)run;
16+
17+
@end

HelpTool/HelperTool.m

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// HelperTool.m
3+
// com.cxy.PPTPVPN.HelpTool
4+
//
5+
// Created by chen on 2018/8/5.
6+
// Copyright © 2018年 ___CXY___. All rights reserved.
7+
//
8+
9+
#import "HelperTool.h"
10+
#include <sys/socket.h>
11+
#include <netinet/in.h>
12+
#include <errno.h>
13+
14+
@interface HelperTool () <NSXPCListenerDelegate, HelperToolProtocol>
15+
16+
@property (atomic, strong, readwrite) NSXPCListener *listener;
17+
18+
@end
19+
20+
@implementation HelperTool
21+
22+
- (id)init {
23+
if (self = [super init]) {
24+
// Set up our XPC listener to handle requests on our Mach service.
25+
self.listener = [[NSXPCListener alloc] initWithMachServiceName:@"com.cxy.PPTPVPN.HelpTool"];
26+
self.listener.delegate = self;
27+
}
28+
return self;
29+
}
30+
31+
- (void)run {
32+
// Tell the XPC listener to start processing requests.
33+
34+
[self.listener resume];
35+
36+
// Run the run loop forever.
37+
38+
[[NSRunLoop currentRunLoop] run];
39+
}
40+
41+
- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection
42+
// Called by our XPC listener when a new connection comes in. We configure the connection
43+
// with our protocol and ourselves as the main object.
44+
{
45+
assert(listener == self.listener);
46+
#pragma unused(listener)
47+
assert(newConnection != nil);
48+
49+
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(HelperToolProtocol)];
50+
newConnection.exportedObject = self;
51+
[newConnection resume];
52+
53+
return YES;
54+
}
55+
56+
57+
#pragma mark - protocol
58+
- (void)executeShellCommand:(NSString*)command withReply:(void(^)(NSDictionary * errorInfo))reply {
59+
NSString *script = [NSString stringWithFormat:@"do shell script \"%@\"",command];
60+
61+
NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:script];
62+
NSDictionary *dicError = @{};
63+
if([appleScript executeAndReturnError:&dicError]) {
64+
reply(dicError);
65+
} else {
66+
reply(dicError);
67+
}
68+
}
69+
@end

HelpTool/main.m

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// main.m
3+
// HelpTool
4+
//
5+
// Created by chen on 2018/8/4.
6+
// Copyright © 2018年 ___CXY___. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
#import "HelperTool.h"
12+
13+
int main(int argc, char **argv) {
14+
#pragma unused(argc)
15+
#pragma unused(argv)
16+
17+
// We just create and start an instance of the main helper tool object and then
18+
// have it run the run loop forever.
19+
20+
@autoreleasepool {
21+
HelperTool * m;
22+
23+
m = [[HelperTool alloc] init];
24+
[m run]; // This never comes back...
25+
}
26+
27+
return EXIT_FAILURE; // ... so this should never be hit.
28+
}

0 commit comments

Comments
 (0)