From d00cf292f1395d73d4068df90bb25527846fb698 Mon Sep 17 00:00:00 2001 From: Goldenkrew3000 Date: Wed, 18 Mar 2026 15:19:28 +1000 Subject: [PATCH] Adding base tooling for macOS bundles, and DYLD_LIBRARY_PATH bypass --- macos_packager/CMakeLists.txt | 22 +++++++ macos_packager/macho.c | 33 +++++++++++ macos_packager/macho.h | 8 +++ macos_packager/main.cpp | 108 ++++++++++++++++++++++++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 macos_packager/CMakeLists.txt create mode 100644 macos_packager/macho.c create mode 100644 macos_packager/macho.h create mode 100644 macos_packager/main.cpp diff --git a/macos_packager/CMakeLists.txt b/macos_packager/CMakeLists.txt new file mode 100644 index 0000000..a1a5d66 --- /dev/null +++ b/macos_packager/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.16) + +set(CMAKE_C_STANDARD 17) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +project(OSSP_Launcher) + +add_executable(OSSP_Launcher MACOSX_BUNDLE + main.cpp + macho.c +) + +set_target_properties(OSSP_Launcher PROPERTIES + MACOSX_BUNDLE_BUNDLE_NAME "OSSP" + MACOSX_BUNDLE_INFO_STRING "OSSP (OpenSubsonicPlayer)" + MACOSX_BUNDLE_SHORT_VERSION_STRING "v0.4a" + MACOSX_BUNDLE_LONG_VERSION_STRING "v0.4a" + MACOSX_BUNDLE_GUI_IDENTIFIER "org.hojuix.ossp" + MACOSX_BUNDLE_COPYRIGHT "Copyright (c) Goldenkrew3000/Hojuix 2025-2026 GPLv3" + MACOSX_BUNDLE_ICON_FILE AppIcon +) diff --git a/macos_packager/macho.c b/macos_packager/macho.c new file mode 100644 index 0000000..0b0c9a3 --- /dev/null +++ b/macos_packager/macho.c @@ -0,0 +1,33 @@ +/* + * OpenSubSonicPlayer Launcher + * Goldenkrew3000 2026 + * License: GNU General Public License 3.0 + * Darwin XNU / macOS OSSP Bundle Launcher + * INFO: macOS doesn't seem to allow usage of mach-o/dyld.h from C++ + */ + +#include +#include +#include +#include +#include + +int dyld_get_executable_path(char** path) { + char* macho_path[PATH_MAX]; + uint32_t macho_path_sz = sizeof(macho_path); + + int dyld_rc = 0; + dyld_rc = _NSGetExecutablePath(macho_path, &macho_path_sz); + if (dyld_rc != 0) { + return 1; + } + + *path = malloc(PATH_MAX); + if (*path == NULL) { + return 1; + } + + memcpy(*path, macho_path, strlen(macho_path)); + + return 0; +} \ No newline at end of file diff --git a/macos_packager/macho.h b/macos_packager/macho.h new file mode 100644 index 0000000..3a05515 --- /dev/null +++ b/macos_packager/macho.h @@ -0,0 +1,8 @@ +#ifndef _MACHO_H +#define _MACHO_H + +extern "C" { +int dyld_get_executable_path(char** path); +} + +#endif diff --git a/macos_packager/main.cpp b/macos_packager/main.cpp new file mode 100644 index 0000000..3f596df --- /dev/null +++ b/macos_packager/main.cpp @@ -0,0 +1,108 @@ +/* + * OpenSubSonicPlayer Launcher + * Goldenkrew3000 2026 + * License: GNU General Public License 3.0 + * Darwin XNU / macOS OSSP Bundle Launcher + */ + +// Yes I know this is some of the worst written code, like ever +// I will clean this up later, it just has to work + +#include +#include +#include +#include +#include +#include +#include +#include "macho.h" + +void removePath(std::string& str) { + size_t pos = str.find_last_of('/'); + if (pos != std::string::npos) { + str.erase(pos); + } +} + +int main(int argc, char** argv) { + printf("OSSP Launcher 1.0a\n"); + + // Get location of the MachO executable + int rc = 0; + char* c_macho_path = NULL; + rc = dyld_get_executable_path(&c_macho_path); + printf("MachO Path: %s\n", c_macho_path); + std::string macho_path(c_macho_path); + free(c_macho_path); + + // Get path of Bundle + std::string bundle_path = macho_path; + removePath(bundle_path); + removePath(bundle_path); + removePath(bundle_path); + printf("Bundle Path: %s\n", bundle_path.c_str()); + + // Create DYLD_LIBRARY_PATH - 'Bundle/sysroot/lib' + std::string dyld_library_path = bundle_path; + dyld_library_path += "/sysroot/lib"; + dyld_library_path = "DYLD_LIBRARY_PATH=" + dyld_library_path; + char* c_dyld_library_path = strdup(dyld_library_path.c_str()); + + // Create LV2_PATH - 'Bundle/sysroot/lib/lv2' + std::string lv2_path = bundle_path; + lv2_path += "/sysroot/lib/lv2"; + lv2_path = "LV2_PATH=" + lv2_path; + char* c_lv2_path = strdup(lv2_path.c_str()); + + // Move current HOME env variable to new env + char* c_home_env = getenv("HOME"); + std::string home_env(c_home_env); + std::string home_env_orig = home_env; + home_env = "HOME=" + home_env; + char* c_home_env_b = strdup(home_env.c_str()); + + // Make new PWD env variable + std::string pwd_env = home_env_orig + "/.config/ossp"; + pwd_env = "PWD=" + pwd_env; + char* c_pwd_env = strdup(pwd_env.c_str()); + printf("New PWD: %s\n", c_pwd_env); + + char test[256]; + strcpy(test, c_dyld_library_path); + char test2[256]; + strcpy(test2, c_lv2_path); + char test3[256]; + strcpy(test3, c_home_env_b); + char test4[256]; + strcpy(test4, c_pwd_env); + free(c_dyld_library_path); + free(c_lv2_path); + free(c_home_env_b); + free(c_pwd_env); + + // NOTE: I have to package the environment variables this way because if they are set through **environ, + // macOS sanitizes it and OSSP doesn't get it + char* envp[] = { + test3, + test, + test2, + test4, + NULL + }; + + printf("--------------------------------\n"); + printf("%s\n", envp[0]); + printf("%s\n", envp[1]); + printf("%s\n", envp[2]); + printf("%s\n", envp[3]); + printf("--------------------------------\n"); + + // Create OSSP path and run + std::string ossp_path = macho_path; + removePath(ossp_path); + ossp_path += "/ossp"; + printf("OSSP Path: %s\n", ossp_path.c_str()); + execve(ossp_path.c_str(), argv, envp); + + return 0; +} \ No newline at end of file