diff options
Diffstat (limited to 'darwin-bootstrap')
-rw-r--r-- | darwin-bootstrap/bundle-loader.c | 34 | ||||
-rw-r--r-- | darwin-bootstrap/posixspawn-hook.c | 24 |
2 files changed, 39 insertions, 19 deletions
diff --git a/darwin-bootstrap/bundle-loader.c b/darwin-bootstrap/bundle-loader.c index 74913b7..af24135 100644 --- a/darwin-bootstrap/bundle-loader.c +++ b/darwin-bootstrap/bundle-loader.c @@ -40,7 +40,6 @@ static struct { typeof(CFStringCreateWithCStringNoCopy) *CFStringCreateWithCStringNoCopy; typeof(CFRelease) *CFRelease; typeof(kCFAllocatorNull) *kCFAllocatorNull; - typeof(kCFStringEncodingUTF8) *kCFStringEncodingUTF8; } cf_funcs; static struct { @@ -48,24 +47,35 @@ static struct { typeof(objc_getClass) *objc_getClass; } objc_funcs; -#define GET(funcs, handle, name) (funcs)->name = dlsym(handle, "_" #name) +#define GET(funcs, handle, name) (funcs)->name = dlsym(handle, #name) + +static void *dlopen_noload(const char *path) { + void *h = dlopen(path, RTLD_LAZY | RTLD_NOLOAD); + if (!h) + return NULL; + dlclose(h); + return dlopen(path, RTLD_LAZY); +} static bool cf_has_bundle(const char *name) { if (!cf_funcs.initialized) { - void *handle = dlopen("/System/Library/Frameworks/CoreFoundation.framework", - RTLD_LAZY | RTLD_NOLOAD); + const char *cf = + "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"; + void *handle = dlopen_noload(cf); + if (IB_VERBOSE) + ib_log("CF handle: %p", handle); if (handle) { GET(&cf_funcs, handle, CFBundleGetBundleWithIdentifier); GET(&cf_funcs, handle, CFStringCreateWithCStringNoCopy); GET(&cf_funcs, handle, CFRelease); GET(&cf_funcs, handle, kCFAllocatorNull); - GET(&cf_funcs, handle, kCFStringEncodingUTF8); } + cf_funcs.initialized = true; } if (!cf_funcs.CFBundleGetBundleWithIdentifier) return false; CFStringRef str = cf_funcs.CFStringCreateWithCStringNoCopy( - NULL, name, *cf_funcs.kCFStringEncodingUTF8, *cf_funcs.kCFAllocatorNull); + NULL, name, kCFStringEncodingUTF8, *cf_funcs.kCFAllocatorNull); if (!str) return false; bool ret = !!cf_funcs.CFBundleGetBundleWithIdentifier(str); @@ -75,10 +85,12 @@ static bool cf_has_bundle(const char *name) { static bool objc_has_class(const char *name) { if (!objc_funcs.initialized) { - void *handle = dlopen("/usr/lib/libobjc.A.dylib", - RTLD_LAZY | RTLD_NOLOAD); + void *handle = dlopen_noload("/usr/lib/libobjc.A.dylib"); + if (IB_VERBOSE) + ib_log("objc handle: %p", handle); if (handle) GET(&objc_funcs, handle, objc_getClass); + objc_funcs.initialized = true; } if (!objc_funcs.objc_getClass) return false; @@ -86,8 +98,9 @@ static bool objc_has_class(const char *name) { } static void use_dylib(const char *name) { - ib_log("loading dylib %s", name); - // .. + if (IB_VERBOSE) + ib_log("loading dylib %s", name); + dlopen(name, RTLD_LAZY); } static void load_bundle_list(const void *buf, size_t size) { @@ -130,6 +143,7 @@ static void load_bundle_list(const void *buf, size_t size) { if (!pop(&buf, end, &opc, &name)) goto invalid; } + break; fail: do { if (!pop(&buf, end, &opc, &name)) diff --git a/darwin-bootstrap/posixspawn-hook.c b/darwin-bootstrap/posixspawn-hook.c index 51ab5b3..86c3d01 100644 --- a/darwin-bootstrap/posixspawn-hook.c +++ b/darwin-bootstrap/posixspawn-hook.c @@ -155,14 +155,15 @@ static int hook_posix_spawn_generic(__typeof__(posix_spawn) *old, posix_spawnattr_t my_attr = NULL; short flags = 0; - if (posix_spawnattr_getflags(attrp, &flags)) + if (attrp && posix_spawnattr_getflags(attrp, &flags)) goto crap; if (IB_VERBOSE) { - ib_log("hook_posix_spawn_generic: path=%s%s%s", + ib_log("hook_posix_spawn_generic: path=%s%s%s (ld=%d)", path, (flags & POSIX_SPAWN_SETEXEC) ? " (exec)" : "", - (flags & POSIX_SPAWN_START_SUSPENDED) ? " (suspend)" : ""); + (flags & POSIX_SPAWN_START_SUSPENDED) ? " (suspend)" : "", + is_launchd); for (char *const *ap = argv; *ap; ap++) ib_log(" %s", *ap); } @@ -175,12 +176,17 @@ static int hook_posix_spawn_generic(__typeof__(posix_spawn) *old, /* which dylib should we add, if any? */ const char *dylib_to_add; - if (!is_launchd) - dylib_to_add = bl_dylib; - else if (!strcmp(path, "/usr/libexec/xpcproxy")) - dylib_to_add = psh_dylib; - else - goto skip; + if (is_launchd) { + if (!strcmp(path, "/usr/libexec/xpcproxy")) + dylib_to_add = psh_dylib; + else + goto skip; + } else { + if (!strcmp(path, "/Library/Substitute/Helpers/substituted")) + goto skip; + else + dylib_to_add = bl_dylib; + } if (attrp) { posix_spawnattr_t attr = *attrp; |