Die UUID einer ausführbaren Datei (Mach-O-Datei) wird vom Linker ld
erstellt und in einem Ladebefehl mit dem Namen LC_UUID
gespeichert. Sie können alle Ladebefehle einer mach-o-Datei otool
mit:
otool -l path_to_executable
> ...
> Load command 8
> cmd LC_UUID
> cmdsize 24
> uuid 3AB82BF6-8F53-39A0-BE2D-D5AEA84D8BA6
> ...
Jeder Prozess seine mach-o-Header mit einem globalen Symbol _mh_execute_header
Namen zugreifen kann. Mit diesem Symbol können Sie über die Ladebefehle iterieren, um nach LC_UUID
zu suchen. Die Nutzlast des Befehls ist die UUID:
#import <mach-o/ldsyms.h>
NSString *executableUUID()
{
const uint8_t *command = (const uint8_t *)(&_mh_execute_header + 1);
for (uint32_t idx = 0; idx < _mh_execute_header.ncmds; ++idx) {
if (((const struct load_command *)command)->cmd == LC_UUID) {
command += sizeof(struct load_command);
return [NSString stringWithFormat:@"%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
command[0], command[1], command[2], command[3],
command[4], command[5],
command[6], command[7],
command[8], command[9],
command[10], command[11], command[12], command[13], command[14], command[15]];
} else {
command += ((const struct load_command *)command)->cmdsize;
}
}
return nil;
}