I am linking a executable with a plist using -sectcreate __TEXT linker flags. Reason for this is mainly to use the SMJobBless() method. But I need to read plist linked from another application. This is only because I need to install the same privileged application on a 10.5 system and I can’t use SMJobBless() on 10.5.
How do I read this linked plist using Objective-C so I can copy it to /Library/LaunchDaemons/ myself?
otool
You can use otool(1) to dump the contents of the section containing the embedded plist:
and then pipe its output to xxd(1) in order to obtain the corresponding ASCII representation:
However, otool is only available in machines where Xcode has been installed.
NSBundle
For the cases where a program needs to read its own embedded plist, NSBundle can be used:
Mach-O
For the cases where a program needs to read the embedded plist of an arbitrary file without resorting to otool, the program can parse the Mach-O information in the file and extract its embedded plist as follows:
and:
Note that
embeddedPlist()has some limitations: it expects the file to be a thin Mach-O file (i.e., it will crash with non-Mach-O files and it won’t work with fat files containing, for example, both i386 and x86_64 Mach-O data); it only works with x86_64 files; it doesn’t report errors.I went ahead and released BVPlistExtractor under the MIT licence. It detects whether the file is indeed a thin Mach-O file or a fat/universal file, and works with both i386 and x86_64.