Re: Getting a mach_header from dlopen
site_archiver@lists.apple.com Delivered-To: Darwin-dev@lists.apple.com User-agent: Mozilla Thunderbird 1.0 (Macintosh/20041206) -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Spencer Nielsen wrote: | Does anybody know offhand a good way to get a code image's mach_header | (for use with getsectdatafromheader) of a specific file? In 10.3 I | used the structure that dlopen returned (dlstatus) and it had a pointer | right in there. However, things have changed in 10.4 and dlopen now | returns a different structure (dlopen_handle). The structure returned | now contains the NSModule for the file among other things. I tried | running through all the loaded images with _dyld_get_image_header and | comparing the names (using _dyld_get_image_name) with the | NSNameOfModule() called on the NSModule in the structure returned by | dlopen but NSNameOfModule() always returns nil. I know that depending | on what is returned by dlopen is probably not the best of strategies | (perhaps that is why the man page still documents it as returning | void*). All I need to be able to do it get the mach_header of code | images that I am loading in with dlopen. Thanks! | Well, you really shouldn't be making any assumptions about what dlopen() returns, it already broke for you 10.3->10.4 and it may break even on minor OS updates because it is just an implementation detail. Since NSAddImage returns a mach_header, I'd suggest using NSAddImage with the path you used to dlopen and NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED | NSADDIMAGE_OPTION_RETURN_ON_ERROR, but I am not quite sure what you are trying to do. Please file an enhancement request with Apple for an api to get information on the handle returned by dlopen. I know that they are trying to reduce the number of dyld apis and standardize on dlopen et.al. where possible, but there are a bunch of things that require a mach_header, so some method of getting a mach_header from a dlopen handle is required. Peter - -- Peter O'Gorman - http://www.pogma.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (Darwin) iQCVAwUBQnbJe7iDAg3OZTLPAQKREwQAr7v95LWZQEW6+vEuoOnb3tpyzIEPFvb8 jgRLFkPsNeVl5lR0gf1L2UG+S6HiV5mXIKVA2yvlzhln7OsG1uykXCWQfFnF6rN0 IpeKIJnK65Yq1Gd+nA7PPhdNZnksPsijkvfdaEl8rxy9A/oUbIlSjDMRkuCYEjbR YOq154YPTL4= =f+36 -----END PGP SIGNATURE----- _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Peter O'Gorman