Login / Register  0 items | $0.00 New What is KVR? Submit News Advertise
TabSel
KVRian
 
553 posts since 13 Mar, 2002

Postby TabSel; Wed Mar 08, 2017 2:59 pm macOS: get CFBundleRef of plugin executable at runtime?

on macOS, vst plugins are bundles.
plugin.vst
: Contents
:: MacOS
::: executable (mach-o type bundle)

within executable at runtime, how do I get a CFBundleRef for the bundle?

I know NSBundle.GetMainBundle(), but this returns the bundle of the process. I need to find the Bundle for a plugin executable at runtime...

and idea?
syntonica
KVRist
 
224 posts since 24 Sep, 2014

Postby syntonica; Wed Mar 08, 2017 5:20 pm Re: macOS: get CFBundleRef of plugin executable at runtime?

Can't remember when I lamed this from. IPlug maybe? Send it a pointer to a char array and it will stuff it for you. The identifier is what is set in General>Identity>Bundle Identifier in XCode.

Code: Select all
void getPath(unsigned char* path)
   {
   unsigned long nSize = size_of_path_array;
   CFBundleRef ref = CFBundleGetBundleWithIdentifier(CFSTR("org.yourdomain.etc"));
   if(ref)
      {
      CFURLRef url = CFBundleCopyBundleURL(ref);
      if(url)
         {
         CFURLGetFileSystemRepresentation(url, true, path, nSize);
         CFRelease(url);            
         }
      }
   }
syntonica
KVRist
 
224 posts since 24 Sep, 2014

Postby syntonica; Wed Mar 08, 2017 5:21 pm Re: macOS: get CFBundleRef of plugin executable at runtime?

Sorry, this returns the absolute path but the bit you want is there.
TabSel
KVRian
 
553 posts since 13 Mar, 2002

Postby TabSel; Wed Mar 08, 2017 10:11 pm Re: macOS: get CFBundleRef of plugin executable at runtime?

syntonica wrote:Can't remember when I lamed this from. IPlug maybe? Send it a pointer to a char array and it will stuff it for you. The identifier is what is set in General>Identity>Bundle Identifier in XCode.

Code: Select all
void getPath(unsigned char* path)
   {
   unsigned long nSize = size_of_path_array;
   CFBundleRef ref = CFBundleGetBundleWithIdentifier(CFSTR("org.yourdomain.etc"));
   if(ref)
      {
      CFURLRef url = CFBundleCopyBundleURL(ref);
      if(url)
         {
         CFURLGetFileSystemRepresentation(url, true, path, nSize);
         CFRelease(url);            
         }
      }
   }


Thanks, but I don't have the bundle identifier... ;)
I'm working on a solution which renames a plugins executable and copies another (my own) mach-o type bundle executable under the plugins executable name in place, which will the be loaded by hosts. When loaded it needs the bundleref of its own bundle.

I already have the filePath. I could traverse up the folder hierarchy and test each parent folder if it's a bundle and I found it's plist executable is my own fileName and create a bundle from this parent folder?
Mayae
KVRist
 
483 posts since 1 Jan, 2013, from Denmark

Postby Mayae; Thu Mar 09, 2017 3:58 pm Re: macOS: get CFBundleRef of plugin executable at runtime?

