96 for (
size_t i = 0; i <
sizeof(fh.
e_magic); ++i)
147 unsigned char dos_magic[2];
149 if (
'M'!=dos_magic[0] ||
'Z'!=dos_magic[1])
153 uint32_t lfanew_disk;
154 file->
read_content(0x3c, &lfanew_disk,
sizeof lfanew_disk);
158 unsigned char le_magic[4];
159 file->
read_content(le_offset, le_magic,
sizeof le_magic);
160 if (
'L'!=le_magic[0] || (
'E'!=le_magic[1] &&
'X'!=le_magic[1]))
236 write(f, 0,
sizeof fh, &fh);
277 sprintf(p,
"%s%sFileHeader[%zd].", prefix,
format_name(), idx);
279 sprintf(p,
"%s%sFileHeader.", prefix,
format_name());
285 fprintf(f,
"%s%-*s = %u\n", p, w,
"e_byte_order",
p_e_byte_order);
286 fprintf(f,
"%s%-*s = %u\n", p, w,
"e_word_order",
p_e_word_order);
288 fprintf(f,
"%s%-*s = %u\n", p, w,
"e_cpu_type",
p_e_cpu_type);
289 fprintf(f,
"%s%-*s = %u\n", p, w,
"e_os_type",
p_e_os_type);
291 fprintf(f,
"%s%-*s = 0x%08x\n", p, w,
"e_flags",
p_e_flags);
292 fprintf(f,
"%s%-*s = %"PRIu64
"\n", p, w,
"e_npages",
p_e_npages);
294 fprintf(f,
"%s%-*s = 0x%08"PRIx64
"\n", p, w,
"e_eip",
p_e_eip);
296 fprintf(f,
"%s%-*s = 0x%08"PRIx64
"\n", p, w,
"e_esp",
p_e_esp);
297 fprintf(f,
"%s%-*s = %"PRIu64
"\n", p, w,
"e_page_size",
p_e_page_size);
308 fprintf(f,
"%s%-*s = %"PRIu64
" (%"PRIu64
" abs)\n", p, w,
"e_secttab_rfo",
311 fprintf(f,
"%s%-*s = %"PRIu64
" (%"PRIu64
" abs)\n", p, w,
"e_pagetab_rfo",
314 fprintf(f,
"%s%-*s = %"PRIu64
" (%"PRIu64
" abs)\n", p, w,
"e_rsrctab_rfo",
317 fprintf(f,
"%s%-*s = %"PRIu64
" (%"PRIu64
" abs)\n", p, w,
"e_resnametab_rfo",
319 fprintf(f,
"%s%-*s = %"PRIu64
" (%"PRIu64
" abs)\n", p, w,
"e_entrytab_rfo",
321 fprintf(f,
"%s%-*s = %"PRIu64
" (%"PRIu64
" abs)\n", p, w,
"e_fmtdirtab_rfo",
324 fprintf(f,
"%s%-*s = %"PRIu64
" (%"PRIu64
" abs)\n", p, w,
"e_fixup_pagetab_rfo",
326 fprintf(f,
"%s%-*s = %"PRIu64
" (%"PRIu64
" abs)\n", p, w,
"e_fixup_rectab_rfo",
328 fprintf(f,
"%s%-*s = %"PRIu64
" (%"PRIu64
" abs)\n", p, w,
"e_import_modtab_rfo",
331 fprintf(f,
"%s%-*s = %"PRIu64
" (%"PRIu64
" abs)\n", p, w,
"e_import_proctab_rfo",
333 fprintf(f,
"%s%-*s = %"PRIu64
" (%"PRIu64
" abs)\n", p, w,
"e_ppcksumtab_rfo",
341 fprintf(f,
"%s%-*s = %"PRIu64
" (%"PRIu64
" abs)\n", p, w,
"e_debug_info_rfo",
346 fprintf(f,
"%s%-*s = %u\n", p, w,
"e_heap_size",
p_e_heap_size);
349 fprintf(f,
"%s%-*s = [%d] \"%s\"\n", p, w,
"dos2_header",
352 fprintf(f,
"%s%-*s = none\n", p, w,
"dos2_header");
355 fprintf(f,
"%s%-*s = [%d] \"%s\"\n", p, w,
"section_table",
358 fprintf(f,
"%s%-*s = none\n", p, w,
"section_table");
361 fprintf(f,
"%s%-*s = [%d] \"%s\"\n", p, w,
"page_table",
364 fprintf(f,
"%s%-*s = none\n", p, w,
"page_table");
367 fprintf(f,
"%s%-*s = [%d] \"%s\"\n", p, w,
"resname_table",
370 fprintf(f,
"%s%-*s = none\n", p, w,
"resname_table");
373 fprintf(f,
"%s%-*s = [%d] \"%s\"\n", p, w,
"nonresname_table",
376 fprintf(f,
"%s%-*s = none\n", p, w,
"nonresname_table");
379 fprintf(f,
"%s%-*s = [%d] \"%s\"\n", p, w,
"entry_table",
382 fprintf(f,
"%s%-*s = none\n", p, w,
"entry_table");
385 fprintf(f,
"%s%-*s = [%d] \"%s\"\n", p, w,
"reloc_table",
388 fprintf(f,
"%s%-*s = none\n", p, w,
"reloc_table");
402 p_pageno = (pageno_hi << 8) | pageno_lo;
422 sprintf(p,
"%sPageTableEntry[%zd].", prefix, idx);
424 sprintf(p,
"%sPageTableEntry.", prefix);
429 fprintf(f,
"%s%-*s = 0x%04x\n", p, w,
"flags",
p_flags);
430 fprintf(f,
"%s%-*s = %u\n", p, w,
"pageno",
p_pageno);
442 ROSE_ASSERT(fhdr!=NULL);
444 char section_name[64];
445 sprintf(section_name,
"%s Page Table", fhdr->
format_name());
462 ROSE_ASSERT(idx > 0);
472 for (
size_t i=0; i <
p_entries.size(); i++) {
475 spos =
write(f, spos,
sizeof disk, &disk);
485 sprintf(p,
"%s%sPageTable[%zd].", prefix,
get_header()->format_name(), idx);
487 sprintf(p,
"%s%sPageTable.", prefix,
get_header()->format_name());
491 for (
size_t i = 0; i <
p_entries.size(); i++) {
531 sprintf(p,
"%sLESectionTableEntry[%zd].", prefix, idx);
533 sprintf(p,
"%sLESectionTableEntry.", prefix);
538 fprintf(f,
"%s%-*s = %"PRIu64
" bytes\n", p, w,
"mapped_size",
p_mapped_size);
539 fprintf(f,
"%s%-*s = 0x%08"PRIx64
"\n", p, w,
"base_addr",
p_base_addr);
541 fprintf(f,
"%s%-*s = 0x%08x", p, w,
"flags",
p_flags);
547 default: fprintf(f,
"type=%u",
p_flags & SF_TYPE_MASK);
break;
567 fprintf(f,
"%s%-*s = 0x%08x\n", p, w,
"res1",
p_res1);
578 sprintf(p,
"%s%sSection[%zd].", prefix, fhdr->
format_name(), idx);
580 sprintf(p,
"%s%sSection.", prefix, fhdr->
format_name());
596 ROSE_ASSERT(fhdr!=NULL);
599 char section_name[64];
600 sprintf(section_name,
"%s Section Table", fhdr->
format_name());
625 ROSE_ASSERT(pageno>0);
674 ROSE_ASSERT(fhdr!=NULL);
677 for (
size_t i = 0; i < sections.size(); i++) {
678 if (sections[i]->
get_id() >= 0) {
682 ROSE_ASSERT(section->
get_id()>0);
683 size_t slot = section->
get_id()-1;
687 write(f, slot*
sizeof(disk),
sizeof disk, &disk);
701 sprintf(p,
"%s%sSectionTable[%zd].", prefix,
get_header()->format_name(), idx);
703 sprintf(p,
"%s%sSectionTable.", prefix,
get_header()->format_name());
721 ROSE_ASSERT(fhdr!=NULL);
724 char section_name[64];
725 sprintf(section_name,
"%s Name Table", fhdr->
format_name());
736 size_t length = byte;
737 if (0==length)
break;
740 char *buf =
new char[length];
742 p_names.push_back(std::string(buf, length));
760 for (
size_t i = 0; i <
p_names.size(); i++) {
762 ROSE_ASSERT(
p_names[i].size() <= 0xff);
763 unsigned char len =
p_names[i].size();
764 spos =
write(f, spos, len);
773 spos =
write(f, spos,
sizeof ordinal_le, &ordinal_le);
777 write(f, spos,
'\0');
786 sprintf(p,
"%sLENameTable[%zd].", prefix, idx);
788 sprintf(p,
"%sLENameTable.", prefix);
795 for (
size_t i = 0; i <
p_names.size(); i++) {
797 fprintf(f,
"%s%-*s = [%zd] %u\n", p, w,
"ordinals", i,
p_ordinals[i]);
825 spos = section->
write(f, spos, byte);
834 spos = section->
write(f, spos,
sizeof disk, &disk);
845 sprintf(p,
"%sEntryPoint[%zd].", prefix, idx);
847 sprintf(p,
"%sEntryPoint.", prefix);
852 fprintf(f,
"%s%-*s = 0x%02x", p, w,
"flags",
p_flags);
854 fprintf(f,
" 32-bit");
856 fprintf(f,
" non-empty\n");
857 fprintf(f,
"%s%-*s = %u\n", p, w,
"objnum",
p_objnum);
858 fprintf(f,
"%s%-*s = 0x%02x", p, w,
"entry_type",
p_entry_type);
861 fprintf(f,
" stack-params=%u\n", (
p_entry_type >> 3) & 0x1f);
862 fprintf(f,
"%s%-*s = %"PRIu64
"\n", p, w,
"entry_offset",
p_entry_offset);
863 fprintf(f,
"%s%-*s = 0x%04x\n", p, w,
"res1",
p_res1);
865 fprintf(f,
" empty\n");
879 ROSE_ASSERT(fhdr!=NULL);
882 char section_name[64];
883 sprintf(section_name,
"%s Entry Table", fhdr->
format_name());
901 size_t nentries = byte;
902 for (
size_t i = 0; i < nentries; i++) {
924 spos =
write(f, spos, byte);
927 for (
size_t i = 0; i <
p_entries.size(); i++) {
928 spos =
p_entries[i]->unparse(f, sex,
this, spos);
938 sprintf(p,
"%s%sEntryTable[%zd].", prefix,
get_header()->format_name(), idx);
940 sprintf(p,
"%s%sEntryTable.", prefix,
get_header()->format_name());
946 fprintf(f,
"%s%-*s = %zu entry points\n", p, w,
"size",
p_entries.size());
947 for (
size_t i = 0; i <
p_entries.size(); i++) {
965 ROSE_ASSERT(fhdr!=NULL);
968 sprintf(name,
"%s Relocation Table", fhdr->
format_name());
980 for (
size_t i = 0; i < nrelocs; i++, at+=reloc_size) {
1001 sprintf(p,
"%s%sRelocTable[%zd].", prefix,
get_header()->format_name(), idx);
1003 sprintf(p,
"%s%sRelocTable.", prefix,
get_header()->format_name());
1009 fprintf(f,
"%s%-*s = %zu entries\n", p, w,
"size",
p_entries.size());
1010 for (
size_t i = 0; i <
p_entries.size(); i++) {
1021 ROSE_ASSERT(dos_header);
1028 dos2_header->
parse();
1059 char section_name[64];
1060 sprintf(section_name,
"%s Resident Name Table", le_header->
format_name());
1069 char section_name[64];
1070 sprintf(section_name,
"%s Non-resident Name Table", le_header->
format_name());