Browse Source

long overdue update

Kevin Bradley 4 years ago
parent
commit
e1b2a8e0c2

+ 1 - 1
AppEnabler/Makefile

@@ -12,7 +12,7 @@ AppEnabler_FILES = Whitelist.xm
 AppEnabler_LIBRARIES = substrate 
 AppEnabler_FRAMEWORKS = Foundation UIKit CoreGraphics MobileCoreServices
 #AppEnabler_LDFLAGS = -undefined dynamic_lookup
-AppEnabler_CODESIGN=ldid2
+AppEnabler_CODESIGN=ldid
 #AppEnabler_LIBRARIES += rocketbootstrap
 AppEnabler_CODESIGN_FLAGS=-Slibrespring.xml
 #AppEnabler_USE_SUBSTRATE=0

+ 22 - 1
AppEnabler/Whitelist.xm

@@ -131,7 +131,9 @@
 
         Class powermanager = objc_getClass("PBSPowerManager");
         id power = [powermanager sharedInstance];
-        [power _performUserEventWakeDevice];
+        if ([power respondsToSelector:@selector(_performUserEventWakeDevice)]){
+            [power _performUserEventWakeDevice];
+        }
         [power wakeDeviceWithOptions:@{@"WakeReason":@"UserActivity"}];
 
 }
@@ -205,4 +207,23 @@
 }
 
 
+%end
+
+%hook PBAppInfo
+
+- (BOOL)isEnabled {
+    //%log;
+    return true;
+}
+
+%end
+
+%hook PBSAppState
+
++ (BOOL)isEnabledForApplicationWithIdentifier:(id)ident {
+
+    //%log;
+    return YES;
+}
+
 %end

+ 3 - 2
Makefile

@@ -4,7 +4,7 @@ export GO_EASY_ON_ME=1
 export SDKVERSION=10.1
 TARGET=appletv:clang:10.1:10.1
 SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS10.1.sdk
-THEOS_DEVICE_IP=bedroom.local
+THEOS_DEVICE_IP=guest-room.local
 
 include theos/makefiles/common.mk
 
@@ -14,7 +14,7 @@ librespring_LIBRARIES = substrate
 #librespring_LIBRARIES += rocketbootstrap
 librespring_FRAMEWORKS = Foundation UIKit CoreGraphics
 #librespring_CODESIGN_FLAGS=-Slibrespring.xml
-librespring_CODESIGN=ldid2
+librespring_CODESIGN=ldid
 librespring_Frameworks += WebCore ImageIO Foundation CFNetwork AppSupport UIKit IOKit MobileCoreServices
 #librespring_PRIVATE_FRAMEWORKS = GraphicsServices FMCore
 
@@ -22,6 +22,7 @@ include $(THEOS_MAKE_PATH)/library.mk
 
 SUBPROJECTS += uicache
 SUBPROJECTS += AppEnabler
+#SUBPROJECTS += BlockReset
 #SUBPROJECTS += libsubstrate
 
 include $(THEOS_MAKE_PATH)/aggregate.mk

+ 1 - 1
PBReloadHelper.m

@@ -10,7 +10,7 @@
 
 #import "NSTask.h"
 #import <objc/runtime.h>
-#import "rocketbootstrap.h"
+//#import "rocketbootstrap.h"
 #import "AppSupport/CPDistributedMessagingCenter.h"
 
 @interface LSApplicationProxy : NSObject

+ 1 - 1
theos/makefiles/targets/Darwin-arm/iphone.mk

@@ -82,7 +82,7 @@ TARGET_LD ?= $(_THEOS_TARGET_CXX)
 TARGET_STRIP ?= strip
 TARGET_STRIP_FLAGS ?= -x
 TARGET_CODESIGN_ALLOCATE ?= codesign_allocate
-TARGET_CODESIGN ?= ldid2
+TARGET_CODESIGN ?= ldid
 TARGET_CODESIGN_FLAGS ?= -S
 
 TARGET_PRIVATE_FRAMEWORK_PATH = $(SYSROOT)/System/Library/PrivateFrameworks

+ 1 - 1
theos/makefiles/targets/Darwin/appletv.mk

@@ -42,7 +42,7 @@ ISYSROOT ?= $(SYSROOT)
 endif
 
 TARGET_STRIP_FLAGS ?= -x
-TARGET_CODESIGN ?= ldid2
+TARGET_CODESIGN ?= ldid
 TARGET_CODESIGN_FLAGS ?= -S
 
 TARGET_PRIVATE_FRAMEWORK_PATH = $(SYSROOT)/System/Library/PrivateFrameworks

+ 1 - 1
theos/makefiles/targets/Darwin/iphone.mk

@@ -82,7 +82,7 @@ TARGET_LD ?= xcrun -sdk iphoneos $(_THEOS_TARGET_CXX)
 TARGET_STRIP ?= xcrun -sdk iphoneos strip
 TARGET_STRIP_FLAGS ?= -x
 TARGET_CODESIGN_ALLOCATE ?= "$(shell xcrun -sdk iphoneos -find codesign_allocate)"
-TARGET_CODESIGN ?= ldid2
+TARGET_CODESIGN ?= ldid
 TARGET_CODESIGN_FLAGS ?= -S
 
 TARGET_PRIVATE_FRAMEWORK_PATH = $(SYSROOT)/System/Library/PrivateFrameworks

+ 1 - 1
theos/makefiles/targets/Linux/iphone.mk

@@ -87,7 +87,7 @@ TARGET_LD ?= $(PREFIX)$(_THEOS_TARGET_CXX)
 TARGET_STRIP ?= $(PREFIX)strip
 TARGET_STRIP_FLAGS ?= -x
 TARGET_CODESIGN_ALLOCATE ?= $(PREFIX)codesign_allocate
-TARGET_CODESIGN ?= $(SDKBINPATH)/ldid2
+TARGET_CODESIGN ?= $(SDKBINPATH)/ldid
 TARGET_CODESIGN_FLAGS ?= -S
 
 TARGET_PRIVATE_FRAMEWORK_PATH = $(SYSROOT)/System/Library/PrivateFrameworks

+ 1 - 1
theos/makefiles/targets/Windows/iphone.mk

@@ -87,7 +87,7 @@ TARGET_LD ?= $(PREFIX)$(_THEOS_TARGET_CXX)
 TARGET_STRIP ?= $(PREFIX)strip
 TARGET_STRIP_FLAGS ?= -x
 TARGET_CODESIGN_ALLOCATE ?= $(PREFIX)codesign_allocate
-TARGET_CODESIGN ?= $(SDKBINPATH)/ldid2
+TARGET_CODESIGN ?= $(SDKBINPATH)/ldid
 TARGET_CODESIGN_FLAGS ?= -S
 
 TARGET_PRIVATE_FRAMEWORK_PATH = $(SYSROOT)/System/Library/PrivateFrameworks

+ 24 - 8
uicache/Makefile

@@ -1,15 +1,17 @@
 IPHONE_ARCHS = arm64
-TARGET = appletv
+TARGET = appletv:10.2.2:10.0
 export GO_EASY_ON_ME=1
 #TARGET_IPHONEOS_DEPLOYMENT_VERSION = 6.0
 DEBUG = 0
+ARCHS=arm64
 include $(THEOS)/makefiles/common.mk
 TOOL_NAME = uicache
-uicache_FILES = uicache.m
-uicache_CFLAGS += -fvisibility=hidden
+uicache_FILES = uicache.mm csstore.cpp
+uicache_CFLAGS += -fvisibility=hidden -I.
+uicache_LDFLAGS += -F. -framework PineBoardServices
 uicache_INSTALL_PATH = /usr/bin
 uicache_CODESIGN_FLAGS=-Suicache.xml
-uicache_CODESIGN=ldid2
+uicache_CODESIGN=ldid
 #uicache_LIBRARIES += rocketbootstrap
 uicache_Frameworks += WebCore ImageIO Foundation CFNetwork AppSupport UIKit IOKit MobileCoreServices
 #uicache_PRIVATE_FRAMEWORKS = GraphicsServices FMCore
@@ -17,20 +19,34 @@ uicache_USE_SUBSTRATE=0
 
 include $(THEOS_MAKE_PATH)/tool.mk
 
+ARCHS=arm64
+TARGET = appletv:10.2.2:10.0
+export GO_EASY_ON_ME=1
+#TARGET_IPHONEOS_DEPLOYMENT_VERSION = 6.0
+
+TARGET = appletv:10.2.2:10.0
 TOOL_NAME = wake
 wake_FILES = wake.m
 wake_INSTALL_PATH = /usr/bin
-wake_CODESIGN_FLAGS=-Suicache.xml
-wake_CODESIGN=ldid2
+wake_CODESIGN_FLAGS=-Ssleep.xml
+wake_CODESIGN=ldid
+#wake_CODESIGN_FLAGS=--sign platform --ent sleep.xml --inplace
+#wake_CODESIGN=jtool
 wake_FRAMEWORKS = Foundation
 
 include $(THEOS_MAKE_PATH)/tool.mk
 
+ARCHS=arm64
+TARGET = appletv:10.2.2:10.0
+export GO_EASY_ON_ME=1
+#TARGET_IPHONEOS_DEPLOYMENT_VERSION = 6.0
+
+TARGET = appletv:10.2.2:10.0
 TOOL_NAME = sleepy
 sleepy_FILES = sleep.m
 sleepy_INSTALL_PATH = /usr/bin
-sleepy_CODESIGN_FLAGS=-Suicache.xml
-sleepy_CODESIGN=ldid2
+sleepy_CODESIGN_FLAGS=-Ssleep.xml
+sleepy_CODESIGN=ldid
 sleepy_FRAMEWORKS = Foundation
 
 include $(THEOS_MAKE_PATH)/tool.mk

+ 74 - 0
uicache/NSTask.h

@@ -0,0 +1,74 @@
+/*	NSTask.h
+	Copyright (c) 1996-2007, Apple Inc. All rights reserved.
+*/
+
+#import <Foundation/NSObject.h>
+
+@class NSString, NSArray, NSDictionary;
+
+@interface NSTask : NSObject
+
+// Create an NSTask which can be run at a later time
+// An NSTask can only be run once. Subsequent attempts to
+// run an NSTask will raise.
+// Upon task death a notification will be sent
+//   { Name = NSTaskDidTerminateNotification; object = task; }
+//
+
+- (id)init;
+
+// set parameters
+// these methods can only be done before a launch
+- (void)setLaunchPath:(NSString *)path;
+- (void)setArguments:(NSArray *)arguments;
+- (void)setEnvironment:(NSDictionary *)dict;
+	// if not set, use current
+- (void)setCurrentDirectoryPath:(NSString *)path;
+	// if not set, use current
+
+// set standard I/O channels; may be either an NSFileHandle or an NSPipe
+- (void)setStandardInput:(id)input;
+- (void)setStandardOutput:(id)output;
+- (void)setStandardError:(id)error;
+
+// get parameters
+- (NSString *)launchPath;
+- (NSArray *)arguments;
+- (NSDictionary *)environment;
+- (NSString *)currentDirectoryPath;
+
+// get standard I/O channels; could be either an NSFileHandle or an NSPipe
+- (id)standardInput;
+- (id)standardOutput;
+- (id)standardError;
+
+// actions
+- (void)launch;
+
+- (void)interrupt; // Not always possible. Sends SIGINT.
+- (void)terminate; // Not always possible. Sends SIGTERM.
+
+- (BOOL)suspend;
+- (BOOL)resume;
+
+// status
+- (int)processIdentifier; 
+- (BOOL)isRunning;
+
+- (int)terminationStatus;
+@property(readonly) long long terminationReason;
+@end
+
+@interface NSTask (NSTaskConveniences)
+
++ (NSTask *)launchedTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)arguments;
+	// convenience; create and launch
+
+- (void)waitUntilExit;
+	// poll the runLoop in defaultMode until task completes
+
+@end
+
+FOUNDATION_EXPORT NSString * const NSTaskDidTerminateNotification;
+
+

+ 47 - 0
uicache/crt_externs.h

@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
+ * @APPLE_LICENSE_HEADER_END@
+ */
+/*
+ * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
+ */
+
+/*
+** Prototypes for the functions to get environment information in
+** the world of dynamic libraries. Lifted from .c file of same name.
+** Fri Jun 23 12:56:47 PDT 1995
+** AOF (afreier@next.com)
+*/
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+extern char ***_NSGetArgv(void);
+extern int *_NSGetArgc(void);
+extern char ***_NSGetEnviron(void);
+extern char **_NSGetProgname(void);
+#ifdef __LP64__
+extern struct mach_header_64 *
+#else /* !__LP64__ */
+extern struct mach_header *
+#endif /* __LP64__ */
+				_NSGetMachExecuteHeader(void);
+__END_DECLS

+ 85 - 0
uicache/csstore.cpp

@@ -0,0 +1,85 @@
+/* UIKit Tools - command-line utilities for UIKit
+ * Copyright (C) 2018-2019  Sam Bingner
+ * Copyright (C) 2008-2012  Jay Freeman (saurik)
+*/
+
+/* This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+/* Modified BSD License {{{ */
+/*
+ *        Redistribution and use in source and binary
+ * forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the
+ *    above copyright notice, this list of conditions
+ *    and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions
+ *    and the following disclaimer in the documentation
+ *    and/or other materials provided with the
+ *    distribution.
+ * 3. The name of the author may not be used to endorse
+ *    or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/* }}} */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <dirent.h>
+
+bool DeleteCSStores(const char *home) {
+    char path[strlen(home) + strlen("/Library/Caches") + 1];
+    sprintf(path, "%s/Library/Caches", home);
+
+    DIR *dir(opendir(path));
+    if (dir == NULL)
+        return false;
+
+    for (struct dirent *entry; (entry = readdir(dir)) != NULL; ) {
+        if (strncmp(entry->d_name, "com.apple.LaunchServices", sizeof("com.apple.LaunchServices") - 1) != 0)
+            continue;
+        if (!strstr(entry->d_name, ".csstore"))
+            continue;
+
+        char csstore[strlen(path) + 1 + strlen(entry->d_name) + 1];
+        snprintf(csstore, sizeof(csstore), "%s/%s", path, entry->d_name);
+        unlink(csstore);
+    }
+
+    closedir(dir);
+    return true;
+}

