-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.m
55 lines (45 loc) · 1.44 KB
/
main.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
//
// main.m
// YubiKeyDetector
//
// Created by Delfim Machado on 24/07/17.
// Copyright © 2017 Delfim Machado. All rights reserved.
//
#import <Foundation/Foundation.h>
#include <xpc/xpc.h>
#include <unistd.h>
BOOL debug = true;
void handleEvent() {
xpc_set_event_stream_handler("com.apple.iokit.matching", NULL, ^(xpc_object_t event) {
const char *name = xpc_dictionary_get_string(event, XPC_EVENT_KEY_NAME);
uint64_t id = xpc_dictionary_get_uint64(event, "IOMatchLaunchServiceID");
NSLog(@"Received event: %s: %llu", name, id);
pid_t p = fork();
int status;
if (p == 0) {
execl("/Users/dbcm/.usbexec/commands", "/Users/dbcm/.usbexec/commands", "-from_daemon", NULL);
if (errno == ENOENT)
_exit(-1);
_exit(-2);
}
wait(&status);
if (WIFEXITED(status)) {
printf("exited, status=%d\n", WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
printf("killed by signal %d\n", WTERMSIG(status));
} else if (WIFSTOPPED(status)) {
printf("stopped by signal %d\n", WSTOPSIG(status));
} else if (WIFCONTINUED(status)) {
printf("continued\n");
}
});
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
handleEvent();
if(debug) {
NSLog(@"Events Purger called!");
}
}
return 0;
}