Index: mach_lookup/mach_lookup.c =================================================================== --- mach_lookup/mach_lookup.c (revision 124) +++ mach_lookup/mach_lookup.c (working copy) @@ -77,25 +77,43 @@ // if we failed to find any one of the load commands we need, bail out if (text_seg_cmd == NULL || linkedit_seg_cmd == NULL || symtab_cmd == NULL || dysymtab_cmd == NULL) return NULL; -// uint32_t vm_symoff = (symtab_cmd->symoff - linkedit_seg_cmd->fileoff); + //uint32_t vm_symoff = (symtab_cmd->symoff - linkedit_seg_cmd->fileoff); uint32_t vm_stroff = (symtab_cmd->stroff - symtab_cmd->symoff); // get the address of the symtab and the first externally defined symbol symtab entry - struct nlist* symtab = (struct nlist*)(linkedit_seg_cmd->vmaddr); - char** name_tbl = generate_nametbl((char*)(linkedit_seg_cmd->vmaddr + vm_stroff), symtab_cmd->strsize); + //char** name_tbl = generate_nametbl((char*)(linkedit_seg_cmd->vmaddr + vm_stroff), symtab_cmd->strsize); + char *name_tbl = (char *)(linkedit_seg_cmd->vmaddr + vm_stroff); + + // Loop through the symtab looking for uint32_t isym = 0; - for (; isym < symtab_cmd->nsyms; isym++) { + uint8_t count = 0; + while (count < 2) { struct nlist c = symtab[isym]; - if (c.n_un.n_strx != 0) printf("%s\n", name_tbl[c.n_un.n_strx]); - else printf("anonymous\n"); - if (strcmp(name_tbl[c.n_un.n_strx], symbol) == 0) { - printf("*** %s is at %p\n", name_tbl[c.n_un.n_strx], c.n_value); + + // we start and end with __no_local_symbols_in_dyld_shared_cache + if(c.n_un.n_strx == 0) { + count ++; isym ++; + if(count == 2) break; + else continue; } + + if (name_tbl[c.n_un.n_strx] != 0) { + //printf("%s at %p\n", name_tbl + c.n_un.n_strx, c.n_value); + if (strcmp(name_tbl + c.n_un.n_strx, symbol) == 0) { + return (void *)c.n_value; + } + } else { + //printf("(anonymous) at %p\n", c.n_value); + } + + isym ++; } - free(name_tbl); + //printf("There were %d symbols\n", isym - 2); + //free(name_tbl); + return NULL; }