2 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * October 31, 2000 Allan Nathanson <ajn@apple.com>
32 #include <sys/types.h>
33 #include <sys/param.h>
35 #include <mach-o/dyld.h>
37 #include "dy_framework.h"
42 static const void *image
= NULL
;
44 const char *framework
= "/System/Library/Frameworks/IOKit.framework/IOKit";
46 const char *suffix
= getenv("DYLD_IMAGE_SUFFIX");
47 char path
[MAXPATHLEN
];
49 strcpy(path
, framework
);
50 if (suffix
) strcat(path
, suffix
);
51 if (0 <= stat(path
, &statbuf
)) {
52 image
= NSAddImage(path
, NSADDIMAGE_OPTION_NONE
);
54 image
= NSAddImage(framework
, NSADDIMAGE_OPTION_NONE
);
61 __private_extern__ CFMutableDictionaryRef
62 _IOBSDNameMatching(mach_port_t masterPort
, unsigned int options
, const char *bsdName
)
64 static CFMutableDictionaryRef (*dyfunc
)(mach_port_t
, unsigned int, const char *) = NULL
;
66 void *image
= __loadIOKit();
67 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOBSDNameMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
69 return dyfunc
? dyfunc(masterPort
, options
, bsdName
) : NULL
;
73 __private_extern__ io_object_t
74 _IOIteratorNext(io_iterator_t iterator
)
76 static io_object_t (*dyfunc
)(io_iterator_t
) = NULL
;
78 void *image
= __loadIOKit();
79 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOIteratorNext", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
81 return dyfunc
? dyfunc(iterator
) : 0;
85 __private_extern__ kern_return_t
86 _IOMasterPort(mach_port_t bootstrapPort
, mach_port_t
*masterPort
)
88 static kern_return_t (*dyfunc
)(mach_port_t
, mach_port_t
*) = NULL
;
90 void *image
= __loadIOKit();
91 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOMasterPort", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
93 return dyfunc
? dyfunc(bootstrapPort
, masterPort
) : KERN_FAILURE
;
97 __private_extern__ kern_return_t
98 _IOObjectRelease(io_object_t object
)
100 static kern_return_t (*dyfunc
)(io_object_t
) = NULL
;
102 void *image
= __loadIOKit();
103 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOObjectRelease", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
105 return dyfunc
? dyfunc(object
) : KERN_FAILURE
;
109 __private_extern__ CFTypeRef
110 _IORegistryEntryCreateCFProperty(io_registry_entry_t entry
, CFStringRef key
, CFAllocatorRef allocator
, IOOptionBits options
)
112 static CFTypeRef (*dyfunc
)(io_registry_entry_t
, CFStringRef
, CFAllocatorRef
, IOOptionBits
) = NULL
;
114 void *image
= __loadIOKit();
115 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryCreateCFProperty", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
117 return dyfunc
? dyfunc(entry
, key
, allocator
, options
) : NULL
;
121 __private_extern__ kern_return_t
122 _IORegistryEntryCreateCFProperties(io_registry_entry_t entry
, CFMutableDictionaryRef
*properties
, CFAllocatorRef allocator
, IOOptionBits options
)
124 static kern_return_t (*dyfunc
)(io_registry_entry_t
, CFMutableDictionaryRef
*, CFAllocatorRef
, IOOptionBits
) = NULL
;
126 void *image
= __loadIOKit();
127 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryCreateCFProperties", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
129 return dyfunc
? dyfunc(entry
, properties
, allocator
, options
) : KERN_FAILURE
;
133 __private_extern__ kern_return_t
134 _IORegistryEntryGetParentEntry(io_registry_entry_t entry
, const io_name_t plane
, io_registry_entry_t
*parent
)
136 static kern_return_t (*dyfunc
)(io_registry_entry_t
, const io_name_t
, io_registry_entry_t
*) = NULL
;
138 void *image
= __loadIOKit();
139 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryGetParentEntry", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
141 return dyfunc
? dyfunc(entry
, plane
, parent
) : NULL
;
145 __private_extern__ kern_return_t
146 _IORegistryEntryGetPath(io_registry_entry_t entry
, const io_name_t plane
, io_string_t path
)
148 static kern_return_t (*dyfunc
)(io_registry_entry_t
, const io_name_t
, io_string_t
) = NULL
;
150 void *image
= __loadIOKit();
151 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryGetPath", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
153 return dyfunc
? dyfunc(entry
, plane
, path
) : KERN_FAILURE
;
157 __private_extern__ kern_return_t
158 _IOServiceGetMatchingServices(mach_port_t masterPort
, CFDictionaryRef matching
, io_iterator_t
*existing
)
160 static kern_return_t (*dyfunc
)(mach_port_t
, CFDictionaryRef
, io_iterator_t
*) = NULL
;
162 void *image
= __loadIOKit();
163 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOServiceGetMatchingServices", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
165 return dyfunc
? dyfunc(masterPort
, matching
, existing
) : KERN_FAILURE
;
169 __private_extern__ CFMutableDictionaryRef
170 _IOServiceMatching(const char *name
)
172 static CFMutableDictionaryRef (*dyfunc
)(const char *) = NULL
;
174 void *image
= __loadIOKit();
175 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOServiceMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
177 return dyfunc
? dyfunc(name
) : NULL
;
181 __loadSecurity(void) {
182 static const void *image
= NULL
;
184 const char *framework
= "/System/Library/Frameworks/Security.framework/Security";
186 const char *suffix
= getenv("DYLD_IMAGE_SUFFIX");
187 char path
[MAXPATHLEN
];
189 strcpy(path
, framework
);
190 if (suffix
) strcat(path
, suffix
);
191 if (0 <= stat(path
, &statbuf
)) {
192 image
= NSAddImage(path
, NSADDIMAGE_OPTION_NONE
);
194 image
= NSAddImage(framework
, NSADDIMAGE_OPTION_NONE
);
197 return (void *)image
;
201 __private_extern__ OSStatus
202 _SecKeychainItemCopyContent(SecKeychainItemRef itemRef
, SecItemClass
*itemClass
, SecKeychainAttributeList
*attrList
, UInt32
*length
, void **outData
)
204 static OSStatus (*dyfunc
)(SecKeychainItemRef
, SecItemClass
*, SecKeychainAttributeList
*, UInt32
*, void **) = NULL
;
206 void *image
= __loadSecurity();
207 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_SecKeychainItemCopyContent", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
209 return dyfunc
? dyfunc(itemRef
, itemClass
, attrList
, length
, outData
) : -1;
212 __private_extern__ OSStatus
213 _SecKeychainSearchCopyNext(SecKeychainSearchRef searchRef
, SecKeychainItemRef
*itemRef
)
215 static OSStatus (*dyfunc
)(SecKeychainSearchRef
, SecKeychainItemRef
*) = NULL
;
217 void *image
= __loadSecurity();
218 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_SecKeychainSearchCopyNext", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
220 return dyfunc
? dyfunc(searchRef
, itemRef
) : -1;
223 __private_extern__ OSStatus
224 _SecKeychainSearchCreateFromAttributes(CFTypeRef keychainOrArray
, SecItemClass itemClass
, const SecKeychainAttributeList
*attrList
, SecKeychainSearchRef
*searchRef
)
226 static OSStatus (*dyfunc
)(CFTypeRef
, SecItemClass
, const SecKeychainAttributeList
*, SecKeychainSearchRef
*) = NULL
;
228 void *image
= __loadSecurity();
229 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_SecKeychainSearchCreateFromAttributes", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
231 return dyfunc
? dyfunc(keychainOrArray
, itemClass
, attrList
, searchRef
) : -1;