]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_utilities/lib/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
24 #include <TargetConditionals.h>
27 #include <security_utilities/refcount.h>
28 #include <security_utilities/cfutilities.h>
29 #include <Security/CodeSigning.h>
33 #include <CoreFoundation/CFBundle.h>
40 // A Signable with OS X support calls added
42 class OSXCode
: public RefCount
{
44 virtual ~OSXCode() { }
47 // creating OSXCode objects
48 static RefPointer
<OSXCode
> main();
49 static RefPointer
<OSXCode
> at(const char *path
);
50 static RefPointer
<OSXCode
> at(const std::string
&path
) { return at(path
.c_str()); }
53 virtual string
canonicalPath() const = 0; // reverse of at()
54 virtual string
executablePath() const = 0; // path to main executable file
55 virtual SecStaticCodeRef
codeRef() const; // defaults to code at canonicalPath()
58 OSXCode() { } // nonpublic
63 // A simple executable tool.
65 class ExecutableTool
: public OSXCode
{
67 ExecutableTool(const char *path
) : mPath(path
) { }
69 string
path() const { return mPath
; }
70 string
canonicalPath() const;
71 string
executablePath() const;
74 string mPath
; // UTF8 pathname to executable
81 class Bundle
: public OSXCode
{
83 Bundle(const char *path
, const char *execPath
= NULL
); // from root and optional exec path
84 Bundle(CFBundleRef bundle
, const char *root
= NULL
); // from existing CFBundleRef
87 string
canonicalPath() const;
88 string
path() const { return mPath
; }
89 string
executablePath() const;
90 string
identifier() const { return cfString(CFBundleGetIdentifier(cfBundle())); }
91 CFTypeRef
infoPlistItem(const char *name
) const; // not retained
93 string
resourcePath() const { return cfStringRelease(CFBundleCopyResourcesDirectoryURL(cfBundle())); }
94 string
resource(const char *name
, const char *type
, const char *subdir
= NULL
);
95 void resources(vector
<string
> &paths
, const char *type
, const char *subdir
= NULL
);
97 virtual void *lookupSymbol(const char *name
);
100 CFBundleRef
cfBundle() const;
103 string mPath
; // UTF8 path to bundle directory
104 mutable string mExecutablePath
; // cached or determined path to main executable
105 mutable CFBundleRef mBundle
; // CF-style bundle object (lazily built)
109 class LoadableBundle
: public Bundle
{
111 LoadableBundle(const char *pathname
) : Bundle(pathname
) { }
112 LoadableBundle(CFBundleRef bundle
) : Bundle(bundle
) { }
114 virtual bool isLoaded() const;
116 virtual void unload();
120 class OSXCodeWrap
: public OSXCode
{
122 OSXCodeWrap(SecStaticCodeRef code
) : mCode(code
) { }
124 string
encode() const;
126 string
canonicalPath() const;
127 string
executablePath() const;
128 SecStaticCodeRef
codeRef() const;
131 CFCopyRef
<SecStaticCodeRef
> mCode
;
135 } // end namespace Security