80 break;
81 } else if (addr_relative > this_value) {
82 // gone past it, use previously seen nlist:
83 found_strx = last_nlist->n_un.n_strx;
84 found_symval = last_nlist->n_value;
85 break;
86 }
87 last_nlist = cur_nlist;
88 cur_nlist = cur_nlist + sizeof(struct nlist_64);
89 }
90 if (found_strx == 0) {
91 return false;
92 }
93 // write the offset:
94 *offset = addr_relative - found_symval;
95
96 // lookup found_strx in the string table
97 char * symname = mach_find_in_stringtable((char*) ((uintptr_t)mach_base + stroff), strsize, found_strx);
98 if (symname) {
99 strncpy(buf, symname, buflen);
100 return true;
101 }
102 DEBUG_ONLY(tty->print_cr("no string or null string found."));
103 return false;
104 }
105
106 void* MachODecoder::mach_find_command(struct mach_header_64 * mach_base, uint32_t command_wanted) {
107 // possibly verify it is a mach_header, use magic number.
108 // commands begin immediately after the header.
109 struct load_command *pos = (struct load_command *) mach_base + sizeof(struct mach_header_64);
110 for (uint32_t i = 0; i < mach_base->ncmds; i++) {
111 struct load_command *this_cmd = (struct load_command *) pos;
112 if (this_cmd->cmd == command_wanted) {
113 return pos;
114 }
115 int cmdsize = this_cmd->cmdsize;
116 pos += cmdsize;
117 }
118 return NULL;
119 }
|
80 break;
81 } else if (addr_relative > this_value) {
82 // gone past it, use previously seen nlist:
83 found_strx = last_nlist->n_un.n_strx;
84 found_symval = last_nlist->n_value;
85 break;
86 }
87 last_nlist = cur_nlist;
88 cur_nlist = cur_nlist + sizeof(struct nlist_64);
89 }
90 if (found_strx == 0) {
91 return false;
92 }
93 // write the offset:
94 *offset = addr_relative - found_symval;
95
96 // lookup found_strx in the string table
97 char * symname = mach_find_in_stringtable((char*) ((uintptr_t)mach_base + stroff), strsize, found_strx);
98 if (symname) {
99 strncpy(buf, symname, buflen);
100 buf[buflen - 1] = '\0';
101 return true;
102 }
103 DEBUG_ONLY(tty->print_cr("no string or null string found."));
104 return false;
105 }
106
107 void* MachODecoder::mach_find_command(struct mach_header_64 * mach_base, uint32_t command_wanted) {
108 // possibly verify it is a mach_header, use magic number.
109 // commands begin immediately after the header.
110 struct load_command *pos = (struct load_command *) mach_base + sizeof(struct mach_header_64);
111 for (uint32_t i = 0; i < mach_base->ncmds; i++) {
112 struct load_command *this_cmd = (struct load_command *) pos;
113 if (this_cmd->cmd == command_wanted) {
114 return pos;
115 }
116 int cmdsize = this_cmd->cmdsize;
117 pos += cmdsize;
118 }
119 return NULL;
120 }
|