1 /* Veency - VNC Remote Access Server for iPhoneOS
2 * Copyright (C) 2008-2010 Jay Freeman (saurik)
6 * Redistribution and use in source and binary
7 * forms, with or without modification, are permitted
8 * provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the
11 * above copyright notice, this list of conditions
12 * and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the
14 * above copyright notice, this list of conditions
15 * and the following disclaimer in the documentation
16 * and/or other materials provided with the
18 * 3. The name of the author may not be used to endorse
19 * or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
24 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
33 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 fprintf(stderr, "_trace()@%s:%u[%s]\n", __FILE__, __LINE__, __FUNCTION__)
40 #define _likely(expr) \
41 __builtin_expect(expr, 1)
42 #define _unlikely(expr) \
43 __builtin_expect(expr, 0)
45 #include <CydiaSubstrate.h>
48 #include <rfb/keysym.h>
50 #include <mach/mach_port.h>
52 #include <sys/sysctl.h>
54 #import <QuartzCore/CAWindowServer.h>
55 #import <QuartzCore/CAWindowServerDisplay.h>
57 #import <CoreGraphics/CGGeometry.h>
58 #import <GraphicsServices/GraphicsServices.h>
59 #import <Foundation/Foundation.h>
60 #import <IOMobileFramebuffer/IOMobileFramebuffer.h>
61 #import <IOKit/IOKitLib.h>
62 #import <UIKit/UIKit.h>
64 #import <SpringBoard/SBAlertItemsController.h>
65 #import <SpringBoard/SBDismissOnlyAlertItem.h>
66 #import <SpringBoard/SBStatusBarController.h>
68 extern "C" void CoreSurfaceBufferFlushProcessorCaches(CoreSurfaceBufferRef buffer);
71 static size_t height_;
72 static NSUInteger ratio_ = 0;
74 static const size_t BytesPerPixel = 4;
75 static const size_t BitsPerSample = 8;
77 static CoreSurfaceAcceleratorRef accelerator_;
78 static CoreSurfaceBufferRef buffer_;
79 static CFDictionaryRef options_;
81 static NSMutableSet *handlers_;
82 static rfbScreenInfoPtr screen_;
87 static unsigned clients_;
89 static CFMessagePortRef ashikase_;
92 static rfbPixel *black_;
94 static void VNCBlack() {
95 if (_unlikely(black_ == NULL))
96 black_ = reinterpret_cast<rfbPixel *>(mmap(NULL, sizeof(rfbPixel) * width_ * height_, PROT_READ, MAP_ANON | MAP_PRIVATE | MAP_NOCACHE, VM_FLAGS_PURGABLE, 0));
97 screen_->frameBuffer = reinterpret_cast<char *>(black_);
100 static bool Ashikase(bool always) {
101 if (!always && !cursor_)
104 if (ashikase_ == NULL)
105 ashikase_ = CFMessagePortCreateRemote(kCFAllocatorDefault, CFSTR("jp.ashikase.mousesupport"));
106 if (ashikase_ != NULL)
113 static CFDataRef cfTrue_;
114 static CFDataRef cfFalse_;
122 static MouseEvent event_;
123 static CFDataRef cfEvent_;
126 MouseMessageTypeEvent,
127 MouseMessageTypeSetEnabled
130 static void AshikaseSendEvent(float x, float y, int buttons = 0) {
133 event_.buttons = buttons;
134 event_.absolute = true;
136 CFMessagePortSendRequest(ashikase_, MouseMessageTypeEvent, cfEvent_, 0, 0, NULL, NULL);
139 static void AshikaseSetEnabled(bool enabled, bool always) {
140 if (!Ashikase(always))
143 CFMessagePortSendRequest(ashikase_, MouseMessageTypeSetEnabled, enabled ? cfTrue_ : cfFalse_, 0, 0, NULL, NULL);
146 AshikaseSendEvent(x_, y_);
149 MSClassHook(SBAlertItemsController)
150 MSClassHook(SBStatusBarController)
153 static Class $VNCAlertItem;
155 static rfbNewClientAction action_ = RFB_CLIENT_ON_HOLD;
156 static NSCondition *condition_;
157 static NSLock *lock_;
159 static rfbClientPtr client_;
161 static void VNCSetup();
162 static void VNCEnabled();
164 @interface VNCBridge : NSObject {
167 + (void) askForConnection;
168 + (void) removeStatusBarItem;
169 + (void) registerClient;
173 @implementation VNCBridge
175 + (void) askForConnection {
176 [[$SBAlertItemsController sharedInstance] activateAlertItem:[[[$VNCAlertItem alloc] init] autorelease]];
179 + (void) removeStatusBarItem {
180 AshikaseSetEnabled(false, false);
182 if ($SBStatusBarController != nil)
183 [[$SBStatusBarController sharedStatusBarController] removeStatusBarItem:@"Veency"];
185 [[UIApplication sharedApplication] removeStatusBarImageNamed:@"Veency"];
188 + (void) registerClient {
189 // XXX: this could find a better home
191 UIScreen *screen([UIScreen mainScreen]);
192 if ([screen respondsToSelector:@selector(scale)])
193 ratio_ = [screen scale];
199 AshikaseSetEnabled(true, false);
201 if ($SBStatusBarController != nil)
202 [[$SBStatusBarController sharedStatusBarController] addStatusBarItem:@"Veency"];
204 [[UIApplication sharedApplication] addStatusBarImageNamed:@"Veency"];
207 + (void) performSetup:(NSThread *)thread {
208 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
209 [thread autorelease];
217 MSInstanceMessage2(void, VNCAlertItem, alertSheet,buttonClicked, id, sheet, int, button) {
222 action_ = RFB_CLIENT_ACCEPT;
224 @synchronized (condition_) {
225 [VNCBridge registerClient];
230 action_ = RFB_CLIENT_REFUSE;
239 MSInstanceMessage2(void, VNCAlertItem, configure,requirePasscodeForActions, BOOL, configure, BOOL, require) {
240 UIModalView *sheet([self alertSheet]);
241 [sheet setDelegate:self];
242 [sheet setTitle:@"Remote Access Request"];
243 [sheet setBodyText:[NSString stringWithFormat:@"Accept connection from\n%s?\n\nVeency VNC Server\nby Jay Freeman (saurik)\nsaurik@saurik.com\nhttp://www.saurik.com/\n\nSet a VNC password in Settings!", client_->host]];
244 [sheet addButtonWithTitle:@"Accept"];
245 [sheet addButtonWithTitle:@"Reject"];
248 MSInstanceMessage0(void, VNCAlertItem, performUnlockAction) {
249 [[$SBAlertItemsController sharedInstance] activateAlertItem:self];
252 static mach_port_t (*GSTakePurpleSystemEventPort)(void);
253 static bool PurpleAllocated;
256 static void FixRecord(GSEventRecord *record) {
258 memmove(&record->windowContextId, &record->windowContextId + 1, sizeof(*record) - (reinterpret_cast<uint8_t *>(&record->windowContextId + 1) - reinterpret_cast<uint8_t *>(record)) + record->size);
261 static void VNCSettings() {
262 NSDictionary *settings([NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.Veency.plist", NSHomeDirectory()]]);
264 @synchronized (lock_) {
265 for (NSValue *handler in handlers_)
266 rfbUnregisterSecurityHandler(reinterpret_cast<rfbSecurityHandler *>([handler pointerValue]));
267 [handlers_ removeAllObjects];
270 @synchronized (condition_) {
274 [reinterpret_cast<NSString *>(screen_->authPasswdData) release];
275 screen_->authPasswdData = NULL;
278 if (NSString *password = [settings objectForKey:@"Password"])
279 if ([password length] != 0)
280 screen_->authPasswdData = [password retain];
282 NSNumber *cursor = [settings objectForKey:@"ShowCursor"];
283 cursor_ = cursor == nil ? true : [cursor boolValue];
286 AshikaseSetEnabled(cursor_, true);
290 static void VNCNotifySettings(
291 CFNotificationCenterRef center,
300 static rfbBool VNCCheck(rfbClientPtr client, const char *data, int size) {
301 @synchronized (condition_) {
302 if (NSString *password = reinterpret_cast<NSString *>(screen_->authPasswdData)) {
303 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
304 rfbEncryptBytes(client->authChallenge, const_cast<char *>([password UTF8String]));
305 bool good(memcmp(client->authChallenge, data, size) == 0);
314 static void VNCPointer(int buttons, int x, int y, rfbClientPtr client) {
318 CGPoint location = {x, y};
323 if (width_ > height_) {
325 x = height_ / ratio_ - 1 - y;
335 int diff = buttons_ ^ buttons;
336 bool twas((buttons_ & 0x1) != 0);
337 bool tis((buttons & 0x1) != 0);
340 rfbDefaultPtrAddEvent(buttons, x, y, client);
342 if (Ashikase(false)) {
343 AshikaseSendEvent(x, y, buttons);
347 mach_port_t purple(0);
349 if ((diff & 0x10) != 0) {
350 struct GSEventRecord record;
352 memset(&record, 0, sizeof(record));
354 record.type = (buttons & 0x4) != 0 ?
355 GSEventTypeHeadsetButtonDown :
356 GSEventTypeHeadsetButtonUp;
358 record.timestamp = GSCurrentEventTimestamp();
361 GSSendSystemEvent(&record);
364 if ((diff & 0x04) != 0) {
365 struct GSEventRecord record;
367 memset(&record, 0, sizeof(record));
369 record.type = (buttons & 0x4) != 0 ?
370 GSEventTypeMenuButtonDown :
371 GSEventTypeMenuButtonUp;
373 record.timestamp = GSCurrentEventTimestamp();
376 GSSendSystemEvent(&record);
379 if ((diff & 0x02) != 0) {
380 struct GSEventRecord record;
382 memset(&record, 0, sizeof(record));
384 record.type = (buttons & 0x2) != 0 ?
385 GSEventTypeLockButtonDown :
386 GSEventTypeLockButtonUp;
388 record.timestamp = GSCurrentEventTimestamp();
391 GSSendSystemEvent(&record);
394 if (twas != tis || tis) {
396 struct GSEventRecord record;
398 struct GSEventRecordInfo info;
399 struct GSPathInfo path;
403 memset(&event, 0, sizeof(event));
405 event.record.type = GSEventTypeMouse;
406 event.record.locationInWindow.x = x;
407 event.record.locationInWindow.y = y;
408 event.record.timestamp = GSCurrentEventTimestamp();
409 event.record.size = sizeof(event.data);
411 event.data.info.handInfo.type = twas == tis ?
412 GSMouseEventTypeDragged :
414 GSMouseEventTypeDown :
417 event.data.info.handInfo.x34 = 0x1;
418 event.data.info.handInfo.x38 = tis ? 0x1 : 0x0;
421 event.data.info.pathPositions = 1;
423 event.data.info.x52 = 1;
425 event.data.path.x00 = 0x01;
426 event.data.path.x01 = 0x02;
427 event.data.path.x02 = tis ? 0x03 : 0x00;
428 event.data.path.position = event.record.locationInWindow;
432 if (CAWindowServer *server = [CAWindowServer serverIfRunning]) {
433 NSArray *displays([server displays]);
434 if (displays != nil && [displays count] != 0)
435 if (CAWindowServerDisplay *display = [displays objectAtIndex:0])
436 port = [display clientPortAtPosition:location];
441 purple = (*GSTakePurpleSystemEventPort)();
445 FixRecord(&event.record);
446 GSSendEvent(&event.record, port);
449 if (purple != 0 && PurpleAllocated)
450 mach_port_deallocate(mach_task_self(), purple);
453 GSEventRef (*$GSEventCreateKeyEvent)(int, CGPoint, CFStringRef, CFStringRef, id, UniChar, short, short);
454 GSEventRef (*$GSCreateSyntheticKeyEvent)(UniChar, BOOL, BOOL);
456 static void VNCKeyboard(rfbBool down, rfbKeySym key, rfbClientPtr client) {
461 case XK_Return: key = '\r'; break;
462 case XK_BackSpace: key = 0x7f; break;
468 CGPoint point(CGPointMake(x_, y_));
470 UniChar unicode(key);
471 CFStringRef string(NULL);
473 GSEventRef event0, event1(NULL);
474 if ($GSEventCreateKeyEvent != NULL) {
475 string = CFStringCreateWithCharacters(kCFAllocatorDefault, &unicode, 1);
476 event0 = (*$GSEventCreateKeyEvent)(10, point, string, string, nil, 0, 0, 1);
477 event1 = (*$GSEventCreateKeyEvent)(11, point, string, string, nil, 0, 0, 1);
478 } else if ($GSCreateSyntheticKeyEvent != NULL) {
479 event0 = (*$GSCreateSyntheticKeyEvent)(unicode, YES, YES);
480 GSEventRecord *record(_GSEventGetGSEventRecord(event0));
481 record->type = GSEventTypeKeyDown;
486 if (CAWindowServer *server = [CAWindowServer serverIfRunning]) {
487 NSArray *displays([server displays]);
488 if (displays != nil && [displays count] != 0)
489 if (CAWindowServerDisplay *display = [displays objectAtIndex:0])
490 port = [display clientPortAtPosition:point];
493 mach_port_t purple(0);
497 purple = (*GSTakePurpleSystemEventPort)();
502 GSSendEvent(_GSEventGetGSEventRecord(event0), port);
504 GSSendEvent(_GSEventGetGSEventRecord(event1), port);
507 if (purple != 0 && PurpleAllocated)
508 mach_port_deallocate(mach_task_self(), purple);
517 static void VNCDisconnect(rfbClientPtr client) {
518 @synchronized (condition_) {
520 [VNCBridge performSelectorOnMainThread:@selector(removeStatusBarItem) withObject:nil waitUntilDone:YES];
524 static rfbNewClientAction VNCClient(rfbClientPtr client) {
525 @synchronized (condition_) {
526 if (screen_->authPasswdData != NULL) {
527 [VNCBridge performSelectorOnMainThread:@selector(registerClient) withObject:nil waitUntilDone:YES];
528 client->clientGoneHook = &VNCDisconnect;
529 return RFB_CLIENT_ACCEPT;
535 [VNCBridge performSelectorOnMainThread:@selector(askForConnection) withObject:nil waitUntilDone:NO];
536 while (action_ == RFB_CLIENT_ON_HOLD)
538 rfbNewClientAction action(action_);
539 action_ = RFB_CLIENT_ON_HOLD;
542 if (action == RFB_CLIENT_ACCEPT)
543 client->clientGoneHook = &VNCDisconnect;
547 extern "C" bool GSSystemHasCapability(NSString *);
549 static CFTypeRef (*$GSSystemCopyCapability)(CFStringRef);
550 static CFTypeRef (*$GSSystemGetCapability)(CFStringRef);
552 static void VNCSetup() {
555 @synchronized (condition_) {
557 char *arg0(strdup("VNCServer"));
558 char *argv[] = {arg0, NULL};
559 screen_ = rfbGetScreen(&argc, argv, width_, height_, BitsPerSample, 3, BytesPerPixel);
565 screen_->desktopName = strdup([[[NSProcessInfo processInfo] hostName] UTF8String]);
567 screen_->alwaysShared = TRUE;
568 screen_->handleEventsEagerly = TRUE;
569 screen_->deferUpdateTime = 1000 / 25;
571 screen_->serverFormat.redShift = BitsPerSample * 2;
572 screen_->serverFormat.greenShift = BitsPerSample * 1;
573 screen_->serverFormat.blueShift = BitsPerSample * 0;
575 $GSSystemCopyCapability = reinterpret_cast<CFTypeRef (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemCopyCapability"));
576 $GSSystemGetCapability = reinterpret_cast<CFTypeRef (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemGetCapability"));
580 if ($GSSystemCopyCapability != NULL) {
581 opengles2 = (*$GSSystemCopyCapability)(CFSTR("opengles-2"));
582 } else if ($GSSystemGetCapability != NULL) {
583 opengles2 = (*$GSSystemGetCapability)(CFSTR("opengles-2"));
584 if (opengles2 != NULL)
589 bool accelerated(opengles2 != NULL && [(NSNumber *)opengles2 boolValue]);
592 CoreSurfaceAcceleratorCreate(NULL, NULL, &accelerator_);
594 if (opengles2 != NULL)
595 CFRelease(opengles2);
597 if (accelerator_ != NULL)
598 buffer_ = CoreSurfaceBufferCreate((CFDictionaryRef) [NSDictionary dictionaryWithObjectsAndKeys:
599 @"PurpleEDRAM", kCoreSurfaceBufferMemoryRegion,
600 [NSNumber numberWithBool:YES], kCoreSurfaceBufferGlobal,
601 [NSNumber numberWithInt:(width_ * BytesPerPixel)], kCoreSurfaceBufferPitch,
602 [NSNumber numberWithInt:width_], kCoreSurfaceBufferWidth,
603 [NSNumber numberWithInt:height_], kCoreSurfaceBufferHeight,
604 [NSNumber numberWithInt:'BGRA'], kCoreSurfaceBufferPixelFormat,
605 [NSNumber numberWithInt:(width_ * height_ * BytesPerPixel)], kCoreSurfaceBufferAllocSize,
610 //screen_->frameBuffer = reinterpret_cast<char *>(mmap(NULL, sizeof(rfbPixel) * width_ * height_, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_NOCACHE, VM_FLAGS_PURGABLE, 0));
612 CoreSurfaceBufferLock(buffer_, 3);
613 screen_->frameBuffer = reinterpret_cast<char *>(CoreSurfaceBufferGetBaseAddress(buffer_));
614 CoreSurfaceBufferUnlock(buffer_);
616 screen_->kbdAddEvent = &VNCKeyboard;
617 screen_->ptrAddEvent = &VNCPointer;
619 screen_->newClientHook = &VNCClient;
620 screen_->passwordCheck = &VNCCheck;
622 screen_->cursor = NULL;
625 static void VNCEnabled() {
629 if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.Veency.plist", NSHomeDirectory()]])
630 if (NSNumber *number = [settings objectForKey:@"Enabled"])
631 enabled = [number boolValue];
633 if (enabled != running_)
636 screen_->socketState = RFB_SOCKET_INIT;
637 rfbInitServer(screen_);
638 rfbRunEventLoop(screen_, -1, true);
640 rfbShutdownServer(screen_, true);
647 static void VNCNotifyEnabled(
648 CFNotificationCenterRef center,
657 void (*$IOMobileFramebufferIsMainDisplay)(IOMobileFramebufferRef, int *);
659 static IOMobileFramebufferRef main_;
660 static CoreSurfaceBufferRef layer_;
662 static void OnLayer(IOMobileFramebufferRef fb, CoreSurfaceBufferRef layer) {
663 if (_unlikely(width_ == 0 || height_ == 0)) {
665 IOMobileFramebufferGetDisplaySize(fb, &size);
668 height_ = size.height;
670 if (width_ == 0 || height_ == 0)
673 NSThread *thread([NSThread alloc]);
676 initWithTarget:[VNCBridge class]
677 selector:@selector(performSetup:)
682 } else if (_unlikely(clients_ != 0)) {
684 if (accelerator_ != NULL)
685 memset(screen_->frameBuffer, 0, sizeof(rfbPixel) * width_ * height_);
689 if (accelerator_ != NULL)
690 CoreSurfaceAcceleratorTransferSurface(accelerator_, layer, buffer_, options_);
692 CoreSurfaceBufferLock(layer, 2);
693 rfbPixel *data(reinterpret_cast<rfbPixel *>(CoreSurfaceBufferGetBaseAddress(layer)));
695 CoreSurfaceBufferFlushProcessorCaches(layer);
697 /*rfbPixel corner(data[0]);
701 screen_->frameBuffer = const_cast<char *>(reinterpret_cast<volatile char *>(data));
702 CoreSurfaceBufferUnlock(layer);
706 rfbMarkRectAsModified(screen_, 0, 0, width_, height_);
710 static bool wait_ = false;
712 MSHook(kern_return_t, IOMobileFramebufferSwapSetLayer,
713 IOMobileFramebufferRef fb,
715 CoreSurfaceBufferRef buffer,
722 if (_unlikely(buffer == NULL))
724 else if (_unlikely(fb == NULL))
726 else if ($IOMobileFramebufferIsMainDisplay == NULL)
729 (*$IOMobileFramebufferIsMainDisplay)(fb, &main);
739 return _IOMobileFramebufferSwapSetLayer(fb, layer, buffer, bounds, frame, flags);
742 // XXX: beg rpetrich for the type of this function
743 extern "C" void *IOMobileFramebufferSwapWait(IOMobileFramebufferRef, void *, unsigned);
745 MSHook(void *, IOMobileFramebufferSwapWait, IOMobileFramebufferRef fb, void *arg1, unsigned flags) {
746 void *value(_IOMobileFramebufferSwapWait(fb, arg1, flags));
752 MSHook(void, rfbRegisterSecurityHandler, rfbSecurityHandler *handler) {
753 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
755 @synchronized (lock_) {
756 [handlers_ addObject:[NSValue valueWithPointer:handler]];
757 _rfbRegisterSecurityHandler(handler);
763 template <typename Type_>
764 static void dlset(Type_ &function, const char *name) {
765 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
769 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
771 MSHookSymbol(GSTakePurpleSystemEventPort, "_GSGetPurpleSystemEventPort");
772 if (GSTakePurpleSystemEventPort == NULL) {
773 MSHookSymbol(GSTakePurpleSystemEventPort, "_GSCopyPurpleSystemEventPort");
774 PurpleAllocated = true;
777 if (dlsym(RTLD_DEFAULT, "GSLibraryCopyGenerationInfoValueForKey") != NULL)
779 else if (dlsym(RTLD_DEFAULT, "GSKeyboardCreate") != NULL)
781 else if (dlsym(RTLD_DEFAULT, "GSEventGetWindowContextId") != NULL)
787 sysctlbyname("hw.machine", NULL, &size, NULL, 0);
789 sysctlbyname("hw.machine", machine, &size, NULL, 0);
790 iPad1_ = strcmp(machine, "iPad1,1") == 0;
792 dlset($GSEventCreateKeyEvent, "GSEventCreateKeyEvent");
793 dlset($GSCreateSyntheticKeyEvent, "_GSCreateSyntheticKeyEvent");
794 dlset($IOMobileFramebufferIsMainDisplay, "IOMobileFramebufferIsMainDisplay");
796 MSHookFunction(&IOMobileFramebufferSwapSetLayer, MSHake(IOMobileFramebufferSwapSetLayer));
797 MSHookFunction(&rfbRegisterSecurityHandler, MSHake(rfbRegisterSecurityHandler));
800 MSHookFunction(&IOMobileFramebufferSwapWait, MSHake(IOMobileFramebufferSwapWait));
802 $VNCAlertItem = objc_allocateClassPair(objc_getClass("SBAlertItem"), "VNCAlertItem", 0);
803 MSAddMessage2(VNCAlertItem, "v@:@i", alertSheet,buttonClicked);
804 MSAddMessage2(VNCAlertItem, "v@:cc", configure,requirePasscodeForActions);
805 MSAddMessage0(VNCAlertItem, "v@:", performUnlockAction);
806 objc_registerClassPair($VNCAlertItem);
808 CFNotificationCenterAddObserver(
809 CFNotificationCenterGetDarwinNotifyCenter(),
810 NULL, &VNCNotifyEnabled, CFSTR("com.saurik.Veency-Enabled"), NULL, 0
813 CFNotificationCenterAddObserver(
814 CFNotificationCenterGetDarwinNotifyCenter(),
815 NULL, &VNCNotifySettings, CFSTR("com.saurik.Veency-Settings"), NULL, 0
818 condition_ = [[NSCondition alloc] init];
819 lock_ = [[NSLock alloc] init];
820 handlers_ = [[NSMutableSet alloc] init];
825 cfTrue_ = CFDataCreate(kCFAllocatorDefault, reinterpret_cast<UInt8 *>(&value), sizeof(value));
828 cfFalse_ = CFDataCreate(kCFAllocatorDefault, reinterpret_cast<UInt8 *>(&value), sizeof(value));
830 cfEvent_ = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast<UInt8 *>(&event_), sizeof(event_), kCFAllocatorNull);
832 options_ = (CFDictionaryRef) [[NSDictionary dictionaryWithObjectsAndKeys: