1 /* Veency - VNC Remote Access Server for iPhoneOS
2 * Copyright (C) 2008-2012 Jay Freeman (saurik)
5 /* GNU Affero General Public License, Version 3 {{{ */
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 fprintf(stderr, "_trace()@%s:%u[%s]\n", __FILE__, __LINE__, __FUNCTION__)
24 #define _likely(expr) \
25 __builtin_expect(expr, 1)
26 #define _unlikely(expr) \
27 __builtin_expect(expr, 0)
29 #include <CydiaSubstrate.h>
32 #include <rfb/keysym.h>
34 #include <mach/mach_port.h>
36 #include <sys/sysctl.h>
38 #import <QuartzCore/CAWindowServer.h>
39 #import <QuartzCore/CAWindowServerDisplay.h>
41 #import <CoreGraphics/CGGeometry.h>
42 #import <GraphicsServices/GraphicsServices.h>
43 #import <Foundation/Foundation.h>
44 #import <IOMobileFramebuffer/IOMobileFramebuffer.h>
45 #import <IOKit/IOKitLib.h>
46 #import <UIKit/UIKit.h>
48 #import <SpringBoard/SBAlertItemsController.h>
49 #import <SpringBoard/SBDismissOnlyAlertItem.h>
50 #import <SpringBoard/SBStatusBarController.h>
52 #include "SpringBoardAccess.h"
54 extern "C" void CoreSurfaceBufferFlushProcessorCaches(CoreSurfaceBufferRef buffer);
57 static size_t height_;
58 static NSUInteger ratio_ = 0;
60 static const size_t BytesPerPixel = 4;
61 static const size_t BitsPerSample = 8;
63 static CoreSurfaceAcceleratorRef accelerator_;
64 static CoreSurfaceBufferRef buffer_;
65 static CFDictionaryRef options_;
67 static NSMutableSet *handlers_;
68 static rfbScreenInfoPtr screen_;
73 static unsigned clients_;
75 static CFMessagePortRef ashikase_;
78 static rfbPixel *black_;
80 static void VNCBlack() {
81 if (_unlikely(black_ == NULL))
82 black_ = reinterpret_cast<rfbPixel *>(mmap(NULL, sizeof(rfbPixel) * width_ * height_, PROT_READ, MAP_ANON | MAP_PRIVATE | MAP_NOCACHE, VM_FLAGS_PURGABLE, 0));
83 screen_->frameBuffer = reinterpret_cast<char *>(black_);
86 static bool Ashikase(bool always) {
87 if (!always && !cursor_)
90 if (ashikase_ == NULL)
91 ashikase_ = CFMessagePortCreateRemote(kCFAllocatorDefault, CFSTR("jp.ashikase.mousesupport"));
92 if (ashikase_ != NULL)
99 static CFDataRef cfTrue_;
100 static CFDataRef cfFalse_;
108 static MouseEvent event_;
109 static CFDataRef cfEvent_;
112 MouseMessageTypeEvent,
113 MouseMessageTypeSetEnabled
116 static void AshikaseSendEvent(float x, float y, int buttons = 0) {
119 event_.buttons = buttons;
120 event_.absolute = true;
122 CFMessagePortSendRequest(ashikase_, MouseMessageTypeEvent, cfEvent_, 0, 0, NULL, NULL);
125 static void AshikaseSetEnabled(bool enabled, bool always) {
126 if (!Ashikase(always))
129 CFMessagePortSendRequest(ashikase_, MouseMessageTypeSetEnabled, enabled ? cfTrue_ : cfFalse_, 0, 0, NULL, NULL);
132 AshikaseSendEvent(x_, y_);
135 MSClassHook(SBAlertItem)
136 MSClassHook(SBAlertItemsController)
137 MSClassHook(SBStatusBarController)
140 static Class $VNCAlertItem;
142 static NSString *DialogTitle(@"Remote Access Request");
143 static NSString *DialogFormat(@"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!");
144 static NSString *DialogAccept(@"Accept");
145 static NSString *DialogReject(@"Reject");
147 static volatile rfbNewClientAction action_ = RFB_CLIENT_ON_HOLD;
148 static NSCondition *condition_;
149 static NSLock *lock_;
151 static rfbClientPtr client_;
153 static void VNCSetup();
154 static void VNCEnabled();
156 static void OnUserNotification(CFUserNotificationRef notification, CFOptionFlags flags) {
159 if ((flags & 0x3) == 1)
160 action_ = RFB_CLIENT_ACCEPT;
162 action_ = RFB_CLIENT_REFUSE;
167 CFRelease(notification);
170 @interface VNCBridge : NSObject {
173 + (void) askForConnection;
174 + (void) removeStatusBarItem;
175 + (void) registerClient;
179 @implementation VNCBridge
181 + (void) askForConnection {
182 if ($VNCAlertItem != nil) {
183 [[$SBAlertItemsController sharedInstance] activateAlertItem:[[[$VNCAlertItem alloc] init] autorelease]];
188 CFUserNotificationRef notification(CFUserNotificationCreate(kCFAllocatorDefault, 0, kCFUserNotificationPlainAlertLevel, &error, (CFDictionaryRef) [NSDictionary dictionaryWithObjectsAndKeys:
189 DialogTitle, kCFUserNotificationAlertHeaderKey,
190 [NSString stringWithFormat:DialogFormat, client_->host], kCFUserNotificationAlertMessageKey,
191 DialogAccept, kCFUserNotificationAlternateButtonTitleKey,
192 DialogReject, kCFUserNotificationDefaultButtonTitleKey,
196 CFRelease(notification);
200 if (notification == NULL) {
202 action_ = RFB_CLIENT_REFUSE;
208 CFRunLoopSourceRef source(CFUserNotificationCreateRunLoopSource(kCFAllocatorDefault, notification, &OnUserNotification, 0));
209 CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
212 + (void) removeStatusBarItem {
213 AshikaseSetEnabled(false, false);
216 SBA_removeStatusBarImage(const_cast<char *>("Veency"));
217 else if ($SBStatusBarController != nil)
218 [[$SBStatusBarController sharedStatusBarController] removeStatusBarItem:@"Veency"];
219 else if (UIApplication *app = [UIApplication sharedApplication])
220 [app removeStatusBarImageNamed:@"Veency"];
223 + (void) registerClient {
224 // XXX: this could find a better home
226 UIScreen *screen([UIScreen mainScreen]);
227 if ([screen respondsToSelector:@selector(scale)])
228 ratio_ = [screen scale];
234 AshikaseSetEnabled(true, false);
237 SBA_addStatusBarImage(const_cast<char *>("Veency"));
238 else if ($SBStatusBarController != nil)
239 [[$SBStatusBarController sharedStatusBarController] addStatusBarItem:@"Veency"];
240 else if (UIApplication *app = [UIApplication sharedApplication])
241 [app addStatusBarImageNamed:@"Veency"];
244 + (void) performSetup:(NSThread *)thread {
245 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
246 [thread autorelease];
254 MSInstanceMessage2(void, VNCAlertItem, alertSheet,buttonClicked, id, sheet, int, button) {
259 action_ = RFB_CLIENT_ACCEPT;
261 @synchronized (condition_) {
262 [VNCBridge registerClient];
267 action_ = RFB_CLIENT_REFUSE;
276 MSInstanceMessage2(void, VNCAlertItem, configure,requirePasscodeForActions, BOOL, configure, BOOL, require) {
277 UIModalView *sheet([self alertSheet]);
278 [sheet setDelegate:self];
279 [sheet setTitle:DialogTitle];
280 [sheet setBodyText:[NSString stringWithFormat:DialogFormat, client_->host]];
281 [sheet addButtonWithTitle:DialogAccept];
282 [sheet addButtonWithTitle:DialogReject];
285 MSInstanceMessage0(void, VNCAlertItem, performUnlockAction) {
286 [[$SBAlertItemsController sharedInstance] activateAlertItem:self];
289 static mach_port_t (*GSTakePurpleSystemEventPort)(void);
290 static bool PurpleAllocated;
293 static void FixRecord(GSEventRecord *record) {
295 memmove(&record->windowContextId, &record->windowContextId + 1, sizeof(*record) - (reinterpret_cast<uint8_t *>(&record->windowContextId + 1) - reinterpret_cast<uint8_t *>(record)) + record->size);
298 static void VNCSettings() {
299 NSDictionary *settings([NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.Veency.plist", NSHomeDirectory()]]);
301 @synchronized (lock_) {
302 for (NSValue *handler in handlers_)
303 rfbUnregisterSecurityHandler(reinterpret_cast<rfbSecurityHandler *>([handler pointerValue]));
304 [handlers_ removeAllObjects];
307 @synchronized (condition_) {
311 [reinterpret_cast<NSString *>(screen_->authPasswdData) release];
312 screen_->authPasswdData = NULL;
315 if (NSString *password = [settings objectForKey:@"Password"])
316 if ([password length] != 0)
317 screen_->authPasswdData = [password retain];
319 NSNumber *cursor = [settings objectForKey:@"ShowCursor"];
320 cursor_ = cursor == nil ? true : [cursor boolValue];
323 AshikaseSetEnabled(cursor_, true);
327 static void VNCNotifySettings(
328 CFNotificationCenterRef center,
337 static rfbBool VNCCheck(rfbClientPtr client, const char *data, int size) {
338 @synchronized (condition_) {
339 if (NSString *password = reinterpret_cast<NSString *>(screen_->authPasswdData)) {
340 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
341 rfbEncryptBytes(client->authChallenge, const_cast<char *>([password UTF8String]));
342 bool good(memcmp(client->authChallenge, data, size) == 0);
352 struct GSEventRecord record;
354 struct GSEventRecordInfo info;
355 struct GSPathInfo path;
359 static void VNCPointer(int buttons, int x, int y, rfbClientPtr client) {
363 CGPoint location = {x, y};
365 if (width_ > height_) {
380 int diff = buttons_ ^ buttons;
381 bool twas((buttons_ & 0x1) != 0);
382 bool tis((buttons & 0x1) != 0);
385 rfbDefaultPtrAddEvent(buttons, x, y, client);
387 if (Ashikase(false)) {
388 AshikaseSendEvent(x, y, buttons);
392 mach_port_t purple(0);
394 if ((diff & 0x10) != 0) {
395 struct GSEventRecord record;
397 memset(&record, 0, sizeof(record));
399 record.type = (buttons & 0x10) != 0 ?
400 GSEventTypeHeadsetButtonDown :
401 GSEventTypeHeadsetButtonUp;
403 record.timestamp = GSCurrentEventTimestamp();
406 GSSendSystemEvent(&record);
409 if ((diff & 0x04) != 0) {
410 struct GSEventRecord record;
412 memset(&record, 0, sizeof(record));
414 record.type = (buttons & 0x04) != 0 ?
415 GSEventTypeMenuButtonDown :
416 GSEventTypeMenuButtonUp;
418 record.timestamp = GSCurrentEventTimestamp();
421 GSSendSystemEvent(&record);
424 if ((diff & 0x02) != 0) {
425 struct GSEventRecord record;
427 memset(&record, 0, sizeof(record));
429 record.type = (buttons & 0x02) != 0 ?
430 GSEventTypeLockButtonDown :
431 GSEventTypeLockButtonUp;
433 record.timestamp = GSCurrentEventTimestamp();
436 GSSendSystemEvent(&record);
439 if (twas != tis || tis) {
440 struct VeencyEvent event;
442 memset(&event, 0, sizeof(event));
444 event.record.type = GSEventTypeMouse;
445 event.record.locationInWindow.x = x;
446 event.record.locationInWindow.y = y;
447 event.record.timestamp = GSCurrentEventTimestamp();
448 event.record.size = sizeof(event.data);
450 event.data.info.handInfo.type = twas == tis ?
451 GSMouseEventTypeDragged :
453 GSMouseEventTypeDown :
456 event.data.info.handInfo.x34 = 0x1;
457 event.data.info.handInfo.x38 = tis ? 0x1 : 0x0;
460 event.data.info.pathPositions = 1;
462 event.data.info.x52 = 1;
464 event.data.path.x00 = 0x01;
465 event.data.path.x01 = 0x02;
466 event.data.path.x02 = tis ? 0x03 : 0x00;
467 event.data.path.position = event.record.locationInWindow;
471 if (CAWindowServer *server = [CAWindowServer serverIfRunning]) {
472 NSArray *displays([server displays]);
473 if (displays != nil && [displays count] != 0)
474 if (CAWindowServerDisplay *display = [displays objectAtIndex:0])
475 port = [display clientPortAtPosition:location];
480 purple = (*GSTakePurpleSystemEventPort)();
484 FixRecord(&event.record);
485 GSSendEvent(&event.record, port);
488 if (purple != 0 && PurpleAllocated)
489 mach_port_deallocate(mach_task_self(), purple);
492 GSEventRef (*$GSEventCreateKeyEvent)(int, CGPoint, CFStringRef, CFStringRef, id, UniChar, short, short);
493 GSEventRef (*$GSCreateSyntheticKeyEvent)(UniChar, BOOL, BOOL);
495 static void VNCKeyboard(rfbBool down, rfbKeySym key, rfbClientPtr client) {
500 case XK_Return: key = '\r'; break;
501 case XK_BackSpace: key = 0x7f; break;
507 CGPoint point(CGPointMake(x_, y_));
509 UniChar unicode(key);
510 CFStringRef string(NULL);
512 GSEventRef event0, event1(NULL);
513 if ($GSEventCreateKeyEvent != NULL) {
514 string = CFStringCreateWithCharacters(kCFAllocatorDefault, &unicode, 1);
515 event0 = (*$GSEventCreateKeyEvent)(10, point, string, string, nil, 0, 0, 1);
516 event1 = (*$GSEventCreateKeyEvent)(11, point, string, string, nil, 0, 0, 1);
517 } else if ($GSCreateSyntheticKeyEvent != NULL) {
518 event0 = (*$GSCreateSyntheticKeyEvent)(unicode, YES, YES);
519 GSEventRecord *record(_GSEventGetGSEventRecord(event0));
520 record->type = GSEventTypeKeyDown;
525 if (CAWindowServer *server = [CAWindowServer serverIfRunning]) {
526 NSArray *displays([server displays]);
527 if (displays != nil && [displays count] != 0)
528 if (CAWindowServerDisplay *display = [displays objectAtIndex:0])
529 port = [display clientPortAtPosition:point];
532 mach_port_t purple(0);
536 purple = (*GSTakePurpleSystemEventPort)();
541 GSSendEvent(_GSEventGetGSEventRecord(event0), port);
543 GSSendEvent(_GSEventGetGSEventRecord(event1), port);
546 if (purple != 0 && PurpleAllocated)
547 mach_port_deallocate(mach_task_self(), purple);
556 static void VNCDisconnect(rfbClientPtr client) {
557 @synchronized (condition_) {
559 [VNCBridge performSelectorOnMainThread:@selector(removeStatusBarItem) withObject:nil waitUntilDone:YES];
563 static rfbNewClientAction VNCClient(rfbClientPtr client) {
564 @synchronized (condition_) {
565 if (screen_->authPasswdData != NULL) {
566 [VNCBridge performSelectorOnMainThread:@selector(registerClient) withObject:nil waitUntilDone:YES];
567 client->clientGoneHook = &VNCDisconnect;
568 return RFB_CLIENT_ACCEPT;
574 [VNCBridge performSelectorOnMainThread:@selector(askForConnection) withObject:nil waitUntilDone:NO];
575 while (action_ == RFB_CLIENT_ON_HOLD)
577 rfbNewClientAction action(action_);
578 action_ = RFB_CLIENT_ON_HOLD;
581 if (action == RFB_CLIENT_ACCEPT)
582 client->clientGoneHook = &VNCDisconnect;
586 extern "C" bool GSSystemHasCapability(NSString *);
588 static CFTypeRef (*$GSSystemCopyCapability)(CFStringRef);
589 static CFTypeRef (*$GSSystemGetCapability)(CFStringRef);
591 static void VNCSetup() {
594 @synchronized (condition_) {
596 char *arg0(strdup("VNCServer"));
597 char *argv[] = {arg0, NULL};
598 screen_ = rfbGetScreen(&argc, argv, width_, height_, BitsPerSample, 3, BytesPerPixel);
604 screen_->desktopName = strdup([[[NSProcessInfo processInfo] hostName] UTF8String]);
606 screen_->alwaysShared = TRUE;
607 screen_->handleEventsEagerly = TRUE;
608 screen_->deferUpdateTime = 1000 / 25;
610 screen_->serverFormat.redShift = BitsPerSample * 2;
611 screen_->serverFormat.greenShift = BitsPerSample * 1;
612 screen_->serverFormat.blueShift = BitsPerSample * 0;
614 $GSSystemCopyCapability = reinterpret_cast<CFTypeRef (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemCopyCapability"));
615 $GSSystemGetCapability = reinterpret_cast<CFTypeRef (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemGetCapability"));
619 if ($GSSystemCopyCapability != NULL) {
620 opengles2 = (*$GSSystemCopyCapability)(CFSTR("opengles-2"));
621 } else if ($GSSystemGetCapability != NULL) {
622 opengles2 = (*$GSSystemGetCapability)(CFSTR("opengles-2"));
623 if (opengles2 != NULL)
628 bool accelerated(opengles2 != NULL && [(NSNumber *)opengles2 boolValue]);
631 CoreSurfaceAcceleratorCreate(NULL, NULL, &accelerator_);
633 if (opengles2 != NULL)
634 CFRelease(opengles2);
636 if (accelerator_ != NULL)
637 buffer_ = CoreSurfaceBufferCreate((CFDictionaryRef) [NSDictionary dictionaryWithObjectsAndKeys:
638 @"PurpleEDRAM", kCoreSurfaceBufferMemoryRegion,
639 [NSNumber numberWithBool:YES], kCoreSurfaceBufferGlobal,
640 [NSNumber numberWithInt:(width_ * BytesPerPixel)], kCoreSurfaceBufferPitch,
641 [NSNumber numberWithInt:width_], kCoreSurfaceBufferWidth,
642 [NSNumber numberWithInt:height_], kCoreSurfaceBufferHeight,
643 [NSNumber numberWithInt:'BGRA'], kCoreSurfaceBufferPixelFormat,
644 [NSNumber numberWithInt:(width_ * height_ * BytesPerPixel)], kCoreSurfaceBufferAllocSize,
649 //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));
651 CoreSurfaceBufferLock(buffer_, 3);
652 screen_->frameBuffer = reinterpret_cast<char *>(CoreSurfaceBufferGetBaseAddress(buffer_));
653 CoreSurfaceBufferUnlock(buffer_);
655 screen_->kbdAddEvent = &VNCKeyboard;
656 screen_->ptrAddEvent = &VNCPointer;
658 screen_->newClientHook = &VNCClient;
659 screen_->passwordCheck = &VNCCheck;
661 screen_->cursor = NULL;
664 static void VNCEnabled() {
668 if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.Veency.plist", NSHomeDirectory()]])
669 if (NSNumber *number = [settings objectForKey:@"Enabled"])
670 enabled = [number boolValue];
672 if (enabled != running_)
675 screen_->socketState = RFB_SOCKET_INIT;
676 rfbInitServer(screen_);
677 rfbRunEventLoop(screen_, -1, true);
679 rfbShutdownServer(screen_, true);
686 static void VNCNotifyEnabled(
687 CFNotificationCenterRef center,
696 void (*$IOMobileFramebufferIsMainDisplay)(IOMobileFramebufferRef, int *);
698 static IOMobileFramebufferRef main_;
699 static CoreSurfaceBufferRef layer_;
701 static void OnLayer(IOMobileFramebufferRef fb, CoreSurfaceBufferRef layer) {
702 if (_unlikely(width_ == 0 || height_ == 0)) {
704 IOMobileFramebufferGetDisplaySize(fb, &size);
707 height_ = size.height;
709 if (width_ == 0 || height_ == 0)
712 NSThread *thread([NSThread alloc]);
715 initWithTarget:[VNCBridge class]
716 selector:@selector(performSetup:)
721 } else if (_unlikely(clients_ != 0)) {
723 if (accelerator_ != NULL)
724 memset(screen_->frameBuffer, 0, sizeof(rfbPixel) * width_ * height_);
728 if (accelerator_ != NULL)
729 CoreSurfaceAcceleratorTransferSurface(accelerator_, layer, buffer_, options_);
731 CoreSurfaceBufferLock(layer, 2);
732 rfbPixel *data(reinterpret_cast<rfbPixel *>(CoreSurfaceBufferGetBaseAddress(layer)));
734 CoreSurfaceBufferFlushProcessorCaches(layer);
736 /*rfbPixel corner(data[0]);
740 screen_->frameBuffer = const_cast<char *>(reinterpret_cast<volatile char *>(data));
741 CoreSurfaceBufferUnlock(layer);
745 rfbMarkRectAsModified(screen_, 0, 0, width_, height_);
749 static bool wait_ = false;
751 MSHook(kern_return_t, IOMobileFramebufferSwapSetLayer,
752 IOMobileFramebufferRef fb,
754 CoreSurfaceBufferRef buffer,
761 if (_unlikely(buffer == NULL))
763 else if (_unlikely(fb == NULL))
765 else if ($IOMobileFramebufferIsMainDisplay == NULL)
768 (*$IOMobileFramebufferIsMainDisplay)(fb, &main);
778 return _IOMobileFramebufferSwapSetLayer(fb, layer, buffer, bounds, frame, flags);
781 // XXX: beg rpetrich for the type of this function
782 extern "C" void *IOMobileFramebufferSwapWait(IOMobileFramebufferRef, void *, unsigned);
784 MSHook(void *, IOMobileFramebufferSwapWait, IOMobileFramebufferRef fb, void *arg1, unsigned flags) {
785 void *value(_IOMobileFramebufferSwapWait(fb, arg1, flags));
791 MSHook(void, rfbRegisterSecurityHandler, rfbSecurityHandler *handler) {
792 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
794 @synchronized (lock_) {
795 [handlers_ addObject:[NSValue valueWithPointer:handler]];
796 _rfbRegisterSecurityHandler(handler);
802 template <typename Type_>
803 static void dlset(Type_ &function, const char *name) {
804 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
808 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
810 MSHookSymbol(GSTakePurpleSystemEventPort, "_GSGetPurpleSystemEventPort");
811 if (GSTakePurpleSystemEventPort == NULL) {
812 MSHookSymbol(GSTakePurpleSystemEventPort, "_GSCopyPurpleSystemEventPort");
813 PurpleAllocated = true;
816 if (dlsym(RTLD_DEFAULT, "GSLibraryCopyGenerationInfoValueForKey") != NULL)
818 else if (dlsym(RTLD_DEFAULT, "GSKeyboardCreate") != NULL)
820 else if (dlsym(RTLD_DEFAULT, "GSEventGetWindowContextId") != NULL)
826 sysctlbyname("hw.machine", NULL, &size, NULL, 0);
828 sysctlbyname("hw.machine", machine, &size, NULL, 0);
829 iPad1_ = strcmp(machine, "iPad1,1") == 0;
831 dlset($GSEventCreateKeyEvent, "GSEventCreateKeyEvent");
832 dlset($GSCreateSyntheticKeyEvent, "_GSCreateSyntheticKeyEvent");
833 dlset($IOMobileFramebufferIsMainDisplay, "IOMobileFramebufferIsMainDisplay");
835 MSHookFunction(&IOMobileFramebufferSwapSetLayer, MSHake(IOMobileFramebufferSwapSetLayer));
836 MSHookFunction(&rfbRegisterSecurityHandler, MSHake(rfbRegisterSecurityHandler));
839 MSHookFunction(&IOMobileFramebufferSwapWait, MSHake(IOMobileFramebufferSwapWait));
841 if ($SBAlertItem != nil) {
842 $VNCAlertItem = objc_allocateClassPair($SBAlertItem, "VNCAlertItem", 0);
843 MSAddMessage2(VNCAlertItem, "v@:@i", alertSheet,buttonClicked);
844 MSAddMessage2(VNCAlertItem, "v@:cc", configure,requirePasscodeForActions);
845 MSAddMessage0(VNCAlertItem, "v@:", performUnlockAction);
846 objc_registerClassPair($VNCAlertItem);
849 CFNotificationCenterAddObserver(
850 CFNotificationCenterGetDarwinNotifyCenter(),
851 NULL, &VNCNotifyEnabled, CFSTR("com.saurik.Veency-Enabled"), NULL, 0
854 CFNotificationCenterAddObserver(
855 CFNotificationCenterGetDarwinNotifyCenter(),
856 NULL, &VNCNotifySettings, CFSTR("com.saurik.Veency-Settings"), NULL, 0
859 condition_ = [[NSCondition alloc] init];
860 lock_ = [[NSLock alloc] init];
861 handlers_ = [[NSMutableSet alloc] init];
866 cfTrue_ = CFDataCreate(kCFAllocatorDefault, reinterpret_cast<UInt8 *>(&value), sizeof(value));
869 cfFalse_ = CFDataCreate(kCFAllocatorDefault, reinterpret_cast<UInt8 *>(&value), sizeof(value));
871 cfEvent_ = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast<UInt8 *>(&event_), sizeof(event_), kCFAllocatorNull);
873 options_ = (CFDictionaryRef) [[NSDictionary dictionaryWithObjectsAndKeys: