]>
git.saurik.com Git - apple/security.git/blob - OSX/include/security_utilities/osxcode.h
2 * Copyright (c) 2000-2001,2011-2012,2014 Apple Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // osxcode - MacOS X's standard code objects
25 #include <security_utilities/refcount.h>
26 #include <security_utilities/cfutilities.h>
27 #include <Security/CodeSigning.h>
31 #include <CoreFoundation/CFBundle.h>
38 // A Signable with OS X support calls added
40 class OSXCode
: public RefCount
{
42 virtual ~OSXCode() { }
45 // creating OSXCode objects
46 static RefPointer
<OSXCode
> main();
47 static RefPointer
<OSXCode
> at(const char *path
);
48 static RefPointer
<OSXCode
> at(const std::string
&path
) { return at(path
.c_str()); }
51 virtual string
canonicalPath() const = 0; // reverse of at()
52 virtual string
executablePath() const = 0; // path to main executable file
53 virtual SecStaticCodeRef
codeRef() const; // defaults to code at canonicalPath()
56 OSXCode() { } // nonpublic
61 // A simple executable tool.
63 class ExecutableTool
: public OSXCode
{
65 ExecutableTool(const char *path
) : mPath(path
) { }
67 string
path() const { return mPath
; }
68 string
canonicalPath() const;
69 string
executablePath() const;
72 string mPath
; // UTF8 pathname to executable
79 class Bundle
: public OSXCode
{
81 Bundle(const char *path
, const char *execPath
= NULL
); // from root and optional exec path
82 Bundle(CFBundleRef bundle
, const char *root
= NULL
); // from existing CFBundleRef
85 string
canonicalPath() const;
86 string
path() const { return mPath
; }
87 string
executablePath() const;
88 string
identifier() const { return cfString(CFBundleGetIdentifier(cfBundle())); }
89 CFTypeRef
infoPlistItem(const char *name
) const; // not retained
91 string
resourcePath() const { return cfStringRelease(CFBundleCopyResourcesDirectoryURL(cfBundle())); }
92 string
resource(const char *name
, const char *type
, const char *subdir
= NULL
);
93 void resources(vector
<string
> &paths
, const char *type
, const char *subdir
= NULL
);
95 virtual void *lookupSymbol(const char *name
);
98 CFBundleRef
cfBundle() const;
101 string mPath
; // UTF8 path to bundle directory
102 mutable string mExecutablePath
; // cached or determined path to main executable
103 mutable CFBundleRef mBundle
; // CF-style bundle object (lazily built)
107 class LoadableBundle
: public Bundle
{
109 LoadableBundle(const char *pathname
) : Bundle(pathname
) { }
110 LoadableBundle(CFBundleRef bundle
) : Bundle(bundle
) { }
112 virtual bool isLoaded() const;
114 virtual void unload();
118 class OSXCodeWrap
: public OSXCode
{
120 OSXCodeWrap(SecStaticCodeRef code
) : mCode(code
) { }
122 string
encode() const;
124 string
canonicalPath() const;
125 string
executablePath() const;
126 SecStaticCodeRef
codeRef() const;
129 CFCopyRef
<SecStaticCodeRef
> mCode
;
133 } // end namespace Security