Remove translocated bundle handling.

Only really useful for portable mode with a downloaded bundle in the Downloads folder.
This commit is contained in:
squidbus 2025-03-23 11:37:18 -07:00
parent 0aff04ba4b
commit eead6db017

View file

@ -1,5 +1,4 @@
#include "zelda_support.h" #include "zelda_support.h"
#include <dlfcn.h>
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <objc/runtime.h> #import <objc/runtime.h>
#import <objc/message.h> #import <objc/message.h>
@ -19,35 +18,8 @@ namespace zelda64 {
} }
std::filesystem::path get_bundle_directory() { std::filesystem::path get_bundle_directory() {
NSURL *bundleUrl = [[NSBundle mainBundle] bundleURL]; NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
return std::filesystem::path([bundlePath UTF8String]);
// The OS may relocate the app elsewhere for security reasons if, for example,
// it was downloaded and opened from the Downloads folder. In this case, we need
// to untranslocate the path to find out where the actual app bundle is.
if (void* securityHandle = dlopen("/System/Library/Frameworks/Security.framework/Security", RTLD_LAZY)) {
using IsTranslocatedURLFunc = Boolean (*)(CFURLRef path, bool* isTranslocated,
CFErrorRef* __nullable error);
using CreateOriginalPathForURLFunc = CFURLRef __nullable (*)(CFURLRef translocatedPath,
CFErrorRef* __nullable error);
const auto IsTranslocatedURL = reinterpret_cast<IsTranslocatedURLFunc>(
dlsym(securityHandle, "SecTranslocateIsTranslocatedURL"));
const auto CreateOriginalPathForURL = reinterpret_cast<CreateOriginalPathForURLFunc>(
dlsym(securityHandle, "SecTranslocateCreateOriginalPathForURL"));
bool translocated = false;
if (IsTranslocatedURL && CreateOriginalPathForURL &&
IsTranslocatedURL((__bridge CFURLRef) bundleUrl, &translocated, nullptr) && translocated) {
CFURLRef untranslocated = CreateOriginalPathForURL((__bridge CFURLRef) bundleUrl, nullptr);
if (untranslocated) {
bundleUrl = (NSURL*) untranslocated;
}
}
dlclose(securityHandle);
}
return std::filesystem::path([bundleUrl fileSystemRepresentation]);
} }
} }