#ifndef _H_OSXCODE
#define _H_OSXCODE
#include <TargetConditionals.h>
#include <security_utilities/refcount.h>
#include <security_utilities/cfutilities.h>
#include <Security/CodeSigning.h>
#include <limits.h>
#include <string>
#include <vector>
#include <CoreFoundation/CFBundle.h>
namespace Security {
class OSXCode : public RefCount {
public:
virtual ~OSXCode() { }
public:
static RefPointer<OSXCode> main();
static RefPointer<OSXCode> at(const char *path);
static RefPointer<OSXCode> at(const std::string &path) { return at(path.c_str()); }
public:
virtual string canonicalPath() const = 0; virtual string executablePath() const = 0; virtual SecStaticCodeRef codeRef() const;
protected:
OSXCode() { } };
class ExecutableTool : public OSXCode {
public:
ExecutableTool(const char *path) : mPath(path) { }
string path() const { return mPath; }
string canonicalPath() const;
string executablePath() const;
private:
string mPath; };
class Bundle : public OSXCode {
public:
Bundle(const char *path, const char *execPath = NULL); Bundle(CFBundleRef bundle, const char *root = NULL); ~Bundle();
string canonicalPath() const;
string path() const { return mPath; }
string executablePath() const;
string identifier() const { return cfString(CFBundleGetIdentifier(cfBundle())); }
CFTypeRef infoPlistItem(const char *name) const;
string resourcePath() const { return cfStringRelease(CFBundleCopyResourcesDirectoryURL(cfBundle())); }
string resource(const char *name, const char *type, const char *subdir = NULL);
void resources(vector<string> &paths, const char *type, const char *subdir = NULL);
virtual void *lookupSymbol(const char *name);
protected:
CFBundleRef cfBundle() const;
protected:
string mPath; mutable string mExecutablePath; mutable CFBundleRef mBundle; };
class LoadableBundle : public Bundle {
public:
LoadableBundle(const char *pathname) : Bundle(pathname) { }
LoadableBundle(CFBundleRef bundle) : Bundle(bundle) { }
virtual bool isLoaded() const;
virtual void load();
virtual void unload();
};
class OSXCodeWrap : public OSXCode {
public:
OSXCodeWrap(SecStaticCodeRef code) : mCode(code) { }
string encode() const;
string canonicalPath() const;
string executablePath() const;
SecStaticCodeRef codeRef() const;
private:
CFCopyRef<SecStaticCodeRef> mCode;
};
}
#endif //_H_OSXCODE