This sounds shady. Presumably, since you replaced some executable in a bundle, you could just obtain the identifier by the very process you used to replace it with (usually you don't really obtain a plugin's/bundle's location without going through some loader and/or using the bundle identifier)?

What are you actually trying to do?
mystran
KVRAF
 
4461 posts since 11 Feb, 2006, from Helsinki, Finland

Postby mystran; Sat Mar 11, 2017 4:43 am Re: macOS: get CFBundleRef of plugin executable at runtime?

Have you tried looking at the contents of Info.plist and setting the CFBundleIdentifier to whatever you feel like?

In general, the Info.plist format (or anything else in the bundle for that matter) isn't really magic and there probably isn't any real reason to "replace an executable" over just building the whole bundle (ie. the directory structure, plus Info.plist, because that's really what it is) from scratch manually if you don't want to use XCode.
Image <- plugins | forum
TabSel
KVRian
 
553 posts since 13 Mar, 2002

Postby TabSel; Sat Mar 11, 2017 6:17 am Re: macOS: get CFBundleRef of plugin executable at runtime?

mystran wrote:...there probably isn't any real reason to "replace an executable" over just building the whole bundle...


With plugins, I tend to think otherwise. Ask some Automap users how they like the Automap Wrapper doubling the plugin bundles, managing double the amount of plugins (on windows at least, along with x32/x64 architectures and differing plugin scan paths, causing hosts scanning double the amount of plugins, maybe causing hiccups with doubled plugin IDs etc....

The goal here is providing a solution which wraps (and extends) any plugin in a more or less seamless way for both the user and hosts.

on win, wrapping will be done by altering file extension of the original plugin, and replacing the plugin file with the wrapper, renamed to original file and extension.
On Mac, wrapping will be done by renaming a bundles executable and replacing it with the wrapper, renamed to the original executable name.

So, on loading the bundle executable/dll the wrapper looks for and loads for the renamed original executable/dll, but, on Mac, it doesn't know anything more than the executable filePath of itself and the wrapped executable. The wrapper executable doesn't know anything about its containing bundle.

It needs to know its containing bundle though, for the plugin extension code...
User avatar
Urs
u-he
 
20378 posts since 7 Aug, 2002, from Berlin

Postby Urs; Sat Mar 11, 2017 6:36 am Re: macOS: get CFBundleRef of plugin executable at runtime?

TabSel wrote:The goal here is providing a solution which wraps (and extends) any plugin in a more or less seamless way for both the user and hosts.

Please put us on a black list for this stuff. The idea that some random software vendor alters our bundles for whatever service they deem interesting is quite frightening and most likely in violation of a lot of things, including the integrity of processes that require a digital signature.
TabSel
KVRian
 
553 posts since 13 Mar, 2002

Postby TabSel; Sat Mar 11, 2017 6:39 am Re: macOS: get CFBundleRef of plugin executable at runtime?

very valid point, Urs.

I'm no vendor (yet), though, this is a private project for myself ;)
User avatar
Urs
u-he
 
20378 posts since 7 Aug, 2002, from Berlin

Postby Urs; Sat Mar 11, 2017 6:43 am Re: macOS: get CFBundleRef of plugin executable at runtime?

TabSel wrote:very valid point, Urs.

I'm no vendor (yet), though, this is a private project for myself ;)

That's a relief :)
TabSel
KVRian
 
553 posts since 13 Mar, 2002

Postby TabSel; Sat Mar 11, 2017 7:50 am Re: macOS: get CFBundleRef of plugin executable at runtime?

Hmm, redesigning....

Would renaming a bundle "plugin.vst" to "plugin.extended-vst" (in order for hosts not scanning these bundles) gain more acceptance? On a technical side: is the bundle name (plugin.vst) part of a digital signage, or "just" the bundl contents? (I know that currently there's no signature check upon loading plugins, so I could alter its content without risking hosts refusing loading them. There's Library Validation, but it currently isn't possible without the host and the plugin sharing the same team in the signature, so there can't be a restriction. But that might change with apple, and it has to, eventually ;)
syntonica
KVRist
 
224 posts since 24 Sep, 2014

Postby syntonica; Sat Mar 11, 2017 5:19 pm Re: macOS: get CFBundleRef of plugin executable at runtime?

No state secrets here, but you can pull the bundle name from the plist file that's in the bundle with the runtime.

Not sure exactly what your end goal is here, but if you can find the VST, you can find the bundle name.

Most wrappers I've seen want you to relocate the plugin to the wrapper's special folder and then will spoof it with a wrapper in the main plugin folder and nobody gets hurt. :lol:

Moderator: Moderators (Main)

Return to DSP and Plug-in Development