fix: findHelperBinary looks for .app bundle, not bare executable
Browse files
Source/Plugin/PluginBridgeProcessor.cpp
CHANGED
|
@@ -17,7 +17,6 @@ PluginBridgeProcessor::PluginBridgeProcessor()
|
|
| 17 |
.withInput("Input", juce::AudioChannelSet::stereo(), true)
|
| 18 |
.withOutput("Output", juce::AudioChannelSet::stereo(), true))
|
| 19 |
{
|
| 20 |
-
// Register plugin formats
|
| 21 |
#if JUCE_PLUGINHOST_VST3
|
| 22 |
formatManager.addFormat(new juce::VST3PluginFormat());
|
| 23 |
#endif
|
|
@@ -25,7 +24,6 @@ PluginBridgeProcessor::PluginBridgeProcessor()
|
|
| 25 |
formatManager.addFormat(new juce::AudioUnitPluginFormat());
|
| 26 |
#endif
|
| 27 |
|
| 28 |
-
// Start MCP server
|
| 29 |
mcpServer = std::make_unique<McpServer>(PluginBridgeConstants::kDefaultMcpPort, *this);
|
| 30 |
mcpServer->start();
|
| 31 |
}
|
|
@@ -76,27 +74,29 @@ juce::AudioProcessorEditor* PluginBridgeProcessor::createEditor()
|
|
| 76 |
}
|
| 77 |
|
| 78 |
// --- Helper Test Load ---
|
| 79 |
-
// Spawns PluginBridgeHelper in a separate process to test if a plugin is safe.
|
| 80 |
-
// If the helper crashes, Ableton stays alive and the plugin gets blocklisted.
|
| 81 |
|
| 82 |
static juce::File findHelperBinary()
|
| 83 |
{
|
| 84 |
-
// Helper is bundled
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
}
|
| 101 |
|
| 102 |
PluginBridgeProcessor::TestResult PluginBridgeProcessor::testPluginSafety(const juce::String& path)
|
|
@@ -107,8 +107,8 @@ PluginBridgeProcessor::TestResult PluginBridgeProcessor::testPluginSafety(const
|
|
| 107 |
auto helperBinary = findHelperBinary();
|
| 108 |
if (!helperBinary.exists())
|
| 109 |
{
|
| 110 |
-
DBG("testPluginSafety: Helper
|
| 111 |
-
return TestResult::Safe;
|
| 112 |
}
|
| 113 |
|
| 114 |
auto helperPathStr = helperBinary.getFullPathName().toStdString();
|
|
@@ -125,19 +125,18 @@ PluginBridgeProcessor::TestResult PluginBridgeProcessor::testPluginSafety(const
|
|
| 125 |
int spawnResult = posix_spawn(&pid, helperPathStr.c_str(), nullptr, nullptr, argv, environ);
|
| 126 |
if (spawnResult != 0)
|
| 127 |
{
|
| 128 |
-
DBG("testPluginSafety: Failed to spawn helper");
|
| 129 |
-
return TestResult::Safe;
|
| 130 |
}
|
| 131 |
|
| 132 |
// Wait for helper to exit (max 10 seconds)
|
| 133 |
int status = 0;
|
| 134 |
-
int waitResult = 0;
|
| 135 |
int waitedMs = 0;
|
| 136 |
const int timeoutMs = 10000;
|
| 137 |
|
| 138 |
while (waitedMs < timeoutMs)
|
| 139 |
{
|
| 140 |
-
waitResult = waitpid(pid, &status, WNOHANG);
|
| 141 |
if (waitResult == pid)
|
| 142 |
break;
|
| 143 |
if (waitResult < 0)
|
|
@@ -147,34 +146,30 @@ PluginBridgeProcessor::TestResult PluginBridgeProcessor::testPluginSafety(const
|
|
| 147 |
waitedMs += 50;
|
| 148 |
}
|
| 149 |
|
| 150 |
-
// Timeout — kill it and assume unsafe
|
| 151 |
if (waitedMs >= timeoutMs)
|
| 152 |
{
|
| 153 |
kill(pid, SIGKILL);
|
| 154 |
waitpid(pid, &status, 0);
|
| 155 |
-
DBG("testPluginSafety:
|
| 156 |
return TestResult::Unsafe;
|
| 157 |
}
|
| 158 |
|
| 159 |
-
// Check exit status
|
| 160 |
if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
|
| 161 |
{
|
| 162 |
-
DBG("testPluginSafety:
|
| 163 |
return TestResult::Safe;
|
| 164 |
}
|
| 165 |
|
| 166 |
-
|
| 167 |
-
DBG("testPluginSafety: Plugin is UNSAFE: " + path);
|
| 168 |
return TestResult::Unsafe;
|
| 169 |
}
|
| 170 |
|
| 171 |
-
// --- Plugin Loading
|
| 172 |
|
| 173 |
void PluginBridgeProcessor::loadPlugin(const juce::String& path)
|
| 174 |
{
|
| 175 |
unloadPlugin();
|
| 176 |
|
| 177 |
-
// 1. Check blocklist
|
| 178 |
if (blocklist.isBlocked(path))
|
| 179 |
{
|
| 180 |
if (onLoadFailed)
|
|
@@ -190,7 +185,7 @@ void PluginBridgeProcessor::loadPlugin(const juce::String& path)
|
|
| 190 |
return;
|
| 191 |
}
|
| 192 |
|
| 193 |
-
//
|
| 194 |
auto testResult = testPluginSafety(path);
|
| 195 |
if (testResult == TestResult::Unsafe)
|
| 196 |
{
|
|
@@ -200,7 +195,7 @@ void PluginBridgeProcessor::loadPlugin(const juce::String& path)
|
|
| 200 |
return;
|
| 201 |
}
|
| 202 |
|
| 203 |
-
//
|
| 204 |
juce::OwnedArray<juce::PluginDescription> typesFound;
|
| 205 |
|
| 206 |
for (int i = 0; i < formatManager.getNumFormats(); ++i)
|
|
@@ -237,7 +232,6 @@ void PluginBridgeProcessor::loadPlugin(const juce::String& path)
|
|
| 237 |
return;
|
| 238 |
}
|
| 239 |
|
| 240 |
-
// Configure the plugin
|
| 241 |
instance->enableAllBuses();
|
| 242 |
|
| 243 |
auto layout = juce::AudioProcessor::BusesLayout();
|
|
@@ -250,7 +244,6 @@ void PluginBridgeProcessor::loadPlugin(const juce::String& path)
|
|
| 250 |
instance->setRateAndBufferSizeDetails(currentSampleRate, currentBlockSize);
|
| 251 |
instance->prepareToPlay(currentSampleRate, currentBlockSize);
|
| 252 |
|
| 253 |
-
// Swap in
|
| 254 |
{
|
| 255 |
juce::ScopedLock sl(pluginLock);
|
| 256 |
hostedPlugin = std::move(instance);
|
|
@@ -274,9 +267,7 @@ void PluginBridgeProcessor::unloadPlugin()
|
|
| 274 |
hostedPlugin.reset();
|
| 275 |
}
|
| 276 |
}
|
| 277 |
-
|
| 278 |
pluginPath.clear();
|
| 279 |
-
|
| 280 |
if (onPluginUnloaded)
|
| 281 |
onPluginUnloaded();
|
| 282 |
}
|
|
@@ -327,7 +318,6 @@ std::vector<PluginBridgeProcessor::ParamInfo> PluginBridgeProcessor::searchParam
|
|
| 327 |
break;
|
| 328 |
}
|
| 329 |
}
|
| 330 |
-
|
| 331 |
return results;
|
| 332 |
}
|
| 333 |
|
|
@@ -405,8 +395,6 @@ juce::Array<juce::File> PluginBridgeProcessor::getInstalledPluginFiles() const
|
|
| 405 |
return results;
|
| 406 |
}
|
| 407 |
|
| 408 |
-
// --- Blocklist ---
|
| 409 |
-
|
| 410 |
bool PluginBridgeProcessor::isBlocked(const juce::String& path) const
|
| 411 |
{
|
| 412 |
return blocklist.isBlocked(path);
|
|
@@ -456,8 +444,6 @@ void PluginBridgeProcessor::setStateInformation(const void* data, int sizeInByte
|
|
| 456 |
}
|
| 457 |
}
|
| 458 |
|
| 459 |
-
// --- MCP ---
|
| 460 |
-
|
| 461 |
bool PluginBridgeProcessor::isMcpServerRunning() const
|
| 462 |
{
|
| 463 |
return mcpServer && mcpServer->isRunning();
|
|
@@ -468,8 +454,6 @@ int PluginBridgeProcessor::getMcpServerPort() const
|
|
| 468 |
return mcpServer ? mcpServer->getPort() : 0;
|
| 469 |
}
|
| 470 |
|
| 471 |
-
// --- Entry Point ---
|
| 472 |
-
|
| 473 |
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
|
| 474 |
{
|
| 475 |
return new PluginBridgeProcessor();
|
|
|
|
| 17 |
.withInput("Input", juce::AudioChannelSet::stereo(), true)
|
| 18 |
.withOutput("Output", juce::AudioChannelSet::stereo(), true))
|
| 19 |
{
|
|
|
|
| 20 |
#if JUCE_PLUGINHOST_VST3
|
| 21 |
formatManager.addFormat(new juce::VST3PluginFormat());
|
| 22 |
#endif
|
|
|
|
| 24 |
formatManager.addFormat(new juce::AudioUnitPluginFormat());
|
| 25 |
#endif
|
| 26 |
|
|
|
|
| 27 |
mcpServer = std::make_unique<McpServer>(PluginBridgeConstants::kDefaultMcpPort, *this);
|
| 28 |
mcpServer->start();
|
| 29 |
}
|
|
|
|
| 74 |
}
|
| 75 |
|
| 76 |
// --- Helper Test Load ---
|
|
|
|
|
|
|
| 77 |
|
| 78 |
static juce::File findHelperBinary()
|
| 79 |
{
|
| 80 |
+
// Helper .app is bundled at: PluginBridge.vst3/Contents/Resources/PluginBridgeHelper.app
|
| 81 |
+
// The actual executable is at: PluginBridgeHelper.app/Contents/MacOS/PluginBridgeHelper
|
| 82 |
+
auto resourcesDir = juce::File::getSpecialLocation(juce::File::currentExecutableFile)
|
| 83 |
+
.getParentDirectory() // MacOS/
|
| 84 |
+
.getParentDirectory() // Contents/
|
| 85 |
+
.getChildFile("Resources");
|
| 86 |
+
|
| 87 |
+
auto helperApp = resourcesDir.getChildFile("PluginBridgeHelper.app");
|
| 88 |
+
auto helperExe = helperApp.getChildFile("Contents").getChildFile("MacOS").getChildFile("PluginBridgeHelper");
|
| 89 |
+
|
| 90 |
+
if (helperExe.exists())
|
| 91 |
+
return helperExe;
|
| 92 |
+
|
| 93 |
+
// Fallback: bare binary (old layout)
|
| 94 |
+
auto bareBinary = resourcesDir.getChildFile("PluginBridgeHelper");
|
| 95 |
+
if (bareBinary.exists())
|
| 96 |
+
return bareBinary;
|
| 97 |
+
|
| 98 |
+
DBG("findHelperBinary: NOT FOUND. Looked at: " + helperExe.getFullPathName());
|
| 99 |
+
return {};
|
| 100 |
}
|
| 101 |
|
| 102 |
PluginBridgeProcessor::TestResult PluginBridgeProcessor::testPluginSafety(const juce::String& path)
|
|
|
|
| 107 |
auto helperBinary = findHelperBinary();
|
| 108 |
if (!helperBinary.exists())
|
| 109 |
{
|
| 110 |
+
DBG("testPluginSafety: Helper not found, skipping test (assuming safe)");
|
| 111 |
+
return TestResult::Safe;
|
| 112 |
}
|
| 113 |
|
| 114 |
auto helperPathStr = helperBinary.getFullPathName().toStdString();
|
|
|
|
| 125 |
int spawnResult = posix_spawn(&pid, helperPathStr.c_str(), nullptr, nullptr, argv, environ);
|
| 126 |
if (spawnResult != 0)
|
| 127 |
{
|
| 128 |
+
DBG("testPluginSafety: Failed to spawn helper: " + juce::String(strerror(spawnResult)));
|
| 129 |
+
return TestResult::Safe;
|
| 130 |
}
|
| 131 |
|
| 132 |
// Wait for helper to exit (max 10 seconds)
|
| 133 |
int status = 0;
|
|
|
|
| 134 |
int waitedMs = 0;
|
| 135 |
const int timeoutMs = 10000;
|
| 136 |
|
| 137 |
while (waitedMs < timeoutMs)
|
| 138 |
{
|
| 139 |
+
int waitResult = waitpid(pid, &status, WNOHANG);
|
| 140 |
if (waitResult == pid)
|
| 141 |
break;
|
| 142 |
if (waitResult < 0)
|
|
|
|
| 146 |
waitedMs += 50;
|
| 147 |
}
|
| 148 |
|
|
|
|
| 149 |
if (waitedMs >= timeoutMs)
|
| 150 |
{
|
| 151 |
kill(pid, SIGKILL);
|
| 152 |
waitpid(pid, &status, 0);
|
| 153 |
+
DBG("testPluginSafety: Timed out for " + path);
|
| 154 |
return TestResult::Unsafe;
|
| 155 |
}
|
| 156 |
|
|
|
|
| 157 |
if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
|
| 158 |
{
|
| 159 |
+
DBG("testPluginSafety: SAFE — " + path);
|
| 160 |
return TestResult::Safe;
|
| 161 |
}
|
| 162 |
|
| 163 |
+
DBG("testPluginSafety: UNSAFE — " + path + " (exit: " + juce::String(WEXITSTATUS(status)) + ")");
|
|
|
|
| 164 |
return TestResult::Unsafe;
|
| 165 |
}
|
| 166 |
|
| 167 |
+
// --- Plugin Loading ---
|
| 168 |
|
| 169 |
void PluginBridgeProcessor::loadPlugin(const juce::String& path)
|
| 170 |
{
|
| 171 |
unloadPlugin();
|
| 172 |
|
|
|
|
| 173 |
if (blocklist.isBlocked(path))
|
| 174 |
{
|
| 175 |
if (onLoadFailed)
|
|
|
|
| 185 |
return;
|
| 186 |
}
|
| 187 |
|
| 188 |
+
// Test safety first
|
| 189 |
auto testResult = testPluginSafety(path);
|
| 190 |
if (testResult == TestResult::Unsafe)
|
| 191 |
{
|
|
|
|
| 195 |
return;
|
| 196 |
}
|
| 197 |
|
| 198 |
+
// Safe — load in-process
|
| 199 |
juce::OwnedArray<juce::PluginDescription> typesFound;
|
| 200 |
|
| 201 |
for (int i = 0; i < formatManager.getNumFormats(); ++i)
|
|
|
|
| 232 |
return;
|
| 233 |
}
|
| 234 |
|
|
|
|
| 235 |
instance->enableAllBuses();
|
| 236 |
|
| 237 |
auto layout = juce::AudioProcessor::BusesLayout();
|
|
|
|
| 244 |
instance->setRateAndBufferSizeDetails(currentSampleRate, currentBlockSize);
|
| 245 |
instance->prepareToPlay(currentSampleRate, currentBlockSize);
|
| 246 |
|
|
|
|
| 247 |
{
|
| 248 |
juce::ScopedLock sl(pluginLock);
|
| 249 |
hostedPlugin = std::move(instance);
|
|
|
|
| 267 |
hostedPlugin.reset();
|
| 268 |
}
|
| 269 |
}
|
|
|
|
| 270 |
pluginPath.clear();
|
|
|
|
| 271 |
if (onPluginUnloaded)
|
| 272 |
onPluginUnloaded();
|
| 273 |
}
|
|
|
|
| 318 |
break;
|
| 319 |
}
|
| 320 |
}
|
|
|
|
| 321 |
return results;
|
| 322 |
}
|
| 323 |
|
|
|
|
| 395 |
return results;
|
| 396 |
}
|
| 397 |
|
|
|
|
|
|
|
| 398 |
bool PluginBridgeProcessor::isBlocked(const juce::String& path) const
|
| 399 |
{
|
| 400 |
return blocklist.isBlocked(path);
|
|
|
|
| 444 |
}
|
| 445 |
}
|
| 446 |
|
|
|
|
|
|
|
| 447 |
bool PluginBridgeProcessor::isMcpServerRunning() const
|
| 448 |
{
|
| 449 |
return mcpServer && mcpServer->isRunning();
|
|
|
|
| 454 |
return mcpServer ? mcpServer->getPort() : 0;
|
| 455 |
}
|
| 456 |
|
|
|
|
|
|
|
| 457 |
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
|
| 458 |
{
|
| 459 |
return new PluginBridgeProcessor();
|