+ 60 - 0
uicache/csstore.hpp

@@ -0,0 +1,60 @@
+/* UIKit Tools - command-line utilities for UIKit
+ * Copyright (C) 2018-2019  Sam Bingner
+ * Copyright (C) 2008-2012  Jay Freeman (saurik)
+*/
+
+/* This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+/* Modified BSD License {{{ */
+/*
+ *        Redistribution and use in source and binary
+ * forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the
+ *    above copyright notice, this list of conditions
+ *    and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions
+ *    and the following disclaimer in the documentation
+ *    and/or other materials provided with the
+ *    distribution.
+ * 3. The name of the author may not be used to endorse
+ *    or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/* }}} */
+
+#ifndef CSSTORE_HPP
+#define CSSTORE_HPP
+
+bool DeleteCSStores(const char *home);
+
+#endif//CSSTORE_HPP

+ 350 - 0
uicache/launch.h

@@ -0,0 +1,350 @@
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_START@
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * @APPLE_APACHE_LICENSE_HEADER_END@
+ */
+
+#ifndef __LAUNCH_H__
+#define __LAUNCH_H__
+
+#include <mach/mach.h>
+#include <sys/cdefs.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+#pragma GCC visibility push(default)
+
+__BEGIN_DECLS
+
+#ifdef __GNUC__
+#define __ld_normal __attribute__((__nothrow__))
+#define __ld_setter __attribute__((__nothrow__, __nonnull__))
+#define __ld_getter __attribute__((__nothrow__, __nonnull__, __pure__, __warn_unused_result__))
+#define __ld_iterator(x, y) __attribute__((__nonnull__(x, y)))
+#define __ld_allocator __attribute__((__nothrow__, __malloc__, __nonnull__, __warn_unused_result__))
+#else
+#define __ld_normal
+#define __ld_setter
+#define __ld_getter
+#define __ld_iterator(x, y)
+#define __ld_allocator
+#endif
+
+#define LAUNCH_KEY_SUBMITJOB "SubmitJob"
+#define LAUNCH_KEY_REMOVEJOB "RemoveJob"
+#define LAUNCH_KEY_STARTJOB "StartJob"
+#define LAUNCH_KEY_STOPJOB "StopJob"
+#define LAUNCH_KEY_GETJOB "GetJob"
+#define LAUNCH_KEY_GETJOBS "GetJobs"
+#define LAUNCH_KEY_CHECKIN "CheckIn"
+
+#define LAUNCH_JOBKEY_DEFAULTS "__Defaults"
+
+#define LAUNCH_JOBKEY_LABEL "Label"
+#define LAUNCH_JOBKEY_DISABLED "Disabled"
+#define LAUNCH_JOBKEY_USERNAME "UserName"
+#define LAUNCH_JOBKEY_GROUPNAME "GroupName"
+#define LAUNCH_JOBKEY_TIMEOUT "TimeOut"
+#define LAUNCH_JOBKEY_EXITTIMEOUT "ExitTimeOut"
+#define LAUNCH_JOBKEY_INITGROUPS "InitGroups"
+#define LAUNCH_JOBKEY_SOCKETS "Sockets"
+#define LAUNCH_JOBKEY_MACHSERVICES "MachServices"
+#define LAUNCH_JOBKEY_MACHSERVICELOOKUPPOLICIES "MachServiceLookupPolicies"
+#define LAUNCH_JOBKEY_INETDCOMPATIBILITY "inetdCompatibility"
+#define LAUNCH_JOBKEY_ENABLEGLOBBING "EnableGlobbing"
+#define LAUNCH_JOBKEY_PROGRAMARGUMENTS "ProgramArguments"
+#define LAUNCH_JOBKEY_PROGRAM "Program"
+#define LAUNCH_JOBKEY_ONDEMAND "OnDemand"
+#define LAUNCH_JOBKEY_KEEPALIVE "KeepAlive"
+#define LAUNCH_JOBKEY_LIMITLOADTOHOSTS "LimitLoadToHosts"
+#define LAUNCH_JOBKEY_LIMITLOADFROMHOSTS "LimitLoadFromHosts"
+#define LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE "LimitLoadToSessionType"
+#define LAUNCH_JOBKEY_LIMITLOADTOHARDWARE "LimitLoadToHardware"
+#define LAUNCH_JOBKEY_LIMITLOADFROMHARDWARE "LimitLoadFromHardware"
+#define LAUNCH_JOBKEY_RUNATLOAD "RunAtLoad"
+#define LAUNCH_JOBKEY_ROOTDIRECTORY "RootDirectory"
+#define LAUNCH_JOBKEY_WORKINGDIRECTORY "WorkingDirectory"
+#define LAUNCH_JOBKEY_ENVIRONMENTVARIABLES "EnvironmentVariables"
+#define LAUNCH_JOBKEY_USERENVIRONMENTVARIABLES "UserEnvironmentVariables"
+#define LAUNCH_JOBKEY_UMASK "Umask"
+#define LAUNCH_JOBKEY_NICE "Nice"
+#define LAUNCH_JOBKEY_HOPEFULLYEXITSFIRST "HopefullyExitsFirst"
+#define LAUNCH_JOBKEY_HOPEFULLYEXITSLAST "HopefullyExitsLast"
+#define LAUNCH_JOBKEY_LOWPRIORITYIO "LowPriorityIO"
+#define LAUNCH_JOBKEY_SESSIONCREATE "SessionCreate"
+#define LAUNCH_JOBKEY_STARTONMOUNT "StartOnMount"
+#define LAUNCH_JOBKEY_SOFTRESOURCELIMITS "SoftResourceLimits"
+#define LAUNCH_JOBKEY_HARDRESOURCELIMITS "HardResourceLimits"
+#define LAUNCH_JOBKEY_STANDARDINPATH "StandardInPath"
+#define LAUNCH_JOBKEY_STANDARDOUTPATH "StandardOutPath"
+#define LAUNCH_JOBKEY_STANDARDERRORPATH "StandardErrorPath"
+#define LAUNCH_JOBKEY_DEBUG "Debug"
+#define LAUNCH_JOBKEY_WAITFORDEBUGGER "WaitForDebugger"
+#define LAUNCH_JOBKEY_QUEUEDIRECTORIES "QueueDirectories"
+#define LAUNCH_JOBKEY_WATCHPATHS "WatchPaths"
+#define LAUNCH_JOBKEY_STARTINTERVAL "StartInterval"
+#define LAUNCH_JOBKEY_STARTCALENDARINTERVAL "StartCalendarInterval"
+#define LAUNCH_JOBKEY_BONJOURFDS "BonjourFDs"
+#define LAUNCH_JOBKEY_LASTEXITSTATUS "LastExitStatus"
+#define LAUNCH_JOBKEY_PID "PID"
+#define LAUNCH_JOBKEY_THROTTLEINTERVAL "ThrottleInterval"
+#define LAUNCH_JOBKEY_LAUNCHONLYONCE "LaunchOnlyOnce"
+#define LAUNCH_JOBKEY_ABANDONPROCESSGROUP "AbandonProcessGroup"
+#define LAUNCH_JOBKEY_IGNOREPROCESSGROUPATSHUTDOWN	"IgnoreProcessGroupAtShutdown"
+#define LAUNCH_JOBKEY_POLICIES "Policies"
+#define LAUNCH_JOBKEY_ENABLETRANSACTIONS "EnableTransactions"
+#define LAUNCH_JOBKEY_CFBUNDLEIDENTIFIER "CFBundleIdentifier"
+#define LAUNCH_JOBKEY_PROCESSTYPE "ProcessType"
+#define LAUNCH_KEY_PROCESSTYPE_APP "App"
+#define LAUNCH_KEY_PROCESSTYPE_STANDARD "Standard"
+#define LAUNCH_KEY_PROCESSTYPE_BACKGROUND "Background"
+#define LAUNCH_KEY_PROCESSTYPE_INTERACTIVE "Interactive"
+#define LAUNCH_KEY_PROCESSTYPE_ADAPTIVE "Adaptive"
+
+#define LAUNCH_JOBPOLICY_DENYCREATINGOTHERJOBS "DenyCreatingOtherJobs"
+
+#define LAUNCH_JOBINETDCOMPATIBILITY_WAIT "Wait"
+
+#define LAUNCH_JOBKEY_MACH_RESETATCLOSE "ResetAtClose"
+#define LAUNCH_JOBKEY_MACH_HIDEUNTILCHECKIN "HideUntilCheckIn"
+#define LAUNCH_JOBKEY_MACH_DRAINMESSAGESONCRASH "DrainMessagesOnCrash"
+#define LAUNCH_JOBKEY_MACH_PINGEVENTUPDATES "PingEventUpdates"
+
+#define LAUNCH_JOBKEY_KEEPALIVE_SUCCESSFULEXIT "SuccessfulExit"
+#define LAUNCH_JOBKEY_KEEPALIVE_NETWORKSTATE "NetworkState"
+#define LAUNCH_JOBKEY_KEEPALIVE_PATHSTATE "PathState"
+#define LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBACTIVE "OtherJobActive"
+#define LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBENABLED "OtherJobEnabled"
+#define LAUNCH_JOBKEY_KEEPALIVE_AFTERINITIALDEMAND	"AfterInitialDemand"
+#define LAUNCH_JOBKEY_KEEPALIVE_CRASHED "Crashed"
+
+#define LAUNCH_JOBKEY_LAUNCHEVENTS "LaunchEvents"
+
+#define LAUNCH_JOBKEY_CAL_MINUTE "Minute"
+#define LAUNCH_JOBKEY_CAL_HOUR "Hour"
+#define LAUNCH_JOBKEY_CAL_DAY "Day"
+#define LAUNCH_JOBKEY_CAL_WEEKDAY "Weekday"
+#define LAUNCH_JOBKEY_CAL_MONTH "Month"
+
+#define LAUNCH_JOBKEY_RESOURCELIMIT_CORE "Core"
+#define LAUNCH_JOBKEY_RESOURCELIMIT_CPU "CPU"
+#define LAUNCH_JOBKEY_RESOURCELIMIT_DATA "Data"
+#define LAUNCH_JOBKEY_RESOURCELIMIT_FSIZE "FileSize"
+#define LAUNCH_JOBKEY_RESOURCELIMIT_MEMLOCK "MemoryLock"
+#define LAUNCH_JOBKEY_RESOURCELIMIT_NOFILE "NumberOfFiles"
+#define LAUNCH_JOBKEY_RESOURCELIMIT_NPROC "NumberOfProcesses"
+#define LAUNCH_JOBKEY_RESOURCELIMIT_RSS "ResidentSetSize"
+#define LAUNCH_JOBKEY_RESOURCELIMIT_STACK "Stack"
+
+#define LAUNCH_JOBKEY_DISABLED_MACHINETYPE "MachineType"
+#define LAUNCH_JOBKEY_DISABLED_MODELNAME "ModelName"
+
+#define LAUNCH_JOBSOCKETKEY_TYPE "SockType"
+#define LAUNCH_JOBSOCKETKEY_PASSIVE "SockPassive"
+#define LAUNCH_JOBSOCKETKEY_BONJOUR "Bonjour"
+#define LAUNCH_JOBSOCKETKEY_SECUREWITHKEY "SecureSocketWithKey"
+#define LAUNCH_JOBSOCKETKEY_PATHNAME "SockPathName"
+#define LAUNCH_JOBSOCKETKEY_PATHMODE "SockPathMode"
+#define LAUNCH_JOBSOCKETKEY_NODENAME "SockNodeName"
+#define LAUNCH_JOBSOCKETKEY_SERVICENAME "SockServiceName"
+#define LAUNCH_JOBSOCKETKEY_FAMILY "SockFamily"
+#define LAUNCH_JOBSOCKETKEY_PROTOCOL "SockProtocol"
+#define LAUNCH_JOBSOCKETKEY_MULTICASTGROUP "MulticastGroup"
+
+/* These APIs are NOT suitable for general use. Their use should be constrained
+ * to checking into launchd to obtain socket file descriptors using the
+ * LAUNCH_CHECK_IN message type.
+ */
+typedef struct _launch_data *launch_data_t;
+
+typedef enum {
+	LAUNCH_DATA_DICTIONARY = 1,
+	LAUNCH_DATA_ARRAY,
+	LAUNCH_DATA_FD,
+	LAUNCH_DATA_INTEGER,
+	LAUNCH_DATA_REAL,
+	LAUNCH_DATA_BOOL,
+	LAUNCH_DATA_STRING,
+	LAUNCH_DATA_OPAQUE,
+	LAUNCH_DATA_ERRNO,
+	LAUNCH_DATA_MACHPORT,
+} launch_data_type_t;
+
+__ld_allocator
+launch_data_t
+launch_data_alloc(launch_data_type_t);
+
+__ld_allocator
+launch_data_t
+launch_data_copy(launch_data_t);
+
+__ld_getter
+launch_data_type_t
+launch_data_get_type(const launch_data_t);
+
+__ld_setter
+void
+launch_data_free(launch_data_t);
+
+__ld_setter
+bool
+launch_data_dict_insert(launch_data_t, const launch_data_t, const char *);
+
+__ld_getter
+launch_data_t
+launch_data_dict_lookup(const launch_data_t, const char *);
+
+__ld_setter
+bool
+launch_data_dict_remove(launch_data_t, const char *);
+
+__ld_iterator(1, 2)
+void
+launch_data_dict_iterate(const launch_data_t,
+	void (*)(const launch_data_t, const char *, void *), void *);
+
+__ld_getter
+size_t
+launch_data_dict_get_count(const launch_data_t);
+
+__ld_setter
+bool
+launch_data_array_set_index(launch_data_t, const launch_data_t, size_t);
+
+__ld_getter
+launch_data_t
+launch_data_array_get_index(const launch_data_t, size_t);
+
+__ld_getter
+size_t
+launch_data_array_get_count(const launch_data_t);
+
+__ld_allocator
+launch_data_t
+launch_data_new_fd(int);
+
+__ld_allocator
+launch_data_t
+launch_data_new_machport(mach_port_t);
+
+__ld_allocator
+launch_data_t
+launch_data_new_integer(long long);
+
+__ld_allocator
+launch_data_t
+launch_data_new_bool(bool);
+
+__ld_allocator
+launch_data_t
+launch_data_new_real(double);
+
+__ld_allocator
+launch_data_t
+launch_data_new_string(const char *);
+
+__ld_allocator
+launch_data_t
+launch_data_new_opaque(const void *, size_t);
+
+ __ld_setter
+bool
+launch_data_set_fd(launch_data_t, int);
+
+ __ld_setter
+bool
+launch_data_set_machport(launch_data_t, mach_port_t);
+
+ __ld_setter
+bool
+launch_data_set_integer(launch_data_t, long long);
+
+ __ld_setter
+bool
+launch_data_set_bool(launch_data_t, bool);
+
+ __ld_setter
+bool
+launch_data_set_real(launch_data_t, double);
+
+ __ld_setter
+bool
+launch_data_set_string(launch_data_t, const char *);
+
+ __ld_setter
+bool
+launch_data_set_opaque(launch_data_t, const void *, size_t);
+
+__ld_getter
+int	
+launch_data_get_fd(const launch_data_t);
+
+__ld_getter
+mach_port_t
+launch_data_get_machport(const launch_data_t);
+
+__ld_getter
+long long
+launch_data_get_integer(const launch_data_t);
+
+__ld_getter
+bool
+launch_data_get_bool(const launch_data_t);
+
+__ld_getter
+double
+launch_data_get_real(const launch_data_t);
+
+__ld_getter
+const char *
+launch_data_get_string(const launch_data_t);
+
+__ld_getter
+void *
+launch_data_get_opaque(const launch_data_t);
+
+__ld_getter
+size_t
+launch_data_get_opaque_size(const launch_data_t);
+
+__ld_getter
+int
+launch_data_get_errno(const launch_data_t);
+
+
+/* launch_get_fd()
+ *
+ * Use this to get the FD if you're doing asynchronous I/O with select(),
+ * poll() or kevent().
+ */
+__ld_normal
+int
+launch_get_fd(void);
+
+/* launch_msg()
+ *
+ * Use this API to check in. Nothing else.
+ */
+__ld_normal
+launch_data_t
+launch_msg(const launch_data_t);
+
+__END_DECLS
+
+#pragma GCC visibility pop
+
+#endif /* __LAUNCH_H__ */

