1 /* 2 * HT Editor 3 * htpe.h 4 * 5 * Copyright (C) 1999-2002 Stefan Weyergraf 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 #ifndef __HTPE_H__ 22 #define __HTPE_H__ 23 24 #include "formats.h" 25 #include "pestruct.h" 26 #include "htpeexp.h" 27 #include "htpeil.h" 28 #include "htpeimp.h" 29 #include "htpedimp.h" 30 #include <deque> 31 32 #define DESC_PE "pe - win32 portable exe" 33 #define DESC_PE_HEADER "pe/header" 34 #define DESC_PE_IMPORTS "pe/imports" 35 #define DESC_PE_DIMPORTS "pe/delay-imports" 36 #define DESC_PE_EXPORTS "pe/exports" 37 #define DESC_PE_RESOURCES "pe/resources" 38 #define DESC_PE_IMAGE "pe/image" 39 #define DESC_PE_IL "pe/il" 40 #define DESC_PE_RELOC "pe/relocations" 41 42 #define ATOM_PE_MACHINES 0x50450000 43 #define ATOM_PE_MACHINES_STR "50450000" 44 45 #define ATOM_PE_OPTIONAL_MAGICS 0x50450001 46 #define ATOM_PE_OPTIONAL_MAGICS_STR "50450001" 47 48 #define ATOM_PE_SUBSYSTEMS 0x50450002 49 #define ATOM_PE_SUBSYSTEMS_STR "50450002" 50 51 #define ATOM_PE_CHARACTERISTICS 0x50450003 52 #define ATOM_PE_CHARACTERISTICS_STR "50450003" 53 54 #define ATOM_PE_DLL_CHARACTERISTICS 0x50450004 55 #define ATOM_PE_DLL_CHARACTERISTICS_STR "50450004" 56 57 #define ATOM_PE_SECTION_CHARACTERISTICS 0x50450005 58 #define ATOM_PE_SECTION_CHARACTERISTICS_STR "50450005" 59 60 extern format_viewer_if htpe_if; 61 62 struct pe_section_headers { 63 uint section_count; 64 COFF_SECTION_HEADER *sections; 65 }; 66 67 /* 68 * STRUCT stored fixup entry 69 */ 70 71 struct fixup_listentry { 72 73 uint32 addr; 74 uint32 size; 75 uint32 idCol; 76 77 }; 78 79 struct ht_pe_shared_data { 80 FileOfs header_ofs; 81 COFF_HEADER coffheader; 82 uint16 opt_magic; 83 union { 84 struct { 85 COFF_OPTIONAL_HEADER32 header; 86 PE_OPTIONAL_HEADER32_NT header_nt; 87 } pe32; 88 struct { 89 COFF_OPTIONAL_HEADER64 header; 90 PE_OPTIONAL_HEADER64_NT header_nt; 91 } pe64; 92 }; 93 pe_section_headers sections; 94 ht_pe_il *il; 95 ht_pe_export exports; 96 ht_pe_import imports; 97 ht_pe_import dimports; 98 ht_format_viewer *v_header; 99 ht_view *v_exports; 100 ht_view *v_imports; 101 ht_view *v_dimports; 102 ht_view *v_resources; 103 ht_view *v_il; 104 ht_format_viewer *v_image; 105 106 std::deque<fixup_listentry> fixupque; 107 }; 108 109 /* 110 * CLASS ht_pe 111 */ 112 113 class ht_pe: public ht_format_group { 114 protected: 115 bool loc_enum; 116 public: 117 void init(Bounds *b, File *file, format_viewer_if **ifs, ht_format_group *format_group, FileOfs header_ofs); 118 virtual void done(); 119 /* overwritten */ 120 virtual void loc_enum_start(); 121 virtual bool loc_enum_next(ht_format_loc *loc); 122 }; 123 124 bool pe_rva_to_section(pe_section_headers *section_headers, RVA rva, int *section); 125 bool pe_rva_to_ofs(pe_section_headers *section_headers, RVA rva, FileOfs *ofs); 126 bool pe_rva_is_valid(pe_section_headers *section_headers, RVA rva); 127 bool pe_rva_is_physical(pe_section_headers *section_headers, RVA rva); 128 129 bool pe_ofs_to_rva(pe_section_headers *section_headers, FileOfs ofs, RVA *rva); 130 bool pe_ofs_to_section(pe_section_headers *section_headers, FileOfs ofs, int *section); 131 bool pe_ofs_to_rva_and_section(pe_section_headers *section_headers, FileOfs ofs, RVA *rva, int *section); 132 133 bool pe_section_name_to_section(pe_section_headers *section_headers, const char *name, int *section); 134 135 #endif /* !__HTPE_H__ */ 136