static void runServer()
{
    IOHIDEventSystemRef eventSystem = IOHIDEventSystemCreate(kCFAllocatorDefault);
    IOHIDNotificationRef notification = NULL;
    
    require(eventSystem, exit);
        
    IOHIDEventSystemOpen(eventSystem, eventCallback, NULL, NULL, 0);
            
    if ( !__serviceNotifications )
        __serviceNotifications = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

    CFArrayRef services = IOHIDEventSystemCopyMatchingServices(eventSystem, NULL, servicesAddedCallback, NULL, NULL, &notification);
    if ( services ) {
        servicesAddedCallback(NULL, NULL, NULL, services);
        CFRelease(services);
        
    }

    CFRunLoopRun();
exit:
    if ( eventSystem )
        CFRelease(eventSystem);

}
Esempio n. 2
0
int main(UNUSED int argc, char **argv) {
    pid_t pid = argv[1] ? atoi(argv[1]) : 1; /* for testing */

    void *event_system = IOHIDEventSystemCreate(NULL);
    if (!event_system) {
        ib_log("couldn't create HID event system");
    } else {

            /* consumer page -> Volume Increment */
        if (button_pressed(event_system, 0x0c, 0xe9) ||
            /* telephony page -> Flash */
            button_pressed(event_system, 0x0b, 0x21)) {
            ib_log("disabling due to button press");
            return 0;
        }
    }
    mach_port_t port = 0;
    kern_return_t kr = mach_port_allocate(mach_task_self(),
                                          MACH_PORT_RIGHT_RECEIVE,
                                          &port);
    if (kr) {
        ib_log("mach_port_allocate: %x", kr);
        return 0;
    }
    const char *lib = "/Library/Substitute/Helpers/posixspawn-hook.dylib";
    struct shuttle shuttle = {
        .type = SUBSTITUTE_SHUTTLE_MACH_PORT,
        .u.mach.right_type = MACH_MSG_TYPE_MAKE_SEND,
        .u.mach.port = port
    };
    char *error;
    int ret = substitute_dlopen_in_pid(pid, lib, 0, &shuttle, 1, &error);
    if (ret) {
        ib_log("substitute_dlopen_in_pid: %s/%s",
               substitute_strerror(ret), error);
        return 0;
    }
    /* wait for it to finish */
    static struct {
        mach_msg_header_t hdr;
        mach_msg_trailer_t huh;
    } msg;
    kr = mach_msg_overwrite(NULL, MACH_RCV_MSG, 0, sizeof(msg), port,
                            MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL,
                            &msg.hdr, 0);
    if (kr)
        ib_log("mach_msg_overwrite: %x", kr);
}