+ 38 - 1
uicache/sleep.m

@@ -3,6 +3,28 @@
 #import <Foundation/Foundation.h>
 #include <TargetConditionals.h>
 
+@interface PBSSystemService : NSObject
++(id)sharedInstance;
+-(void)deactivateScreenSaver;
+@end
+
+@interface PBSPowerManager : NSObject
+
++(id)sharedInstance;
++(void)load;
++(void)setupPowerManagement;
+-(void)_performUserEventWakeDevice;
+-(void)wakeDeviceWithOptions:(id)arg1;
+-(void)setNeedsDisplayWakeOnPowerOn:(BOOL)arg1;
+- (void)sleepDeviceWithOptions:(id)arg1;
+-(void)_registerForPowerNotifications;
+-(void)_registerForThermalNotifications;
+-(void)_enableIdleSleepAndWatchdog;
+-(void)_registerForBackBoardNotifications;
+-(void)_updateIdleTimer;
+@end
+
+
 @interface NSDistributedNotificationCenter : NSNotificationCenter
 
 + (id)defaultCenter;
@@ -35,11 +57,26 @@ void platformizeme() {
 int main(){
 	@autoreleasepool {
 		platformizeme();
-
+        
+        //[ATVPowerManager setupPowerManagement]
+        NSString *pineBoardServices = @"/System/Library/PrivateFrameworks/PineBoardServices.framework/";
+        NSBundle *pbs = [NSBundle bundleWithPath:pineBoardServices];
+        [pbs load];
+        Class pss = objc_getClass("PBSSystemService");
+        id sysService = [pss sharedInstance];
+        [sysService deactivateScreenSaver];
+        Class powermanager = objc_getClass("PBSPowerManager");
+        [powermanager setupPowerManagement];
+        [powermanager load];
+        id power = [powermanager sharedInstance];
+        [power sleepDeviceWithOptions:@{@"SleepReason": @"UserSettings"}];
+        
+        /*
         Class notecenter = objc_getClass("NSDistributedNotificationCenter");
         id note = [notecenter defaultCenter];
         [note postNotificationName:@"com.nitoTV.sleep" object:nil ];
         sleep(3);
+         */
 	}
 	return 0;
 }

+ 27 - 0
uicache/sleep.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>com.apple.private.skip-library-validation</key>
+	<true/>
+	<key>platform-application</key>
+	<true/>
+	<key>com.apple.appletv.pbs.allow-screen-saver</key>
+	<true/>
+	<key>com.apple.appletv.pbs.allow-shared-state-access</key>
+	<true/>
+	<key>com.apple.appletv.pbs.allow-sleep</key>
+	<true/>
+	<key>com.apple.appletv.pbs.allow-sleep-timeout</key>
+	<true/>
+	<key>com.apple.backboard.client</key>
+	<true/>
+	<key>com.apple.SystemConfiguration.SCPreferences-write-access</key>
+	<array>
+		<string>com.apple.wifi.plist</string>
+		<string>preferences.plist</string>
+		<string>com.apple.network.identification.plist</string>
+		<string>com.apple.PowerManagement.plist</string>
+	</array>
+</dict>
+</plist>

+ 2 - 2
uicache/uicache.m

@@ -50,7 +50,7 @@
 #include <spawn.h>
 #include <assert.h>
 #import <objc/runtime.h>
-#import "rocketbootstrap.h"
+//#import "rocketbootstrap.h"
 #import "AppSupport/CPDistributedMessagingCenter.h"
 #import <MobileCoreServices/MobileCoreServices.h>
 #import "NSTask.h"
@@ -257,7 +257,7 @@ static void inject_dylib(const char* name, pid_t pid, const char* dylib) {
 {
     DLog(@"Rebuilding cache...\n");
     LSApplicationWorkspace *workspace = [LSApplicationWorkspace defaultWorkspace];
-    //[workspace _LSClearSchemaCaches]; //may or may not be necessary
+    [workspace _LSClearSchemaCaches]; //may or may not be necessary
     [workspace _LSPrivateRebuildApplicationDatabasesForSystemApps:YES internal:YES user:NO];
     
     BOOL forceReboot = [self forceReboot];

+ 706 - 0
uicache/uicache.mm

@@ -0,0 +1,706 @@
+/* UIKit Tools - command-line utilities for UIKit
+ * Copyright (C) 2018-2019  Sam Bingner
+ * Copyright (C) 2008-2012  Jay Freeman (saurik)
+ * Portions Copyright (C) 2019  Sam Bingner
+*/
+
+/* This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+/* Modified BSD License {{{ */
+/*
+ *        Redistribution and use in source and binary
+ * forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the
+ *    above copyright notice, this list of conditions
+ *    and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions
+ *    and the following disclaimer in the documentation
+ *    and/or other materials provided with the
+ *    distribution.
+ * 3. The name of the author may not be used to endorse
+ *    or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/* }}} */
+
+#import <Foundation/Foundation.h>
+#import "NSTask.h"
+#import <dlfcn.h>
+#import <notify.h>
+#import <sys/types.h>
+#import <sys/stat.h>
+#import <unistd.h>
+#import <getopt.h>
+#import <launch.h>
+#import <objc/runtime.h>
+#import <crt_externs.h>
+#import <xpc/xpc.h>
+#include <spawn.h>
+#include <sys/wait.h>
+#include "csstore.hpp"
+
+@interface PBSSystemService : NSObject
++(id)sharedInstance;
+-(void)relaunchBackboardd;
+@end
+
+@interface PBSSystemServiceConnection : NSObject
++(id)sharedConnection;
+-(id)systemServiceProxy;
+@end
+
+@interface NSMutableArray (Cydia)
+- (void) addInfoDictionary:(NSDictionary *)info;
+@end
+
+@implementation NSMutableArray (Cydia)
+
+- (void) addInfoDictionary:(NSDictionary *)info {
+    [self addObject:info];
+}
+
+- (NSArray *) allInfoDictionaries {
+    return self;
+}
+
+@end
+
+@interface NSMutableDictionary (Cydia)
+- (void) addInfoDictionary:(NSDictionary *)info;
+@end
+
+@implementation NSMutableDictionary (Cydia)
+
+- (void) addInfoDictionary:(NSDictionary *)info {
+    NSString *bundle = [info objectForKey:@"CFBundleIdentifier"];
+    [self setObject:info forKey:bundle];
+}
+
+- (NSArray *) allInfoDictionaries {
+    return [self allValues];
+}
+
+@end
+
+@interface LSApplicationProxy : NSObject
+- (NSString*) applicationIdentifier;
+- (NSURL*) bundleURL;
+- (NSDate*) registeredDate;
+@end
+
+@interface LSApplicationWorkspace : NSObject
++ (id) defaultWorkspace;
+- (BOOL) registerApplication:(id)application;
+- (BOOL) unregisterApplication:(id)application;
+- (BOOL) invalidateIconCache:(id)bundle;
+- (BOOL) registerApplicationDictionary:(id)application;
+- (BOOL) installApplication:(id)application withOptions:(id)options;
+- (BOOL) _LSPrivateRebuildApplicationDatabasesForSystemApps:(BOOL)system internal:(BOOL)internal user:(BOOL)user;
+- (NSArray<LSApplicationProxy*>*) allApplications;
+@end
+
+@interface MCMAppDataContainer
++(id)containerWithIdentifier:(NSString*)identifier createIfNecessary:(bool)create existed:(bool*)existed error:(NSError*)error;
+-(NSURL*)url;
+@end
+
+@interface FBSSystemService
++(id)sharedService;
+-(void)sendActions:(NSSet*)actions withResult:(id)result;
+@end
+
+typedef enum {
+    None                   = 0,
+    RestartRenderServer    = (1 << 0), // also relaunch backboardd
+    SnapshotTransition     = (1 << 1),
+    FadeToBlackTransition  = (1 << 2),
+} SBSRelaunchActionStyle;
+
+@interface SBSRelaunchAction
++(id)actionWithReason:(id)reason options:(int64_t)options targetURL:(NSURL*)url;
+@end
+
+static int verbose=0;
+static int standard_uicache(void);
+static Class $MCMPluginKitPluginDataContainer;
+static Class $MCMAppDataContainer;
+static Class $LSApplicationWorkspace;
+LSApplicationWorkspace *workspace=nil;
+extern char **environ;
+
+int my_system(const char *cmd) {
+    pid_t pid;
+    char *argv[] = {"sh", "-c", (char*)cmd, NULL};
+    int status;
+    fprintf(stderr, "Run command: %s\n", cmd);
+    status = posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ);
+    if (status == 0) {
+        printf("Child pid: %i\n", pid);
+        if (waitpid(pid, &status, 0) != -1) {
+            printf("Child exited with status %i\n", status);
+            
+        } else {
+            perror("waitpid");
+        }
+    } else {
+        printf("posix_spawn: %s\n", strerror(status));
+    }
+    return status;
+}
+
+NSString *getAppPath(NSString *path)
+{
+    path = [path stringByResolvingSymlinksInPath];
+    if (![path hasPrefix:@"/Applications/"]) {
+        fprintf(stderr, "Error: Path must be within /Applications/\n");
+        return nil;
+    }
+    return [NSString pathWithComponents:[[path pathComponents] subarrayWithRange:NSMakeRange(0, 3)]];
+}
+
+bool appIsRegistered(NSString *path)
+{
+    @autoreleasepool {
+        path = getAppPath(path);
+        if (!path) return false;
+        for (LSApplicationProxy *app in [workspace allApplications]) {
+            if ([path isEqualToString:[[app bundleURL] path]]) return true;
+        }
+        return false;
+    }
+}
+
+bool unregisterPath(NSString *path)
+{
+    @autoreleasepool {
+        if (verbose) fprintf(stderr, "Unregistering %s\n", path.lastPathComponent.UTF8String);
+        path = getAppPath(path);
+        if (!path) return false;
+        if (appIsRegistered(path) && ![workspace unregisterApplication:[NSURL fileURLWithPath:path]]) {
+            fprintf(stderr, "Error: unregisterApplication failed for %s\n", path.lastPathComponent.UTF8String);
+            return false;
+        }
+    }
+    return true;
+}
+
+// Credit to coolstar for finding how to do this and not sharing with the community thereby forcing me to figure out how to do the same thing.
+bool registerPath(NSString *path)
+{
+    if (!path) {
+        if (verbose) fprintf(stderr, "registerPath called with no path\n");
+        return false;
+    }
+    NSString *realPath = getAppPath(path);
+    if (!realPath) {
+        if (verbose) fprintf(stderr, "unable to determine path for %s\n", path.UTF8String);
+        return false;
+    }
+    NSDictionary *infoDictionary = [NSDictionary dictionaryWithContentsOfFile:
+                                    [realPath stringByAppendingPathComponent:@"Info.plist"]];
+    NSString *bundleID = [infoDictionary objectForKey:@"CFBundleIdentifier"];
+
+    if (bundleID) {
+        NSFileManager *fm = [NSFileManager defaultManager];
+
+        if ([infoDictionary objectForKey:@"CFBundleExecutable"]) {
+            NSString *executable = [realPath stringByAppendingPathComponent:[infoDictionary objectForKey:@"CFBundleExecutable"]];
+            if (![fm fileExistsAtPath:executable]) {
+                fprintf(stderr, "Error: CFBundleExecutable defined but missing for %s - this is a fatal error. Aborting.\n", realPath.lastPathComponent.UTF8String);
+                return false;
+            }
+        }
+
+        NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+                                     @"System", @"ApplicationType",
+                                     @YES, @"BundleNameIsLocalized",
+                                     bundleID, @"CFBundleIdentifier",
+                                     @NO, @"CompatibilityState",
+                                     @NO, @"IsDeletable",
+                                     realPath, @"Path",
+                                     [NSMutableDictionary dictionary], @"_LSBundlePlugins",
+                                     nil];
+
+        id appContainer = [$MCMAppDataContainer containerWithIdentifier:bundleID
+                                                createIfNecessary:YES existed:NULL error:nil];
+
+        NSString *appContainerPath = [[appContainer url] path];
+        if (appContainerPath) {
+            dict[@"Container"] = appContainerPath;
+        }
+        NSString *pluginsPath = [realPath stringByAppendingPathComponent:@"PlugIns"];
+        for (NSString *plugin in [fm contentsOfDirectoryAtPath:pluginsPath error:nil]) {
+            NSString *pluginPath = [pluginsPath stringByAppendingPathComponent:plugin];
+            NSString *pluginInfoPlistPath = [pluginPath stringByAppendingPathComponent:@"Info.plist"];
+            NSString *pluginBundleIdentifier = [[NSDictionary dictionaryWithContentsOfFile:pluginInfoPlistPath] objectForKey:@"CFBundleIdentifier"];
+            if (pluginBundleIdentifier) {
+                id pluginContainer = [$MCMPluginKitPluginDataContainer containerWithIdentifier:pluginBundleIdentifier
+                                                                       createIfNecessary:YES existed:NULL error:nil];
+                NSURL *pluginContainerURL = [pluginContainer url];
+                NSString *pluginContainerPath = [pluginContainerURL path];
+                dict[@"_LSBundlePlugins"][pluginBundleIdentifier] = @{
+                    @"ApplicationType": @"PluginKitPlugin",
+                    @"BundleNameIsLocalized": @YES,
+                    @"CFBundleIdentifier": pluginBundleIdentifier,
+                    @"CompatibilityState": @NO,
+                    @"Container": pluginContainerPath,
+                    @"Path": pluginPath,
+                    @"PluginOwnerBundleID": bundleID
+                };
+            }
+        }
+        if (![[$LSApplicationWorkspace defaultWorkspace] registerApplicationDictionary:dict]) {
+            fprintf(stderr, "Error: registerApplicationDictionary failed for %s\n", path.lastPathComponent.UTF8String);
+            return false;
+        }
+    } else {
+        return unregisterPath(realPath);
+    }
+    return true;
+}
+
+void usage(void)
+{
+    fprintf(stderr, "Usage: %s [-hrv] [[-p | -u] /Applications/App.app]]\n", getprogname());
+    exit(EXIT_FAILURE);
+}
+
+pid_t launch_get_job_pid(const char * job)
+{
+    launch_data_t resp;
+    launch_data_t msg;
+    
+    msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY);
+    if (msg == NULL) {
+        return -1;
+    }
+    
+    launch_data_dict_insert(msg, launch_data_new_string(job), LAUNCH_KEY_GETJOB);
+    
+    resp = launch_msg(msg);
+    launch_data_free(msg);
+    
+    if (resp == NULL) {
+        return -1;
+    }
+    
+    if (launch_data_get_type(resp) != LAUNCH_DATA_DICTIONARY) return -1;
+    
+    launch_data_t pid_data = launch_data_dict_lookup(resp, "PID");
+    if (launch_data_get_type(pid_data) != LAUNCH_DATA_INTEGER) return -1;
+    
+    pid_t pid = (pid_t)launch_data_get_integer(pid_data);
+    launch_data_free(resp);
+    return pid;
+}
+
+int standard_uicache(void)
+{
+  @autoreleasepool {
+    if (kCFCoreFoundationVersionNumber > 1000 && // this API is on iOS 7 but invaliding the icon cache is harder there
+        [workspace respondsToSelector:@selector(_LSPrivateRebuildApplicationDatabasesForSystemApps:internal:user:)]) {
+        if (![workspace _LSPrivateRebuildApplicationDatabasesForSystemApps:YES internal:YES user:NO])
+            fprintf(stderr, "failed to rebuild application databases");
+        return 0;
+    }
+
+    bool respring(false);
+
+    NSString *home(NSHomeDirectory());
+    NSString *path([NSString stringWithFormat:@"%@/Library/Caches/com.apple.mobile.installation.plist", home]);
+
+    my_system("killall -SIGSTOP SpringBoard");
+    sleep(1);
+
+    @try {
+
+    DeleteCSStores([home UTF8String]);
+
+    my_system("killall lsd");
+
+    if ([workspace respondsToSelector:@selector(invalidateIconCache:)])
+        while (![workspace invalidateIconCache:nil])
+            sleep(1);
+
+    if (NSMutableDictionary *cache = [NSMutableDictionary dictionaryWithContentsOfFile:path]) {
+        NSFileManager *manager = [NSFileManager defaultManager];
+        NSError *error = nil;
+
+        NSMutableDictionary *bundles([NSMutableDictionary dictionaryWithCapacity:16]);
+
+        id after = [cache objectForKey:@"System"];
+        if (after == nil) { error:
+            fprintf(stderr, "%s\n", error == nil ? strerror(errno) : [[error localizedDescription] UTF8String]);
+            goto cached;
+        }
+
+        id before([[after copy] autorelease]);
+        [after removeAllObjects];
+
+        NSArray *cached([cache objectForKey:@"InfoPlistCachedKeys"]);
+
+        NSMutableSet *removed([NSMutableSet set]);
+        for (NSDictionary *info in [before allInfoDictionaries])
+            if (NSString *path = [info objectForKey:@"Path"])
+                [removed addObject:path];
+
+        if (NSArray *apps = [manager contentsOfDirectoryAtPath:@"/Applications" error:&error]) {
+            for (NSString *app in apps)
+                if ([app hasSuffix:@".app"]) {
+                    NSString *path = [@"/Applications" stringByAppendingPathComponent:app];
+                    NSString *plist = [path stringByAppendingPathComponent:@"Info.plist"];
+
+                    if (NSMutableDictionary *info = [NSMutableDictionary dictionaryWithContentsOfFile:plist]) {
+                        if (NSString *identifier = [info objectForKey:@"CFBundleIdentifier"]) {
+                            [bundles setObject:path forKey:identifier];
+                            [removed removeObject:path];
+
+                            if (cached != nil) {
+                                NSMutableDictionary *merged([before objectForKey:identifier]);
+                                if (merged == nil)
+                                    merged = [NSMutableDictionary dictionary];
+                                else
+                                    merged = [[merged mutableCopy] autorelease];
+
+                                for (NSString *key in cached)
+                                    if (NSObject *value = [info objectForKey:key])
+                                        [merged setObject:value forKey:key];
+                                    else
+                                        [merged removeObjectForKey:key];
+
+                                info = merged;
+                            }
+
+                            [info setObject:path forKey:@"Path"];
+                            [info setObject:@"System" forKey:@"ApplicationType"];
+                            [after addInfoDictionary:info];
+                        } else
+                            fprintf(stderr, "%s missing CFBundleIdentifier", [app UTF8String]);
+                    }
+                }
+        } else goto error;
+
+        [cache writeToFile:path atomically:YES];
+
+        if (workspace != nil) {
+            if ([workspace respondsToSelector:@selector(invalidateIconCache:)]) {
+                for (NSString *identifier in bundles)
+                    [workspace invalidateIconCache:identifier];
+            } else {
+                for (NSString *identifier in bundles) {
+                    NSString *path([bundles objectForKey:identifier]);
+                    [workspace unregisterApplication:[NSURL fileURLWithPath:path]];
+                }
+            }
+
+            for (NSString *identifier in bundles) {
+                NSString *path([bundles objectForKey:identifier]);
+                if (kCFCoreFoundationVersionNumber >= 800)
+                    [workspace registerApplicationDictionary:[after objectForKey:identifier]];
+                else
+                    [workspace registerApplication:[NSURL fileURLWithPath:path]];
+            }
+
+            for (NSString *path in removed)
+                [workspace unregisterApplication:[NSURL fileURLWithPath:path]];
+        }
+    } else fprintf(stderr, "cannot open cache file. incorrect user?\n");
+  cached:
+
+    if (respring || kCFCoreFoundationVersionNumber >= 550.32) {
+        unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-icons", home] UTF8String]);
+        unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-icons.plist", home] UTF8String]);
+
+        unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-smallicons", home] UTF8String]);
+        unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-smallicons.plist", home] UTF8String]);
+
+        my_system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache", home] UTF8String]);
+        my_system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache-small", home] UTF8String]);
+
+        my_system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/com.apple.IconsCache", home] UTF8String]);
+    }
+
+    my_system("killall installd");
+
+    } @finally {
+        my_system("killall -SIGCONT SpringBoard");
+    }
+
+    notify_post("com.apple.mobile.application_installed");
+
+    return 0;
+  }
+}
+
+pid_t pidOfCydia(void) {
+    launch_data_t request = launch_data_new_string(LAUNCH_KEY_GETJOBS);
+    launch_data_t response = launch_msg(request);
+    launch_data_free(request);
+    __block pid_t pid=-1;
+
+    if (response == NULL || launch_data_get_type(response) != LAUNCH_DATA_DICTIONARY) return -1;
+
+    xpc_dictionary_apply((xpc_object_t)response, ^bool(const char *key, xpc_object_t value) {
+        if (xpc_get_type(value) == XPC_TYPE_DICTIONARY) {
+            const char *program = xpc_dictionary_get_string(value, "Program");
+            if (program && strcmp(program, "/Applications/Cydia.app/Cydia") == 0) {
+                pid = (pid_t)xpc_dictionary_get_int64(value, "PID");
+                if (verbose) fprintf(stderr, "Found Cydia running with PID: %d\n", pid);
+                return false;
+            }
+        }
+        return true;
+    });
+
+    if (pid>0) {
+        return pid;
+    }
+    return -1;
+}
+
+int optimized_uicache(void) {
+    __block int rv=0;
+    NSMutableDictionary *registered = [NSMutableDictionary new];
+    static void (^readHandler)(NSFileHandle*) = ^(NSFileHandle *fh) {
+        NSData *output = [fh readDataToEndOfFile];
+        if (output.length==0) return;
+        const char *found_path = (const char *)[output bytes];
+        NSArray *found = [@(found_path) pathComponents];
+        if (found.count >= 3) {
+            NSString *appPath = [@"/Applications" stringByAppendingPathComponent:found[2]];
+            @synchronized (registered) {
+                if (registered[appPath]) return;
+                if (verbose) fprintf(stderr, "Updating %s\n", appPath.lastPathComponent.UTF8String);
+                registered[appPath] = @YES;
+            }
+            pid_t cydia_pid;
+            if ([found[2] isEqualToString:@"Cydia.app"] &&
+                    (cydia_pid = pidOfCydia()) > 0) {
+                // We are in cydia and trying to refresh it - this will kill it.  Let's schedule it for later.
+                if (verbose) fprintf(stderr, "Waiting to refresh Cydia...\n");
+                pid_t pid = fork();
+                if (pid == 0) {
+                    setpgrp();
+                    signal(SIGHUP, SIG_IGN);
+                    signal(SIGPIPE, SIG_IGN);
+                    fclose(stdin);
+                    freopen("/dev/null", "a", stderr);
+                    freopen("/dev/null", "a", stdout);
+                    pid = fork();
+                    if (pid == 0) {
+                        while (kill(cydia_pid, 0)==0) {
+                            sleep(1);
+                        }
+                        const char *uicache = (*_NSGetArgv())[0];
+                        execl(uicache, uicache, "-vvvvvvv", NULL);
+                        fprintf(stderr, "Unable to exec\n");
+                        fflush(stderr);
+                        exit(-1);
+                    }
+                    exit(0);
+                } else if (pid > 0) {
+                    int stat;
+                    waitpid(pid, &stat, 0);
+                    return;
+                } else {
+                    fprintf(stderr, "Unable to fork\n");
+                }
+            }
+            if (!registerPath(appPath)) rv++;
+        }
+    };
+    NSFileManager *fm = [NSFileManager defaultManager];
+    NSMutableDictionary *apps = [NSMutableDictionary new];
+    NSMutableArray *cleanup = [NSMutableArray new];
+    NSMutableArray *finds = [NSMutableArray new];
+    if (verbose>1) fprintf(stderr, "Enumerating apps\n");
+    for (LSApplicationProxy *app in [workspace allApplications]) {
+        NSString *path = [[app bundleURL] path];
+        if (![path hasPrefix:@"/Applications/"]) continue;
+        if (verbose>1) fprintf(stderr, "Checking %s\n", path.lastPathComponent.UTF8String);
+        
+        NSDate *lastRegistered = [app registeredDate];
+        
+        if ([fm fileExistsAtPath:path]) {
+            // Check for updated components
+            NSTask *find = [NSTask new];
+            [find setLaunchPath:@"/usr/bin/find"];
+            [find setStandardOutput:[NSPipe pipe]];
+            NSString *stampPath = [NSString stringWithFormat:@"/var/tmp/uicache.stamp.%@", app.applicationIdentifier];
+            [fm createFileAtPath:stampPath contents:nil attributes:@{NSFileModificationDate: lastRegistered}];
+            [cleanup addObject:stampPath];
+            [find setArguments:@[ path, @"-newer", stampPath, @"-print0", @"-quit"]];
+            [finds addObject:find];
+            [find launch];
+            apps[path.lastPathComponent] = app;
+        } else {
+            if (verbose) fprintf(stderr, "De-registering removed app: %s\n", path.lastPathComponent.UTF8String);
+            @synchronized (registered) {
+                if (registered[path]) continue;
+                registered[path] = @YES;
+            }
+            if (!unregisterPath(path)) rv++;
+        }
+    }
+    
+    for (NSString* existing in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/Applications" error:nil]) {
+        NSString *path = [@"/Applications" stringByAppendingPathComponent:existing];
+        if (apps[existing] || registered[path] || ![existing hasSuffix:@".app"]) continue;
+        if (verbose) fprintf(stderr, "Registering new app: %s\n", existing.UTF8String);
+        @synchronized (registered) {
+            registered[path] = @YES;
+        }
+        if (!registerPath(path)) rv++;
+    }
+    for (NSTask *find in finds) {
+        if (verbose>2) fprintf(stderr, "waiting for find %s\n", [find.arguments componentsJoinedByString:@" "].UTF8String);
+        readHandler([find.standardOutput fileHandleForReading]);
+        [find waitUntilExit];
+    }
+    for (NSString *path in cleanup) {
+        [fm removeItemAtPath:path error:nil];
+    }
+    return rv;
+}
+
+
+
+int main(int argc, const char *argv[])
+{
+    if (getuid() == 0) {
+        // Be mobile
+        if (setuid(501)) {
+            fprintf(stderr, "Error: unable to become mobile");
+            return -1;
+        }
+    }
+    dlopen("/System/Library/PrivateFrameworks/MobileContainerManager.framework/MobileContainerManager", RTLD_LAZY);
+    dlopen("/System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices", RTLD_LAZY);
+    dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_LAZY);
+    Class $SBSRelaunchAction = objc_getClass("SBSRelaunchAction");
+    Class $FBSSystemService = objc_getClass("FBSSystemService");
+    $MCMPluginKitPluginDataContainer = objc_getClass("MCMPluginKitPluginDataContainer");
+    $MCMAppDataContainer = objc_getClass("MCMAppDataContainer");
+    $LSApplicationWorkspace = objc_getClass("LSApplicationWorkspace");
+    workspace = [$LSApplicationWorkspace defaultWorkspace];
+
+    static int rv=0;
+    @autoreleasepool {
+        bool respring=false, do_all=false;
+        void (*jb_oneshot_entitle_now)(pid_t a, uint64_t b);
+        void *libjb = dlopen("/usr/lib/libjailbreak.dylib", RTLD_LAZY);
+        
+        if (libjb) {
+            dlerror();
+            jb_oneshot_entitle_now = (void (*)(pid_t, uint64_t))dlsym(libjb, "jb_oneshot_entitle_now");
+            if (!dlerror()) jb_oneshot_entitle_now(getpid(), 2);
+        }
+        
+        NSMutableDictionary *paths = [NSMutableDictionary new];
+        NSMutableDictionary *unregister_paths = [NSMutableDictionary new];
+        static struct option long_options[] =
+        {
+            {"all",        no_argument,       0, 'a'},
+            {"help",       no_argument,       0, 'h'},
+            {"path",       required_argument, 0, 'p'},
+            {"unregister", required_argument, 0, 'u'},
+            {"respring",   no_argument,       0, 'r'},
+            {"verbose",    no_argument,       0, 'v'},
+            {0, 0, 0, 0}
+        };
+        int option_index = 0;
+        char ch;
+        bool have_path = false;
+        while ((ch = getopt_long(argc, (char *const *)argv, "ap:ru:vh?", long_options, &option_index)) != -1) {
+            switch (ch)
+            {
+                case 'a':
+                    do_all = true;
+                    break;
+                case 'h':
+                    usage();
+                    break;
+                case 'p':
+                    paths[@(optarg)] = @YES;
+                    have_path = true;
+                    break;
+                case 'r':
+                    respring = true;
+                    break;
+                case 'u':
+                    unregister_paths[@(optarg)] = @YES;
+                    have_path = true;
+                    break;
+                case 'v':
+                    verbose++;
+                    break;
+                default:
+                    break;
+            }
+        }
+        if (do_all || !$MCMPluginKitPluginDataContainer || !$MCMAppDataContainer || !$LSApplicationWorkspace) {
+            rv = standard_uicache();
+        } else if (have_path) {
+            for (NSString *path in [paths allKeys]) {
+                if (verbose) fprintf(stderr, "Refreshing %s\n", path.UTF8String);
+                if (!registerPath(path)) rv++;
+            }
+            for (NSString *path in [unregister_paths allKeys]) {
+                if (!unregisterPath(path)) rv++;
+            }
+        } else {
+            rv += optimized_uicache();
+        }
+        if ( respring )
+        {
+            [[[PBSSystemServiceConnection sharedConnection] systemServiceProxy] relaunchBackboardd];
+             
+            pid_t sb_pid = launch_get_job_pid("com.apple.SpringBoard");
+            if ($SBSRelaunchAction && $FBSSystemService) {
+                id action = [$SBSRelaunchAction actionWithReason:@"respring" options:RestartRenderServer targetURL:nil];
+                id sharedService = [$FBSSystemService sharedService];
+                [sharedService sendActions:[NSSet setWithObject:action] withResult:nil];
+                for (int i=0; i<100; i++) {
+                    if (kill(sb_pid, 0)) {
+                        break;
+                    }
+                    usleep(1000);
+                }
+            } else {
+                my_system("launchctl stop com.apple.PineBoard");
+                my_system("launchctl stop com.apple.backboardd");
+            }
+        }
+    } // @autoreleasepool
+    return rv;
+}

