X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/6d2010ae8f7a6078e10b361c6962983bab233e0f..bb59bff194111743b33cc36712410b5656329d3c:/libkern/kernel_mach_header.c?ds=inline diff --git a/libkern/kernel_mach_header.c b/libkern/kernel_mach_header.c index 0edc6b64d..ebef5b5ab 100644 --- a/libkern/kernel_mach_header.c +++ b/libkern/kernel_mach_header.c @@ -59,7 +59,7 @@ getlastaddr(void) sgp = (kernel_segment_command_t *) ((uintptr_t)header + sizeof(kernel_mach_header_t)); for (i = 0; i < header->ncmds; i++){ - if ( sgp->cmd == LC_SEGMENT_KERNEL) { + if (sgp->cmd == LC_SEGMENT_KERNEL) { if (sgp->vmaddr + sgp->vmsize > last_addr) last_addr = sgp->vmaddr + sgp->vmsize; } @@ -69,32 +69,47 @@ getlastaddr(void) } /* - * Find the UUID load command in the Mach-O headers, and return - * the address of the UUID blob and size in "*size". If the - * Mach-O image is missing a UUID, NULL is returned. + * Find the specified load command in the Mach-O headers, and return + * the command. If there is no such load command, NULL is returned. */ void * -getuuidfromheader(kernel_mach_header_t *mhp, unsigned long *size) -{ - struct uuid_command *uuidp; +getcommandfromheader(kernel_mach_header_t *mhp, uint32_t cmd) { + struct load_command *lcp; unsigned long i; - uuidp = (struct uuid_command *) - ((uintptr_t)mhp + sizeof(kernel_mach_header_t)); + lcp = (struct load_command *) (mhp + 1); for(i = 0; i < mhp->ncmds; i++){ - if(uuidp->cmd == LC_UUID) { - if (size) - *size = sizeof(uuidp->uuid); - - return (void *)uuidp->uuid; + if(lcp->cmd == cmd) { + return (void *)lcp; } - uuidp = (struct uuid_command *)((uintptr_t)uuidp + uuidp->cmdsize); + lcp = (struct load_command *)((uintptr_t)lcp + lcp->cmdsize); } return NULL; } +/* + * Find the UUID load command in the Mach-O headers, and return + * the address of the UUID blob and size in "*size". If the + * Mach-O image is missing a UUID, NULL is returned. + */ +void * +getuuidfromheader(kernel_mach_header_t *mhp, unsigned long *size) +{ + struct uuid_command *cmd = (struct uuid_command *) + getcommandfromheader(mhp, LC_UUID); + + if (cmd != NULL) { + if (size) { + *size = sizeof(cmd->uuid); + } + return cmd->uuid; + } + + return NULL; +} + /* * This routine returns the a pointer to the data for the named section in the * named segment if it exist in the mach header passed to it. Also it returns @@ -323,68 +338,3 @@ nextsect(kernel_segment_command_t *sgp, kernel_section_t *sp) return sp+1; } - -#ifdef MACH_KDB -/* - * This routine returns the section command for the symbol table in the - * named segment for the mach_header pointer passed to it if it exist. - * Otherwise it returns zero. - */ -static struct symtab_command * -getsectcmdsymtabfromheader( - kernel_mach_header_t *mhp) -{ - kernel_segment_command_t *sgp; - unsigned long i; - - sgp = (kernel_segment_command_t *) - ((uintptr_t)mhp + sizeof(kernel_mach_header_t)); - for(i = 0; i < mhp->ncmds; i++){ - if(sgp->cmd == LC_SYMTAB) - return((struct symtab_command *)sgp); - sgp = (kernel_segment_command_t *)((uintptr_t)sgp + sgp->cmdsize); - } - return((struct symtab_command *)NULL); -} - -boolean_t getsymtab(kernel_mach_header_t *header, - vm_offset_t *symtab, - int *nsyms, - vm_offset_t *strtab, - vm_size_t *strtabsize) -{ - kernel_segment_command_t *seglink_cmd; - struct symtab_command *symtab_cmd; - - seglink_cmd = NULL; - - if((header->magic != MH_MAGIC) - && (header->magic != MH_MAGIC_64)) { /* Check if this is a valid header format */ - return (FALSE); /* Bye y'all... */ - } - - seglink_cmd = getsegbynamefromheader(header,"__LINKEDIT"); - if (seglink_cmd == NULL) { - return(FALSE); - } - - symtab_cmd = NULL; - symtab_cmd = getsectcmdsymtabfromheader(header); - if (symtab_cmd == NULL) - return(FALSE); - - *nsyms = symtab_cmd->nsyms; - if(symtab_cmd->nsyms == 0) return (FALSE); /* No symbols */ - - *strtabsize = symtab_cmd->strsize; - if(symtab_cmd->strsize == 0) return (FALSE); /* Symbol length is 0 */ - - *symtab = seglink_cmd->vmaddr + symtab_cmd->symoff - - seglink_cmd->fileoff; - - *strtab = seglink_cmd->vmaddr + symtab_cmd->stroff - - seglink_cmd->fileoff; - - return(TRUE); -} -#endif