Un UUID di un file eseguibile (mach-o file) viene creato dal linker ld
ed è memorizzato in un comando di caricamento denominato LC_UUID
. Potete vedere tutti i comandi di caricamento di un file mach-o utilizzando otool
:
otool -l path_to_executable
> ...
> Load command 8
> cmd LC_UUID
> cmdsize 24
> uuid 3AB82BF6-8F53-39A0-BE2D-D5AEA84D8BA6
> ...
Qualsiasi processo può accedere al suo colpo di testa mach-o utilizzando un simbolo globale di nome _mh_execute_header
. Usando questo simbolo puoi scorrere i comandi di caricamento per cercare LC_UUID
. Il payload del comando è l'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;
}
fonte
2012-04-12 09:54:07