+ 2 - 0
uicache/uicache.xml

@@ -23,6 +23,8 @@
     
     <key>platform-application</key>
     <true/>
+    <key>com.apple.appletv.pbs.allow-relaunch-backboardd</key>
+    <true/>
     
 </dict>
 </plist>

+ 35 - 1
uicache/wake.m

@@ -3,6 +3,27 @@
 #import <Foundation/Foundation.h>
 #include <TargetConditionals.h>
 
+@interface PBSSystemService : NSObject
++(id)sharedInstance;
+-(void)deactivateScreenSaver;
+@end
+
+@interface PBSPowerManager : NSObject
+
++(id)sharedInstance;
++(void)load;
++(void)setupPowerManagement;
+-(void)_performUserEventWakeDevice;
+-(void)wakeDeviceWithOptions:(id)arg1;
+-(void)setNeedsDisplayWakeOnPowerOn:(BOOL)arg1;
+- (void)sleepDeviceWithOptions:(id)arg1;
+-(void)_registerForPowerNotifications;
+-(void)_registerForThermalNotifications;
+-(void)_enableIdleSleepAndWatchdog;
+-(void)_registerForBackBoardNotifications;
+-(void)_updateIdleTimer;
+@end
+
 @interface NSDistributedNotificationCenter : NSNotificationCenter
 
 + (id)defaultCenter;
