this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Some very early work on launchservicesd

+500 -154
+7 -1
src/frameworks/ApplicationServices/HIServices/CMakeLists.txt
··· 3 3 set(DYLIB_COMPAT_VERSION "1.0.0") 4 4 set(DYLIB_CURRENT_VERSION "628.0.0") 5 5 6 + include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src/external/libcxx/include) 7 + 6 8 add_framework(HIServices 7 9 FAT 8 10 CURRENT_VERSION ··· 11 13 12 14 SOURCES 13 15 src/HIServices.c 16 + src/Processes.cpp 14 17 15 18 DEPENDENCIES 16 - CoreFoundation 19 + CoreFoundation 17 20 system 21 + cxx 22 + LaunchServices 23 + CoreGraphics 18 24 )
+13
src/frameworks/ApplicationServices/HIServices/include/HIServices/HIServices.h
··· 20 20 21 21 #ifndef _HIServices_H_ 22 22 #define _HIServices_H_ 23 + #include <CoreServices/MacTypes.h> 24 + #include "Processes.h" 25 + 26 + #ifdef __cplusplus 27 + extern "C" { 28 + #endif 29 + 30 + OSStatus SetApplicationIsDaemon(Boolean daemon); 31 + Boolean GetApplicationIsDaemon(void); 32 + 33 + #ifdef __cplusplus 34 + } 35 + #endif 23 36 24 37 #endif
+19 -126
src/frameworks/ApplicationServices/HIServices/src/HIServices.c
··· 22 22 #include <stdlib.h> 23 23 #include <stdio.h> 24 24 #include <CoreFoundation/CoreFoundation.h> 25 + #include <LaunchServices/LaunchServicesPriv.h> 26 + #include <CoreGraphics/CGS.h> 25 27 26 28 const CFStringRef kAXUIElementCopyHierarchyArrayAttributesKey = CFSTR("AXCHAA"); 27 29 const CFStringRef kAXUIElementCopyHierarchyMaxArrayCountKey = CFSTR("AXCHMAC"); ··· 33 35 CFStringRef kAXTrustedCheckOptionPrompt = CFSTR("AXTrustedCheckOptionPrompt"); 34 36 35 37 static int verbose = 0; 38 + static Boolean g_isDaemon = FALSE; 36 39 37 40 __attribute__((constructor)) 38 41 static void initme(void) { 39 42 verbose = getenv("STUB_VERBOSE") != NULL; 43 + } 44 + 45 + OSStatus SetApplicationIsDaemon(Boolean daemon) 46 + { 47 + g_isDaemon = daemon; 48 + if (daemon) 49 + CGSSetDenyWindowServerConnections(TRUE); 50 + 51 + _LSSetApplicationLaunchServicesServerConnectionStatus(daemon ? 2 : 0, NULL); 52 + 53 + return noErr; 54 + } 55 + 56 + Boolean GetApplicationIsDaemon(void) 57 + { 58 + return g_isDaemon; 40 59 } 41 60 42 61 void* AXAPIEnabled(void) ··· 348 367 void* CopyLabelColorAndName(void) 349 368 { 350 369 if (verbose) puts("STUB: CopyLabelColorAndName called"); 351 - return NULL; 352 - } 353 - 354 - void* CopyProcessName(void) 355 - { 356 - if (verbose) puts("STUB: CopyProcessName called"); 357 370 return NULL; 358 371 } 359 372 ··· 1509 1522 return NULL; 1510 1523 } 1511 1524 1512 - void* ExitToShell(void) 1513 - { 1514 - if (verbose) puts("STUB: ExitToShell called"); 1515 - return NULL; 1516 - } 1517 - 1518 - void* GetApplicationIsDaemon(void) 1519 - { 1520 - if (verbose) puts("STUB: GetApplicationIsDaemon called"); 1521 - return NULL; 1522 - } 1523 - 1524 - void* GetCurrentProcess(void) 1525 - { 1526 - if (verbose) puts("STUB: GetCurrentProcess called"); 1527 - return NULL; 1528 - } 1529 - 1530 - void* GetFrontProcess(void) 1531 - { 1532 - if (verbose) puts("STUB: GetFrontProcess called"); 1533 - return NULL; 1534 - } 1535 - 1536 1525 void* GetGlobalIconImagesCacheMaxEntriesAndMaxDataSize(void) 1537 1526 { 1538 1527 if (verbose) puts("STUB: GetGlobalIconImagesCacheMaxEntriesAndMaxDataSize called"); ··· 1551 1540 return NULL; 1552 1541 } 1553 1542 1554 - void* GetNextProcess(void) 1555 - { 1556 - if (verbose) puts("STUB: GetNextProcess called"); 1557 - return NULL; 1558 - } 1559 - 1560 - void* GetProcessBundleLocation(void) 1561 - { 1562 - if (verbose) puts("STUB: GetProcessBundleLocation called"); 1563 - return NULL; 1564 - } 1565 - 1566 - void* GetProcessForPID(void) 1567 - { 1568 - if (verbose) puts("STUB: GetProcessForPID called"); 1569 - return NULL; 1570 - } 1571 - 1572 - void* GetProcessInformation(void) 1573 - { 1574 - if (verbose) puts("STUB: GetProcessInformation called"); 1575 - return NULL; 1576 - } 1577 - 1578 - void* GetProcessPID(void) 1579 - { 1580 - if (verbose) puts("STUB: GetProcessPID called"); 1581 - return NULL; 1582 - } 1583 - 1584 1543 void* HIS_XPC_CFNotificationCenterPostNotification(void) 1585 1544 { 1586 1545 if (verbose) puts("STUB: HIS_XPC_CFNotificationCenterPostNotification called"); ··· 2121 2080 return NULL; 2122 2081 } 2123 2082 2124 - void* IsProcessVisible(void) 2125 - { 2126 - if (verbose) puts("STUB: IsProcessVisible called"); 2127 - return NULL; 2128 - } 2129 - 2130 - void* KillProcess(void) 2131 - { 2132 - if (verbose) puts("STUB: KillProcess called"); 2133 - return NULL; 2134 - } 2135 - 2136 - void* LaunchApplication(void) 2137 - { 2138 - if (verbose) puts("STUB: LaunchApplication called"); 2139 - return NULL; 2140 - } 2141 - 2142 2083 void* LaunchProcess(void) 2143 2084 { 2144 2085 if (verbose) puts("STUB: LaunchProcess called"); ··· 2289 2230 return NULL; 2290 2231 } 2291 2232 2292 - void* ProcessInformationCopyDictionary(void) 2293 - { 2294 - if (verbose) puts("STUB: ProcessInformationCopyDictionary called"); 2295 - return NULL; 2296 - } 2297 - 2298 2233 void* SXArbitrationAddQueuedOutputRequest(void) 2299 2234 { 2300 2235 if (verbose) puts("STUB: SXArbitrationAddQueuedOutputRequest called"); ··· 2331 2266 return NULL; 2332 2267 } 2333 2268 2334 - void* SameProcess(void) 2335 - { 2336 - if (verbose) puts("STUB: SameProcess called"); 2337 - return NULL; 2338 - } 2339 - 2340 2269 void* SerializeCFType(void) 2341 2270 { 2342 2271 if (verbose) puts("STUB: SerializeCFType called"); 2343 2272 return NULL; 2344 2273 } 2345 2274 2346 - void* SetApplicationIsDaemon(void) 2347 - { 2348 - if (verbose) puts("STUB: SetApplicationIsDaemon called"); 2349 - return NULL; 2350 - } 2351 - 2352 - void* SetFrontProcess(void) 2353 - { 2354 - if (verbose) puts("STUB: SetFrontProcess called"); 2355 - return NULL; 2356 - } 2357 - 2358 - void* SetFrontProcessWithOptions(void) 2359 - { 2360 - if (verbose) puts("STUB: SetFrontProcessWithOptions called"); 2361 - return NULL; 2362 - } 2363 - 2364 2275 void* SetGlobalIconImagesCacheMaxEntriesAndMaxDataSize(void) 2365 2276 { 2366 2277 if (verbose) puts("STUB: SetGlobalIconImagesCacheMaxEntriesAndMaxDataSize called"); ··· 2385 2296 return NULL; 2386 2297 } 2387 2298 2388 - void* ShowHideProcess(void) 2389 - { 2390 - if (verbose) puts("STUB: ShowHideProcess called"); 2391 - return NULL; 2392 - } 2393 - 2394 2299 void* StartIPCPing(void) 2395 2300 { 2396 2301 if (verbose) puts("STUB: StartIPCPing called"); 2397 - return NULL; 2398 - } 2399 - 2400 - void* TransformProcessType(void) 2401 - { 2402 - if (verbose) puts("STUB: TransformProcessType called"); 2403 2302 return NULL; 2404 2303 } 2405 2304 ··· 2472 2371 void* UnserializeCFType(void) 2473 2372 { 2474 2373 if (verbose) puts("STUB: UnserializeCFType called"); 2475 - return NULL; 2476 - } 2477 - 2478 - void* WakeUpProcess(void) 2479 - { 2480 - if (verbose) puts("STUB: WakeUpProcess called"); 2481 2374 return NULL; 2482 2375 } 2483 2376
-1
src/frameworks/CoreServices/CMakeLists.txt
··· 26 26 VERSION "A" 27 27 SOURCES 28 28 constants.m 29 - CoreServicesPriv.cpp 30 29 DEPENDENCIES 31 30 FSEvents 32 31 LaunchServices
+2 -1
src/frameworks/CoreServices/CoreServicesPriv.cpp src/frameworks/CoreServices/src/CarbonCore/CoreServicesPriv.cpp
··· 1 - #include "CoreServicesPriv.h" 1 + #include <CoreServices/CoreServicesPriv.h> 2 2 3 3 // TODO: Security.framework expects this symbol to be available in 4 4 // /System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Versions/A/CarbonCore 5 5 6 6 Boolean _CSCheckFix(CFStringRef str) 7 7 { 8 + // Checks whether given issue number is fixed in this release or something 8 9 return 0; 9 10 } 10 11
-1
src/frameworks/CoreServices/CoreServicesPriv.h
··· 1 - include/CoreServices/CoreServicesPriv.h
-1
src/frameworks/CoreServices/include/CoreServices/CoreServices.h
··· 15 15 #include <CoreServices/Math64.h> 16 16 #include <CoreServices/Multiprocessing.h> 17 17 #include <CoreServices/OpenTransport.h> 18 - #include <CoreServices/Processes.h> 19 18 #include <CoreServices/ScriptManager.h> 20 19 #include <CoreServices/TextUtils.h> 21 20 #include <CoreServices/Timer.h>
src/frameworks/CoreServices/include/CoreServices/Processes.h src/frameworks/ApplicationServices/HIServices/include/HIServices/Processes.h
+1 -5
src/frameworks/CoreServices/include/LaunchServices/LaunchServices.h
··· 3 3 4 4 #include <CoreServices/MacTypes.h> 5 5 #include <CoreServices/FileManager.h> 6 - #include <CoreServices/Processes.h> 6 + #include <HIServices/Processes.h> 7 7 #include <CoreFoundation/CFDictionary.h> 8 8 #include <CoreFoundation/CFArray.h> 9 9 #include <CoreFoundation/CFURL.h> ··· 84 84 OSStatus LSGetExtensionInfo(UniCharCount inNameLen, const UniChar* inNameBuffer, UniCharCount *outExtStartIndex); 85 85 OSStatus LSSetExtensionHiddenForRef(const FSRef *inRef, Boolean hide); 86 86 OSStatus LSSetExtensionHiddenForURL(CFURLRef inURL, Boolean hide); 87 - 88 - extern CFStringRef _kLSBundlePathKey; 89 - extern CFStringRef _kLSDisplayNameKey; 90 - extern CFStringRef _kLSExecutablePathKey; 91 87 92 88 CFTypeRef _LSCopyApplicationInformationItem(int /* hopefully */, CFTypeRef asn, CFStringRef what); 93 89
+79
src/frameworks/CoreServices/include/LaunchServices/LaunchServicesPriv.h
··· 1 + #ifndef LAUNCH_SERVICES_PRIV_H_ 2 + #define LAUNCH_SERVICES_PRIV_H_ 3 + #include <LaunchServices/LaunchServices.h> 4 + #include <CoreFoundation/CFDictionary.h> 5 + #include <CoreFoundation/CFString.h> 6 + 7 + #ifdef __cplusplus 8 + extern "C" { 9 + #endif 10 + 11 + enum 12 + { 13 + _kLSDefaultSessionID = -2, 14 + }; 15 + 16 + enum 17 + { 18 + /***** MASTER SERVICE COMMANDS *****/ 19 + // IN: 20 + // clientversion, session 21 + // OUT: 22 + // serverversion, endpoint 23 + _kLSXPCHello = 0x64, 24 + 25 + /***** ENDPOINT COMMANDS *****/ 26 + // OUT: 27 + // bool success 28 + // dictionary result 29 + _kLSXPCWeirdCheckIn = 0x1F9, 30 + // IN: 31 + // dictionary info 32 + // mach_port_name_t deathport 33 + // OUT: 34 + // bool success 35 + // dictionary result (appInfo) 36 + _kLSXPCCheckIn = 0x1F4, 37 + }; 38 + 39 + extern const CFStringRef _kLSArchitecturePowerPCValue; 40 + extern const CFStringRef _kLSArchitecturePowerPC64Value; 41 + extern const CFStringRef _kLSArchitecturei386Value; 42 + extern const CFStringRef _kLSArchitecturex86_64Value; 43 + extern const CFStringRef _kLSArchitectureUnknownValue; 44 + 45 + extern const CFStringRef _kLSArchitectureKey; 46 + 47 + extern const CFStringRef _kLSPIDKey; 48 + extern const CFStringRef _kLSExecutablePathKey; 49 + extern const CFStringRef _kLSCheckInTimeKey; 50 + extern const CFStringRef _kLSDisplayNameKey; 51 + extern const CFStringRef _kLSArchitectureKey; 52 + extern const CFStringRef _kLSBundlePathKey; 53 + extern const CFStringRef _kLSApplicationTypeKey; 54 + 55 + extern const CFStringRef _kLSASNKey; 56 + 57 + extern const CFStringRef _kLSApplicationForegroundTypeKey; 58 + extern const CFStringRef _kLSApplicationBackgroundOnlyTypeKey; 59 + 60 + extern const CFStringRef _kLSExecutableFormatKey; 61 + extern const CFStringRef _kLSExecutableFormatMachOKey; 62 + extern const CFStringRef _kLSExecutableFormatCFMKey; 63 + 64 + // Example call: 65 + // _LSApplicationCheckIn(_kLSDefaultSessionID, CFBundleGetInfoDictionary(CFBundleGetMainBundle())) 66 + // Normally to be called from -[NSApplication init] 67 + CFDictionaryRef _LSApplicationCheckIn(int sessionID, CFDictionaryRef applicationInfo); 68 + 69 + CFTypeRef _LSGetCurrentApplicationASN(void); 70 + OSStatus _LSSetApplicationInformationItem(int sessionID, LSASNRef asn, CFStringRef key, CFStringRef value, CFDictionaryRef *info); 71 + 72 + typedef bool (^LSServerConnectionAllowedBlock) ( CFDictionaryRef optionsRef ); 73 + void _LSSetApplicationLaunchServicesServerConnectionStatus(uint64_t flags, LSServerConnectionAllowedBlock block); 74 + 75 + #ifdef __cplusplus 76 + } 77 + #endif 78 + 79 + #endif
+1 -1
src/frameworks/CoreServices/src/CarbonCore/CMakeLists.txt
··· 14 14 DriverSynchronization.cpp 15 15 DriverServices.cpp 16 16 Components.cpp 17 - Processes.cpp 18 17 OpenTransport.cpp 19 18 Timer.cpp 20 19 TextCommon.cpp ··· 26 25 MacErrors.cpp 27 26 UserBreak.cpp 28 27 Debugging.cpp 28 + CoreServicesPriv.cpp 29 29 ) 30 30 31 31 set(DYLIB_COMPAT_VERSION "1.0.0")
+6
src/frameworks/CoreServices/src/CarbonCore/Debugging.cpp
··· 61 61 return 0; 62 62 } 63 63 64 + void DebugStr(ConstStr255Param msg) 65 + { 66 + std::cerr.write((const char*) &msg[1], msg[0]); 67 + std::cerr << std::endl; 68 + doUserBreak(); 69 + }
+3 -8
src/frameworks/CoreServices/src/CarbonCore/Processes.cpp src/frameworks/ApplicationServices/HIServices/src/Processes.cpp
··· 17 17 along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 18 */ 19 19 20 - #include <CoreServices/Processes.h> 20 + #include <HIServices/Processes.h> 21 21 #include <CoreServices/MacErrors.h> 22 22 #include <unistd.h> 23 23 #include <signal.h> ··· 30 30 #include <stdio.h> 31 31 #include <ctype.h> 32 32 #include <iostream> 33 - #include "UserBreak.h" 34 33 35 34 #define STUB() // TODO 36 35 #ifndef PATH_MAX 37 36 # define PATH_MAX 4096 38 37 #endif 38 + 39 + // TODO: 99% of these should be rewritten to call LaunchServices instead 39 40 40 41 // CFStringRef kCFBundleExecutableKey = CFSTR("kCFBundleExecutableKey"); 41 42 // CFStringRef kCFBundleNameKey = CFSTR("kCFBundleNameKey"); ··· 243 244 return noErr; 244 245 } 245 246 246 - void DebugStr(ConstStr255Param msg) 247 - { 248 - std::cerr.write((const char*) &msg[1], msg[0]); 249 - std::cerr << std::endl; 250 - doUserBreak(); 251 - }
+4
src/frameworks/CoreServices/src/LaunchServices/CMakeLists.txt
··· 9 9 LaunchServices.cpp 10 10 LSApplicationProxy.m 11 11 LSApplicationWorkspace.m 12 + LaunchServicesNew.cpp 13 + constants.c 12 14 DEPENDENCIES 13 15 CoreFoundation 14 16 Foundation ··· 17 19 system 18 20 CarbonCore 19 21 ) 22 + 23 + add_subdirectory(launchservicesd)
-9
src/frameworks/CoreServices/src/LaunchServices/LaunchServices.cpp
··· 261 261 262 262 // TODO: See https://gist.github.com/zorgiepoo/d751cba19a0167a589a2 263 263 264 - CFStringRef _kLSBundlePathKey = CFSTR("LSBundlePath"); 265 - CFStringRef _kLSDisplayNameKey = CFSTR("LSDisplayName"); 266 - CFStringRef _kLSExecutablePathKey = CFSTR("LSExecutablePath"); 267 - 268 264 CFTypeRef _LSCopyApplicationInformationItem(int /* hopefully */, CFTypeRef asn, CFStringRef what) 269 265 { 270 266 return NULL; 271 267 } 272 268 273 269 CFDictionaryRef _LSCopyApplicationInformation(int, CFTypeRef asn, int) 274 - { 275 - return NULL; 276 - } 277 - 278 - LSASNRef _LSASNCreateWithPid(CFAllocatorRef allocator, pid_t pid) 279 270 { 280 271 return NULL; 281 272 }
+244
src/frameworks/CoreServices/src/LaunchServices/LaunchServicesNew.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include <xpc/xpc.h> 21 + #include <xpc/private.h> 22 + #include <LaunchServices/LaunchServices.h> 23 + #include <LaunchServices/LaunchServicesPriv.h> 24 + #include <CoreFoundation/CFPriv.h> 25 + #include <CoreFoundation/CFBundlePriv.h> 26 + #include <CoreFoundation/CFDate.h> 27 + #include <CoreServices/MacErrors.h> 28 + #include <dispatch/dispatch.h> 29 + #include <cstdlib> 30 + #include <iostream> 31 + #include <Block.h> 32 + 33 + static xpc_connection_t g_lsdConnection, g_endpointConnection; 34 + 35 + static xpc_connection_t getLSDConnection(); 36 + static xpc_object_t createCommandDictionary(uint64_t command); 37 + static mach_port_name_t deathPort(); 38 + static CFTypeRef g_ourASN; 39 + 40 + static CFStringRef g_applicationType = _kLSApplicationForegroundTypeKey; 41 + static LSServerConnectionAllowedBlock g_connectionAllowedBlock = nullptr; 42 + 43 + CFDictionaryRef _LSApplicationCheckIn(int sessionID, CFDictionaryRef applicationInfo) 44 + { 45 + if (g_connectionAllowedBlock && !g_connectionAllowedBlock(applicationInfo)) 46 + return nullptr; 47 + 48 + CFMutableDictionaryRef modAppInfo = CFDictionaryCreateMutableCopy(nullptr, 0, applicationInfo); 49 + 50 + if (!CFDictionaryContainsValue(modAppInfo, _kLSArchitectureKey)) 51 + { 52 + #if defined(__x86_64__) 53 + CFDictionaryAddValue(modAppInfo, _kLSArchitectureKey, _kLSArchitecturex86_64Value); 54 + #elif defined(__i386__) 55 + CFDictionaryAddValue(modAppInfo, _kLSArchitectureKey, _kLSArchitecturei386Value); 56 + #elif defined(__ppc__) 57 + CFDictionaryAddValue(modAppInfo, _kLSArchitectureKey, _kLSArchitecturePowerPCValue); 58 + #elif defined(__ppc64__) 59 + CFDictionaryAddValue(modAppInfo, _kLSArchitectureKey, _kLSArchitecturePowerPC64Value); 60 + #else 61 + CFDictionaryAddValue(modAppInfo, _kLSArchitectureKey, _kLSArchitectureUnknownValue); 62 + #endif 63 + } 64 + 65 + if (!CFDictionaryContainsValue(modAppInfo, _kLSExecutablePathKey)) 66 + { 67 + CFStringRef path = CFStringCreateWithFileSystemRepresentation(nullptr, _CFProcessPath()); 68 + CFDictionaryAddValue(modAppInfo, _kLSExecutablePathKey, path); 69 + CFRelease(path); 70 + } 71 + 72 + if (!CFDictionaryContainsValue(modAppInfo, _kLSPIDKey)) 73 + { 74 + // Are we supposed to set this one if not present? 75 + long pid = getpid(); 76 + CFNumberRef num = CFNumberCreate(nullptr, kCFNumberLongType, &pid); 77 + CFDictionaryAddValue(modAppInfo, _kLSPIDKey, num); 78 + CFRelease(num); 79 + } 80 + 81 + if (!CFDictionaryContainsValue(modAppInfo, _kLSDisplayNameKey) && 82 + !CFDictionaryContainsValue(modAppInfo, _kCFBundleDisplayNameKey) && 83 + !CFDictionaryContainsValue(modAppInfo, kCFBundleNameKey)) 84 + { 85 + // TODO: Generate app name from bundle path / process path etc. 86 + } 87 + 88 + if (!CFDictionaryContainsValue(modAppInfo, _kLSCheckInTimeKey)) 89 + { 90 + CFDateRef now = CFDateCreate(nullptr, CFAbsoluteTimeGetCurrent()); 91 + CFDictionaryAddValue(modAppInfo, _kLSCheckInTimeKey, now); 92 + CFRelease(now); 93 + } 94 + 95 + if (!CFDictionaryContainsValue(modAppInfo, _kLSApplicationTypeKey)) 96 + { 97 + CFDictionaryAddValue(modAppInfo, _kLSApplicationTypeKey, g_applicationType); 98 + } 99 + 100 + xpc_object_t dict = createCommandDictionary(_kLSXPCCheckIn); 101 + 102 + xpc_object_t info = _CFXPCCreateXPCObjectFromCFObject(modAppInfo); 103 + CFRelease(modAppInfo); 104 + 105 + xpc_dictionary_set_value(dict, "info", info); 106 + xpc_release(info); 107 + 108 + xpc_dictionary_set_mach_send(dict, "deathport", deathPort()); 109 + xpc_object_t reply = xpc_connection_send_message_with_reply_sync(getLSDConnection(), dict); 110 + xpc_release(dict); 111 + 112 + if (reply && reply != XPC_ERROR_CONNECTION_INTERRUPTED && reply != XPC_ERROR_CONNECTION_INVALID) 113 + { 114 + if (!xpc_dictionary_get_bool(reply, "success")) 115 + { 116 + std::cerr << "LaunchServices: check-in failed\n"; 117 + return nullptr; 118 + } 119 + 120 + CFDictionaryRef result = (CFDictionaryRef) _CFXPCCreateCFObjectFromXPCObject(xpc_dictionary_get_value(reply, "result")); 121 + g_ourASN = CFDictionaryGetValue(result, _kLSASNKey); 122 + CFRetain(g_ourASN); 123 + 124 + // Is this really what should be returned? 125 + return result; 126 + } 127 + else 128 + { 129 + std::cerr << "LaunchServices: check-in operation didn't execute\n"; 130 + } 131 + 132 + return nullptr; 133 + } 134 + 135 + CFTypeRef _LSGetCurrentApplicationASN(void) 136 + { 137 + return g_ourASN; 138 + } 139 + 140 + OSStatus _LSSetApplicationInformationItem(int sessionID, LSASNRef asn, CFStringRef key, CFStringRef value, CFDictionaryRef *info) 141 + { 142 + // TODO: This talks to lsd to change the property of *any* app 143 + return unimpErr; 144 + } 145 + 146 + void _LSSetApplicationLaunchServicesServerConnectionStatus(uint64_t flags, LSServerConnectionAllowedBlock block) 147 + { 148 + // TODO 149 + if (flags & 2) // Called from ApplicationServices/HIServices - this disables connecting to lsd??? 150 + g_applicationType = _kLSApplicationBackgroundOnlyTypeKey; 151 + 152 + if (g_connectionAllowedBlock) 153 + Block_release(g_connectionAllowedBlock); 154 + 155 + g_connectionAllowedBlock = nullptr; 156 + if (block) 157 + g_connectionAllowedBlock = Block_copy(block); 158 + } 159 + 160 + LSASNRef _LSASNCreateWithPid(CFAllocatorRef allocator, pid_t pid) 161 + { 162 + long lpid = pid; 163 + return CFNumberCreate(nullptr, kCFNumberLongType, &lpid); 164 + } 165 + 166 + static mach_port_name_t deathPort() 167 + { 168 + static dispatch_once_t onceDeathPort; 169 + static mach_port_name_t port; 170 + dispatch_once(&onceDeathPort, ^{ 171 + kern_return_t kr; 172 + kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port); 173 + 174 + if (kr == KERN_SUCCESS) 175 + mach_port_insert_right(mach_task_self(), port, port, MACH_MSG_TYPE_MAKE_SEND); 176 + }); 177 + 178 + return port; 179 + } 180 + 181 + static xpc_connection_t getLSDConnection() 182 + { 183 + static dispatch_once_t once; 184 + dispatch_once(&once, ^{ 185 + if (const char* env = getenv("SCDontUseServer"); env != nullptr && atoi(env) != 0) 186 + return; 187 + 188 + const char* serviceName = "com.apple.coreservices.launchservicesd"; 189 + if (const char* altName = getenv("__LSXPCSERVICENAME"); altName != nullptr) 190 + serviceName = altName; 191 + 192 + xpc_connection_t master = xpc_connection_create_mach_service(serviceName, 193 + dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), 0); 194 + 195 + xpc_connection_set_event_handler(master, ^(xpc_object_t peer) { 196 + if (peer == 0) 197 + { 198 + // TODO: 199 + std::cerr << "LaunchServices: Cannot connect to lsd\n"; 200 + return; 201 + } 202 + g_lsdConnection = (xpc_connection_t) xpc_retain(peer); 203 + 204 + xpc_object_t dict = createCommandDictionary(_kLSXPCHello); 205 + xpc_object_t reply = xpc_connection_send_message_with_reply_sync(g_lsdConnection, dict); 206 + xpc_release(dict); 207 + 208 + if (reply == XPC_ERROR_CONNECTION_INTERRUPTED || reply == XPC_ERROR_CONNECTION_INVALID) 209 + { 210 + std::cerr << "LaunchServices: lsd connection broken\n"; 211 + return; 212 + } 213 + if (!xpc_dictionary_get_bool(reply, "success")) 214 + { 215 + std::cerr << "LaunchServices: lsd hello failed\n"; 216 + return; 217 + } 218 + xpc_object_t result = xpc_dictionary_get_value(reply, "result"); 219 + xpc_object_t ep = xpc_dictionary_get_value(result, "endpoint"); 220 + 221 + if (xpc_get_type(ep) == XPC_TYPE_ENDPOINT) 222 + { 223 + xpc_connection_t conn = g_endpointConnection = xpc_connection_create_from_endpoint((xpc_endpoint_t) ep); 224 + xpc_connection_set_target_queue(conn, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)); 225 + xpc_connection_set_event_handler(conn, ^(xpc_object_t conn) { 226 + // TODO? 227 + }); 228 + xpc_connection_resume(conn); 229 + } 230 + 231 + xpc_release(reply); 232 + }); 233 + xpc_connection_resume(master); 234 + }); 235 + 236 + return g_endpointConnection; 237 + } 238 + 239 + static xpc_object_t createCommandDictionary(uint64_t command) 240 + { 241 + xpc_object_t dict = xpc_dictionary_create(nullptr, nullptr, 0); 242 + xpc_dictionary_set_int64(dict, "command", command); 243 + return dict; 244 + }
+25
src/frameworks/CoreServices/src/LaunchServices/constants.c
··· 1 + #include <LaunchServices/LaunchServices.h> 2 + #include <LaunchServices/LaunchServicesPriv.h> 3 + 4 + const CFStringRef _kLSArchitecturePowerPCValue = CFSTR("ppc"); 5 + const CFStringRef _kLSArchitecturePowerPC64Value = CFSTR("ppc64"); 6 + const CFStringRef _kLSArchitecturei386Value = CFSTR("i386"); 7 + const CFStringRef _kLSArchitecturex86_64Value = CFSTR("x86_64"); 8 + const CFStringRef _kLSArchitectureUnknownValue = CFSTR("unknown"); 9 + 10 + const CFStringRef _kLSPIDKey = CFSTR("LSPID"); 11 + const CFStringRef _kLSExecutablePathKey = CFSTR("LSExecutablePath"); 12 + const CFStringRef _kLSCheckInTimeKey = CFSTR("LSCheckInTime"); 13 + const CFStringRef _kLSDisplayNameKey = CFSTR("LSDisplayName"); 14 + const CFStringRef _kLSArchitectureKey = CFSTR("LSArchitecture"); 15 + const CFStringRef _kLSBundlePathKey = CFSTR("LSBundlePath"); 16 + 17 + const CFStringRef _kLSApplicationTypeKey = CFSTR("ApplicationType"); 18 + const CFStringRef _kLSApplicationForegroundTypeKey = CFSTR("Foreground"); 19 + const CFStringRef _kLSApplicationBackgroundOnlyTypeKey = CFSTR("BackgroundOnly"); 20 + 21 + const CFStringRef _kLSExecutableFormatKey = CFSTR("LSExecutableFormat"); 22 + const CFStringRef _kLSExecutableFormatMachOKey = CFSTR("LSExecutableMachOFormat"); 23 + const CFStringRef _kLSExecutableFormatCFMKey = CFSTR("LSExecutableCFMFormat"); 24 + 25 + const CFStringRef _kLSASNKey = CFSTR("LSASN");
+10
src/frameworks/CoreServices/src/LaunchServices/launchservicesd/CMakeLists.txt
··· 1 + project(lslaunchservicesdd) 2 + 3 + set(sources 4 + launchservicesd.cpp 5 + ) 6 + 7 + add_darling_executable(launchservicesd ${sources}) 8 + 9 + target_link_libraries(launchservicesd system CoreServices sqlite3 cxx) 10 + install(TARGETS launchservicesd DESTINATION libexec/darling/System/Library/CoreServices)
+21
src/frameworks/CoreServices/src/LaunchServices/launchservicesd/com.apple.coreservices.launchservicesd.plist
··· 1 + <?xml version="1.0" encoding="UTF-8"?> 2 + <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 3 + <plist version="1.0"> 4 + <dict> 5 + <key>Label</key> 6 + <string>com.apple.coreservices.launchservicesd</string> 7 + <key>MachServices</key> 8 + <dict> 9 + <key>com.apple.coreservices.launchservicesd</key> 10 + <true/> 11 + </dict> 12 + <key>POSIXSpawnType</key> 13 + <string>Adaptive</string> 14 + <key>ProgramArguments</key> 15 + <array> 16 + <string>/System/Library/CoreServices/launchservicesd</string> 17 + </array> 18 + <key>RunAtLoad</key> 19 + <true/> 20 + </dict> 21 + </plist>
+65
src/frameworks/CoreServices/src/LaunchServices/launchservicesd/launchservicesd.cpp
··· 1 + #include <xpc/xpc.h> 2 + #include <FSEvents/FSEvents.h> 3 + #include <iostream> 4 + #include <dispatch/dispatch.h> 5 + #include <sqlite3.h> 6 + 7 + #define DATABASE_VERSION 1 8 + 9 + static void connectionCallback(xpc_connection_t connection); 10 + static void handleMessage(xpc_connection_t connection, xpc_object_t msg); 11 + 12 + sqlite3* g_database; 13 + 14 + static const char* MONITORED_DIRECTORIES[] = { 15 + "/Applications", 16 + "/System/Applications" 17 + "/System/Library/Frameworks" 18 + }; 19 + 20 + int main(int argc, const char** argv) 21 + { 22 + if (int err = sqlite3_open("/var/cache/launchservices.db", &g_database); err != SQLITE_OK) 23 + { 24 + std::cerr << "SQLite error: " << sqlite3_errstr(err) << std::endl; 25 + exit(1); 26 + } 27 + 28 + // xpc_main(connectionCallback); 29 + // Our xpc_main() isn't done yet, so we do this manually 30 + 31 + dispatch_queue_t server_queue = dispatch_queue_create("xpc service", NULL); 32 + 33 + xpc_connection_t listener = xpc_connection_create_mach_service("com.apple.coreservices.launchservicesd", 34 + server_queue, XPC_CONNECTION_MACH_SERVICE_LISTENER); 35 + 36 + xpc_connection_set_event_handler(listener, ^(xpc_object_t peer) { 37 + if (xpc_get_type(peer) == XPC_TYPE_CONNECTION) 38 + connectionCallback(xpc_connection_t(peer)); 39 + }); 40 + xpc_connection_resume(listener); 41 + 42 + dispatch_main(); 43 + return 0; 44 + } 45 + 46 + static void connectionCallback(xpc_connection_t connection) 47 + { 48 + pid_t pid = xpc_connection_get_pid(connection); 49 + xpc_connection_set_event_handler(connection, ^(xpc_object_t msg) { 50 + handleMessage(connection, msg); 51 + }); 52 + xpc_connection_resume(connection); 53 + } 54 + 55 + static void handleMessage(xpc_connection_t connection, xpc_object_t msg) 56 + { 57 + xpc_type_t type = xpc_get_type(msg); 58 + 59 + if (type == XPC_TYPE_DICTIONARY) 60 + { 61 + xpc_object_t reply = xpc_dictionary_create_reply(msg); 62 + 63 + xpc_connection_send_message(connection, reply); 64 + } 65 + }