100 sprintf(p,
"%sElfSegmentTableEntry[%zd].", prefix, idx);
102 sprintf(p,
"%sElfSegmentTableEntry.", prefix);
106 fprintf(f,
"%s%-*s = %zu\n", p, w,
"index", p_index);
107 fprintf(f,
"%s%-*s = 0x%08x = %s\n", p, w,
"type",
p_type, to_string(
p_type).c_str());
108 fprintf(f,
"%s%-*s = 0x%08x ", p, w,
"flags",
p_flags);
109 fputc(
p_flags & PF_RPERM ?
'r' :
'-', f);
110 fputc(
p_flags & PF_WPERM ?
'w' :
'-', f);
111 fputc(
p_flags & PF_XPERM ?
'x' :
'-', f);
112 if (
p_flags & PF_OS_MASK) fputs(
" os", f);
113 if (
p_flags & PF_PROC_MASK) fputs(
" proc", f);
114 if (
p_flags & PF_RESERVED) fputs(
" *", f);
116 fprintf(f,
"%s%-*s = 0x%08"PRIx64
" (%"PRIu64
") bytes into file\n", p, w,
"offset",
p_offset,
p_offset);
117 fprintf(f,
"%s%-*s = 0x%08"PRIx64
" (%"PRIu64
")\n", p, w,
"vaddr",
p_vaddr,
p_vaddr);
118 fprintf(f,
"%s%-*s = 0x%08"PRIx64
" (%"PRIu64
")\n", p, w,
"paddr",
p_paddr,
p_paddr);
119 fprintf(f,
"%s%-*s = 0x%08"PRIx64
" (%"PRIu64
") bytes\n", p, w,
"filesz",
p_filesz,
p_filesz);
120 fprintf(f,
"%s%-*s = 0x%08"PRIx64
" (%"PRIu64
") bytes\n", p, w,
"memsz",
p_memsz,
p_memsz);
121 fprintf(f,
"%s%-*s = 0x%08"PRIx64
" (%"PRIu64
") bytes\n", p, w,
"align",
p_align,
p_align);
122 if (p_extra.size()>0) {
123 fprintf(f,
"%s%-*s = %zu bytes\n", p, w,
"extra", p_extra.size());
124 hexdump(f, 0, std::string(p)+
"extra at ", p_extra);
143 for(
size_t i=0; (1u << i) <= PF_RPERM; ++i){
148 case PF_XPERM: str +=
"EXECUTE";
break;
149 case PF_WPERM: str +=
"WRITE";
break;
150 case PF_RPERM: str +=
"READ";
break;
154 uint32_t os = (val & ~(uint32_t)(PF_OS_MASK));
155 uint32_t proc = (val & ~(uint32_t)(PF_PROC_MASK));
156 uint32_t rest = (val & ~(uint32_t)(PF_RESERVED));
160 snprintf(buf,
sizeof(buf),
"os flags(%2x)", os >> 20);
166 snprintf(buf,
sizeof(buf),
"proc flags(%1x)", proc >> 28);
172 snprintf(buf,
sizeof(buf),
"unknown(%x)", rest);
191 set_synthesized(
true);
193 set_purpose(SP_HEADER);
206 ROSE_ASSERT(fhdr!=NULL);
209 size_t ent_size, struct_size, opt_size, nentries;
210 calculate_sizes(&ent_size, &struct_size, &opt_size, &nentries);
216 if (get_size()<=1 && get_size()<nentries*ent_size)
217 extend(nentries*ent_size - get_size());
220 for (
size_t i=0; i<nentries; i++, offset+=ent_size) {
225 read_content_local(offset, &disk, struct_size);
229 read_content_local(offset, &disk, struct_size);
234 shdr->
get_extra() = read_content_local_ucl(offset+struct_size, opt_size);
245 for (
size_t j=0; !s && j<possible.size(); j++) {
246 if (possible[j]->get_offset()!=shdr->
get_offset() || possible[j]->get_size()!=shdr->
get_filesz())
248 if (possible[j]->is_mapped()) {
249 if (possible[j]->get_mapped_preferred_rva()!=shdr->
get_vaddr() ||
250 possible[j]->get_mapped_size()!=shdr->
get_memsz())
252 unsigned section_perms = (possible[j]->get_mapped_rperm() ? 0x01 : 0x00) |
253 (possible[j]->get_mapped_wperm() ? 0x02 : 0x00) |
254 (possible[j]->get_mapped_xperm() ? 0x04 : 0x00);
258 if (section_perms != segment_perms)
295 ROSE_ASSERT(section!=NULL);
296 ROSE_ASSERT(section->
get_file()==get_file());
297 ROSE_ASSERT(section->
get_header()==get_header());
304 int idx = fhdr->get_e_phnum();
305 fhdr->set_e_phnum(idx+1);
322 ROSE_ASSERT(fhdr!=NULL);
324 size_t struct_size = 0;
326 size_t entry_size = 0;
339 entry_size = struct_size;
344 for (
size_t i=0; i<sections.size(); i++) {
360 *entsize = entry_size;
362 *required = struct_size;
364 *optional = extra_size;
366 *entcount = nentries;
367 return entry_size * nentries;
374 bool reallocated =
false;
377 size_t opt_size, nentries;
378 rose_addr_t need = calculate_sizes(NULL, NULL, &opt_size, &nentries);
379 if (need < get_size()) {
381 ROSE_ASSERT(get_mapped_size()==get_size());
382 set_mapped_size(need);
386 }
else if (need > get_size()) {
404 ROSE_ASSERT(fhdr!=NULL);
409 for (
size_t i=0; i<sections.size(); i++)
410 sections[i]->unparse(f);
414 size_t ent_size, struct_size, opt_size, nentries;
415 calculate_sizes(&ent_size, &struct_size, &opt_size, &nentries);
420 for (
size_t i=0; i < sections.size(); ++i) {
422 ROSE_ASSERT(section!=NULL);
424 ROSE_ASSERT(shdr!=NULL);
428 ROSE_ASSERT(
id>=0 && (
size_t)
id<nentries);
435 disk = shdr->
encode(sex, &disk32);
437 disk = shdr->
encode(sex, &disk64);
439 ROSE_ASSERT(!
"invalid word size");
443 rose_addr_t spos = write(f,
id*ent_size, struct_size, disk);
455 sprintf(p,
"%sSegmentTable[%zd].", prefix, idx);
457 sprintf(p,
"%sSegmentTable.", prefix);
463 hexdump(f, 0, std::string(p)+
"data at ", p_data);