@@ -35,11 +56,24 @@ void platformizeme() {
 int main(){
 	@autoreleasepool {
 		platformizeme();
-
+        
+        NSString *pineBoardServices = @"/System/Library/PrivateFrameworks/PineBoardServices.framework/";
+        NSBundle *pbs = [NSBundle bundleWithPath:pineBoardServices];
+        [pbs load];
+        Class powermanager = objc_getClass("PBSPowerManager");
+        [powermanager setupPowerManagement];
+        [powermanager load];
+        id power = [powermanager sharedInstance];
+        if ([power respondsToSelector:@selector(_performUserEventWakeDevice)]){
+            [power _performUserEventWakeDevice];
+        }
+        [power wakeDeviceWithOptions:@{@"WakeReason":@"UserActivity"}];
+        /*
         Class notecenter = objc_getClass("NSDistributedNotificationCenter");
         id note = [notecenter defaultCenter];
         [note postNotificationName:@"com.nitoTV.wakeup" object:nil ];
         sleep(3);
+         */
 	}
 	return 0;
 }

+ 418 - 0
uicache/xpc/activity.h

@@ -0,0 +1,418 @@
+#ifndef __XPC_ACTIVITY_H__
+#define __XPC_ACTIVITY_H__
+
+#ifndef __XPC_INDIRECT__
+#error "Please #include <xpc/xpc.h> instead of this file directly."
+// For HeaderDoc.
+#include <xpc/base.h>
+#endif // __XPC_INDIRECT__ 
+
+#ifdef __BLOCKS__
+
+__BEGIN_DECLS
+
+/*
+ * The following are a collection of keys and values used to set an activity's
+ * execution criteria.
+ */
+
+/*!
+ * @constant XPC_ACTIVITY_INTERVAL
+ * An integer property indicating the desired time interval (in seconds) of the 
+ * activity. The activity will not be run more than once per time interval.
+ * Due to the nature of XPC Activity finding an opportune time to run
+ * the activity, any two occurrences may be more or less than 'interval'
+ * seconds apart, but on average will be 'interval' seconds apart.
+ * The presence of this key implies the following, unless overridden:
+ * - XPC_ACTIVITY_REPEATING with a value of true
+ * - XPC_ACTIVITY_DELAY with a value of half the 'interval'
+ *   The delay enforces a minimum distance between any two occurrences.
+ * - XPC_ACTIVITY_GRACE_PERIOD with a value of half the 'interval'.
+ *   The grace period is the amount of time allowed to pass after the end of
+ *   the interval before more aggressive scheduling occurs. The grace period
+ *   does not increase the size of the interval.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const char *XPC_ACTIVITY_INTERVAL;
+
+/*!
+ * @constant XPC_ACTIVITY_REPEATING
+ * A boolean property indicating whether this is a repeating activity.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const char *XPC_ACTIVITY_REPEATING;
+
+/*!
+ * @constant XPC_ACTIVITY_DELAY
+ * An integer property indicating the number of seconds to delay before
+ * beginning the activity.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const char *XPC_ACTIVITY_DELAY;
+
+/*!
+ * @constant XPC_ACTIVITY_GRACE_PERIOD
+ * An integer property indicating the number of seconds to allow as a grace
+ * period before the scheduling of the activity becomes more aggressive.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const char *XPC_ACTIVITY_GRACE_PERIOD;
+
+
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const int64_t XPC_ACTIVITY_INTERVAL_1_MIN;
+
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const int64_t XPC_ACTIVITY_INTERVAL_5_MIN;
+
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const int64_t XPC_ACTIVITY_INTERVAL_15_MIN;
+
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const int64_t XPC_ACTIVITY_INTERVAL_30_MIN;
+
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const int64_t XPC_ACTIVITY_INTERVAL_1_HOUR;
+
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const int64_t XPC_ACTIVITY_INTERVAL_4_HOURS;
+
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const int64_t XPC_ACTIVITY_INTERVAL_8_HOURS;
+
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const int64_t XPC_ACTIVITY_INTERVAL_1_DAY;
+
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const int64_t XPC_ACTIVITY_INTERVAL_7_DAYS;
+
+/*!
+ * @constant XPC_ACTIVITY_PRIORITY
+ * A string property indicating the priority of the activity.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const char *XPC_ACTIVITY_PRIORITY;
+
+/*!
+ * @constant XPC_ACTIVITY_PRIORITY_MAINTENANCE
+ * A string indicating activity is maintenance priority.
+ * Maintenance priority is intended for user-invisible maintenance tasks
+ * such as garbage collection or optimization.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const char *XPC_ACTIVITY_PRIORITY_MAINTENANCE;
+
+/*!
+ * @constant XPC_ACTIVITY_PRIORITY_UTILITY
+ * A string indicating activity is utility priority.
+ * Utility priority is intended for user-visible tasks such as fetching data
+ * from the network, copying files, or importing data.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const char *XPC_ACTIVITY_PRIORITY_UTILITY;
+
+/*!
+ * @constant XPC_ACTIVITY_ALLOW_BATTERY
+ * A Boolean value indicating whether the activity should be allowed to run
+ * while the computer is on battery power. The default value is false for
+ * maintenance priority activity and true for utility priority activity.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const char *XPC_ACTIVITY_ALLOW_BATTERY;
+
+/*!
+ * @constant XPC_ACTIVITY_REQUIRE_SCREEN_SLEEP
+ * A Boolean value indicating whether the activity should only be performed
+ * while the primary screen is in sleep mode. Defaults to false.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const char *XPC_ACTIVITY_REQUIRE_SCREEN_SLEEP; // bool
+
+/*!
+ * @constant XPC_ACTIVITY_REQUIRE_BATTERY_LEVEL
+ * An integer percentage of minimum battery charge required to allow the
+ * activity to run. A default minimum battery level is determined by the
+ * system.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const char *XPC_ACTIVITY_REQUIRE_BATTERY_LEVEL; // int (%)
+
+/*!
+ * @constant XPC_ACTIVITY_REQUIRE_HDD_SPINNING
+ * A Boolean value indicating whether the activity should only be performed
+ * while the hard disk drive (HDD) is spinning. Computers with flash storage
+ * are considered to be equivalent to HDD spinning. Defaults to false.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const char *XPC_ACTIVITY_REQUIRE_HDD_SPINNING; // bool
+
+/*!
+ * @define XPC_TYPE_ACTIVITY
+ * A type representing a connection to a named service. This connection is
+ * bidirectional and can be used to both send and receive messages. A
+ * connection carries the credentials of the remote service provider.
+ */
+#define XPC_TYPE_ACTIVITY (&_xpc_type_activity)
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+XPC_TYPE(_xpc_type_activity);
+
+/*!
+ * @typedef xpc_activity_t
+ *
+ * @abstract
+ * An XPC activity object.
+ *
+ * @discussion
+ * This object represents a set of execution criteria and a current execution
+ * state for background activity on the system. Once an activity is registered,
+ * the system will evaluate its criteria to determine whether the activity is
+ * eligible to run under current system conditions. When an activity becomes
+ * eligible to run, its execution state will be updated and an invocation of
+ * its handler block will be made.
+ */
+XPC_DECL(xpc_activity);
+
+/*!
+ * @typedef xpc_activity_handler_t
+ *
+ * @abstract
+ * A block that is called when an XPC activity becomes eligible to run.
+ */
+typedef void (^xpc_activity_handler_t)(xpc_activity_t activity);
+
+/*!
+ * @constant XPC_ACTIVITY_CHECK_IN
+ * This constant may be passed to xpc_activity_register() as the criteria
+ * dictionary in order to check in with the system for previously registered
+ * activity using the same identifier (for example, an activity taken from a
+ * launchd property list).
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+const xpc_object_t XPC_ACTIVITY_CHECK_IN;
+
+/*!
+ * @function xpc_activity_register
+ *
+ * @abstract
+ * Registers an activity with the system.
+ *
+ * @discussion
+ * Registers a new activity with the system. The criteria of the activity are
+ * described by the dictionary passed to this function. If an activity with the
+ * same identifier already exists, the criteria provided override the existing
+ * criteria unless the special dictionary XPC_ACTIVITY_CHECK_IN is used. The
+ * XPC_ACTIVITY_CHECK_IN dictionary instructs the system to first look up an
+ * existing activity without modifying its criteria. Once the existing activity
+ * is found (or a new one is created with an empty set of criteria) the handler
+ * will be called with an activity object in the XPC_ACTIVITY_STATE_CHECK_IN
+ * state.
+ *
+ * @param identifier
+ * A unique identifier for the activity. Each application has its own namespace.
+ *
+ * @param criteria
+ * A dictionary of criteria for the activity.
+ *
+ * @param handler
+ * The handler block to be called when the activity changes state to one of the
+ * following states:
+ * - XPC_ACTIVITY_STATE_CHECK_IN (optional)
+ * - XPC_ACTIVITY_STATE_RUN
+ *
+ * The handler block is never invoked reentrantly. It will be invoked on a
+ * dispatch queue with an appropriate priority to perform the activity.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 XPC_NONNULL3
+void
+xpc_activity_register(const char *identifier, xpc_object_t criteria,
+	xpc_activity_handler_t handler);
+
+/*!
+ * @function xpc_activity_copy_criteria
+ *
+ * @abstract
+ * Returns an XPC dictionary describing the execution criteria of an activity.
+ * This will return NULL in cases where the activity has already completed, e.g.
+ * when checking in to an event that finished and was not rescheduled.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT XPC_WARN_RESULT XPC_RETURNS_RETAINED
+xpc_object_t
+xpc_activity_copy_criteria(xpc_activity_t activity);
+
+/*!
+ * @function xpc_activity_set_criteria
+ *
+ * @abstract
+ * Modifies the execution criteria of an activity.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2
+void
+xpc_activity_set_criteria(xpc_activity_t activity, xpc_object_t criteria);
+
+/*!
+ * @enum xpc_activity_state_t
+ * An activity is defined to be in one of the following states. Applications
+ * may check the current state of the activity using xpc_activity_get_state()
+ * in the handler block provided to xpc_activity_register().
+ *
+ * The application can modify the state of the activity by calling
+ * xpc_activity_set_state() with one of the following:
+ * - XPC_ACTIVITY_STATE_DEFER
+ * - XPC_ACTIVITY_STATE_CONTINUE
+ * - XPC_ACTIVITY_STATE_DONE
+ *
+ * @constant XPC_ACTIVITY_STATE_CHECK_IN
+ * An activity in this state has just completed a checkin with the system after
+ * XPC_ACTIVITY_CHECK_IN was provided as the criteria dictionary to
+ * xpc_activity_register. The state gives the application an opportunity to
+ * inspect and modify the activity's criteria.
+ *
+ * @constant XPC_ACTIVITY_STATE_WAIT
+ * An activity in this state is waiting for an opportunity to run. This value
+ * is never returned within the activity's handler block, as the block is
+ * invoked in response to XPC_ACTIVITY_STATE_CHECK_IN or XPC_ACTIVITY_STATE_RUN.
+ *
+ * Note:
+ * A launchd job may idle exit while an activity is in the wait state and be
+ * relaunched in response to the activity becoming runnable. The launchd job
+ * simply needs to re-register for the activity on its next launch by passing
+ * XPC_ACTIVITY_STATE_CHECK_IN to xpc_activity_register().
+ *
+ * @constant XPC_ACTIVITY_STATE_RUN
+ * An activity in this state is eligible to run based on its criteria.
+ *
+ * @constant XPC_ACTIVITY_STATE_DEFER
+ * An application may pass this value to xpc_activity_set_state() to indicate
+ * that the activity should be deferred (placed back into the WAIT state) until
+ * a time when its criteria are met again. Deferring an activity does not reset
+ * any of its time-based criteria (in other words, it will remain past due).
+ * This should be done in response to observing xpc_activity_should_defer().
+ *
+ * @constant XPC_ACTIVITY_STATE_CONTINUE
+ * An application may pass this value to xpc_activity_set_state() to indicate
+ * that the activity will continue its operation beyond the return of its
+ * handler block. This can be used to extend an activity to include asynchronous
+ * operations. The activity's handler block will not be invoked again until the
+ * state has been updated to either XPC_ACTIVITY_STATE_DEFER or, in the case
+ * of repeating activity, XPC_ACTIVITY_STATE_DONE.
+ *
+ * @constant XPC_ACTIVITY_STATE_DONE
+ * An application may pass this value to xpc_activity_set_state() to indicate
+ * that the activity has completed. For non-repeating activity, the resources
+ * associated with the activity will be automatically released upon return from
+ * the handler block. For repeating activity, timers present in the activity's
+ * criteria will be reset.
+ */
+enum {
+	XPC_ACTIVITY_STATE_CHECK_IN,
+	XPC_ACTIVITY_STATE_WAIT,
+	XPC_ACTIVITY_STATE_RUN,
+	XPC_ACTIVITY_STATE_DEFER,
+	XPC_ACTIVITY_STATE_CONTINUE,
+	XPC_ACTIVITY_STATE_DONE,
+};
+typedef long xpc_activity_state_t;
+
+/*!
+ * @function xpc_activity_get_state
+ *
+ * @abstract
+ * Returns the current state of an activity.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
+xpc_activity_state_t
+xpc_activity_get_state(xpc_activity_t activity);
+
+/*!
+ * @function xpc_activity_set_state
+ *
+ * @abstract
+ * Updates the current state of an activity.
+ *
+ * @return
+ * Returns true if the state was successfully updated; otherwise, returns
+ * false if the requested state transition is not valid.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
+bool
+xpc_activity_set_state(xpc_activity_t activity, xpc_activity_state_t state);
+
+/*!
+ * @function xpc_activity_should_defer
+ *
+ * @abstract
+ * Test whether an activity should be deferred.
+ *
+ * @discussion
+ * This function may be used to test whether the criteria of a long-running
+ * activity are still satisfied. If not, the system indicates that the
+ * application should defer the activity. The application may acknowledge the
+ * deferral by calling xpc_activity_set_state() with XPC_ACTIVITY_STATE_DEFER.
+ * Once deferred, the system will place the activity back into the WAIT state
+ * and re-invoke the handler block at the earliest opportunity when the criteria
+ * are once again satisfied.
+ *
+ * @return
+ * Returns true if the activity should be deferred.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT
+bool
+xpc_activity_should_defer(xpc_activity_t activity);
+
+/*!
+ * @function xpc_activity_unregister
+ *
+ * @abstract
+ * Unregisters an activity found by its identifier.
+ *
+ * @discussion
+ * A dynamically registered activity will be deleted in response to this call.
+ * Statically registered activity (from a launchd property list) will be
+ * reverted to its original criteria if any modifications were made.
+ *
+ * Unregistering an activity has no effect on any outstanding xpc_activity_t
+ * objects or any currently executing xpc_activity_handler_t blocks; however,
+ * no new handler block invocations will be made after it is unregistered.
+ *
+ * @param identifier
+ * The identifier of the activity to unregister.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+XPC_EXPORT XPC_NONNULL1
+void
+xpc_activity_unregister(const char *identifier);
+
+__END_DECLS
+
+#endif // __BLOCKS__
+
+#endif // __XPC_ACTIVITY_H__ 
+

+ 189 - 0
uicache/xpc/base.h

@@ -0,0 +1,189 @@
+// Copyright (c) 2009-2011 Apple Inc. All rights reserved.
+
+#ifndef __XPC_BASE_H__
+#define __XPC_BASE_H__
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+// Certain parts of the project use all the project's headers but have to build
+// against Zin -- liblaunch_host being the example. So we need to define these.
+#ifndef __MAC_10_9
+#define __MAC_10_9 1090
+#define __AVAILABILITY_INTERNAL__MAC_10_9 \
+	__attribute__((availability(macosx, introduced=10.9)))
+#endif
+
+#ifndef __IPHONE_7_0
+#define __IPHONE_7_0 70000
+#define __AVAILABILITY_INTERNAL__IPHONE_7_0 \
+	__attribute__((availability(ios, introduced=7.0)))
+#endif
+
+#ifndef __AVAILABILITY_INTERNAL__MAC_10_4_DEP__MAC_10_9
+#define __AVAILABILITY_INTERNAL__MAC_10_4_DEP__MAC_10_9
+#endif // __AVAILABILITY_INTERNAL__MAC_10_4_DEP__MAC_10_9
+
+#ifndef __AVAILABILITY_INTERNAL__MAC_10_5_DEP__MAC_10_9
+#define __AVAILABILITY_INTERNAL__MAC_10_5_DEP__MAC_10_9
+#endif // __AVAILABILITY_INTERNAL__MAC_10_5_DEP__MAC_10_9
+
+#ifndef __AVAILABILITY_INTERNAL__MAC_10_6_DEP__MAC_10_9
+#define __AVAILABILITY_INTERNAL__MAC_10_6_DEP__MAC_10_9
+#endif // __AVAILABILITY_INTERNAL__MAC_10_6_DEP__MAC_10_9
+
+#ifndef __AVAILABILITY_INTERNAL__MAC_10_7_DEP__MAC_10_9
+#define __AVAILABILITY_INTERNAL__MAC_10_7_DEP__MAC_10_9
+#endif // __AVAILABILITY_INTERNAL__MAC_10_7_DEP__MAC_10_9
+
+#if !defined(__has_include)
+#define __has_include(x) 0
+#endif
+
+#if !defined(__has_attribute)
+#define __has_attribute(x) 0
+#endif
+
+#if __has_include(<xpc/availability.h>)
+#include <xpc/availability.h>
+#else
+#include <Availability.h>
+#define __XPC_IOS_SIMULATOR_AVAILABLE_STARTING(version)
+#endif
+
+#ifndef __XPC_INDIRECT__
+#error "Please #include <xpc/xpc.h> instead of this file directly."
+#endif // __XPC_INDIRECT__ 
+
+#pragma mark Attribute Shims
+#ifdef __GNUC__
+#define XPC_CONSTRUCTOR __attribute__((constructor))
+#define XPC_NORETURN __attribute__((__noreturn__))
+#define XPC_NOTHROW __attribute__((__nothrow__))
+#define XPC_NONNULL1 __attribute__((__nonnull__(1)))
+#define XPC_NONNULL2 __attribute__((__nonnull__(2)))
+#define XPC_NONNULL3 __attribute__((__nonnull__(3)))
+#define XPC_NONNULL4 __attribute__((__nonnull__(4)))
+#define XPC_NONNULL5 __attribute__((__nonnull__(5)))
+#define XPC_NONNULL6 __attribute__((__nonnull__(6)))
+#define XPC_NONNULL7 __attribute__((__nonnull__(7)))
+#define XPC_NONNULL8 __attribute__((__nonnull__(8)))
+#define XPC_NONNULL9 __attribute__((__nonnull__(9)))
+#define XPC_NONNULL10 __attribute__((__nonnull__(10)))
+#define XPC_NONNULL11 __attribute__((__nonnull__(11)))
+#define XPC_NONNULL_ALL __attribute__((__nonnull__))
+#define XPC_SENTINEL __attribute__((__sentinel__))
+#define XPC_PURE __attribute__((__pure__))
+#define XPC_WARN_RESULT __attribute__((__warn_unused_result__))
+#define XPC_MALLOC __attribute__((__malloc__))
+#define XPC_UNUSED __attribute__((unused))
+#define XPC_USED __attribute__((used))
+#define XPC_PACKED __attribute__((__packed__))
+#define XPC_PRINTF(m, n) __attribute__((format(printf, m, n)))
+#define XPC_INLINE static __inline__ __attribute__((__always_inline__))
+#define XPC_NOINLINE __attribute__((noinline))
+#define XPC_NOIMPL __attribute__((unavailable))
+
+#if __has_extension(attribute_unavailable_with_message)
+#define XPC_UNAVAILABLE(m) __attribute__((unavailable(m)))
+#else // __has_extension(attribute_unavailable_with_message)
+#define XPC_UNAVAILABLE(m) XPC_NOIMPL
+#endif // __has_extension(attribute_unavailable_with_message)
+
+#define XPC_EXPORT extern __attribute__((visibility("default")))
+#define XPC_NOEXPORT __attribute__((visibility("hidden")))
+#define XPC_WEAKIMPORT extern __attribute__((weak_import))
+#define XPC_DEBUGGER_EXCL XPC_NOEXPORT XPC_USED
+#define XPC_TRANSPARENT_UNION __attribute__((transparent_union))
+#if __clang__
+#define XPC_DEPRECATED(m)	__attribute__((deprecated(m)))
+#else
+#define XPC_DEPRECATED(m)	__attribute__((deprecated))
+#endif // __clang 
+
+#if __OBJC__
+#define XPC_GIVES_REFERENCE __strong
+#define XPC_UNRETAINED __unsafe_unretained
+#define XPC_BRIDGE(xo) ((__bridge void *)(xo))
+#define XPC_BRIDGEREF_BEGIN(xo) ((__bridge_retained void *)(xo))
+#define XPC_BRIDGEREF_BEGIN_WITH_REF(xo) ((__bridge void *)(xo))
+#define XPC_BRIDGEREF_MIDDLE(xo) ((__bridge id)(xo))
+#define XPC_BRIDGEREF_END(xo) ((__bridge_transfer id)(xo))
+#else // __OBJC__
+#define XPC_GIVES_REFERENCE
+#define XPC_UNRETAINED
+#define XPC_BRIDGE(xo)
+#define XPC_BRIDGEREF_BEGIN(xo) (xo)
+#define XPC_BRIDGEREF_BEGIN_WITH_REF(xo) (xo)
+#define XPC_BRIDGEREF_MIDDLE(xo) (xo)
+#define XPC_BRIDGEREF_END(xo) (xo)
+#endif // __OBJC__
+#else // __GNUC__ 
+/*! @parseOnly */
+#define XPC_CONSTRUCTOR
+/*! @parseOnly */
+#define XPC_NORETURN
+/*! @parseOnly */
+#define XPC_NOTHROW
+/*! @parseOnly */
+#define XPC_NONNULL1
+/*! @parseOnly */
+#define XPC_NONNULL2
+/*! @parseOnly */
+#define XPC_NONNULL3
+/*! @parseOnly */
+#define XPC_NONNULL4
+/*! @parseOnly */
+#define XPC_NONNULL5
+/*! @parseOnly */
+#define XPC_NONNULL6
+/*! @parseOnly */
+#define XPC_NONNULL7
+/*! @parseOnly */
+#define XPC_NONNULL8
+/*! @parseOnly */
+#define XPC_NONNULL9
+/*! @parseOnly */
+#define XPC_NONNULL10
+/*! @parseOnly */
+#define XPC_NONNULL11
+/*! @parseOnly */
+#define XPC_NONNULL(n)
+/*! @parseOnly */
+#define XPC_NONNULL_ALL
+/*! @parseOnly */
+#define XPC_SENTINEL
+/*! @parseOnly */
+#define XPC_PURE
+/*! @parseOnly */
+#define XPC_WARN_RESULT
+/*! @parseOnly */
+#define XPC_MALLOC
+/*! @parseOnly */
+#define XPC_UNUSED
+/*! @parseOnly */
+#define XPC_PACKED
+/*! @parseOnly */
+#define XPC_PRINTF(m, n)
+/*! @parseOnly */
+#define XPC_INLINE static inline
+/*! @parseOnly */
+#define XPC_NOINLINE
+/*! @parseOnly */
+#define XPC_NOIMPL
+/*! @parseOnly */
+#define XPC_EXPORT extern
+/*! @parseOnly */
+#define XPC_WEAKIMPORT
+/*! @parseOnly */
+#define XPC_DEPRECATED
+/*! @parseOnly */
+#define XPC_UNAVAILABLE(m)
+#endif // __GNUC__ 
+
+#define XPC_PROJECT_EXPORT XPC_EXPORT
+
+__END_DECLS
+
+#endif // __XPC_BASE_H__ 

+ 710 - 0
uicache/xpc/connection.h

@@ -0,0 +1,710 @@
+#ifndef __XPC_CONNECTION_H__
+#define __XPC_CONNECTION_H__
+
+#ifndef __XPC_INDIRECT__
+#error "Please #include <xpc/xpc.h> instead of this file directly."
+// For HeaderDoc. 
+#include <xpc/base.h>
+#endif // __XPC_INDIRECT__ 
+
+#ifndef __BLOCKS__
+#error "XPC connections require Blocks support."
+#endif // __BLOCKS__
+
+__BEGIN_DECLS
+
+/*!
+ * @constant XPC_ERROR_CONNECTION_INTERRUPTED
+ * Will be delivered to the connection's event handler if the remote service
+ * exited. The connection is still live even in this case, and resending a
+ * message will cause the service to be launched on-demand. This error serves
+ * as a client's indication that it should resynchronize any state that it had
+ * given the service.
+ *
+ * Any messages in the queue to be sent will be unwound and canceled when this
+ * error occurs. In the case where a message waiting to be sent has a reply
+ * handler, that handler will be invoked with this error. In the context of the
+ * reply handler, this error indicates that a reply to the message will never
+ * arrive.
+ *
+ * Messages that do not have reply handlers associated with them will be
+ * silently disposed of. This error will only be given to peer connections.
+ */
+#define XPC_ERROR_CONNECTION_INTERRUPTED \
+	XPC_GLOBAL_OBJECT(_xpc_error_connection_interrupted)
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT
+const struct _xpc_dictionary_s _xpc_error_connection_interrupted;
+
+/*!
+ * @constant XPC_ERROR_CONNECTION_INVALID
+ * Will be delivered to the connection's event handler if the named service
+ * provided to xpc_connection_create() could not be found in the XPC service
+ * namespace. The connection is useless and should be disposed of.
+ *
+ * Any messages in the queue to be sent will be unwound and canceled when this
+ * error occurs, similarly to the behavior when XPC_ERROR_CONNECTION_INTERRUPTED
+ * occurs. The only difference is that the XPC_ERROR_CONNECTION_INVALID will be
+ * given to outstanding reply handlers and the connection's event handler.
+ *
+ * This error may be given to any type of connection.
+ */
+#define XPC_ERROR_CONNECTION_INVALID \
+	XPC_GLOBAL_OBJECT(_xpc_error_connection_invalid)
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT
+const struct _xpc_dictionary_s _xpc_error_connection_invalid;
+
+/*!
+ * @constant XPC_ERROR_TERMINATION_IMMINENT
+ * This error will be delivered to a peer connection's event handler when the
+ * XPC runtime has determined that the program should exit and that all
+ * outstanding transactions must be wound down, and no new transactions can be
+ * opened.
+ *
+ * After this error has been delivered to the event handler, no more messages
+ * will be received by the connection. The runtime will still attempt to deliver
+ * outgoing messages, but this error should be treated as an indication that
+ * the program will exit very soon, and any outstanding business over the
+ * connection should be wrapped up as quickly as possible and the connection
+ * canceled shortly thereafter.
+ *
+ * This error will only be delivered to peer connections received through a
+ * listener or the xpc_main() event handler.
+ */
+#define XPC_ERROR_TERMINATION_IMMINENT \
+	XPC_GLOBAL_OBJECT(_xpc_error_termination_imminent)
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT
+const struct _xpc_dictionary_s _xpc_error_termination_imminent;
+
+/*!
+ * @constant XPC_CONNECTION_MACH_SERVICE_LISTENER
+ * Passed to xpc_connection_create_mach_service(). This flag indicates that the
+ * caller is the listener for the named service. This flag may only be passed
+ * for services which are advertised in the process' launchd.plist(5). You may
+ * not use this flag to dynamically add services to the Mach bootstrap
+ * namespace.
+ */
+#define XPC_CONNECTION_MACH_SERVICE_LISTENER (1 << 0)
+
+/*!
+ * @constant XPC_CONNECTION_MACH_SERVICE_PRIVILEGED
+ * Passed to xpc_connection_create_mach_service(). This flag indicates that the
+ * job advertising the service name in its launchd.plist(5) should be in the
+ * privileged Mach bootstrap. This is typically accomplished by placing your
+ * launchd.plist(5) in /Library/LaunchDaemons. If specified alongside the
+ * XPC_CONNECTION_MACH_SERVICE_LISTENER flag, this flag is a no-op.
+ */
+#define XPC_CONNECTION_MACH_SERVICE_PRIVILEGED (1 << 1)
+
+/*!
+ * @typedef xpc_finalizer_f
+ * A function that is invoked when a connection is being torn down and its
+ * context needs to be freed. It is not safe to reference the connection from
+ * within this function.
+ *
+ * @param value
+ * The context object that is to be disposed of.
+ */
+typedef void (*xpc_finalizer_t)(void *value);
+
+/*!
+ * @function xpc_connection_create
+ * Creates a new connection object.
+ * 
+ * @param name
+ * If non-NULL, the name of the service with which to connect. The returned
+ * connection will be a peer.
+ * 
+ * If NULL, an anonymous listener connection will be created. You can embed the
+ * ability to create new peer connections in an endpoint, which can be inserted
+ * into a message and sent to another process .
+ *
+ * @param targetq
+ * The GCD queue to which the event handler block will be submitted. This
+ * parameter may be NULL, in which case the connection's target queue will be
+ * libdispatch's default target queue, defined as DISPATCH_TARGET_QUEUE_DEFAULT.
+ * The target queue may be changed later with a call to
+ * xpc_connection_set_target_queue().
+ *
+ * @result
+ * A new connection object. The caller is responsible for disposing of the
+ * returned object with {@link xpc_release} when it is no longer needed.
+ *
+ * @discussion
+ * This method will succeed even if the named service does not exist. This is
+ * because the XPC namespace is not queried for the service name until
+ * the first call to xpc_connection_resume().
+ *
+ * XPC connections, like dispatch sources, are returned in a suspended state, so 
+ * you must call {@link xpc_connection_resume()} in order to begin receiving
+ * events from the connection. Also like dispatch sources, connections must be
+ * resumed in order to be safely released. It is a programming error to release
+ * a suspended connection.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT
+xpc_connection_t
+xpc_connection_create(const char *name, dispatch_queue_t targetq);
+
+/*!
+ * @function xpc_connection_create_mach_service
+ * Creates a new connection object representing a Mach service.
+ * 
+ * @param name
+ * The name of the remote service with which to connect. The service name must
+ * exist in a Mach bootstrap that is accessible to the process and be advertised
+ * in a launchd.plist.
+ *
+ * @param targetq
+ * The GCD queue to which the event handler block will be submitted. This
+ * parameter may be NULL, in which case the connection's target queue will be
+ * libdispatch's default target queue, defined as DISPATCH_TARGET_QUEUE_DEFAULT.
+ * The target queue may be changed later with a call to
+ * xpc_connection_set_target_queue().
+ *
+ * @param flags
+ * Additional attributes with which to create the connection.
+ *
+ * @result
+ * A new connection object. 
+ *
+ * @discussion
+ * If the XPC_CONNECTION_MACH_SERVICE_LISTENER flag is given to this method,
+ * then the connection returned will be a listener connection. Otherwise, a peer
+ * connection will be returned. See the documentation for
+ * {@link xpc_connection_set_event_handler()} for the semantics of listener
+ * connections versus peer connections.
+ * 
+ * This method will succeed even if the named service does not exist. This is
+ * because the Mach namespace is not queried for the service name until the
+ * first call to {@link xpc_connection_resume()}.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1
+xpc_connection_t
+xpc_connection_create_mach_service(const char *name, dispatch_queue_t targetq,
+	uint64_t flags);
+
+/*!
+ * @function xpc_connection_create_from_endpoint
+ * Creates a new connection from the given endpoint.
+ * 
+ * @param endpoint
+ * The endpoint from which to create the new connection.
+ *
+ * @result
+ * A new peer connection to the listener represented by the given endpoint.
+ * 
+ * The same responsibilities of setting an event handler and resuming the 
+ * connection after calling xpc_connection_create() apply to the connection
+ * returned by this API. Since the connection yielded by this API is not
+ * associated with a name (and therefore is not rediscoverable), this connection
+ * will receive XPC_ERROR_CONNECTION_INVALID if the listening side crashes,
+ * exits or cancels the listener connection.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL_ALL
+xpc_connection_t
+xpc_connection_create_from_endpoint(xpc_endpoint_t endpoint);
+
+/*!
+ * @function xpc_connection_set_target_queue
+ * Sets the target queue of the given connection.
+ * 
+ * @param connection
+ * The connection object which is to be manipulated.
+ *
+ * @param targetq
+ * The GCD queue to which the event handler block will be submitted. This
+ * parameter may be NULL, in which case the connection's target queue will be
+ * libdispatch's default target queue, defined as DISPATCH_TARGET_QUEUE_DEFAULT.
+ *
+ * @discussion
+ * Setting the target queue is asynchronous and non-preemptive and therefore
+ * this method will not interrupt the execution of an already-running event
+ * handler block. Setting the target queue may be likened to issuing a barrier
+ * to the connection which does the actual work of changing the target queue.
+ *
+ * The XPC runtime guarantees this non-preemptiveness even for concurrent target
+ * queues. If the target queue is a concurrent queue, then XPC still guarantees
+ * that there will never be more than one invocation of the connection's event
+ * handler block executing concurrently. If you wish to process events
+ * concurrently, you can dispatch_async(3) to a concurrent queue from within
+ * the event handler.
+ *
+ * IMPORTANT: When called from within the event handler block,
+ * dispatch_get_current_queue(3) is NOT guaranteed to return a pointer to the
+ * queue set with this method.
+ * 
+ * Despite this seeming inconsistency, the XPC runtime guarantees that, when the
+ * target queue is a serial queue, the event handler block will execute
+ * synchonously with respect to other blocks submitted to that same queue. When
+ * the target queue is a concurrent queue, the event handler block may run
+ * concurrently with other blocks submitted to that queue, but it will never run
+ * concurrently with other invocations of itself for the same connection, as
+ * discussed previously.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL1
+void
+xpc_connection_set_target_queue(xpc_connection_t connection,
+	dispatch_queue_t targetq);
+
+/*!
+ * @function xpc_connection_set_event_handler
+ * Sets the event handler block for the connection.
+ * 
+ * @param connection
+ * The connection object which is to be manipulated.
+ *
+ * @param handler
+ * The event handler block.
+ *
+ * @discussion
+ * Setting the event handler is asynchronous and non-preemptive, and therefore
+ * this method will not interrupt the execution of an already-running event
+ * handler block. If the event handler is executing at the time of this call, it
+ * will finish, and then the connection's event handler will be changed before
+ * the next invocation of the event handler. The XPC runtime guarantees this
+ * non-preemptiveness even for concurrent target queues.
+ *
+ * Connection event handlers are non-reentrant, so it is safe to call
+ * xpc_connection_set_event_handler() from within the event handler block.
+ *
+ * The event handler's execution should be treated as a barrier to all
+ * connection activity. When it is executing, the connection will not attempt to
+ * send or receive messages, including reply messages. Thus, it is not safe to
+ * call xpc_connection_send_message_with_reply_sync() on the connection from
+ * within the event handler.
+ *
+ * You do not hold a reference on the object received as the event handler's
+ * only argument. Regardless of the type of object received, it is safe to call
+ * xpc_retain() on the object to obtain a reference to it.
+ *
+ * A connection may receive different events depending upon whether it is a
+ * listener or not. Any connection may receive an error in its event handler.
+ * But while normal connections may receive messages in addition to errors, 
+ * listener connections will receive connections and and not messages.
+ *
+ * Connections received by listeners are equivalent to those returned by
+ * xpc_connection_create() with a non-NULL name argument and a NULL targetq
+ * argument with the exception that you do not hold a reference on them.
+ * You must set an event handler and resume the connection. If you do not wish
+ * to accept the connection, you may simply call xpc_connection_cancel() on it
+ * and return. The runtime will dispose of it for you.
+ * 
+ * If there is an error in the connection, this handler will be invoked with the
+ * error dictionary as its argument. This dictionary will be one of the well-
+ * known XPC_ERROR_* dictionaries.
+ *
+ * Regardless of the type of event, ownership of the event object is NOT
+ * implicitly transferred. Thus, the object will be released and deallocated at
+ * some point in the future after the event handler returns. If you wish the
+ * event's lifetime to persist, you must retain it with xpc_retain().
+ *
+ * Connections received through the event handler will be released and
+ * deallocated after the connection has gone invalid and delivered that event to
+ * its event handler.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL_ALL
+void
+xpc_connection_set_event_handler(xpc_connection_t connection, 
+	xpc_handler_t handler);
+
+/*!
+ * @function xpc_connection_suspend
+ * Suspends the connection so that the event handler block will not fire and
+ * that the connection will not attempt to send any messages it has in its
+ * queue. All calls to xpc_connection_suspend() must be balanced with calls to
+ * xpc_connection_resume() before releasing the last reference to the
+ * connection.
+ * 
+ * @param connection
+ * The connection object which is to be manipulated.
+ *
+ * @discussion
+ * Suspension is asynchronous and non-preemptive, and therefore this method will
+ * not interrupt the execution of an already-running event handler block. If
+ * the event handler is executing at the time of this call, it will finish, and
+ * then the connection will be suspended before the next scheduled invocation
+ * of the event handler. The XPC runtime guarantees this non-preemptiveness even
+ * for concurrent target queues.
+ *
+ * Connection event handlers are non-reentrant, so it is safe to call
+ * xpc_connection_suspend() from within the event handler block.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL_ALL
+void
+xpc_connection_suspend(xpc_connection_t connection);
+
+/*!
+ * @function xpc_connection_resume
+ * Resumes the connection. Connections start in a suspended state, so you must
+ * call xpc_connection_resume() on a connection before it will send or receive
+ * any messages.
+ * 
+ * @param connection
+ * The connection object which is to be manipulated.
+ *
+ * @discussion
+ * In order for a connection to become live, every call to
+ * xpc_connection_suspend() must be balanced with a call to 
+ * xpc_connection_resume() after the initial call to xpc_connection_resume().
+ * After the initial resume of the connection, calling xpc_connection_resume()
+ * more times than xpc_connection_suspend() has been called is considered an
+ * error.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL_ALL
+void
+xpc_connection_resume(xpc_connection_t connection);
+
+/*!
+ * @function xpc_connection_send_message
+ * Sends a message over the connection to the destination service.
+ * 
+ * @param connection
+ * The connection over which the message shall be sent.
+ *
+ * @param message
+ * The message to send. This must be a dictionary object. This dictionary is
+ * logically copied by the connection, so it is safe to modify the dictionary
+ * after this call.
+ *
+ * @discussion
+ * Messages are delivered in FIFO order. This API is safe to call from multiple
+ * GCD queues. There is no indication that a message was delivered successfully.
+ * This is because even once the message has been successfully enqueued on the
+ * remote end, there are no guarantees about when the runtime will dequeue the
+ * message and invoke the other connection's event handler block.
+ *
+ * If this API is used to send a message that is in reply to another message,
+ * there is no guarantee of ordering between the invocations of the connection's
+ * event handler and the reply handler for that message, even if they are
+ * targeted to the same queue.
+ *
+ * After extensive study, we have found that clients who are interested in
+ * the state of the message on the server end are typically holding open
+ * transactions related to that message. And the only reliable way to track the
+ * lifetime of that transaction is at the protocol layer. So the server should
+ * send a reply message, which upon receiving, will cause the client to close
+ * its transaction.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL_ALL
+void
+xpc_connection_send_message(xpc_connection_t connection, xpc_object_t message);
+
+/*!
+ * @function xpc_connection_send_barrier
+ * Issues a barrier against the connection's message-send activity.
+ * 
+ * @param connection
+ * The connection against which the barrier is to be issued.
+ *
+ * @param barrier
+ * The barrier block to issue. This barrier prevents concurrent message-send
+ * activity on the connection. No messages will be sent while the barrier block
+ * is executing.
+ *
+ * @discussion
+ * XPC guarantees that, even if the connection's target queue is a concurrent
+ * queue, there are no other messages being sent concurrently while the barrier
+ * block is executing. XPC does not guarantee that the reciept of messages
+ * (either through the connection's event handler or through reply handlers)
+ * will be suspended while the barrier is executing.
+ *
+ * A barrier is issued relative to the message-send queue. Thus, if you call
+ * xpc_connection_send_message() five times and then call
+ * xpc_connection_send_barrier(), the barrier will be invoked after the fifth
+ * message has been sent and its memory disposed of. You may safely cancel a
+ * connection from within a barrier block.
+ *
+ * If a barrier is issued after sending a message which expects a reply, the
+ * behavior is the same as described above. The receipt of a reply message will
+ * not influence when the barrier runs.
+ *
+ * A barrier block can be useful for throttling resource consumption on the
+ * connected side of a connection. For example, if your connection sends many
+ * large messages, you can use a barrier to limit the number of messages that
+ * are inflight at any given time. This can be particularly useful for messages
+ * that contain kernel resources (like file descriptors) which have a system-
+ * wide limit.
+ *
+ * If a barrier is issued on a canceled connection, it will be invoked
+ * immediately. If a connection has been canceled and still has outstanding
+ * barriers, those barriers will be invoked as part of the connection's
+ * unwinding process.
+ *
+ * It is important to note that a barrier block's execution order is not
+ * guaranteed with respect to other blocks that have been scheduled on the
+ * target queue of the connection. Or said differently,
+ * xpc_connection_send_barrier(3) is not equivalent to dispatch_async(3).
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL_ALL
+void
+xpc_connection_send_barrier(xpc_connection_t connection, 
+	dispatch_block_t barrier);
+
+/*!
+ * @function xpc_connection_send_message_with_reply
+ * Sends a message over the connection to the destination service and associates
+ * a handler to be invoked when the remote service sends a reply message.
+ * 
+ * @param connection
+ * The connection over which the message shall be sent.
+ *
+ * @param message
+ * The message to send. This must be a dictionary object.
+ *
+ * @param replyq
+ * The GCD queue to which the reply handler will be submitted. This may be a
+ * concurrent queue.
+ *
+ * @param handler
+ * The handler block to invoke when a reply to the message is received from
+ * the connection. If the remote service exits prematurely before the reply was
+ * received, the XPC_ERROR_CONNECTION_INTERRUPTED error will be returned.
+ * If the connection went invalid before the message could be sent, the
+ * XPC_ERROR_CONNECTION_INVALID error will be returned.
+ *
+ * @discussion
+ * If the given GCD queue is a concurrent queue, XPC cannot guarantee that there
+ * will not be multiple reply handlers being invoked concurrently. XPC does not
+ * guarantee any ordering for the invocation of reply handers. So if multiple
+ * messages are waiting for replies and the connection goes invalid, there is no
+ * guarantee that the reply handlers will be invoked in FIFO order. Similarly,
+ * XPC does not guarantee that reply handlers will not run concurrently with
+ * the connection's event handler in the case that the reply queue and the
+ * connection's target queue are the same concurrent queue.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 XPC_NONNULL4
+void
+xpc_connection_send_message_with_reply(xpc_connection_t connection,
+	xpc_object_t message, dispatch_queue_t replyq, xpc_handler_t handler);
+
+/*!
+ * @function xpc_connection_send_message_with_reply_sync
+ * Sends a message over the connection and blocks the caller until a reply is
+ * received.
+ * 
+ * @param connection
+ * The connection over which the message shall be sent.
+ *
+ * @param message
+ * The message to send. This must be a dictionary object.
+ *
+ * @result
+ * The message that the remote service sent in reply to the original message.
+ * If the remote service exits prematurely before the reply was received, the
+ * XPC_ERROR_CONNECTION_INTERRUPTED error will be returned. If the connection
+ * went invalid before the message could be sent, the
+ * XPC_ERROR_CONNECTION_INVALID error will be returned.
+ *
+ * You are responsible for releasing the returned object.
+ *
+ * @discussion
+ * This API is primarily for transitional purposes. Its implementation is
+ * conceptually equivalent to calling xpc_connection_send_message_with_reply()
+ * and then immediately blocking the calling thread on a semaphore and
+ * signaling the semaphore from the reply block. 
+ *
+ * Be judicious about your use of this API. It can block indefinitely, so if you
+ * are using it to implement an API that can be called from the main thread, you
+ * may wish to consider allowing the API to take a queue and callback block so
+ * that results may be delivered asynchrously if possible.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT XPC_RETURNS_RETAINED
+xpc_object_t
+xpc_connection_send_message_with_reply_sync(xpc_connection_t connection,
+	xpc_object_t message);
+
+/*!
+ * @function xpc_connection_cancel
+ * Cancels the connection and ensures that its event handler will not fire
+ * again. After this call, any messages that have not yet been sent will be
+ * discarded, and the connection will be unwound. If there are messages that are
+ * awaiting replies, they will have their reply handlers invoked with the
+ * XPC_ERROR_CONNECTION_INVALID error.
+ * 
+ * @param connection
+ * The connection object which is to be manipulated.
+ *
+ * @discussion
+ * Cancellation is asynchronous and non-preemptive and therefore this method
+ * will not interrupt the execution of an already-running event handler block.
+ * If the event handler is executing at the time of this call, it will finish,
+ * and then the connection will be canceled, causing a final invocation of the
+ * event handler to be scheduled with the XPC_ERROR_CONNECTION_INVALID error.
+ * After that invocation, there will be no further invocations of the event
+ * handler.
+ *
+ * The XPC runtime guarantees this non-preemptiveness even for concurrent target
+ * queues.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL_ALL
+void
+xpc_connection_cancel(xpc_connection_t connection);
+
+/*!
+ * @function xpc_connection_get_name
+ * Returns the name of the service with which the connections was created.
+ * 
+ * @param connection
+ * The connection object which is to be examined.
+ *
+ * @result
+ * The name of the remote service. If you obtained the connection through an
+ * invocation of another connection's event handler, NULL is returned.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT
+const char *
+xpc_connection_get_name(xpc_connection_t connection);
+
+/*!
+ * @function xpc_connection_get_euid
+ * Returns the EUID of the remote peer.
+ * 
+ * @param connection
+ * The connection object which is to be examined.
+ *
+ * @result
+ * The EUID of the remote peer at the time the connection was made.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT
+uid_t
+xpc_connection_get_euid(xpc_connection_t connection);
+
+/*!
+ * @function xpc_connection_get_egid
+ * Returns the EGID of the remote peer.
+ * 
+ * @param connection
+ * The connection object which is to be examined.
+ *
+ * @result
+ * The EGID of the remote peer at the time the connection was made.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT
+gid_t
+xpc_connection_get_egid(xpc_connection_t connection);
+
+/*!
+ * @function xpc_connection_get_pid
+ * Returns the PID of the remote peer.
+ * 
+ * @param connection
+ * The connection object which is to be examined.
+ *
+ * @result
+ * The PID of the remote peer.
+ *
+ * @discussion
+ * A given PID is not guaranteed to be unique across an entire boot cycle.
+ * Great care should be taken when dealing with this information, as it can go
+ * stale after the connection is established. Mac OS X recycles PIDs, and
+ * therefore another process could spawn and claim the PID before a message is 
+ * actually received from the connection.
+ *
+ * XPC will deliver an error to your event handler if the remote process goes
+ * away, but there are no guarantees as to the timing of this notification's
+ * delivery either at the kernel layer or at the XPC layer.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT
+pid_t
+xpc_connection_get_pid(xpc_connection_t connection);
+
+/*!
+ * @function xpc_connection_get_asid
+ * Returns the audit session identifier of the remote peer.
+ * 
+ * @param connection
+ * The connection object which is to be examined.
+ *
+ * @result
+ * The audit session ID of the remote peer at the time the connection was made.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT
+au_asid_t
+xpc_connection_get_asid(xpc_connection_t connection);
+
+/*!
+ * @function xpc_connection_set_context
+ * Sets context on an connection.
+ *
+ * @param connection
+ * The connection which is to be manipulated.
+ *
+ * @param context
+ * The context to associate with the connection.
+ *
+ * @discussion
+ * If you must manage the memory of the context object, you must set a finalizer
+ * to dispose of it. If this method is called on a connection which already has
+ * context associated with it, the finalizer will NOT be invoked. The finalizer
+ * is only invoked when the connection is being deallocated.
+ *
+ * It is recommended that, instead of changing the actual context pointer
+ * associated with the object, you instead change the state of the context
+ * object itself. 
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL1
+void
+xpc_connection_set_context(xpc_connection_t connection, void *context);
+
+/*!
+ * @function xpc_connection_get_context
+ * Returns the context associated with the connection.
+ *
+ * @param connection
+ * The connection which is to be examined.
+ *
+ * @result
+ * The context associated with the connection. NULL if there has been no context
+ * associated with the object.
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL_ALL XPC_WARN_RESULT
+void *
+xpc_connection_get_context(xpc_connection_t connection);
+
+/*!
+ * @function xpc_connection_set_finalizer_f
+ * Sets the finalizer for the given connection.
+ *
+ * @param connection
+ * The connection on which to set the finalizer.
+ *
+ * @param finalizer
+ * The function that will be invoked when the connection's retain count has
+ * dropped to zero and is being torn down.
+ *
+ * @discussion
+ * For many uses of context objects, this API allows for a convenient shorthand
+ * for freeing them. For example, for a context object allocated with malloc(3):
+ *
+ * xpc_connection_set_finalizer_f(object, free);
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_NONNULL1
+void
+xpc_connection_set_finalizer_f(xpc_connection_t connection,
+	xpc_finalizer_t finalizer);
+
+__END_DECLS
+
+#endif // __XPC_CONNECTION_H__ 

+ 23 - 0
uicache/xpc/debug.h

@@ -0,0 +1,23 @@
+#ifndef __XPC_DEBUG_H__
+#define __XPC_DEBUG_H__
+
+/*!
+ * @function xpc_debugger_api_misuse_info
+ * Returns a pointer to a string describing the reason XPC aborted the calling
+ * process. On OS X, this will be the same string present in the "Application
+ * Specific Information" section of the crash report.
+ * 
+ * @result
+ * A pointer to the human-readable string describing the reason the caller was
+ * aborted. If XPC was not responsible for the program's termination, NULL will
+ * be returned.
+ *
+ * @discussion
+ * This function is only callable from within a debugger. It is not meant to be
+ * called by the program directly.
+ */
+XPC_DEBUGGER_EXCL
+const char *
+xpc_debugger_api_misuse_info(void);
+
+#endif // __XPC_DEBUG_H__ 

+ 22 - 0
uicache/xpc/endpoint.h

@@ -0,0 +1,22 @@
+#ifndef __XPC_ENDPOINT_H__
+#define __XPC_ENDPOINT_H__
+
+/*!
+ * @function xpc_endpoint_create
+ * Creates a new endpoint from a connection that is suitable for embedding into
+ * messages.
+ * 
+ * @param connection
+ * Only connections obtained through calls to xpc_connection_create*() may be
+ * given to this API. Passing any other type of connection is not supported and
+ * will result in undefined behavior.
+ *
+ * @result
+ * A new endpoint object. 
+ */
+__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
+XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1
+xpc_endpoint_t
+xpc_endpoint_create(xpc_connection_t connection);
+
+#endif // __XPC_ENDPOINT_H__ 

File diff suppressed because it is too large
+ 2506 - 0
uicache/xpc/xpc.h