summaryrefslogtreecommitdiff
path: root/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.h')
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.h1768
1 files changed, 884 insertions, 884 deletions
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.h b/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.h
index 4aed866a7d..cfce60796f 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.h
@@ -1,884 +1,884 @@
1/* 1/*
2* PeLibAux.cpp - Part of the PeLib library. 2* PeLibAux.cpp - Part of the PeLib library.
3* 3*
4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) 4* Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5* All rights reserved. 5* All rights reserved.
6* 6*
7* This software is licensed under the zlib/libpng License. 7* This software is licensed under the zlib/libpng License.
8* For more details see http://www.opensource.org/licenses/zlib-license.php 8* For more details see http://www.opensource.org/licenses/zlib-license.php
9* or the license information file (license.htm) in the root directory 9* or the license information file (license.htm) in the root directory
10* of PeLib. 10* of PeLib.
11*/ 11*/
12 12
13#ifndef PELIBAUX_H 13#ifndef PELIBAUX_H
14#define PELIBAUX_H 14#define PELIBAUX_H
15 15
16//#include "PeLibInc.h" 16//#include "PeLibInc.h"
17//#include "PeHeader.h" 17//#include "PeHeader.h"
18#include "buffer/OutputBuffer.h" 18#include "buffer/OutputBuffer.h"
19#include "buffer/InputBuffer.h" 19#include "buffer/InputBuffer.h"
20//#include "buffer/ResTree.h" 20//#include "buffer/ResTree.h"
21#include <numeric> 21#include <numeric>
22#include <limits> 22#include <limits>
23 23
24namespace PeLib 24namespace PeLib
25{ 25{
26 enum errorCodes 26 enum errorCodes
27 { 27 {
28 NO_ERROR = 0, 28 NO_ERROR = 0,
29 ERROR_OPENING_FILE = -1, 29 ERROR_OPENING_FILE = -1,
30 ERROR_INVALID_FILE = -2, 30 ERROR_INVALID_FILE = -2,
31 ERROR_TOO_MANY_SECTIONS = -3, 31 ERROR_TOO_MANY_SECTIONS = -3,
32 ERROR_NOT_ENOUGH_SPACE = -4, 32 ERROR_NOT_ENOUGH_SPACE = -4,
33 ERROR_NO_FILE_ALIGNMENT = -5, 33 ERROR_NO_FILE_ALIGNMENT = -5,
34 ERROR_NO_SECTION_ALIGNMENT = -6, 34 ERROR_NO_SECTION_ALIGNMENT = -6,
35 ERROR_ENTRY_NOT_FOUND = -7, 35 ERROR_ENTRY_NOT_FOUND = -7,
36 ERROR_DUPLICATE_ENTRY = -8, 36 ERROR_DUPLICATE_ENTRY = -8,
37 ERROR_DIRECTORY_DOES_NOT_EXIST = -9 37 ERROR_DIRECTORY_DOES_NOT_EXIST = -9
38 }; 38 };
39 39
40 class PeFile; 40 class PeFile;
41 bool isEqualNc(const std::string& s1, const std::string& s2); 41 bool isEqualNc(const std::string& s1, const std::string& s2);
42 42
43// It's necessary to make sure that a byte has 8 bits and that the platform has a 8 bit type, 43// It's necessary to make sure that a byte has 8 bits and that the platform has a 8 bit type,
44// a 16bit type and a bit type. That's because binary PE files are pretty picky about their 44// a 16bit type and a bit type. That's because binary PE files are pretty picky about their
45// structure. 45// structure.
46 46
47 #if CHAR_BIT == 8 47 #if CHAR_BIT == 8
48 #if UCHAR_MAX == 255 48 #if UCHAR_MAX == 255
49 typedef unsigned char byte; 49 typedef unsigned char byte;
50 // typedef std::bitset<8> byte; 50 // typedef std::bitset<8> byte;
51 #else 51 #else
52 #error You need to change some typedefs (Code: 8). Please read the PeLib documentation. 52 #error You need to change some typedefs (Code: 8). Please read the PeLib documentation.
53 #endif 53 #endif
54 54
55 #if USHRT_MAX == 65535U 55 #if USHRT_MAX == 65535U
56 typedef unsigned short word; 56 typedef unsigned short word;
57 // typedef std::bitset<16> word; 57 // typedef std::bitset<16> word;
58 #else 58 #else
59 #error You need to change some typedefs (Code: 16). Please read the PeLib documentation. 59 #error You need to change some typedefs (Code: 16). Please read the PeLib documentation.
60 #endif 60 #endif
61 61
62 #if UINT_MAX == 4294967295UL 62 #if UINT_MAX == 4294967295UL
63 typedef unsigned int dword; 63 typedef unsigned int dword;
64 // typedef std::bitset<32> dword; 64 // typedef std::bitset<32> dword;
65 #else 65 #else
66 #error You need to change some typedefs (Code: 32). Please read the PeLib documentation. 66 #error You need to change some typedefs (Code: 32). Please read the PeLib documentation.
67 #endif 67 #endif
68 68
69 typedef unsigned long long qword; 69 typedef unsigned long long qword;
70 70
71// #if ULLONG_MAX == 18446744073709551615 71// #if ULLONG_MAX == 18446744073709551615
72// typedef unsigned long long qword; 72// typedef unsigned long long qword;
73// #else 73// #else
74// #error You need to change some typedefs (Code: 32). Please read the PeLib documentation. 74// #error You need to change some typedefs (Code: 32). Please read the PeLib documentation.
75// #endif 75// #endif
76 #else 76 #else
77 #error You need to change some typedefs. Please read the PeLib documentation. 77 #error You need to change some typedefs. Please read the PeLib documentation.
78 #endif 78 #endif
79 79
80 80
81/* enum bits {BITS_BYTE = 8, BITS_WORD = 16, BITS_DWORD = 32}; 81/* enum bits {BITS_BYTE = 8, BITS_WORD = 16, BITS_DWORD = 32};
82 82
83 template<bits value> 83 template<bits value>
84 class DataType 84 class DataType
85 { 85 {
86 private: 86 private:
87 std::bitset<value> bsValue; 87 std::bitset<value> bsValue;
88 unsigned long ulValue; 88 unsigned long ulValue;
89 89
90 public: 90 public:
91 void operator=(unsigned long ulValue) 91 void operator=(unsigned long ulValue)
92 { 92 {
93 bsValue = ulValue; 93 bsValue = ulValue;
94 } 94 }
95 95
96 operator unsigned long() const 96 operator unsigned long() const
97 { 97 {
98 return bsValue.to_ulong(); 98 return bsValue.to_ulong();
99 } 99 }
100 100
101 const int operator&() 101 const int operator&()
102 { 102 {
103 ulValue = bsValue; 103 ulValue = bsValue;
104 return ulValue; 104 return ulValue;
105 } 105 }
106 106
107 }; 107 };
108 108
109 typedef DataType<BITS_BYTE> byte; 109 typedef DataType<BITS_BYTE> byte;
110 typedef DataType<BITS_WORD> word; 110 typedef DataType<BITS_WORD> word;
111 typedef DataType<BITS_DWORD> dword; 111 typedef DataType<BITS_DWORD> dword;
112*/ 112*/
113 113
114 enum {PEFILE32 = 32, 114 enum {PEFILE32 = 32,
115 PEFILE64 = 64, 115 PEFILE64 = 64,
116 PEFILE_UNKNOWN = 0}; 116 PEFILE_UNKNOWN = 0};
117 117
118 enum {BoundImportDirectoryId = 1, 118 enum {BoundImportDirectoryId = 1,
119 ComHeaderDirectoryId, 119 ComHeaderDirectoryId,
120 ExportDirectoryId, 120 ExportDirectoryId,
121 IatDirectoryId, 121 IatDirectoryId,
122 ImportDirectoryId, 122 ImportDirectoryId,
123 MzHeaderId, 123 MzHeaderId,
124 PeHeaderId, 124 PeHeaderId,
125 RelocationsId, 125 RelocationsId,
126 PeFileId, 126 PeFileId,
127 ResourceDirectoryId, 127 ResourceDirectoryId,
128 DebugDirectoryId, 128 DebugDirectoryId,
129 TlsDirectoryId 129 TlsDirectoryId
130 }; 130 };
131 131
132 const word PELIB_IMAGE_DOS_SIGNATURE = 0x5A4D; 132 const word PELIB_IMAGE_DOS_SIGNATURE = 0x5A4D;
133 133
134 const dword PELIB_IMAGE_NT_SIGNATURE = 0x00004550; 134 const dword PELIB_IMAGE_NT_SIGNATURE = 0x00004550;
135 135
136 template<int bits> 136 template<int bits>
137 struct PELIB_IMAGE_ORDINAL_FLAGS; 137 struct PELIB_IMAGE_ORDINAL_FLAGS;
138 138
139 template<> 139 template<>
140 struct PELIB_IMAGE_ORDINAL_FLAGS<32> 140 struct PELIB_IMAGE_ORDINAL_FLAGS<32>
141 { 141 {
142 static const dword IMAGE_ORDINAL_FLAG = 0x80000000; 142 static const dword IMAGE_ORDINAL_FLAG = 0x80000000;
143 }; 143 };
144 144
145 template<> 145 template<>
146 struct PELIB_IMAGE_ORDINAL_FLAGS<64> 146 struct PELIB_IMAGE_ORDINAL_FLAGS<64>
147 { 147 {
148 static const qword IMAGE_ORDINAL_FLAG; 148 static const qword IMAGE_ORDINAL_FLAG;
149 }; 149 };
150 150
151 const unsigned long PELIB_IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16; 151 const unsigned long PELIB_IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16;
152 152
153 const unsigned long PELIB_IMAGE_RESOURCE_NAME_IS_STRING = 0x80000000; 153 const unsigned long PELIB_IMAGE_RESOURCE_NAME_IS_STRING = 0x80000000;
154 154
155 const unsigned long PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY = 0x80000000; 155 const unsigned long PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY = 0x80000000;
156 156
157 enum 157 enum
158 { 158 {
159 PELIB_IMAGE_DIRECTORY_ENTRY_EXPORT, // OK 159 PELIB_IMAGE_DIRECTORY_ENTRY_EXPORT, // OK
160 PELIB_IMAGE_DIRECTORY_ENTRY_IMPORT, // OK 160 PELIB_IMAGE_DIRECTORY_ENTRY_IMPORT, // OK
161 PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE, // OK 161 PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE, // OK
162 PELIB_IMAGE_DIRECTORY_ENTRY_EXCEPTION, 162 PELIB_IMAGE_DIRECTORY_ENTRY_EXCEPTION,
163 PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY, 163 PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY,
164 PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC, // OK 164 PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC, // OK
165 PELIB_IMAGE_DIRECTORY_ENTRY_DEBUG, 165 PELIB_IMAGE_DIRECTORY_ENTRY_DEBUG,
166 PELIB_IMAGE_DIRECTORY_ENTRY_ARCHITECTURE, 166 PELIB_IMAGE_DIRECTORY_ENTRY_ARCHITECTURE,
167 PELIB_IMAGE_DIRECTORY_ENTRY_GLOBALPTR, 167 PELIB_IMAGE_DIRECTORY_ENTRY_GLOBALPTR,
168 PELIB_IMAGE_DIRECTORY_ENTRY_TLS, 168 PELIB_IMAGE_DIRECTORY_ENTRY_TLS,
169 PELIB_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG, 169 PELIB_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG,
170 PELIB_IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT, // OK 170 PELIB_IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT, // OK
171 PELIB_IMAGE_DIRECTORY_ENTRY_IAT, // OK 171 PELIB_IMAGE_DIRECTORY_ENTRY_IAT, // OK
172 PELIB_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT, 172 PELIB_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT,
173 PELIB_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 173 PELIB_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR
174 }; 174 };
175 175
176 enum 176 enum
177 { 177 {
178 PELIB_IMAGE_SCN_TYPE_NO_PAD = 0x00000008, 178 PELIB_IMAGE_SCN_TYPE_NO_PAD = 0x00000008,
179 PELIB_IMAGE_SCN_CNT_CODE = 0x00000020, 179 PELIB_IMAGE_SCN_CNT_CODE = 0x00000020,
180 PELIB_IMAGE_SCN_CNT_INITIALIZED_DATA = 0x00000040, 180 PELIB_IMAGE_SCN_CNT_INITIALIZED_DATA = 0x00000040,
181 PELIB_IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080, 181 PELIB_IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080,
182 PELIB_IMAGE_SCN_LNK_OTHER = 0x00000100, 182 PELIB_IMAGE_SCN_LNK_OTHER = 0x00000100,
183 PELIB_IMAGE_SCN_LNK_INFO = 0x00000200, 183 PELIB_IMAGE_SCN_LNK_INFO = 0x00000200,
184 PELIB_IMAGE_SCN_LNK_REMOVE = 0x00000800, 184 PELIB_IMAGE_SCN_LNK_REMOVE = 0x00000800,
185 PELIB_IMAGE_SCN_LNK_COMDAT = 0x00001000, 185 PELIB_IMAGE_SCN_LNK_COMDAT = 0x00001000,
186 PELIB_IMAGE_SCN_NO_DEFER_SPEC_EXC = 0x00004000, 186 PELIB_IMAGE_SCN_NO_DEFER_SPEC_EXC = 0x00004000,
187 PELIB_IMAGE_SCN_GPREL = 0x00008000, 187 PELIB_IMAGE_SCN_GPREL = 0x00008000,
188 PELIB_IMAGE_SCN_MEM_FARDATA = 0x00008000, 188 PELIB_IMAGE_SCN_MEM_FARDATA = 0x00008000,
189 PELIB_IMAGE_SCN_MEM_PURGEABLE = 0x00020000, 189 PELIB_IMAGE_SCN_MEM_PURGEABLE = 0x00020000,
190 PELIB_IMAGE_SCN_MEM_16BIT = 0x00020000, 190 PELIB_IMAGE_SCN_MEM_16BIT = 0x00020000,
191 PELIB_IMAGE_SCN_MEM_LOCKED = 0x00040000, 191 PELIB_IMAGE_SCN_MEM_LOCKED = 0x00040000,
192 PELIB_IMAGE_SCN_MEM_PRELOAD = 0x00080000, 192 PELIB_IMAGE_SCN_MEM_PRELOAD = 0x00080000,
193 PELIB_IMAGE_SCN_ALIGN_1BYTES = 0x00100000, 193 PELIB_IMAGE_SCN_ALIGN_1BYTES = 0x00100000,
194 PELIB_IMAGE_SCN_ALIGN_2BYTES = 0x00200000, 194 PELIB_IMAGE_SCN_ALIGN_2BYTES = 0x00200000,
195 PELIB_IMAGE_SCN_ALIGN_4BYTES = 0x00300000, 195 PELIB_IMAGE_SCN_ALIGN_4BYTES = 0x00300000,
196 PELIB_IMAGE_SCN_ALIGN_8BYTES = 0x00400000, 196 PELIB_IMAGE_SCN_ALIGN_8BYTES = 0x00400000,
197 PELIB_IMAGE_SCN_ALIGN_16BYTES = 0x00500000, 197 PELIB_IMAGE_SCN_ALIGN_16BYTES = 0x00500000,
198 PELIB_IMAGE_SCN_ALIGN_BYTES = 0x00600000, 198 PELIB_IMAGE_SCN_ALIGN_BYTES = 0x00600000,
199 PELIB_IMAGE_SCN_ALIGN_64BYTES = 0x00700000, 199 PELIB_IMAGE_SCN_ALIGN_64BYTES = 0x00700000,
200 PELIB_IMAGE_SCN_ALIGN_128BYTES = 0x00800000, 200 PELIB_IMAGE_SCN_ALIGN_128BYTES = 0x00800000,
201 PELIB_IMAGE_SCN_ALIGN_256BYTES = 0x00900000, 201 PELIB_IMAGE_SCN_ALIGN_256BYTES = 0x00900000,
202 PELIB_IMAGE_SCN_ALIGN_512BYTES = 0x00A00000, 202 PELIB_IMAGE_SCN_ALIGN_512BYTES = 0x00A00000,
203 PELIB_IMAGE_SCN_ALIGN_1024BYTES = 0x00B00000, 203 PELIB_IMAGE_SCN_ALIGN_1024BYTES = 0x00B00000,
204 PELIB_IMAGE_SCN_ALIGN_2048BYTES = 0x00C00000, 204 PELIB_IMAGE_SCN_ALIGN_2048BYTES = 0x00C00000,
205 PELIB_IMAGE_SCN_ALIGN_4096BYTES = 0x00D00000, 205 PELIB_IMAGE_SCN_ALIGN_4096BYTES = 0x00D00000,
206 PELIB_IMAGE_SCN_ALIGN_8192BYTES = 0x00E00000, 206 PELIB_IMAGE_SCN_ALIGN_8192BYTES = 0x00E00000,
207 PELIB_IMAGE_SCN_LNK_NRELOC_OVFL = 0x01000000, 207 PELIB_IMAGE_SCN_LNK_NRELOC_OVFL = 0x01000000,
208 PELIB_IMAGE_SCN_MEM_DISCARDABLE = 0x02000000, 208 PELIB_IMAGE_SCN_MEM_DISCARDABLE = 0x02000000,
209 PELIB_IMAGE_SCN_MEM_NOT_CACHED = 0x04000000, 209 PELIB_IMAGE_SCN_MEM_NOT_CACHED = 0x04000000,
210 PELIB_IMAGE_SCN_MEM_NOT_PAGED = 0x08000000, 210 PELIB_IMAGE_SCN_MEM_NOT_PAGED = 0x08000000,
211 PELIB_IMAGE_SCN_MEM_SHARED = 0x10000000, 211 PELIB_IMAGE_SCN_MEM_SHARED = 0x10000000,
212 PELIB_IMAGE_SCN_MEM_EXECUTE = 0x20000000, 212 PELIB_IMAGE_SCN_MEM_EXECUTE = 0x20000000,
213 PELIB_IMAGE_SCN_MEM_READ = 0x40000000, 213 PELIB_IMAGE_SCN_MEM_READ = 0x40000000,
214 PELIB_IMAGE_SCN_MEM_WRITE = 0x80000000 214 PELIB_IMAGE_SCN_MEM_WRITE = 0x80000000
215 }; 215 };
216 216
217 enum 217 enum
218 { 218 {
219 PELIB_IMAGE_FILE_MACHINE_UNKNOWN = 0, 219 PELIB_IMAGE_FILE_MACHINE_UNKNOWN = 0,
220 PELIB_IMAGE_FILE_MACHINE_I386 = 0x014c, 220 PELIB_IMAGE_FILE_MACHINE_I386 = 0x014c,
221 PELIB_IMAGE_FILE_MACHINE_R3000 = 0x0162, 221 PELIB_IMAGE_FILE_MACHINE_R3000 = 0x0162,
222 PELIB_IMAGE_FILE_MACHINE_R4000 = 0x0166, 222 PELIB_IMAGE_FILE_MACHINE_R4000 = 0x0166,
223 PELIB_IMAGE_FILE_MACHINE_R10000 = 0x0168, 223 PELIB_IMAGE_FILE_MACHINE_R10000 = 0x0168,
224 PELIB_IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x0169, 224 PELIB_IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x0169,
225 PELIB_IMAGE_FILE_MACHINE_ALPHA = 0x0184, 225 PELIB_IMAGE_FILE_MACHINE_ALPHA = 0x0184,
226 PELIB_IMAGE_FILE_MACHINE_POWERPC = 0x01F0, 226 PELIB_IMAGE_FILE_MACHINE_POWERPC = 0x01F0,
227 PELIB_IMAGE_FILE_MACHINE_SH3 = 0x01a2, 227 PELIB_IMAGE_FILE_MACHINE_SH3 = 0x01a2,
228 PELIB_IMAGE_FILE_MACHINE_SH3E = 0x01a4, 228 PELIB_IMAGE_FILE_MACHINE_SH3E = 0x01a4,
229 PELIB_IMAGE_FILE_MACHINE_SH4 = 0x01a6, 229 PELIB_IMAGE_FILE_MACHINE_SH4 = 0x01a6,
230 PELIB_IMAGE_FILE_MACHINE_ARM = 0x01c0, 230 PELIB_IMAGE_FILE_MACHINE_ARM = 0x01c0,
231 PELIB_IMAGE_FILE_MACHINE_THUMB = 0x01c2, 231 PELIB_IMAGE_FILE_MACHINE_THUMB = 0x01c2,
232 PELIB_IMAGE_FILE_MACHINE_IA64 = 0x0200, 232 PELIB_IMAGE_FILE_MACHINE_IA64 = 0x0200,
233 PELIB_IMAGE_FILE_MACHINE_MIPS16 = 0x0266, 233 PELIB_IMAGE_FILE_MACHINE_MIPS16 = 0x0266,
234 PELIB_IMAGE_FILE_MACHINE_MIPSFPU = 0x0366, 234 PELIB_IMAGE_FILE_MACHINE_MIPSFPU = 0x0366,
235 PELIB_IMAGE_FILE_MACHINE_MIPSFPU16 = 0x0466, 235 PELIB_IMAGE_FILE_MACHINE_MIPSFPU16 = 0x0466,
236 PELIB_IMAGE_FILE_MACHINE_ALPHA64 = 0x0284, 236 PELIB_IMAGE_FILE_MACHINE_ALPHA64 = 0x0284,
237 PELIB_IMAGE_FILE_MACHINE_AXP64 = PELIB_IMAGE_FILE_MACHINE_ALPHA64 237 PELIB_IMAGE_FILE_MACHINE_AXP64 = PELIB_IMAGE_FILE_MACHINE_ALPHA64
238 }; 238 };
239 239
240 enum 240 enum
241 { 241 {
242 PELIB_IMAGE_FILE_RELOCS_STRIPPED = 0x0001, 242 PELIB_IMAGE_FILE_RELOCS_STRIPPED = 0x0001,
243 PELIB_IMAGE_FILE_EXECUTABLE_IMAGE = 0x0002, 243 PELIB_IMAGE_FILE_EXECUTABLE_IMAGE = 0x0002,
244 PELIB_IMAGE_FILE_LINE_NUMS_STRIPPED = 0x0004, 244 PELIB_IMAGE_FILE_LINE_NUMS_STRIPPED = 0x0004,
245 PELIB_IMAGE_FILE_LOCAL_SYMS_STRIPPED = 0x0008, 245 PELIB_IMAGE_FILE_LOCAL_SYMS_STRIPPED = 0x0008,
246 PELIB_IMAGE_FILE_AGGRESIVE_WS_TRIM = 0x0010, 246 PELIB_IMAGE_FILE_AGGRESIVE_WS_TRIM = 0x0010,
247 PELIB_IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x0020, 247 PELIB_IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x0020,
248 PELIB_IMAGE_FILE_BYTES_REVERSED_LO = 0x0080, 248 PELIB_IMAGE_FILE_BYTES_REVERSED_LO = 0x0080,
249 PELIB_IMAGE_FILE_32BIT_MACHINE = 0x0100, 249 PELIB_IMAGE_FILE_32BIT_MACHINE = 0x0100,
250 PELIB_IMAGE_FILE_DEBUG_STRIPPED = 0x0200, 250 PELIB_IMAGE_FILE_DEBUG_STRIPPED = 0x0200,
251 PELIB_IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = 0x0400, 251 PELIB_IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = 0x0400,
252 PELIB_IMAGE_FILE_NET_RUN_FROM_SWAP = 0x0800, 252 PELIB_IMAGE_FILE_NET_RUN_FROM_SWAP = 0x0800,
253 PELIB_IMAGE_FILE_SYSTEM = 0x1000, 253 PELIB_IMAGE_FILE_SYSTEM = 0x1000,
254 PELIB_IMAGE_FILE_DLL = 0x2000, 254 PELIB_IMAGE_FILE_DLL = 0x2000,
255 PELIB_IMAGE_FILE_UP_SYSTEM_ONLY = 0x4000, 255 PELIB_IMAGE_FILE_UP_SYSTEM_ONLY = 0x4000,
256 PELIB_IMAGE_FILE_BYTES_REVERSED_HI = 0x8000 256 PELIB_IMAGE_FILE_BYTES_REVERSED_HI = 0x8000
257 }; 257 };
258 258
259 enum 259 enum
260 { 260 {
261 PELIB_IMAGE_NT_OPTIONAL_HDR32_MAGIC = 0x10b, 261 PELIB_IMAGE_NT_OPTIONAL_HDR32_MAGIC = 0x10b,
262 PELIB_IMAGE_NT_OPTIONAL_HDR64_MAGIC = 0x20b, 262 PELIB_IMAGE_NT_OPTIONAL_HDR64_MAGIC = 0x20b,
263 PELIB_IMAGE_ROM_OPTIONAL_HDR_MAGIC = 0x107 263 PELIB_IMAGE_ROM_OPTIONAL_HDR_MAGIC = 0x107
264 }; 264 };
265 265
266 enum 266 enum
267 { 267 {
268 PELIB_IMAGE_SUBSYSTEM_UNKNOWN = 0, 268 PELIB_IMAGE_SUBSYSTEM_UNKNOWN = 0,
269 PELIB_IMAGE_SUBSYSTEM_NATIVE = 1, 269 PELIB_IMAGE_SUBSYSTEM_NATIVE = 1,
270 PELIB_IMAGE_SUBSYSTEM_WINDOWS_GUI = 2, 270 PELIB_IMAGE_SUBSYSTEM_WINDOWS_GUI = 2,
271 PELIB_IMAGE_SUBSYSTEM_WINDOWS_CUI = 3, 271 PELIB_IMAGE_SUBSYSTEM_WINDOWS_CUI = 3,
272 PELIB_IMAGE_SUBSYSTEM_OS2_CUI = 5, 272 PELIB_IMAGE_SUBSYSTEM_OS2_CUI = 5,
273 PELIB_IMAGE_SUBSYSTEM_POSIX_CUI = 7, 273 PELIB_IMAGE_SUBSYSTEM_POSIX_CUI = 7,
274 PELIB_IMAGE_SUBSYSTEM_NATIVE_WINDOWS = 8, 274 PELIB_IMAGE_SUBSYSTEM_NATIVE_WINDOWS = 8,
275 PELIB_IMAGE_SUBSYSTEM_WINDOWS_CE_GUI = 9 275 PELIB_IMAGE_SUBSYSTEM_WINDOWS_CE_GUI = 9
276 }; 276 };
277 277
278 enum 278 enum
279 { 279 {
280 PELIB_RT_CURSOR = 1, // 1 280 PELIB_RT_CURSOR = 1, // 1
281 PELIB_RT_BITMAP, // 2 281 PELIB_RT_BITMAP, // 2
282 PELIB_RT_ICON, // 3 282 PELIB_RT_ICON, // 3
283 PELIB_RT_MENU, // 4 283 PELIB_RT_MENU, // 4
284 PELIB_RT_DIALOG, // 5 284 PELIB_RT_DIALOG, // 5
285 PELIB_RT_STRING, // 6 285 PELIB_RT_STRING, // 6
286 PELIB_RT_FONTDIR, // 7 286 PELIB_RT_FONTDIR, // 7
287 PELIB_RT_FONT, // 8 287 PELIB_RT_FONT, // 8
288 PELIB_RT_ACCELERATOR, // 9 288 PELIB_RT_ACCELERATOR, // 9
289 PELIB_RT_RCDATA, // 10 289 PELIB_RT_RCDATA, // 10
290 PELIB_RT_MESSAGETABLE, // 11 290 PELIB_RT_MESSAGETABLE, // 11
291 PELIB_RT_GROUP_CURSOR, // 12 291 PELIB_RT_GROUP_CURSOR, // 12
292 PELIB_RT_GROUP_ICON = 14, // 14 292 PELIB_RT_GROUP_ICON = 14, // 14
293 PELIB_RT_VERSION = 16, 293 PELIB_RT_VERSION = 16,
294 PELIB_RT_DLGINCLUDE, 294 PELIB_RT_DLGINCLUDE,
295 PELIB_RT_PLUGPLAY = 19, 295 PELIB_RT_PLUGPLAY = 19,
296 PELIB_RT_VXD, 296 PELIB_RT_VXD,
297 PELIB_RT_ANICURSOR, 297 PELIB_RT_ANICURSOR,
298 PELIB_RT_ANIICON, 298 PELIB_RT_ANIICON,
299 PELIB_RT_HTML, 299 PELIB_RT_HTML,
300 PELIB_RT_MANIFEST 300 PELIB_RT_MANIFEST
301 }; 301 };
302 302
303 template<typename T> 303 template<typename T>
304 unsigned int accumulate(unsigned int size, const T& v) 304 unsigned int accumulate(unsigned int size, const T& v)
305 { 305 {
306 return size + v.size(); 306 return size + v.size();
307 } 307 }
308 308
309 309
310 struct PELIB_IMAGE_DOS_HEADER 310 struct PELIB_IMAGE_DOS_HEADER
311 { 311 {
312 word e_magic; 312 word e_magic;
313 word e_cblp; 313 word e_cblp;
314 word e_cp; 314 word e_cp;
315 word e_crlc; 315 word e_crlc;
316 word e_cparhdr; 316 word e_cparhdr;
317 word e_minalloc; 317 word e_minalloc;
318 word e_maxalloc; 318 word e_maxalloc;
319 word e_ss; 319 word e_ss;
320 word e_sp; 320 word e_sp;
321 word e_csum; 321 word e_csum;
322 word e_ip; 322 word e_ip;
323 word e_cs; 323 word e_cs;
324 word e_lfarlc; 324 word e_lfarlc;
325 word e_ovno; 325 word e_ovno;
326 word e_res[4]; 326 word e_res[4];
327 word e_oemid; 327 word e_oemid;
328 word e_oeminfo; 328 word e_oeminfo;
329 word e_res2[10]; 329 word e_res2[10];
330 dword e_lfanew; 330 dword e_lfanew;
331 331
332 PELIB_IMAGE_DOS_HEADER(); 332 PELIB_IMAGE_DOS_HEADER();
333 333
334 static inline unsigned int size() {return 64;} 334 static inline unsigned int size() {return 64;}
335 }; 335 };
336 336
337 struct PELIB_IMAGE_FILE_HEADER 337 struct PELIB_IMAGE_FILE_HEADER
338 { 338 {
339 word Machine; 339 word Machine;
340 word NumberOfSections; 340 word NumberOfSections;
341 dword TimeDateStamp; 341 dword TimeDateStamp;
342 dword PointerToSymbolTable; 342 dword PointerToSymbolTable;
343 dword NumberOfSymbols; 343 dword NumberOfSymbols;
344 word SizeOfOptionalHeader; 344 word SizeOfOptionalHeader;
345 word Characteristics; 345 word Characteristics;
346 346
347 PELIB_IMAGE_FILE_HEADER() 347 PELIB_IMAGE_FILE_HEADER()
348 { 348 {
349 Machine = 0; 349 Machine = 0;
350 NumberOfSections = 0; 350 NumberOfSections = 0;
351 TimeDateStamp = 0; 351 TimeDateStamp = 0;
352 PointerToSymbolTable = 0; 352 PointerToSymbolTable = 0;
353 NumberOfSymbols = 0; 353 NumberOfSymbols = 0;
354 SizeOfOptionalHeader = 0; 354 SizeOfOptionalHeader = 0;
355 Characteristics = 0; 355 Characteristics = 0;
356 } 356 }
357 357
358 static inline unsigned int size() {return 20;} 358 static inline unsigned int size() {return 20;}
359 }; 359 };
360 360
361 struct PELIB_IMAGE_DATA_DIRECTORY 361 struct PELIB_IMAGE_DATA_DIRECTORY
362 { 362 {
363 dword VirtualAddress; 363 dword VirtualAddress;
364 dword Size; 364 dword Size;
365 365
366 PELIB_IMAGE_DATA_DIRECTORY() 366 PELIB_IMAGE_DATA_DIRECTORY()
367 { 367 {
368 VirtualAddress = 0; 368 VirtualAddress = 0;
369 Size = 0; 369 Size = 0;
370 } 370 }
371 371
372 static inline unsigned int size() {return 8;} 372 static inline unsigned int size() {return 8;}
373 }; 373 };
374 374
375 template<int> 375 template<int>
376 struct FieldSizes; 376 struct FieldSizes;
377 377
378 template<> 378 template<>
379 struct FieldSizes<32> 379 struct FieldSizes<32>
380 { 380 {
381 typedef dword VAR4_8; 381 typedef dword VAR4_8;
382 }; 382 };
383 383
384 template<> 384 template<>
385 struct FieldSizes<64> 385 struct FieldSizes<64>
386 { 386 {
387 typedef qword VAR4_8; 387 typedef qword VAR4_8;
388 }; 388 };
389 389
390 template<int x> 390 template<int x>
391 struct PELIB_IMAGE_OPTIONAL_HEADER_BASE 391 struct PELIB_IMAGE_OPTIONAL_HEADER_BASE
392 { 392 {
393 typedef typename FieldSizes<x>::VAR4_8 VAR4_8; 393 typedef typename FieldSizes<x>::VAR4_8 VAR4_8;
394 394
395 word Magic; 395 word Magic;
396 byte MajorLinkerVersion; 396 byte MajorLinkerVersion;
397 byte MinorLinkerVersion; 397 byte MinorLinkerVersion;
398 dword SizeOfCode; 398 dword SizeOfCode;
399 dword SizeOfInitializedData; 399 dword SizeOfInitializedData;
400 dword SizeOfUninitializedData; 400 dword SizeOfUninitializedData;
401 dword AddressOfEntryPoint; 401 dword AddressOfEntryPoint;
402 dword BaseOfCode; 402 dword BaseOfCode;
403 dword BaseOfData; 403 dword BaseOfData;
404 VAR4_8 ImageBase; 404 VAR4_8 ImageBase;
405 dword SectionAlignment; 405 dword SectionAlignment;
406 dword FileAlignment; 406 dword FileAlignment;
407 word MajorOperatingSystemVersion; 407 word MajorOperatingSystemVersion;
408 word MinorOperatingSystemVersion; 408 word MinorOperatingSystemVersion;
409 word MajorImageVersion; 409 word MajorImageVersion;
410 word MinorImageVersion; 410 word MinorImageVersion;
411 word MajorSubsystemVersion; 411 word MajorSubsystemVersion;
412 word MinorSubsystemVersion; 412 word MinorSubsystemVersion;
413 dword Win32VersionValue; 413 dword Win32VersionValue;
414 dword SizeOfImage; 414 dword SizeOfImage;
415 dword SizeOfHeaders; 415 dword SizeOfHeaders;
416 dword CheckSum; 416 dword CheckSum;
417 word Subsystem; 417 word Subsystem;
418 word DllCharacteristics; 418 word DllCharacteristics;
419 VAR4_8 SizeOfStackReserve; 419 VAR4_8 SizeOfStackReserve;
420 VAR4_8 SizeOfStackCommit; 420 VAR4_8 SizeOfStackCommit;
421 VAR4_8 SizeOfHeapReserve; 421 VAR4_8 SizeOfHeapReserve;
422 VAR4_8 SizeOfHeapCommit; 422 VAR4_8 SizeOfHeapCommit;
423 dword LoaderFlags; 423 dword LoaderFlags;
424 dword NumberOfRvaAndSizes; 424 dword NumberOfRvaAndSizes;
425// PELIB_IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; 425// PELIB_IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
426 426
427 PELIB_IMAGE_OPTIONAL_HEADER_BASE(); 427 PELIB_IMAGE_OPTIONAL_HEADER_BASE();
428 }; 428 };
429 429
430 template<int x> 430 template<int x>
431 PELIB_IMAGE_OPTIONAL_HEADER_BASE<x>::PELIB_IMAGE_OPTIONAL_HEADER_BASE() 431 PELIB_IMAGE_OPTIONAL_HEADER_BASE<x>::PELIB_IMAGE_OPTIONAL_HEADER_BASE()
432 { 432 {
433 Magic = 0; 433 Magic = 0;
434 MajorLinkerVersion = 0; 434 MajorLinkerVersion = 0;
435 MinorLinkerVersion = 0; 435 MinorLinkerVersion = 0;
436 SizeOfCode = 0; 436 SizeOfCode = 0;
437 SizeOfInitializedData = 0; 437 SizeOfInitializedData = 0;
438 SizeOfUninitializedData = 0; 438 SizeOfUninitializedData = 0;
439 AddressOfEntryPoint = 0; 439 AddressOfEntryPoint = 0;
440 BaseOfCode = 0; 440 BaseOfCode = 0;
441// BaseOfData = 0; 441// BaseOfData = 0;
442 ImageBase = 0; 442 ImageBase = 0;
443 SectionAlignment = 0; 443 SectionAlignment = 0;
444 FileAlignment = 0; 444 FileAlignment = 0;
445 MajorOperatingSystemVersion = 0; 445 MajorOperatingSystemVersion = 0;
446 MinorOperatingSystemVersion = 0; 446 MinorOperatingSystemVersion = 0;
447 MajorImageVersion = 0; 447 MajorImageVersion = 0;
448 MinorImageVersion = 0; 448 MinorImageVersion = 0;
449 MajorSubsystemVersion = 0; 449 MajorSubsystemVersion = 0;
450 MinorSubsystemVersion = 0; 450 MinorSubsystemVersion = 0;
451 Win32VersionValue = 0; 451 Win32VersionValue = 0;
452 SizeOfImage = 0; 452 SizeOfImage = 0;
453 SizeOfHeaders = 0; 453 SizeOfHeaders = 0;
454 CheckSum = 0; 454 CheckSum = 0;
455 Subsystem = 0; 455 Subsystem = 0;
456 DllCharacteristics = 0; 456 DllCharacteristics = 0;
457 SizeOfStackReserve = 0; 457 SizeOfStackReserve = 0;
458 SizeOfStackCommit = 0; 458 SizeOfStackCommit = 0;
459 SizeOfHeapReserve = 0; 459 SizeOfHeapReserve = 0;
460 SizeOfHeapCommit = 0; 460 SizeOfHeapCommit = 0;
461 LoaderFlags = 0; 461 LoaderFlags = 0;
462 NumberOfRvaAndSizes = 0; 462 NumberOfRvaAndSizes = 0;
463 } 463 }
464 464
465 template<int> 465 template<int>
466 struct PELIB_IMAGE_OPTIONAL_HEADER; 466 struct PELIB_IMAGE_OPTIONAL_HEADER;
467 467
468 template<> 468 template<>
469 struct PELIB_IMAGE_OPTIONAL_HEADER<32> : public PELIB_IMAGE_OPTIONAL_HEADER_BASE<32> 469 struct PELIB_IMAGE_OPTIONAL_HEADER<32> : public PELIB_IMAGE_OPTIONAL_HEADER_BASE<32>
470 { 470 {
471 dword BaseOfData; 471 dword BaseOfData;
472 472
473 static inline unsigned int size() {return 224 - 0x10 * 8;} 473 static inline unsigned int size() {return 224 - 0x10 * 8;}
474 }; 474 };
475 475
476 template<> 476 template<>
477 struct PELIB_IMAGE_OPTIONAL_HEADER<64> : public PELIB_IMAGE_OPTIONAL_HEADER_BASE<64> 477 struct PELIB_IMAGE_OPTIONAL_HEADER<64> : public PELIB_IMAGE_OPTIONAL_HEADER_BASE<64>
478 { 478 {
479 static inline unsigned int size() {return 240 - 0x10 * 8;} 479 static inline unsigned int size() {return 240 - 0x10 * 8;}
480 }; 480 };
481 481
482 template<int x> 482 template<int x>
483 struct PELIB_IMAGE_NT_HEADERS 483 struct PELIB_IMAGE_NT_HEADERS
484 { 484 {
485 dword Signature; 485 dword Signature;
486 PELIB_IMAGE_FILE_HEADER FileHeader; 486 PELIB_IMAGE_FILE_HEADER FileHeader;
487 PELIB_IMAGE_OPTIONAL_HEADER<x> OptionalHeader; 487 PELIB_IMAGE_OPTIONAL_HEADER<x> OptionalHeader;
488 std::vector<PELIB_IMAGE_DATA_DIRECTORY> dataDirectories; 488 std::vector<PELIB_IMAGE_DATA_DIRECTORY> dataDirectories;
489 489
490 unsigned int size() const 490 unsigned int size() const
491 { 491 {
492 return sizeof(dword) 492 return sizeof(dword)
493 + PELIB_IMAGE_FILE_HEADER::size() 493 + PELIB_IMAGE_FILE_HEADER::size()
494 + PELIB_IMAGE_OPTIONAL_HEADER<x>::size() 494 + PELIB_IMAGE_OPTIONAL_HEADER<x>::size()
495 + static_cast<unsigned int>(dataDirectories.size()) * PELIB_IMAGE_DATA_DIRECTORY::size(); 495 + static_cast<unsigned int>(dataDirectories.size()) * PELIB_IMAGE_DATA_DIRECTORY::size();
496 } 496 }
497 497
498 PELIB_IMAGE_NT_HEADERS() 498 PELIB_IMAGE_NT_HEADERS()
499 { 499 {
500 Signature = 0; 500 Signature = 0;
501 } 501 }
502 }; 502 };
503 503
504 const unsigned int PELIB_IMAGE_SIZEOF_SHORT_NAME = 8; 504 const unsigned int PELIB_IMAGE_SIZEOF_SHORT_NAME = 8;
505 505
506 struct PELIB_IMAGE_SECTION_HEADER 506 struct PELIB_IMAGE_SECTION_HEADER
507 { 507 {
508 byte Name[PELIB_IMAGE_SIZEOF_SHORT_NAME]; 508 byte Name[PELIB_IMAGE_SIZEOF_SHORT_NAME];
509 dword VirtualSize; 509 dword VirtualSize;
510 dword VirtualAddress; 510 dword VirtualAddress;
511 dword SizeOfRawData; 511 dword SizeOfRawData;
512 dword PointerToRawData; 512 dword PointerToRawData;
513 dword PointerToRelocations; 513 dword PointerToRelocations;
514 dword PointerToLinenumbers; 514 dword PointerToLinenumbers;
515 word NumberOfRelocations; 515 word NumberOfRelocations;
516 word NumberOfLinenumbers; 516 word NumberOfLinenumbers;
517 dword Characteristics; 517 dword Characteristics;
518 518
519 PELIB_IMAGE_SECTION_HEADER() 519 PELIB_IMAGE_SECTION_HEADER()
520 { 520 {
521 VirtualSize = 0; 521 VirtualSize = 0;
522 VirtualAddress = 0; 522 VirtualAddress = 0;
523 SizeOfRawData = 0; 523 SizeOfRawData = 0;
524 PointerToRawData = 0; 524 PointerToRawData = 0;
525 PointerToRelocations = 0; 525 PointerToRelocations = 0;
526 PointerToLinenumbers = 0; 526 PointerToLinenumbers = 0;
527 NumberOfRelocations = 0; 527 NumberOfRelocations = 0;
528 NumberOfLinenumbers = 0; 528 NumberOfLinenumbers = 0;
529 Characteristics = 0; 529 Characteristics = 0;
530 } 530 }
531 531
532 static inline unsigned int size() {return 40;} 532 static inline unsigned int size() {return 40;}
533 bool biggerFileOffset(const PELIB_IMAGE_SECTION_HEADER& ish) const; 533 bool biggerFileOffset(const PELIB_IMAGE_SECTION_HEADER& ish) const;
534 bool biggerVirtualAddress(const PELIB_IMAGE_SECTION_HEADER& ish) const; 534 bool biggerVirtualAddress(const PELIB_IMAGE_SECTION_HEADER& ish) const;
535 }; 535 };
536 536
537 template<int bits> 537 template<int bits>
538 struct PELIB_IMAGE_THUNK_DATA 538 struct PELIB_IMAGE_THUNK_DATA
539 { 539 {
540 typename FieldSizes<bits>::VAR4_8 Ordinal; 540 typename FieldSizes<bits>::VAR4_8 Ordinal;
541 541
542 PELIB_IMAGE_THUNK_DATA() 542 PELIB_IMAGE_THUNK_DATA()
543 { 543 {
544 Ordinal = 0; 544 Ordinal = 0;
545 } 545 }
546 546
547 static inline unsigned int size() {return 4;} 547 static inline unsigned int size() {return 4;}
548 }; 548 };
549 549
550 struct PELIB_IMAGE_IMPORT_DESCRIPTOR 550 struct PELIB_IMAGE_IMPORT_DESCRIPTOR
551 { 551 {
552 dword OriginalFirstThunk; 552 dword OriginalFirstThunk;
553 dword TimeDateStamp; 553 dword TimeDateStamp;
554 dword ForwarderChain; 554 dword ForwarderChain;
555 dword Name; 555 dword Name;
556 dword FirstThunk; 556 dword FirstThunk;
557 557
558 PELIB_IMAGE_IMPORT_DESCRIPTOR() 558 PELIB_IMAGE_IMPORT_DESCRIPTOR()
559 { 559 {
560 OriginalFirstThunk = 0; 560 OriginalFirstThunk = 0;
561 TimeDateStamp = 0; 561 TimeDateStamp = 0;
562 ForwarderChain = 0; 562 ForwarderChain = 0;
563 Name = 0; 563 Name = 0;
564 FirstThunk = 0; 564 FirstThunk = 0;
565 } 565 }
566 566
567 static inline unsigned int size() {return 20;} 567 static inline unsigned int size() {return 20;}
568 }; 568 };
569 569
570 struct PELIB_IMAGE_EXPORT_DIRECTORY 570 struct PELIB_IMAGE_EXPORT_DIRECTORY
571 { 571 {
572 dword Characteristics; 572 dword Characteristics;
573 dword TimeDateStamp; 573 dword TimeDateStamp;
574 word MajorVersion; 574 word MajorVersion;
575 word MinorVersion; 575 word MinorVersion;
576 dword Name; 576 dword Name;
577 dword Base; 577 dword Base;
578 dword NumberOfFunctions; 578 dword NumberOfFunctions;
579 dword NumberOfNames; 579 dword NumberOfNames;
580 dword AddressOfFunctions; 580 dword AddressOfFunctions;
581 dword AddressOfNames; 581 dword AddressOfNames;
582 dword AddressOfNameOrdinals; 582 dword AddressOfNameOrdinals;
583 583
584 PELIB_IMAGE_EXPORT_DIRECTORY() 584 PELIB_IMAGE_EXPORT_DIRECTORY()
585 { 585 {
586 Characteristics = 0; 586 Characteristics = 0;
587 TimeDateStamp = 0; 587 TimeDateStamp = 0;
588 MajorVersion = 0; 588 MajorVersion = 0;
589 MinorVersion = 0; 589 MinorVersion = 0;
590 Name = 0; 590 Name = 0;
591 Base = 0; 591 Base = 0;
592 NumberOfFunctions = 0; 592 NumberOfFunctions = 0;
593 NumberOfNames = 0; 593 NumberOfNames = 0;
594 AddressOfFunctions = 0; 594 AddressOfFunctions = 0;
595 NumberOfNames = 0; 595 NumberOfNames = 0;
596 AddressOfNameOrdinals = 0; 596 AddressOfNameOrdinals = 0;
597 } 597 }
598 598
599 static inline unsigned int size() {return 40;} 599 static inline unsigned int size() {return 40;}
600 }; 600 };
601 601
602 struct PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR 602 struct PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR
603 { 603 {
604 dword TimeDateStamp; 604 dword TimeDateStamp;
605 word OffsetModuleName; 605 word OffsetModuleName;
606 word NumberOfModuleForwarderRefs; 606 word NumberOfModuleForwarderRefs;
607 607
608 PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR() 608 PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR()
609 { 609 {
610 TimeDateStamp = 0; 610 TimeDateStamp = 0;
611 OffsetModuleName = 0; 611 OffsetModuleName = 0;
612 NumberOfModuleForwarderRefs = 0; 612 NumberOfModuleForwarderRefs = 0;
613 } 613 }
614 614
615 static unsigned int size() 615 static unsigned int size()
616 { 616 {
617 return 8; 617 return 8;
618 } 618 }
619 }; 619 };
620 620
621 // Stores all necessary information about a BoundImport field. 621 // Stores all necessary information about a BoundImport field.
622 struct PELIB_IMAGE_BOUND_DIRECTORY 622 struct PELIB_IMAGE_BOUND_DIRECTORY
623 { 623 {
624 PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR ibdDescriptor; ///< Information about the imported file. 624 PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR ibdDescriptor; ///< Information about the imported file.
625 std::string strModuleName; ///< Name of the imported file. 625 std::string strModuleName; ///< Name of the imported file.
626 std::vector<PELIB_IMAGE_BOUND_DIRECTORY> moduleForwarders; 626 std::vector<PELIB_IMAGE_BOUND_DIRECTORY> moduleForwarders;
627 627
628 // Will be used in std::find_if 628 // Will be used in std::find_if
629 // Passing by-reference not possible (see C++ Standard Core Language Defect Reports, Revision 29, Issue 106) 629 // Passing by-reference not possible (see C++ Standard Core Language Defect Reports, Revision 29, Issue 106)
630 /// Compares the passed filename to the struct's filename. 630 /// Compares the passed filename to the struct's filename.
631 bool equal(const std::string strModuleName) const; 631 bool equal(const std::string strModuleName) const;
632 632
633 unsigned int size() const; 633 unsigned int size() const;
634 }; 634 };
635 635
636 struct PELIB_EXP_FUNC_INFORMATION 636 struct PELIB_EXP_FUNC_INFORMATION
637 { 637 {
638 dword addroffunc; 638 dword addroffunc;
639 dword addrofname; 639 dword addrofname;
640 word ordinal; 640 word ordinal;
641 std::string funcname; 641 std::string funcname;
642 642
643 PELIB_EXP_FUNC_INFORMATION(); 643 PELIB_EXP_FUNC_INFORMATION();
644 644
645 bool equal(const std::string strFunctionName) const; 645 bool equal(const std::string strFunctionName) const;
646 inline unsigned int size() const 646 inline unsigned int size() const
647 { 647 {
648 unsigned int uiSize = 4; 648 unsigned int uiSize = 4;
649 if (addroffunc) uiSize += 2;// + 4; 649 if (addroffunc) uiSize += 2;// + 4;
650 if (!funcname.empty()) uiSize += 4 + (unsigned int)funcname.size() + 1; 650 if (!funcname.empty()) uiSize += 4 + (unsigned int)funcname.size() + 1;
651 return uiSize; 651 return uiSize;
652 } 652 }
653 }; 653 };
654 654
655 struct PELIB_IMAGE_RESOURCE_DIRECTORY 655 struct PELIB_IMAGE_RESOURCE_DIRECTORY
656 { 656 {
657 dword Characteristics; 657 dword Characteristics;
658 dword TimeDateStamp; 658 dword TimeDateStamp;
659 word MajorVersion; 659 word MajorVersion;
660 word MinorVersion; 660 word MinorVersion;
661 word NumberOfNamedEntries; 661 word NumberOfNamedEntries;
662 word NumberOfIdEntries; 662 word NumberOfIdEntries;
663 663
664 PELIB_IMAGE_RESOURCE_DIRECTORY(); 664 PELIB_IMAGE_RESOURCE_DIRECTORY();
665 665
666 static inline unsigned int size() {return 16;} 666 static inline unsigned int size() {return 16;}
667 }; 667 };
668 668
669 struct PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY 669 struct PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY
670 { 670 {
671 dword Name; 671 dword Name;
672 dword OffsetToData; 672 dword OffsetToData;
673 PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY(); 673 PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY();
674 static inline unsigned int size() {return 8;} 674 static inline unsigned int size() {return 8;}
675 }; 675 };
676 676
677 const unsigned int PELIB_IMAGE_SIZEOF_BASE_RELOCATION = 8; 677 const unsigned int PELIB_IMAGE_SIZEOF_BASE_RELOCATION = 8;
678 678
679 struct PELIB_IMG_RES_DIR_ENTRY 679 struct PELIB_IMG_RES_DIR_ENTRY
680 { 680 {
681 PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY irde; 681 PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY irde;
682 std::string wstrName; 682 std::string wstrName;
683 683
684 bool operator<(const PELIB_IMG_RES_DIR_ENTRY& first) const; 684 bool operator<(const PELIB_IMG_RES_DIR_ENTRY& first) const;
685 685
686 }; 686 };
687 687
688 struct PELIB_IMAGE_BASE_RELOCATION 688 struct PELIB_IMAGE_BASE_RELOCATION
689 { 689 {
690 dword VirtualAddress; 690 dword VirtualAddress;
691 dword SizeOfBlock; 691 dword SizeOfBlock;
692 692
693 PELIB_IMAGE_BASE_RELOCATION(); 693 PELIB_IMAGE_BASE_RELOCATION();
694 static inline unsigned int size() {return 8;} 694 static inline unsigned int size() {return 8;}
695 }; 695 };
696 696
697 struct PELIB_IMAGE_COR20_HEADER 697 struct PELIB_IMAGE_COR20_HEADER
698 { 698 {
699 dword cb; 699 dword cb;
700 word MajorRuntimeVersion; 700 word MajorRuntimeVersion;
701 word MinorRuntimeVersion; 701 word MinorRuntimeVersion;
702 PELIB_IMAGE_DATA_DIRECTORY MetaData; 702 PELIB_IMAGE_DATA_DIRECTORY MetaData;
703 dword Flags; 703 dword Flags;
704 dword EntryPointToken; 704 dword EntryPointToken;
705 PELIB_IMAGE_DATA_DIRECTORY Resources; 705 PELIB_IMAGE_DATA_DIRECTORY Resources;
706 PELIB_IMAGE_DATA_DIRECTORY StrongNameSignature; 706 PELIB_IMAGE_DATA_DIRECTORY StrongNameSignature;
707 PELIB_IMAGE_DATA_DIRECTORY CodeManagerTable; 707 PELIB_IMAGE_DATA_DIRECTORY CodeManagerTable;
708 PELIB_IMAGE_DATA_DIRECTORY VTableFixups; 708 PELIB_IMAGE_DATA_DIRECTORY VTableFixups;
709 PELIB_IMAGE_DATA_DIRECTORY ExportAddressTableJumps; 709 PELIB_IMAGE_DATA_DIRECTORY ExportAddressTableJumps;
710 PELIB_IMAGE_DATA_DIRECTORY ManagedNativeHeader; 710 PELIB_IMAGE_DATA_DIRECTORY ManagedNativeHeader;
711 711
712 PELIB_IMAGE_COR20_HEADER(); 712 PELIB_IMAGE_COR20_HEADER();
713 static inline unsigned int size() {return 72;} 713 static inline unsigned int size() {return 72;}
714 }; 714 };
715 715
716 // Used to store a file's export table. 716 // Used to store a file's export table.
717 struct PELIB_IMAGE_EXP_DIRECTORY 717 struct PELIB_IMAGE_EXP_DIRECTORY
718 { 718 {
719 /// The IMAGE_EXPORTED_DIRECTORY of a file's export table. 719 /// The IMAGE_EXPORTED_DIRECTORY of a file's export table.
720 PELIB_IMAGE_EXPORT_DIRECTORY ied; 720 PELIB_IMAGE_EXPORT_DIRECTORY ied;
721 /// The original filename of current file. 721 /// The original filename of current file.
722 std::string name; 722 std::string name;
723 std::vector<PELIB_EXP_FUNC_INFORMATION> functions; 723 std::vector<PELIB_EXP_FUNC_INFORMATION> functions;
724 inline unsigned int size() const 724 inline unsigned int size() const
725 { 725 {
726 return PELIB_IMAGE_EXPORT_DIRECTORY::size() + name.size() + 1 + 726 return PELIB_IMAGE_EXPORT_DIRECTORY::size() + name.size() + 1 +
727 std::accumulate(functions.begin(), functions.end(), 0, accumulate<PELIB_EXP_FUNC_INFORMATION>); 727 std::accumulate(functions.begin(), functions.end(), 0, accumulate<PELIB_EXP_FUNC_INFORMATION>);
728 } 728 }
729 }; 729 };
730 730
731 // Used for parsing a file's import table. It combines the function name, the hint 731 // Used for parsing a file's import table. It combines the function name, the hint
732 // and the IMAGE_THUNK_DATA of an imported function. 732 // and the IMAGE_THUNK_DATA of an imported function.
733 template<int bits> 733 template<int bits>
734 struct PELIB_THUNK_DATA 734 struct PELIB_THUNK_DATA
735 { 735 {
736 /// The IMAGE_THUNK_DATA struct of an imported function. 736 /// The IMAGE_THUNK_DATA struct of an imported function.
737 PELIB_IMAGE_THUNK_DATA<bits> itd; 737 PELIB_IMAGE_THUNK_DATA<bits> itd;
738 /// The hint of an imported function. 738 /// The hint of an imported function.
739 word hint; 739 word hint;
740 /// The function name of an imported function. 740 /// The function name of an imported function.
741 std::string fname; 741 std::string fname;
742 742
743 bool equalHint(word wHint) const 743 bool equalHint(word wHint) const
744 { 744 {
745 return hint == wHint; 745 return hint == wHint;
746// return itd.Ordinal == (wHint | IMAGE_ORDINAL_FLAGS<bits>::IMAGE_ORDINAL_FLAG); 746// return itd.Ordinal == (wHint | IMAGE_ORDINAL_FLAGS<bits>::IMAGE_ORDINAL_FLAG);
747 } 747 }
748 748
749 bool equalFunctionName(std::string strFunctionName) const 749 bool equalFunctionName(std::string strFunctionName) const
750 { 750 {
751 return isEqualNc(fname, strFunctionName); 751 return isEqualNc(fname, strFunctionName);
752 } 752 }
753 753
754 unsigned int size() const {return PELIB_IMAGE_THUNK_DATA<bits>::size() + fname.size() + 1 + sizeof(hint);} 754 unsigned int size() const {return PELIB_IMAGE_THUNK_DATA<bits>::size() + fname.size() + 1 + sizeof(hint);}
755 }; 755 };
756 756
757 // Used to store a file's import table. Every struct of this sort 757 // Used to store a file's import table. Every struct of this sort
758 // can store import information of one DLL. 758 // can store import information of one DLL.
759 template<int bits> 759 template<int bits>
760 struct PELIB_IMAGE_IMPORT_DIRECTORY 760 struct PELIB_IMAGE_IMPORT_DIRECTORY
761 { 761 {
762 /// The IMAGE_IMPORT_DESCRIPTOR of an imported DLL. 762 /// The IMAGE_IMPORT_DESCRIPTOR of an imported DLL.
763 PELIB_IMAGE_IMPORT_DESCRIPTOR impdesc; 763 PELIB_IMAGE_IMPORT_DESCRIPTOR impdesc;
764 /// The name of an imported DLL. 764 /// The name of an imported DLL.
765 std::string name; 765 std::string name;
766 /// All original first thunk values of an imported DLL. 766 /// All original first thunk values of an imported DLL.
767 std::vector<PELIB_THUNK_DATA<bits> > originalfirstthunk; 767 std::vector<PELIB_THUNK_DATA<bits> > originalfirstthunk;
768 /// All first thunk value of an imported DLL. 768 /// All first thunk value of an imported DLL.
769 std::vector<PELIB_THUNK_DATA<bits> > firstthunk; 769 std::vector<PELIB_THUNK_DATA<bits> > firstthunk;
770 770
771// bool operator==(std::string strFilename) const; 771// bool operator==(std::string strFilename) const;
772 inline unsigned int size() const 772 inline unsigned int size() const
773 { 773 {
774 return PELIB_IMAGE_IMPORT_DESCRIPTOR::size() + name.size() + 1 + // descriptor + dllname 774 return PELIB_IMAGE_IMPORT_DESCRIPTOR::size() + name.size() + 1 + // descriptor + dllname
775 std::accumulate(originalfirstthunk.begin(), originalfirstthunk.end(), 0, accumulate<PELIB_THUNK_DATA<bits> >) + // thunks (PeLib uses only one thunk) 775 std::accumulate(originalfirstthunk.begin(), originalfirstthunk.end(), 0, accumulate<PELIB_THUNK_DATA<bits> >) + // thunks (PeLib uses only one thunk)
776 PELIB_IMAGE_THUNK_DATA<bits>::size(); // zero-termination 776 PELIB_IMAGE_THUNK_DATA<bits>::size(); // zero-termination
777 } 777 }
778 778
779 bool operator==(std::string strFilename) const 779 bool operator==(std::string strFilename) const
780 { 780 {
781 return isEqualNc(this->name, strFilename); 781 return isEqualNc(this->name, strFilename);
782 } 782 }
783 }; 783 };
784 784
785 struct PELIB_IMAGE_RESOURCE_DATA_ENTRY 785 struct PELIB_IMAGE_RESOURCE_DATA_ENTRY
786 { 786 {
787 dword OffsetToData; 787 dword OffsetToData;
788 dword Size; 788 dword Size;
789 dword CodePage; 789 dword CodePage;
790 dword Reserved; 790 dword Reserved;
791 791
792 static inline unsigned int size() {return 16;} 792 static inline unsigned int size() {return 16;}
793 }; 793 };
794 794
795 struct PELIB_IMAGE_RESOURCE_DATA 795 struct PELIB_IMAGE_RESOURCE_DATA
796 { 796 {
797 PELIB_IMAGE_RESOURCE_DATA_ENTRY irdEntry; 797 PELIB_IMAGE_RESOURCE_DATA_ENTRY irdEntry;
798 std::vector<byte> vData; 798 std::vector<byte> vData;
799 }; 799 };
800 800
801 struct IMG_BASE_RELOC 801 struct IMG_BASE_RELOC
802 { 802 {
803 PELIB_IMAGE_BASE_RELOCATION ibrRelocation; 803 PELIB_IMAGE_BASE_RELOCATION ibrRelocation;
804 std::vector<word> vRelocData; 804 std::vector<word> vRelocData;
805 }; 805 };
806 806
807 struct PELIB_IMAGE_DEBUG_DIRECTORY 807 struct PELIB_IMAGE_DEBUG_DIRECTORY
808 { 808 {
809 dword Characteristics; 809 dword Characteristics;
810 dword TimeDateStamp; 810 dword TimeDateStamp;
811 word MajorVersion; 811 word MajorVersion;
812 word MinorVersion; 812 word MinorVersion;
813 dword Type; 813 dword Type;
814 dword SizeOfData; 814 dword SizeOfData;
815 dword AddressOfRawData; 815 dword AddressOfRawData;
816 dword PointerToRawData; 816 dword PointerToRawData;
817 817
818 static unsigned int size() {return 28;} 818 static unsigned int size() {return 28;}
819 }; 819 };
820 820
821 struct PELIB_IMG_DEBUG_DIRECTORY 821 struct PELIB_IMG_DEBUG_DIRECTORY
822 { 822 {
823 PELIB_IMAGE_DEBUG_DIRECTORY idd; 823 PELIB_IMAGE_DEBUG_DIRECTORY idd;
824 std::vector<byte> data; 824 std::vector<byte> data;
825 }; 825 };
826 826
827 template<int bits> 827 template<int bits>
828 struct PELIB_IMAGE_TLS_DIRECTORY_BASE 828 struct PELIB_IMAGE_TLS_DIRECTORY_BASE
829 { 829 {
830 typename FieldSizes<bits>::VAR4_8 StartAddressOfRawData; 830 typename FieldSizes<bits>::VAR4_8 StartAddressOfRawData;
831 typename FieldSizes<bits>::VAR4_8 EndAddressOfRawData; 831 typename FieldSizes<bits>::VAR4_8 EndAddressOfRawData;
832 typename FieldSizes<bits>::VAR4_8 AddressOfIndex; 832 typename FieldSizes<bits>::VAR4_8 AddressOfIndex;
833 typename FieldSizes<bits>::VAR4_8 AddressOfCallBacks; 833 typename FieldSizes<bits>::VAR4_8 AddressOfCallBacks;
834 dword SizeOfZeroFill; 834 dword SizeOfZeroFill;
835 dword Characteristics; 835 dword Characteristics;
836 }; 836 };
837 837
838 template<int bits> 838 template<int bits>
839 struct PELIB_IMAGE_TLS_DIRECTORY;// : public PELIB_IMAGE_TLS_DIRECTORY_BASE<bits> 839 struct PELIB_IMAGE_TLS_DIRECTORY;// : public PELIB_IMAGE_TLS_DIRECTORY_BASE<bits>
840 840
841 template<> 841 template<>
842 struct PELIB_IMAGE_TLS_DIRECTORY<32> : public PELIB_IMAGE_TLS_DIRECTORY_BASE<32> 842 struct PELIB_IMAGE_TLS_DIRECTORY<32> : public PELIB_IMAGE_TLS_DIRECTORY_BASE<32>
843 { 843 {
844// enum {size = 24}; 844// enum {size = 24};
845 static unsigned int size(){return 24;} 845 static unsigned int size(){return 24;}
846 }; 846 };
847 847
848 template<> 848 template<>
849 struct PELIB_IMAGE_TLS_DIRECTORY<64> : public PELIB_IMAGE_TLS_DIRECTORY_BASE<64> 849 struct PELIB_IMAGE_TLS_DIRECTORY<64> : public PELIB_IMAGE_TLS_DIRECTORY_BASE<64>
850 { 850 {
851// enum {size = 40}; 851// enum {size = 40};
852 static unsigned int size(){return 40;} 852 static unsigned int size(){return 40;}
853 }; 853 };
854 854
855 unsigned int fileSize(const std::string& filename); 855 unsigned int fileSize(const std::string& filename);
856 unsigned int fileSize(std::ifstream& file); 856 unsigned int fileSize(std::ifstream& file);
857 unsigned int fileSize(std::ofstream& file); 857 unsigned int fileSize(std::ofstream& file);
858 unsigned int fileSize(std::fstream& file); 858 unsigned int fileSize(std::fstream& file);
859 unsigned int alignOffset(unsigned int uiOffset, unsigned int uiAlignment); 859 unsigned int alignOffset(unsigned int uiOffset, unsigned int uiAlignment);
860 860
861 /// Determines if a file is a 32bit or 64bit PE file. 861 /// Determines if a file is a 32bit or 64bit PE file.
862 unsigned int getFileType(const std::string strFilename); 862 unsigned int getFileType(const std::string strFilename);
863 863
864 /// Opens a PE file. 864 /// Opens a PE file.
865 PeFile* openPeFile(const std::string& strFilename); 865 PeFile* openPeFile(const std::string& strFilename);
866 866
867 /* enum MzHeader_Field {e_magic, e_cblp, e_cp, e_crlc, e_cparhdr, e_minalloc, e_maxalloc, 867 /* enum MzHeader_Field {e_magic, e_cblp, e_cp, e_crlc, e_cparhdr, e_minalloc, e_maxalloc,
868 e_ss, e_sp, e_csum, e_ip, e_cs, e_lfarlc, e_ovno, e_res, e_oemid, 868 e_ss, e_sp, e_csum, e_ip, e_cs, e_lfarlc, e_ovno, e_res, e_oemid,
869 e_oeminfo, e_res2, e_lfanew}; 869 e_oeminfo, e_res2, e_lfanew};
870 enum PeHeader_Field {NtSignature, Machine, NumberOfSections, TimeDateStamp, PointerToSymbolTable, 870 enum PeHeader_Field {NtSignature, Machine, NumberOfSections, TimeDateStamp, PointerToSymbolTable,
871 NumberOfSymbols, SizeOfOptionalHeader, Characteristics, Magic, 871 NumberOfSymbols, SizeOfOptionalHeader, Characteristics, Magic,
872 MajorLinkerVersion, MinorLinkerVersion, SizeOfCode, SizeOfInitializedData, 872 MajorLinkerVersion, MinorLinkerVersion, SizeOfCode, SizeOfInitializedData,
873 SizeOfUninitializedData, AddressOfEntryPoint, BaseOfCode, BaseOfData, ImageBase, 873 SizeOfUninitializedData, AddressOfEntryPoint, BaseOfCode, BaseOfData, ImageBase,
874 SectionAlignment, FileAlignment, MajorOperatingSystemVersion, MinorOperatingSystemVersion, 874 SectionAlignment, FileAlignment, MajorOperatingSystemVersion, MinorOperatingSystemVersion,
875 MajorImageVersion, MinorImageVersion, MajorSubsystemVersion, MinorSubsystemVersion, 875 MajorImageVersion, MinorImageVersion, MajorSubsystemVersion, MinorSubsystemVersion,
876 Win32VersionValue, SizeOfImage, SizeOfHeaders, CheckSum, Subsystem, DllCharacteristics, 876 Win32VersionValue, SizeOfImage, SizeOfHeaders, CheckSum, Subsystem, DllCharacteristics,
877 SizeOfStackReserve, SizeOfStackCommit, SizeOfHeapReserve, SizeOfHeapCommit, 877 SizeOfStackReserve, SizeOfStackCommit, SizeOfHeapReserve, SizeOfHeapCommit,
878 LoaderFlags, NumberOfRvaAndSizes, DataDirectoryRva, DataDirectorySize}; 878 LoaderFlags, NumberOfRvaAndSizes, DataDirectoryRva, DataDirectorySize};
879 enum Section_Field {SectionName, VirtualSize, VirtualAddress, SizeOfRawData, PointerToRawData, PointerToRelocations, 879 enum Section_Field {SectionName, VirtualSize, VirtualAddress, SizeOfRawData, PointerToRawData, PointerToRelocations,
880 PointerToLinenumbers, NumberOfRelocations, NumberOfLinenumbers, SectionCharacteristics}; 880 PointerToLinenumbers, NumberOfRelocations, NumberOfLinenumbers, SectionCharacteristics};
881*/ 881*/
882} 882}
883 883
884#endif 884#endif