Adding base tooling for macOS bundles, and DYLD_LIBRARY_PATH bypass

This commit is contained in:
2026-03-18 15:19:28 +10:00
parent 42e67d30bc
commit d00cf292f1
4 changed files with 171 additions and 0 deletions
+22
View File
@@ -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
)
+33
View File
@@ -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 <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
#include <mach-o/dyld.h>
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;
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef _MACHO_H
#define _MACHO_H
extern "C" {
int dyld_get_executable_path(char** path);
}
#endif
+108
View File
@@ -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 <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#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;
}