2 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * Modification History
29 * October 31, 2000 Allan Nathanson <ajn@apple.com>
34 #include <sys/types.h>
35 #include <sys/param.h>
37 #include <mach-o/dyld.h>
39 #include "dy_framework.h"
44 static const void *image
= NULL
;
46 const char *framework
= "/System/Library/Frameworks/IOKit.framework/IOKit";
48 const char *suffix
= getenv("DYLD_IMAGE_SUFFIX");
49 char path
[MAXPATHLEN
];
51 strcpy(path
, framework
);
52 if (suffix
) strcat(path
, suffix
);
53 if (0 <= stat(path
, &statbuf
)) {
54 image
= NSAddImage(path
, NSADDIMAGE_OPTION_NONE
);
56 image
= NSAddImage(framework
, NSADDIMAGE_OPTION_NONE
);
63 __private_extern__ CFMutableDictionaryRef
64 _IOBSDNameMatching(mach_port_t masterPort
, unsigned int options
, const char *bsdName
)
66 static CFMutableDictionaryRef (*dyfunc
)(mach_port_t
, unsigned int, const char *) = NULL
;
68 void *image
= __loadIOKit();
69 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOBSDNameMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
71 return dyfunc
? dyfunc(masterPort
, options
, bsdName
) : NULL
;
75 __private_extern__ io_object_t
76 _IOIteratorNext(io_iterator_t iterator
)
78 static io_object_t (*dyfunc
)(io_iterator_t
) = NULL
;
80 void *image
= __loadIOKit();
81 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOIteratorNext", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
83 return dyfunc
? dyfunc(iterator
) : 0;
87 __private_extern__ kern_return_t
88 _IOMasterPort(mach_port_t bootstrapPort
, mach_port_t
*masterPort
)
90 static kern_return_t (*dyfunc
)(mach_port_t
, mach_port_t
*) = NULL
;
92 void *image
= __loadIOKit();
93 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOMasterPort", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
95 return dyfunc
? dyfunc(bootstrapPort
, masterPort
) : KERN_FAILURE
;
99 __private_extern__ kern_return_t
100 _IOObjectRelease(io_object_t object
)
102 static kern_return_t (*dyfunc
)(io_object_t
) = NULL
;
104 void *image
= __loadIOKit();
105 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOObjectRelease", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
107 return dyfunc
? dyfunc(object
) : KERN_FAILURE
;
111 __private_extern__ CFTypeRef
112 _IORegistryEntryCreateCFProperty(io_registry_entry_t entry
, CFStringRef key
, CFAllocatorRef allocator
, IOOptionBits options
)
114 static CFTypeRef (*dyfunc
)(io_registry_entry_t
, CFStringRef
, CFAllocatorRef
, IOOptionBits
) = NULL
;
116 void *image
= __loadIOKit();
117 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryCreateCFProperty", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
119 return dyfunc
? dyfunc(entry
, key
, allocator
, options
) : NULL
;
123 __private_extern__ kern_return_t
124 _IORegistryEntryCreateCFProperties(io_registry_entry_t entry
, CFMutableDictionaryRef
*properties
, CFAllocatorRef allocator
, IOOptionBits options
)
126 static kern_return_t (*dyfunc
)(io_registry_entry_t
, CFMutableDictionaryRef
*, CFAllocatorRef
, IOOptionBits
) = NULL
;
128 void *image
= __loadIOKit();
129 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryCreateCFProperties", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
131 return dyfunc
? dyfunc(entry
, properties
, allocator
, options
) : KERN_FAILURE
;
135 __private_extern__ kern_return_t
136 _IORegistryEntryGetParentEntry(io_registry_entry_t entry
, const io_name_t plane
, io_registry_entry_t
*parent
)
138 static kern_return_t (*dyfunc
)(io_registry_entry_t
, const io_name_t
, io_registry_entry_t
*) = NULL
;
140 void *image
= __loadIOKit();
141 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryGetParentEntry", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
143 return dyfunc
? dyfunc(entry
, plane
, parent
) : NULL
;
147 __private_extern__ kern_return_t
148 _IORegistryEntryGetPath(io_registry_entry_t entry
, const io_name_t plane
, io_string_t path
)
150 static kern_return_t (*dyfunc
)(io_registry_entry_t
, const io_name_t
, io_string_t
) = NULL
;
152 void *image
= __loadIOKit();
153 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IORegistryEntryGetPath", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
155 return dyfunc
? dyfunc(entry
, plane
, path
) : KERN_FAILURE
;
159 __private_extern__ kern_return_t
160 _IOServiceGetMatchingServices(mach_port_t masterPort
, CFDictionaryRef matching
, io_iterator_t
*existing
)
162 static kern_return_t (*dyfunc
)(mach_port_t
, CFDictionaryRef
, io_iterator_t
*) = NULL
;
164 void *image
= __loadIOKit();
165 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOServiceGetMatchingServices", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
167 return dyfunc
? dyfunc(masterPort
, matching
, existing
) : KERN_FAILURE
;
171 __private_extern__ CFMutableDictionaryRef
172 _IOServiceMatching(const char *name
)
174 static CFMutableDictionaryRef (*dyfunc
)(const char *) = NULL
;
176 void *image
= __loadIOKit();
177 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_IOServiceMatching", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
179 return dyfunc
? dyfunc(name
) : NULL
;
183 __loadSecurity(void) {
184 static const void *image
= NULL
;
186 const char *framework
= "/System/Library/Frameworks/Security.framework/Security";
188 const char *suffix
= getenv("DYLD_IMAGE_SUFFIX");
189 char path
[MAXPATHLEN
];
191 strcpy(path
, framework
);
192 if (suffix
) strcat(path
, suffix
);
193 if (0 <= stat(path
, &statbuf
)) {
194 image
= NSAddImage(path
, NSADDIMAGE_OPTION_NONE
);
196 image
= NSAddImage(framework
, NSADDIMAGE_OPTION_NONE
);
199 return (void *)image
;
203 __private_extern__ OSStatus
204 _SecKeychainItemCopyContent(SecKeychainItemRef itemRef
, SecItemClass
*itemClass
, SecKeychainAttributeList
*attrList
, UInt32
*length
, void **outData
)
206 static OSStatus (*dyfunc
)(SecKeychainItemRef
, SecItemClass
*, SecKeychainAttributeList
*, UInt32
*, void **) = NULL
;
208 void *image
= __loadSecurity();
209 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_SecKeychainItemCopyContent", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
211 return dyfunc
? dyfunc(itemRef
, itemClass
, attrList
, length
, outData
) : -1;
214 __private_extern__ OSStatus
215 _SecKeychainSearchCopyNext(SecKeychainSearchRef searchRef
, SecKeychainItemRef
*itemRef
)
217 static OSStatus (*dyfunc
)(SecKeychainSearchRef
, SecKeychainItemRef
*) = NULL
;
219 void *image
= __loadSecurity();
220 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_SecKeychainSearchCopyNext", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
222 return dyfunc
? dyfunc(searchRef
, itemRef
) : -1;
225 __private_extern__ OSStatus
226 _SecKeychainSearchCreateFromAttributes(CFTypeRef keychainOrArray
, SecItemClass itemClass
, const SecKeychainAttributeList
*attrList
, SecKeychainSearchRef
*searchRef
)
228 static OSStatus (*dyfunc
)(CFTypeRef
, SecItemClass
, const SecKeychainAttributeList
*, SecKeychainSearchRef
*) = NULL
;
230 void *image
= __loadSecurity();
231 if (image
) dyfunc
= NSAddressOfSymbol(NSLookupSymbolInImage(image
, "_SecKeychainSearchCreateFromAttributes", NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
));
233 return dyfunc
? dyfunc(keychainOrArray
, itemClass
, attrList
, searchRef
) : -1;