]> git.saurik.com Git - veency.git/blob - Tweak.mm
c3898efbb54f8206bcc758f63f1eab6e6def0052
[veency.git] / Tweak.mm
1 /* Veency - VNC Remote Access Server for iPhoneOS
2 * Copyright (C) 2008-2010 Jay Freeman (saurik)
3 */
4
5 /*
6 * Redistribution and use in source and binary
7 * forms, with or without modification, are permitted
8 * provided that the following conditions are met:
9 *
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
17 * distribution.
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.
21 *
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.
36 */
37
38 #define _trace() \
39 fprintf(stderr, "_trace()@%s:%u[%s]\n", __FILE__, __LINE__, __FUNCTION__)
40 #define _unlikely(expr) \
41 __builtin_expect(expr, 0)
42
43 #include <substrate.h>
44
45 #include <rfb/rfb.h>
46 #include <rfb/keysym.h>
47
48 #include <mach/mach_port.h>
49 #include <sys/mman.h>
50
51 #import <QuartzCore/CAWindowServer.h>
52 #import <QuartzCore/CAWindowServerDisplay.h>
53
54 #import <CoreGraphics/CGGeometry.h>
55 #import <GraphicsServices/GraphicsServices.h>
56 #import <Foundation/Foundation.h>
57 #import <IOMobileFramebuffer/IOMobileFramebuffer.h>
58 #import <IOKit/IOKitLib.h>
59 #import <UIKit/UIKit.h>
60
61 #import <SpringBoard/SBAlertItemsController.h>
62 #import <SpringBoard/SBDismissOnlyAlertItem.h>
63 #import <SpringBoard/SBStatusBarController.h>
64
65 extern "C" void CoreSurfaceBufferFlushProcessorCaches(CoreSurfaceBufferRef buffer);
66
67 static size_t width_;
68 static size_t height_;
69
70 static const size_t BytesPerPixel = 4;
71 static const size_t BitsPerSample = 8;
72
73 static CoreSurfaceAcceleratorRef accelerator_;
74 static CoreSurfaceBufferRef buffer_;
75 static CFDictionaryRef options_;
76
77 static NSMutableSet *handlers_;
78 static rfbScreenInfoPtr screen_;
79 static bool running_;
80 static int buttons_;
81 static int x_, y_;
82
83 static unsigned clients_;
84
85 static CFMessagePortRef ashikase_;
86 static bool cursor_;
87
88 static bool Ashikase(bool always) {
89 if (!always && !cursor_)
90 return false;
91
92 if (ashikase_ == NULL)
93 ashikase_ = CFMessagePortCreateRemote(kCFAllocatorDefault, CFSTR("jp.ashikase.mousesupport"));
94 if (ashikase_ != NULL)
95 return true;
96
97 cursor_ = false;
98 return false;
99 }
100
101 static CFDataRef cfTrue_;
102 static CFDataRef cfFalse_;
103
104 typedef struct {
105 float x, y;
106 int buttons;
107 BOOL absolute;
108 } MouseEvent;
109
110 static MouseEvent event_;
111 static CFDataRef cfEvent_;
112
113 typedef enum {
114 MouseMessageTypeEvent,
115 MouseMessageTypeSetEnabled
116 } MouseMessageType;
117
118 static void AshikaseSendEvent(float x, float y, int buttons = 0) {
119 event_.x = x;
120 event_.y = y;
121 event_.buttons = buttons;
122 event_.absolute = true;
123
124 CFMessagePortSendRequest(ashikase_, MouseMessageTypeEvent, cfEvent_, 0, 0, NULL, NULL);
125 }
126
127 static void AshikaseSetEnabled(bool enabled, bool always) {
128 if (!Ashikase(always))
129 return;
130
131 CFMessagePortSendRequest(ashikase_, MouseMessageTypeSetEnabled, enabled ? cfTrue_ : cfFalse_, 0, 0, NULL, NULL);
132
133 if (enabled)
134 AshikaseSendEvent(x_, y_);
135 }
136
137 MSClassHook(SBAlertItemsController)
138 MSClassHook(SBStatusBarController)
139
140 @class VNCAlertItem;
141 static Class $VNCAlertItem;
142
143 static rfbNewClientAction action_ = RFB_CLIENT_ON_HOLD;
144 static NSCondition *condition_;
145 static NSLock *lock_;
146
147 static rfbClientPtr client_;
148
149 @interface VNCBridge : NSObject {
150 }
151
152 + (void) askForConnection;
153 + (void) removeStatusBarItem;
154 + (void) registerClient;
155
156 @end
157
158 @implementation VNCBridge
159
160 + (void) askForConnection {
161 [[$SBAlertItemsController sharedInstance] activateAlertItem:[[[$VNCAlertItem alloc] init] autorelease]];
162 }
163
164 + (void) removeStatusBarItem {
165 AshikaseSetEnabled(false, false);
166 [[$SBStatusBarController sharedStatusBarController] removeStatusBarItem:@"Veency"];
167 }
168
169 + (void) registerClient {
170 ++clients_;
171 AshikaseSetEnabled(true, false);
172 [[$SBStatusBarController sharedStatusBarController] addStatusBarItem:@"Veency"];
173 }
174
175 @end
176
177 MSInstanceMessage2(void, VNCAlertItem, alertSheet,buttonClicked, id, sheet, int, button) {
178 [condition_ lock];
179
180 switch (button) {
181 case 1:
182 action_ = RFB_CLIENT_ACCEPT;
183
184 @synchronized (condition_) {
185 [VNCBridge registerClient];
186 }
187 break;
188
189 case 2:
190 action_ = RFB_CLIENT_REFUSE;
191 break;
192 }
193
194 [condition_ signal];
195 [condition_ unlock];
196 [self dismiss];
197 }
198
199 MSInstanceMessage2(void, VNCAlertItem, configure,requirePasscodeForActions, BOOL, configure, BOOL, require) {
200 UIModalView *sheet([self alertSheet]);
201 [sheet setDelegate:self];
202 [sheet setTitle:@"Remote Access Request"];
203 [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]];
204 [sheet addButtonWithTitle:@"Accept"];
205 [sheet addButtonWithTitle:@"Reject"];
206 }
207
208 MSInstanceMessage0(void, VNCAlertItem, performUnlockAction) {
209 [[$SBAlertItemsController sharedInstance] activateAlertItem:self];
210 }
211
212 static mach_port_t (*GSTakePurpleSystemEventPort)(void);
213 static bool PurpleAllocated;
214 static int Level_;
215
216 static void FixRecord(GSEventRecord *record) {
217 if (Level_ < 1)
218 memmove(&record->windowContextId, &record->windowContextId + 1, sizeof(*record) - (reinterpret_cast<uint8_t *>(&record->windowContextId + 1) - reinterpret_cast<uint8_t *>(record)) + record->size);
219 }
220
221 static void VNCSettings() {
222 NSDictionary *settings([NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.Veency.plist", NSHomeDirectory()]]);
223
224 @synchronized (lock_) {
225 for (NSValue *handler in handlers_)
226 rfbUnregisterSecurityHandler(reinterpret_cast<rfbSecurityHandler *>([handler pointerValue]));
227 [handlers_ removeAllObjects];
228 }
229
230 @synchronized (condition_) {
231 if (screen_ == NULL)
232 return;
233
234 [reinterpret_cast<NSString *>(screen_->authPasswdData) release];
235 screen_->authPasswdData = NULL;
236
237 if (settings != nil)
238 if (NSString *password = [settings objectForKey:@"Password"])
239 if ([password length] != 0)
240 screen_->authPasswdData = [password retain];
241
242 NSNumber *cursor = [settings objectForKey:@"ShowCursor"];
243 cursor_ = cursor == nil ? true : [cursor boolValue];
244
245 if (clients_ != 0)
246 AshikaseSetEnabled(cursor_, true);
247 }
248 }
249
250 static void VNCNotifySettings(
251 CFNotificationCenterRef center,
252 void *observer,
253 CFStringRef name,
254 const void *object,
255 CFDictionaryRef info
256 ) {
257 VNCSettings();
258 }
259
260 static rfbBool VNCCheck(rfbClientPtr client, const char *data, int size) {
261 @synchronized (condition_) {
262 if (NSString *password = reinterpret_cast<NSString *>(screen_->authPasswdData)) {
263 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
264 rfbEncryptBytes(client->authChallenge, const_cast<char *>([password UTF8String]));
265 bool good(memcmp(client->authChallenge, data, size) == 0);
266 [pool release];
267 return good;
268 } return TRUE;
269 }
270 }
271
272 static void VNCPointer(int buttons, int x, int y, rfbClientPtr client) {
273 CGPoint location = {x, y};
274
275 if (Level_ == 2) {
276 int t(x);
277 x = height_ - 1 - y;
278 y = t;
279 }
280
281 x_ = x; y_ = y;
282 int diff = buttons_ ^ buttons;
283 bool twas((buttons_ & 0x1) != 0);
284 bool tis((buttons & 0x1) != 0);
285 buttons_ = buttons;
286
287 rfbDefaultPtrAddEvent(buttons, x, y, client);
288
289 if (Ashikase(false)) {
290 AshikaseSendEvent(x, y, buttons);
291 return;
292 }
293
294 mach_port_t purple(0);
295
296 if ((diff & 0x10) != 0) {
297 struct GSEventRecord record;
298
299 memset(&record, 0, sizeof(record));
300
301 record.type = (buttons & 0x4) != 0 ?
302 GSEventTypeHeadsetButtonDown :
303 GSEventTypeHeadsetButtonUp;
304
305 record.timestamp = GSCurrentEventTimestamp();
306
307 FixRecord(&record);
308 GSSendSystemEvent(&record);
309 }
310
311 if ((diff & 0x04) != 0) {
312 struct GSEventRecord record;
313
314 memset(&record, 0, sizeof(record));
315
316 record.type = (buttons & 0x4) != 0 ?
317 GSEventTypeMenuButtonDown :
318 GSEventTypeMenuButtonUp;
319
320 record.timestamp = GSCurrentEventTimestamp();
321
322 FixRecord(&record);
323 GSSendSystemEvent(&record);
324 }
325
326 if ((diff & 0x02) != 0) {
327 struct GSEventRecord record;
328
329 memset(&record, 0, sizeof(record));
330
331 record.type = (buttons & 0x2) != 0 ?
332 GSEventTypeLockButtonDown :
333 GSEventTypeLockButtonUp;
334
335 record.timestamp = GSCurrentEventTimestamp();
336
337 FixRecord(&record);
338 GSSendSystemEvent(&record);
339 }
340
341 if (twas != tis || tis) {
342 struct {
343 struct GSEventRecord record;
344 struct {
345 struct GSEventRecordInfo info;
346 struct GSPathInfo path;
347 } data;
348 } event;
349
350 memset(&event, 0, sizeof(event));
351
352 event.record.type = GSEventTypeMouse;
353 event.record.locationInWindow.x = x;
354 event.record.locationInWindow.y = y;
355 event.record.timestamp = GSCurrentEventTimestamp();
356 event.record.size = sizeof(event.data);
357
358 event.data.info.handInfo.type = twas == tis ?
359 GSMouseEventTypeDragged :
360 tis ?
361 GSMouseEventTypeDown :
362 GSMouseEventTypeUp;
363
364 event.data.info.handInfo.x34 = 0x1;
365 event.data.info.handInfo.x38 = tis ? 0x1 : 0x0;
366
367 event.data.info.pathPositions = 1;
368
369 event.data.path.x00 = 0x01;
370 event.data.path.x01 = 0x02;
371 event.data.path.x02 = tis ? 0x03 : 0x00;
372 event.data.path.position = event.record.locationInWindow;
373
374 mach_port_t port(0);
375
376 if (CAWindowServer *server = [CAWindowServer serverIfRunning]) {
377 NSArray *displays([server displays]);
378 if (displays != nil && [displays count] != 0)
379 if (CAWindowServerDisplay *display = [displays objectAtIndex:0])
380 port = [display clientPortAtPosition:location];
381 }
382
383 if (port == 0) {
384 if (purple == 0)
385 purple = (*GSTakePurpleSystemEventPort)();
386 port = purple;
387 }
388
389 FixRecord(&event.record);
390 GSSendEvent(&event.record, port);
391 }
392
393 if (purple != 0 && PurpleAllocated)
394 mach_port_deallocate(mach_task_self(), purple);
395 }
396
397 GSEventRef (*$GSEventCreateKeyEvent)(int, CGPoint, CFStringRef, CFStringRef, id, UniChar, short, short);
398 GSEventRef (*$GSCreateSyntheticKeyEvent)(UniChar, BOOL, BOOL);
399
400 static void VNCKeyboard(rfbBool down, rfbKeySym key, rfbClientPtr client) {
401 if (!down)
402 return;
403
404 switch (key) {
405 case XK_Return: key = '\r'; break;
406 case XK_BackSpace: key = 0x7f; break;
407 }
408
409 if (key > 0xfff)
410 return;
411
412 CGPoint point(CGPointMake(x_, y_));
413
414 UniChar unicode(key);
415 CFStringRef string(NULL);
416
417 GSEventRef event0, event1(NULL);
418 if ($GSEventCreateKeyEvent != NULL) {
419 string = CFStringCreateWithCharacters(kCFAllocatorDefault, &unicode, 1);
420 event0 = (*$GSEventCreateKeyEvent)(10, point, string, string, nil, 0, 0, 1);
421 event1 = (*$GSEventCreateKeyEvent)(11, point, string, string, nil, 0, 0, 1);
422 } else if ($GSCreateSyntheticKeyEvent != NULL) {
423 event0 = (*$GSCreateSyntheticKeyEvent)(unicode, YES, YES);
424 GSEventRecord *record(_GSEventGetGSEventRecord(event0));
425 record->type = GSEventTypeKeyDown;
426 } else return;
427
428 mach_port_t port(0);
429
430 if (CAWindowServer *server = [CAWindowServer serverIfRunning]) {
431 NSArray *displays([server displays]);
432 if (displays != nil && [displays count] != 0)
433 if (CAWindowServerDisplay *display = [displays objectAtIndex:0])
434 port = [display clientPortAtPosition:point];
435 }
436
437 mach_port_t purple(0);
438
439 if (port == 0) {
440 if (purple == 0)
441 purple = (*GSTakePurpleSystemEventPort)();
442 port = purple;
443 }
444
445 if (port != 0) {
446 GSSendEvent(_GSEventGetGSEventRecord(event0), port);
447 if (event1 != NULL)
448 GSSendEvent(_GSEventGetGSEventRecord(event1), port);
449 }
450
451 if (purple != 0 && PurpleAllocated)
452 mach_port_deallocate(mach_task_self(), purple);
453
454 CFRelease(event0);
455 if (event1 != NULL)
456 CFRelease(event1);
457 if (string != NULL)
458 CFRelease(string);
459 }
460
461 static void VNCDisconnect(rfbClientPtr client) {
462 @synchronized (condition_) {
463 if (--clients_ == 0)
464 [VNCBridge performSelectorOnMainThread:@selector(removeStatusBarItem) withObject:nil waitUntilDone:YES];
465 }
466 }
467
468 static rfbNewClientAction VNCClient(rfbClientPtr client) {
469 @synchronized (condition_) {
470 if (screen_->authPasswdData != NULL) {
471 [VNCBridge performSelectorOnMainThread:@selector(registerClient) withObject:nil waitUntilDone:YES];
472 client->clientGoneHook = &VNCDisconnect;
473 return RFB_CLIENT_ACCEPT;
474 }
475 }
476
477 [condition_ lock];
478 client_ = client;
479 [VNCBridge performSelectorOnMainThread:@selector(askForConnection) withObject:nil waitUntilDone:NO];
480 while (action_ == RFB_CLIENT_ON_HOLD)
481 [condition_ wait];
482 rfbNewClientAction action(action_);
483 action_ = RFB_CLIENT_ON_HOLD;
484 [condition_ unlock];
485
486 if (action == RFB_CLIENT_ACCEPT)
487 client->clientGoneHook = &VNCDisconnect;
488 return action;
489 }
490
491 static void VNCSetup() {
492 rfbLogEnable(false);
493
494 @synchronized (condition_) {
495 int argc(1);
496 char *arg0(strdup("VNCServer"));
497 char *argv[] = {arg0, NULL};
498 screen_ = rfbGetScreen(&argc, argv, width_, height_, BitsPerSample, 3, BytesPerPixel);
499 free(arg0);
500
501 VNCSettings();
502 }
503
504 screen_->desktopName = strdup([[[NSProcessInfo processInfo] hostName] UTF8String]);
505
506 screen_->alwaysShared = TRUE;
507 screen_->handleEventsEagerly = TRUE;
508 screen_->deferUpdateTime = 1000 / 25;
509
510 screen_->serverFormat.redShift = BitsPerSample * 2;
511 screen_->serverFormat.greenShift = BitsPerSample * 1;
512 screen_->serverFormat.blueShift = BitsPerSample * 0;
513
514 buffer_ = CoreSurfaceBufferCreate((CFDictionaryRef) [NSDictionary dictionaryWithObjectsAndKeys:
515 @"PurpleEDRAM", kCoreSurfaceBufferMemoryRegion,
516 [NSNumber numberWithBool:YES], kCoreSurfaceBufferGlobal,
517 [NSNumber numberWithInt:(width_ * BytesPerPixel)], kCoreSurfaceBufferPitch,
518 [NSNumber numberWithInt:width_], kCoreSurfaceBufferWidth,
519 [NSNumber numberWithInt:height_], kCoreSurfaceBufferHeight,
520 [NSNumber numberWithInt:'BGRA'], kCoreSurfaceBufferPixelFormat,
521 [NSNumber numberWithInt:(width_ * height_ * BytesPerPixel)], kCoreSurfaceBufferAllocSize,
522 nil]);
523
524 //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));
525
526 CoreSurfaceBufferLock(buffer_, 3);
527 screen_->frameBuffer = reinterpret_cast<char *>(CoreSurfaceBufferGetBaseAddress(buffer_));
528 CoreSurfaceBufferUnlock(buffer_);
529
530 screen_->kbdAddEvent = &VNCKeyboard;
531 screen_->ptrAddEvent = &VNCPointer;
532
533 screen_->newClientHook = &VNCClient;
534 screen_->passwordCheck = &VNCCheck;
535
536 screen_->cursor = NULL;
537 }
538
539 static void VNCEnabled() {
540 [lock_ lock];
541
542 bool enabled(true);
543 if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.Veency.plist", NSHomeDirectory()]])
544 if (NSNumber *number = [settings objectForKey:@"Enabled"])
545 enabled = [number boolValue];
546
547 if (enabled != running_)
548 if (enabled) {
549 running_ = true;
550 screen_->socketState = RFB_SOCKET_INIT;
551 rfbInitServer(screen_);
552 rfbRunEventLoop(screen_, -1, true);
553 } else {
554 rfbShutdownServer(screen_, true);
555 running_ = false;
556 }
557
558 [lock_ unlock];
559 }
560
561 static void VNCNotifyEnabled(
562 CFNotificationCenterRef center,
563 void *observer,
564 CFStringRef name,
565 const void *object,
566 CFDictionaryRef info
567 ) {
568 VNCEnabled();
569 }
570
571 MSHook(kern_return_t, IOMobileFramebufferSwapSetLayer,
572 IOMobileFramebufferRef fb,
573 int layer,
574 CoreSurfaceBufferRef buffer,
575 CGRect bounds,
576 CGRect frame,
577 int flags
578 ) {
579 if (_unlikely(screen_ == NULL)) {
580 CGSize size;
581 IOMobileFramebufferGetDisplaySize(fb, &size);
582
583 width_ = size.width;
584 height_ = size.height;
585
586 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
587 VNCSetup();
588 VNCEnabled();
589 [pool release];
590 } else if (_unlikely(clients_ != 0)) {
591 if (buffer == NULL) {
592 //CoreSurfaceBufferLock(buffer_, 3);
593 memset(screen_->frameBuffer, 0, sizeof(rfbPixel) * width_ * height_);
594 //CoreSurfaceBufferUnlock(buffer_);
595 } else {
596 //CoreSurfaceBufferLock(buffer_, 3);
597 //CoreSurfaceBufferLock(buffer, 2);
598
599 //rfbPixel *data(reinterpret_cast<rfbPixel *>(CoreSurfaceBufferGetBaseAddress(buffer)));
600
601 /*rfbPixel corner(data[0]);
602 data[0] = 0;
603 data[0] = corner;*/
604
605 CoreSurfaceAcceleratorTransferSurface(accelerator_, buffer, buffer_, options_);
606
607 //CoreSurfaceBufferUnlock(buffer);
608 //CoreSurfaceBufferUnlock(buffer_);
609 }
610
611 //CoreSurfaceBufferFlushProcessorCaches(buffer);
612 rfbMarkRectAsModified(screen_, 0, 0, width_, height_);
613 }
614
615 return _IOMobileFramebufferSwapSetLayer(fb, layer, buffer, bounds, frame, flags);
616 }
617
618 MSHook(void, rfbRegisterSecurityHandler, rfbSecurityHandler *handler) {
619 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
620
621 @synchronized (lock_) {
622 [handlers_ addObject:[NSValue valueWithPointer:handler]];
623 _rfbRegisterSecurityHandler(handler);
624 }
625
626 [pool release];
627 }
628
629 template <typename Type_>
630 static void dlset(Type_ &function, const char *name) {
631 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
632 }
633
634 MSInitialize {
635 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
636
637 MSHookSymbol(GSTakePurpleSystemEventPort, "GSGetPurpleSystemEventPort");
638 if (GSTakePurpleSystemEventPort == NULL) {
639 MSHookSymbol(GSTakePurpleSystemEventPort, "GSCopyPurpleSystemEventPort");
640 PurpleAllocated = true;
641 }
642
643 if (dlsym(RTLD_DEFAULT, "GSKeyboardCreate") != NULL)
644 Level_ = 2;
645 else if (dlsym(RTLD_DEFAULT, "GSEventGetWindowContextId") != NULL)
646 Level_ = 1;
647 else
648 Level_ = 0;
649
650 dlset($GSEventCreateKeyEvent, "GSEventCreateKeyEvent");
651 dlset($GSCreateSyntheticKeyEvent, "_GSCreateSyntheticKeyEvent");
652
653 MSHookFunction(&IOMobileFramebufferSwapSetLayer, MSHake(IOMobileFramebufferSwapSetLayer));
654 MSHookFunction(&rfbRegisterSecurityHandler, MSHake(rfbRegisterSecurityHandler));
655
656 $VNCAlertItem = objc_allocateClassPair(objc_getClass("SBAlertItem"), "VNCAlertItem", 0);
657 MSAddMessage2(VNCAlertItem, "v@:@i", alertSheet,buttonClicked);
658 MSAddMessage2(VNCAlertItem, "v@:cc", configure,requirePasscodeForActions);
659 MSAddMessage0(VNCAlertItem, "v@:", performUnlockAction);
660 objc_registerClassPair($VNCAlertItem);
661
662 CFNotificationCenterAddObserver(
663 CFNotificationCenterGetDarwinNotifyCenter(),
664 NULL, &VNCNotifyEnabled, CFSTR("com.saurik.Veency-Enabled"), NULL, 0
665 );
666
667 CFNotificationCenterAddObserver(
668 CFNotificationCenterGetDarwinNotifyCenter(),
669 NULL, &VNCNotifySettings, CFSTR("com.saurik.Veency-Settings"), NULL, 0
670 );
671
672 condition_ = [[NSCondition alloc] init];
673 lock_ = [[NSLock alloc] init];
674 handlers_ = [[NSMutableSet alloc] init];
675
676 bool value;
677
678 value = true;
679 cfTrue_ = CFDataCreate(kCFAllocatorDefault, reinterpret_cast<UInt8 *>(&value), sizeof(value));
680
681 value = false;
682 cfFalse_ = CFDataCreate(kCFAllocatorDefault, reinterpret_cast<UInt8 *>(&value), sizeof(value));
683
684 cfEvent_ = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast<UInt8 *>(&event_), sizeof(event_), kCFAllocatorNull);
685
686 CoreSurfaceAcceleratorCreate(NULL, NULL, &accelerator_);
687
688 options_ = (CFDictionaryRef) [[NSDictionary dictionaryWithObjectsAndKeys:
689 nil] retain];
690
691 [pool release];
692 }