diff options
author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2008-07-11 15:50:46 +0000 |
---|---|---|
committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2008-07-11 15:50:46 +0000 |
commit | 14c7f45cdae826f88dc539c8c38dd95caf305731 (patch) | |
tree | 832da054b7cfb2dc6fd63339af736625f31d21aa /utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.h | |
parent | 7c84ede3781c27db73403bd6302f320c76a58c8c (diff) | |
download | rockbox-14c7f45cdae826f88dc539c8c38dd95caf305731.tar.gz rockbox-14c7f45cdae826f88dc539c8c38dd95caf305731.zip |
Add zook's ZenUtils to SVN
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18010 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.h')
-rwxr-xr-x | utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.h | 2685 |
1 files changed, 2685 insertions, 0 deletions
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.h b/utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.h new file mode 100755 index 0000000000..08eaca4072 --- /dev/null +++ b/utils/zenutils/libraries/pelib-0.9/pelib/PeHeader.h | |||
@@ -0,0 +1,2685 @@ | |||
1 | /* | ||
2 | * PeHeader.h - Part of the PeLib library. | ||
3 | * | ||
4 | * Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * This software is licensed under the zlib/libpng License. | ||
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 | ||
10 | * of PeLib. | ||
11 | */ | ||
12 | |||
13 | #ifndef PEHEADER_H | ||
14 | #define PEHEADER_H | ||
15 | |||
16 | #include "PeLibAux.h" | ||
17 | |||
18 | namespace PeLib | ||
19 | { | ||
20 | class PeHeader | ||
21 | { | ||
22 | // protected: | ||
23 | // virtual void readBaseOfData(InputBuffer& ibBuffer) = 0; | ||
24 | // virtual void rebuildBaseOfData(OutputBuffer& obBuffer) const = 0; | ||
25 | |||
26 | public: | ||
27 | virtual ~PeHeader(){}; | ||
28 | }; | ||
29 | |||
30 | /// Class that handles the PE header of files. | ||
31 | /** | ||
32 | * This class can read and modify PE headers. It provides set- and get functions to access | ||
33 | * all individual members of a PE header. Furthermore it's possible to validate and rebuild | ||
34 | * PE headers. A PE header includes the IMAGE_Nt_HEADERS and the section definitions of a PE file. | ||
35 | * \todo getIdReservedRva | ||
36 | **/ | ||
37 | template<int x> | ||
38 | class PeHeaderT : public PeHeader | ||
39 | { | ||
40 | private: | ||
41 | void readBaseOfData(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const; | ||
42 | void rebuildBaseOfData(OutputBuffer& obBuffer) const; | ||
43 | |||
44 | protected: | ||
45 | std::vector<PELIB_IMAGE_SECTION_HEADER> m_vIsh; ///< Stores section header information. | ||
46 | PELIB_IMAGE_NT_HEADERS<x> m_inthHeader; ///< Stores Nt header information. | ||
47 | dword m_uiOffset; ///< Equivalent to the value returned by #PeLib::MzHeader::getAddressOfPeFile | ||
48 | |||
49 | public: | ||
50 | typedef typename FieldSizes<x>::VAR4_8 VAR4_8; | ||
51 | |||
52 | PeHeaderT() : m_uiOffset(0) | ||
53 | { | ||
54 | } | ||
55 | |||
56 | /// Add a section to the header. | ||
57 | int addSection(const std::string& strName, dword dwSize); // EXPORT | ||
58 | |||
59 | unsigned int calcSizeOfImage() const; // EXPORT | ||
60 | |||
61 | /// Returns the unused space after the header. | ||
62 | unsigned int calcSpaceAfterHeader() const; // EXPORT | ||
63 | |||
64 | /// Returns the address of the physically first section (not the first defined section). | ||
65 | unsigned int calcStartOfCode() const; // EXPORT | ||
66 | |||
67 | /// Calculates the offset for a new section of size uiSize. | ||
68 | unsigned int calcOffset() const; // EXPORT | ||
69 | |||
70 | /// Calculates the Rva for a new section of size uiSize. | ||
71 | unsigned int calcRva() const; // EXPORT | ||
72 | |||
73 | /// Returns the number of sections in the current file. | ||
74 | word calcNumberOfSections() const; // EXPORT | ||
75 | |||
76 | void enlargeLastSection(unsigned int uiSize); // EXPORT | ||
77 | |||
78 | /// Returns the section Id of the section that contains the offset. | ||
79 | word getSectionWithOffset(VAR4_8 dwOffset) const; // EXPORT | ||
80 | |||
81 | /// Returns the number of the section which the given relative address points to. | ||
82 | word getSectionWithRva(VAR4_8 rva) const; // EXPORT | ||
83 | |||
84 | bool isValid() const; // EXPORT | ||
85 | bool isValid(unsigned int foo) const; // EXPORT | ||
86 | |||
87 | /// Corrects the current PE header. | ||
88 | void makeValid(dword dwOffset); // EXPORT | ||
89 | |||
90 | /// Converts a file offset to a relative virtual offset. | ||
91 | unsigned int offsetToRva(VAR4_8 dwOffset) const; // EXPORT | ||
92 | |||
93 | /// Converts a file offset to a virtual address. | ||
94 | unsigned int offsetToVa(VAR4_8 dwOffset) const; // EXPORT | ||
95 | |||
96 | /// Reads the PE header of a file. | ||
97 | int read(std::string strFilename, unsigned int uiOffset); // EXPORT | ||
98 | |||
99 | int read(const unsigned char* pcBuffer, unsigned int uiSize, unsigned int uiOffset); // EXPORT | ||
100 | |||
101 | void readHeader(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const; | ||
102 | void readDataDirectories(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const; | ||
103 | std::vector<PELIB_IMAGE_SECTION_HEADER> readSections(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const; | ||
104 | |||
105 | /// Rebuilds the current PE header. | ||
106 | void rebuild(std::vector<byte>& vBuffer) const; // EXPORT | ||
107 | |||
108 | /// Converts a relative virtual address to a file offset. | ||
109 | VAR4_8 rvaToOffset(VAR4_8 dwRva) const; // EXPORT | ||
110 | |||
111 | /// Converts a relative virtual address to a virtual address. | ||
112 | VAR4_8 rvaToVa(VAR4_8 dwRva) const; // EXPORT | ||
113 | |||
114 | /// Calculates the size for the current PE header including all section definitions. | ||
115 | unsigned int size() const; | ||
116 | |||
117 | VAR4_8 vaToRva(VAR4_8 dwRva) const; // EXPORT | ||
118 | VAR4_8 vaToOffset(VAR4_8 dwRva) const; // EXPORT | ||
119 | |||
120 | /// Save the PE header to a file. | ||
121 | int write(std::string strFilename, unsigned int uiOffset) const; // EXPORT | ||
122 | |||
123 | /// Writes sections to a file. | ||
124 | int writeSections(const std::string& strFilename) const; // EXPORT | ||
125 | /// Overwrites a section with new data. | ||
126 | int writeSectionData(const std::string& strFilename, word wSecnr, const std::vector<byte>& vBuffer) const; // EXPORT | ||
127 | |||
128 | // header getters | ||
129 | /// Returns the Signature value of the header. | ||
130 | dword getNtSignature() const; // EXPORT | ||
131 | /// Returns the Machine value of the header. | ||
132 | word getMachine() const; // EXPORT | ||
133 | /// Returns the Sections value of the header. | ||
134 | word getNumberOfSections() const; // EXPORT | ||
135 | /// Returns the TimeDateStamp value of the header. | ||
136 | dword getTimeDateStamp() const; // EXPORT | ||
137 | /// Returns the PointerToSymbolTable value of the header. | ||
138 | dword getPointerToSymbolTable() const; // EXPORT | ||
139 | /// Returns the NumberOfSymbols value of the header. | ||
140 | dword getNumberOfSymbols() const; // EXPORT | ||
141 | /// Returns the SizeOfOptionalHeader value of the header. | ||
142 | word getSizeOfOptionalHeader() const; // EXPORT | ||
143 | /// Returns the Characteristics value of the header. | ||
144 | word getCharacteristics() const; // EXPORT | ||
145 | |||
146 | /// Returns the Magic value of the header. | ||
147 | word getMagic() const; // EXPORT | ||
148 | /// Returns the MajorLinkerVersion value of the header. | ||
149 | byte getMajorLinkerVersion() const; // EXPORT | ||
150 | /// Returns the MinorLinkerVersion value of the header. | ||
151 | byte getMinorLinkerVersion() const; // EXPORT | ||
152 | /// Returns the SizeOfCode value of the header. | ||
153 | dword getSizeOfCode() const; // EXPORT | ||
154 | /// Returns the SizeOfInitializedData value of the header. | ||
155 | dword getSizeOfInitializedData() const; // EXPORT | ||
156 | /// Returns the SizeOfUninitializedData value of the header. | ||
157 | dword getSizeOfUninitializedData() const; // EXPORT | ||
158 | /// Returns the AddressOfEntryPoint value of the header. | ||
159 | dword getAddressOfEntryPoint() const; // EXPORT | ||
160 | /// Returns the BaseOfCode value of the header. | ||
161 | dword getBaseOfCode() const; // EXPORT | ||
162 | /// Returns the ImageBase value of the header. | ||
163 | VAR4_8 getImageBase() const; // EXPORT | ||
164 | /// Returns the SectionAlignment value of the header. | ||
165 | dword getSectionAlignment() const; // EXPORT | ||
166 | /// Returns the FileAlignment value of the header. | ||
167 | dword getFileAlignment() const; // EXPORT | ||
168 | /// Returns the MajorOperatingSystemVersion value of the header. | ||
169 | word getMajorOperatingSystemVersion() const; // EXPORT | ||
170 | /// Returns the MinorOperatingSystemVersion value of the header. | ||
171 | word getMinorOperatingSystemVersion() const; // EXPORT | ||
172 | /// Returns the MajorImageVersion value of the header. | ||
173 | word getMajorImageVersion() const; // EXPORT | ||
174 | /// Returns the MinorImageVersion value of the header. | ||
175 | word getMinorImageVersion() const; // EXPORT | ||
176 | /// Returns the MajorSubsystemVersion value of the header. | ||
177 | word getMajorSubsystemVersion() const; // EXPORT | ||
178 | /// Returns the MinorSubsystemVersion value of the header. | ||
179 | word getMinorSubsystemVersion() const; // EXPORT | ||
180 | /// Returns the Reserved1 value of the header. | ||
181 | dword getWin32VersionValue() const; // EXPORT | ||
182 | /// Returns the SizeOfImage value of the header. | ||
183 | dword getSizeOfImage() const; // EXPORT | ||
184 | /// Returns the SizeOfHeaders value of the header. | ||
185 | dword getSizeOfHeaders() const; // EXPORT | ||
186 | /// Returns the CheckSum value of the header. | ||
187 | dword getCheckSum() const; // EXPORT | ||
188 | /// Returns the Subsystem value of the header. | ||
189 | word getSubsystem() const; // EXPORT | ||
190 | /// Returns the DllCharacteristics value of the header. | ||
191 | word getDllCharacteristics() const; // EXPORT | ||
192 | /// Returns the SizeOfStackReserve value of the header. | ||
193 | VAR4_8 getSizeOfStackReserve() const; // EXPORT | ||
194 | /// Returns the SizeOfStackCommit value of the header. | ||
195 | VAR4_8 getSizeOfStackCommit() const; // EXPORT | ||
196 | /// Returns the SizeOfHeapReserve value of the header. | ||
197 | VAR4_8 getSizeOfHeapReserve() const; // EXPORT | ||
198 | /// Returns the SizeOfHeapCommit value of the header. | ||
199 | VAR4_8 getSizeOfHeapCommit() const; // EXPORT | ||
200 | /// Returns the LoaderFlags value of the header. | ||
201 | dword getLoaderFlags() const; // EXPORT | ||
202 | /// Returns the NumberOfRvaAndSizes value of the header. | ||
203 | dword getNumberOfRvaAndSizes() const; // EXPORT | ||
204 | dword calcNumberOfRvaAndSizes() const; // EXPORT | ||
205 | |||
206 | void addDataDirectory(); // EXPORT | ||
207 | void removeDataDirectory(dword index); // EXPORT | ||
208 | |||
209 | // image directory getters | ||
210 | /// Returns the relative virtual address of the image directory Export. | ||
211 | dword getIddExportRva() const; // EXPORT | ||
212 | /// Returns the size of the image directory Export. | ||
213 | dword getIddExportSize() const; // EXPORT | ||
214 | /// Returns the relative virtual address of the image directory Import. | ||
215 | dword getIddImportRva() const; // EXPORT | ||
216 | /// Returns the size of the image directory Import. | ||
217 | dword getIddImportSize() const; // EXPORT | ||
218 | /// Returns the relative virtual address of the image directory Resource. | ||
219 | dword getIddResourceRva() const; // EXPORT | ||
220 | /// Returns the size of the image directory Resource. | ||
221 | dword getIddResourceSize() const; // EXPORT | ||
222 | /// Returns the relative virtual address of the image directory Exception. | ||
223 | dword getIddExceptionRva() const; // EXPORT | ||
224 | /// Returns the size of the image directory Exception. | ||
225 | dword getIddExceptionSize() const; // EXPORT | ||
226 | /// Returns the relative virtual address of the image directory Security. | ||
227 | dword getIddSecurityRva() const; // EXPORT | ||
228 | /// Returns the size of the image directory Security. | ||
229 | dword getIddSecuritySize() const; // EXPORT | ||
230 | /// Returns the relative virtual address of the image directory Base Reloc. | ||
231 | dword getIddBaseRelocRva() const; // EXPORT | ||
232 | /// Returns the size of the image directory Base Reloc. | ||
233 | dword getIddBaseRelocSize() const; // EXPORT | ||
234 | /// Returns the relative virtual address of the image directory Debug. | ||
235 | dword getIddDebugRva() const; // EXPORT | ||
236 | /// Returns the size of the image directory Debug. | ||
237 | dword getIddDebugSize() const; // EXPORT | ||
238 | /// Returns the relative virtual address of the image directory Architecture. | ||
239 | dword getIddArchitectureRva() const; // EXPORT | ||
240 | /// Returns the size of the image directory Architecture. | ||
241 | dword getIddArchitectureSize() const; // EXPORT | ||
242 | /// Returns the relative virtual address of the image directory GlobalPtr. | ||
243 | dword getIddGlobalPtrRva() const; // EXPORT | ||
244 | /// Returns the size of the image directory GlobalPtr. | ||
245 | dword getIddGlobalPtrSize() const; // EXPORT | ||
246 | /// Returns the relative virtual address of the image directory Tls. | ||
247 | dword getIddTlsRva() const; // EXPORT | ||
248 | /// Returns the size of the image directory Tls. | ||
249 | dword getIddTlsSize() const; // EXPORT | ||
250 | /// Returns the relative virtual address of the image directory LoadConfig. | ||
251 | dword getIddLoadConfigRva() const; // EXPORT | ||
252 | /// Returns the size of the image directory LoadConfig. | ||
253 | dword getIddLoadConfigSize() const; // EXPORT | ||
254 | /// Returns the relative virtual address of the image directory BoundImport. | ||
255 | dword getIddBoundImportRva() const; // EXPORT | ||
256 | /// Returns the size of the image directory BoundImport. | ||
257 | dword getIddBoundImportSize() const; // EXPORT | ||
258 | /// Returns the relative virtual address of the image directory Iat. | ||
259 | dword getIddIatRva() const; // EXPORT | ||
260 | /// Returns the size of the image directory Iat. | ||
261 | dword getIddIatSize() const; // EXPORT | ||
262 | /// Returns the relative virtual address of the image directory DelayImport. | ||
263 | dword getIddDelayImportRva() const; // EXPORT | ||
264 | /// Returns the size of the image directory DelayImport. | ||
265 | dword getIddDelayImportSize() const; // EXPORT | ||
266 | /// Returns the relative virtual address of the image directory COM Descriptor. | ||
267 | dword getIddComHeaderRva() const; // EXPORT | ||
268 | /// Returns the size of the image directory COM Descriptor. | ||
269 | dword getIddComHeaderSize() const; // EXPORT | ||
270 | |||
271 | /// Returns the relative virtual address of an image directory. | ||
272 | dword getImageDataDirectoryRva(dword dwDirectory) const; // EXPORT | ||
273 | /// Returns the size of an image directory. | ||
274 | dword getImageDataDirectorySize(dword dwDirectory) const; // EXPORT | ||
275 | |||
276 | void setImageDataDirectoryRva(dword dwDirectory, dword value); // EXPORT | ||
277 | void setImageDataDirectorySize(dword dwDirectory, dword value); // EXPORT | ||
278 | |||
279 | // section getters | ||
280 | /// Returns the name of a section. | ||
281 | std::string getSectionName(word uiSectionnr) const; // EXPORT | ||
282 | /// Returns the virtual size of a section. | ||
283 | dword getVirtualSize(word uiSectionnr) const; // EXPORT | ||
284 | /// Returns the virtual address of a section. | ||
285 | dword getVirtualAddress(word uiSectionnr) const; // EXPORT | ||
286 | /// Returns the size of a section's raw data. | ||
287 | dword getSizeOfRawData(word uiSectionnr) const; // EXPORT | ||
288 | /// Returns file offset of the data of a section. | ||
289 | dword getPointerToRawData(word uiSectionnr) const; // EXPORT | ||
290 | /// Returns the rva of the relocations of a section. | ||
291 | dword getPointerToRelocations(word uiSectionnr) const; // EXPORT | ||
292 | /// Returns the rva of the line numbers of a section. | ||
293 | dword getPointerToLinenumbers(word uiSectionnr) const; // EXPORT | ||
294 | /// Returns the number of relocations of a section. | ||
295 | dword getNumberOfRelocations(word uiSectionnr) const; // EXPORT | ||
296 | /// Returns the number of line numbers of a section. | ||
297 | dword getNumberOfLinenumbers(word uiSectionnr) const; // EXPORT | ||
298 | /// Returns the characteristics of a section. | ||
299 | dword getCharacteristics(word uiSectionnr) const; // EXPORT _section | ||
300 | |||
301 | // header setters | ||
302 | /// Sets the Signature value of the header. | ||
303 | void setNtSignature(dword value); // EXPORT | ||
304 | /// Sets the Machine value of the header. | ||
305 | void setMachine(word value); // EXPORT | ||
306 | /// Sets the Sections value of the header. | ||
307 | void setNumberOfSections(word value); // EXPORT | ||
308 | /// Sets the TimeDateStamp value of the header. | ||
309 | void setTimeDateStamp(dword value); // EXPORT | ||
310 | /// Sets the PointerToSymbolTable value of the header. | ||
311 | void setPointerToSymbolTable(dword value); // EXPORT | ||
312 | /// Sets the NumberOfSymbols value of the header. | ||
313 | void setNumberOfSymbols(dword value); // EXPORT | ||
314 | /// Sets the SizeOfOptionalHeader value of the header. | ||
315 | void setSizeOfOptionalHeader(word value); // EXPORT | ||
316 | /// Sets the Characteristics value of the header. | ||
317 | void setCharacteristics(word value); // EXPORT _section | ||
318 | |||
319 | /// Sets the Magic value of the header. | ||
320 | void setMagic(word value); // EXPORT | ||
321 | /// Sets the MajorLinkerVersion value of the header. | ||
322 | void setMajorLinkerVersion(byte value); // EXPORT | ||
323 | /// Sets the MinorLinkerVersion value of the header. | ||
324 | void setMinorLinkerVersion(byte value); // EXPORT | ||
325 | /// Sets the SizeOfCode value of the header. | ||
326 | void setSizeOfCode(dword value); // EXPORT | ||
327 | /// Sets the SizeOfInitializedData value of the header. | ||
328 | void setSizeOfInitializedData(dword value); // EXPORT | ||
329 | /// Sets the SizeOfUninitializedData value of the header. | ||
330 | void setSizeOfUninitializedData(dword value); // EXPORT | ||
331 | /// Sets the AddressOfEntryPoint value of the header. | ||
332 | void setAddressOfEntryPoint(dword value); // EXPORT | ||
333 | /// Sets the BaseOfCode value of the header. | ||
334 | void setBaseOfCode(dword value); // EXPORT | ||
335 | /// Sets the ImageBase value of the header. | ||
336 | void setImageBase(VAR4_8 value); // EXPORT | ||
337 | /// Sets the SectionAlignment value of the header. | ||
338 | void setSectionAlignment(dword value); // EXPORT | ||
339 | /// Sets the FileAlignment value of the header. | ||
340 | void setFileAlignment(dword value); // EXPORT | ||
341 | /// Sets the MajorOperatingSystemVersion value of the header. | ||
342 | void setMajorOperatingSystemVersion(word value); // EXPORT | ||
343 | /// Sets the MinorOperatingSystemVersion value of the header. | ||
344 | void setMinorOperatingSystemVersion(word value); // EXPORT | ||
345 | /// Sets the MajorImageVersion value of the header. | ||
346 | void setMajorImageVersion(word value); // EXPORT | ||
347 | /// Sets the MinorImageVersion value of the header. | ||
348 | void setMinorImageVersion(word value); // EXPORT | ||
349 | /// Sets the MajorSubsystemVersion value of the header. | ||
350 | void setMajorSubsystemVersion(word value); // EXPORT | ||
351 | /// Sets the MinorSubsystemVersion value of the header. | ||
352 | void setMinorSubsystemVersion(word value); // EXPORT | ||
353 | /// Sets the Reserved1 value of the header. | ||
354 | void setWin32VersionValue(dword value); // EXPORT | ||
355 | /// Sets the SizeOfImage value of the header. | ||
356 | void setSizeOfImage(dword value); // EXPORT | ||
357 | /// Sets the SizeOfHeaders value of the header. | ||
358 | void setSizeOfHeaders(dword value); // EXPORT | ||
359 | /// Sets the CheckSum value of the header. | ||
360 | void setCheckSum(dword value); // EXPORT | ||
361 | /// Sets the Subsystem value of the header. | ||
362 | void setSubsystem(word value); // EXPORT | ||
363 | /// Sets the DllCharacteristics value of the header. | ||
364 | void setDllCharacteristics(word value); // EXPORT | ||
365 | /// Sets the SizeOfStackReserve value of the header. | ||
366 | void setSizeOfStackReserve(VAR4_8 value); // EXPORT | ||
367 | /// Sets the SizeOfStackCommit value of the header. | ||
368 | void setSizeOfStackCommit(VAR4_8 value); // EXPORT | ||
369 | /// Sets the SizeOfHeapReserve value of the header. | ||
370 | void setSizeOfHeapReserve(VAR4_8 value); // EXPORT | ||
371 | /// Sets the SizeOfHeapCommit value of the header. | ||
372 | void setSizeOfHeapCommit(VAR4_8 value); // EXPORT | ||
373 | /// Sets the LoaderFlags value of the header. | ||
374 | void setLoaderFlags(dword value); // EXPORT | ||
375 | /// Sets the NumberOfRvaAndSizes value of the header. | ||
376 | void setNumberOfRvaAndSizes(dword value); // EXPORT | ||
377 | |||
378 | // image directory getters | ||
379 | void setIddDebugRva(dword dwValue); // EXPORT | ||
380 | void setIddDebugSize(dword dwValue); // EXPORT | ||
381 | void setIddDelayImportRva(dword dwValue); // EXPORT | ||
382 | void setIddDelayImportSize(dword dwValue); // EXPORT | ||
383 | void setIddExceptionRva(dword dwValue); // EXPORT | ||
384 | void setIddExceptionSize(dword dwValue); // EXPORT | ||
385 | void setIddGlobalPtrRva(dword dwValue); // EXPORT | ||
386 | void setIddGlobalPtrSize(dword dwValue); // EXPORT | ||
387 | void setIddIatRva(dword dwValue); // EXPORT | ||
388 | void setIddIatSize(dword dwValue); // EXPORT | ||
389 | void setIddLoadConfigRva(dword dwValue); // EXPORT | ||
390 | void setIddLoadConfigSize(dword dwValue); // EXPORT | ||
391 | void setIddResourceRva(dword dwValue); // EXPORT | ||
392 | void setIddResourceSize(dword dwValue); // EXPORT | ||
393 | void setIddSecurityRva(dword dwValue); // EXPORT | ||
394 | void setIddSecuritySize(dword dwValue); // EXPORT | ||
395 | void setIddTlsRva(dword dwValue); // EXPORT | ||
396 | void setIddTlsSize(dword dwValue); // EXPORT | ||
397 | |||
398 | void setIddImportRva(dword dwValue); // EXPORT | ||
399 | void setIddImportSize(dword dwValue); // EXPORT | ||
400 | void setIddExportRva(dword dwValue); // EXPORT | ||
401 | void setIddExportSize(dword dwValue); // EXPORT | ||
402 | |||
403 | void setIddBaseRelocRva(dword value); // EXPORT | ||
404 | void setIddBaseRelocSize(dword value); // EXPORT | ||
405 | void setIddArchitectureRva(dword value); // EXPORT | ||
406 | void setIddArchitectureSize(dword value); // EXPORT | ||
407 | void setIddComHeaderRva(dword value); // EXPORT | ||
408 | void setIddComHeaderSize(dword value); // EXPORT | ||
409 | |||
410 | /// Set the name of a section. | ||
411 | void setSectionName(word uiSectionnr, std::string strName); // EXPORT | ||
412 | /// Set the virtual size of a section. | ||
413 | void setVirtualSize(word uiSectionnr, dword dwValue); // EXPORT | ||
414 | /// Set the virtual address of a section. | ||
415 | void setVirtualAddress(word uiSectionnr, dword dwValue); // EXPORT | ||
416 | /// Set the size of raw data of a section. | ||
417 | void setSizeOfRawData(word uiSectionnr, dword dwValue); // EXPORT | ||
418 | /// Set the file offset of a section. | ||
419 | void setPointerToRawData(word uiSectionnr, dword dwValue); // EXPORT | ||
420 | /// Set the pointer to relocations of a section. | ||
421 | void setPointerToRelocations(word uiSectionnr, dword dwValue); // EXPORT | ||
422 | /// Set the pointer to linenumbers of a section. | ||
423 | void setPointerToLinenumbers(word uiSectionnr, dword dwValue); // EXPORT | ||
424 | /// Set the number of relocations a section. | ||
425 | void setNumberOfRelocations(word uiSectionnr, dword dwValue); // EXPORT | ||
426 | /// Set the number of linenumbers section. | ||
427 | void setNumberOfLinenumbers(word uiSectionnr, dword dwValue); // EXPORT | ||
428 | /// Set the characteristics of a section. | ||
429 | void setCharacteristics(word uiSectionnr, dword dwValue); // EXPORT | ||
430 | }; | ||
431 | |||
432 | class PeHeader32 : public PeHeaderT<32> | ||
433 | { | ||
434 | public: | ||
435 | /// Returns the BaseOfData value of the header. | ||
436 | dword getBaseOfData() const; // EXPORT | ||
437 | /// Sets the BaseOfData value of the header. | ||
438 | void setBaseOfData(dword value); // EXPORT | ||
439 | }; | ||
440 | |||
441 | class PeHeader64 : public PeHeaderT<64> | ||
442 | { | ||
443 | }; | ||
444 | |||
445 | template<int x> | ||
446 | void PeHeaderT<x>::addDataDirectory() | ||
447 | { | ||
448 | m_inthHeader.dataDirectories.push_back(PELIB_IMAGE_DATA_DIRECTORY()); | ||
449 | } | ||
450 | |||
451 | template<int x> | ||
452 | void PeHeaderT<x>::removeDataDirectory(dword index) | ||
453 | { | ||
454 | m_inthHeader.dataDirectories.erase(m_inthHeader.dataDirectories.begin() + index); | ||
455 | } | ||
456 | |||
457 | /** | ||
458 | * Adds a new section to the header. The physical and virtual address as well as the virtual | ||
459 | * size of the section will be determined automatically from the raw size. The section | ||
460 | * characteristics will be set to IMAGE_SCN_MEM_WRITE | IMAGE_SCN_MEM_READ | | ||
461 | * IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_CNT_CODE. All other values will be set to 0. | ||
462 | * Note: It's important that if the current header's FileAlignment and/or SectionAlignment values are | ||
463 | * 0 this function will fail. | ||
464 | * @param strName Name of the new section. If this name is longer than 8 bytes only the first 8 bytes will be used. | ||
465 | * @param dwSize Physical size of the new section in bytes. | ||
466 | * \todo Better code that handles files with 0 sections. | ||
467 | **/ | ||
468 | template<int x> | ||
469 | int PeHeaderT<x>::addSection(const std::string& strName, dword dwSize) | ||
470 | { | ||
471 | unsigned int uiSecnr = calcNumberOfSections(); | ||
472 | |||
473 | if (!getFileAlignment()) | ||
474 | { | ||
475 | return ERROR_NO_FILE_ALIGNMENT; | ||
476 | } | ||
477 | else if (!getSectionAlignment()) | ||
478 | { | ||
479 | return ERROR_NO_SECTION_ALIGNMENT; | ||
480 | } | ||
481 | |||
482 | if (uiSecnr) // Always allow 1 section. | ||
483 | { | ||
484 | if (uiSecnr == 0xFFFF) | ||
485 | { | ||
486 | return ERROR_TOO_MANY_SECTIONS; | ||
487 | } | ||
488 | else if (calcSpaceAfterHeader() < PELIB_IMAGE_SECTION_HEADER::size()) | ||
489 | { | ||
490 | return ERROR_NOT_ENOUGH_SPACE; | ||
491 | } | ||
492 | } | ||
493 | |||
494 | dword dwOffset = calcOffset(/*dwSize*/); | ||
495 | dword dwRva = calcRva(/*dwSize*/); | ||
496 | |||
497 | PELIB_IMAGE_SECTION_HEADER ishdCurr; | ||
498 | m_vIsh.push_back(ishdCurr); | ||
499 | |||
500 | setSectionName(uiSecnr, strName); | ||
501 | setSizeOfRawData(uiSecnr, alignOffset(dwSize, getFileAlignment())); | ||
502 | setPointerToRawData(uiSecnr, dwOffset); | ||
503 | setVirtualSize(uiSecnr, alignOffset(dwSize, getSectionAlignment())); | ||
504 | setVirtualAddress(uiSecnr, dwRva); | ||
505 | setCharacteristics(uiSecnr, PELIB_IMAGE_SCN_MEM_WRITE | PELIB_IMAGE_SCN_MEM_READ | PELIB_IMAGE_SCN_CNT_INITIALIZED_DATA | PELIB_IMAGE_SCN_CNT_CODE); | ||
506 | |||
507 | return NO_ERROR; | ||
508 | } | ||
509 | |||
510 | /** | ||
511 | * Calculates a valid SizeOfImage value given the information from the current PE header. | ||
512 | * Note that this calculation works in Win2K but probably does not work in Win9X. I didn't test that though. | ||
513 | * @return Valid SizeOfImage value. | ||
514 | **/ | ||
515 | template<int x> | ||
516 | unsigned int PeHeaderT<x>::calcSizeOfImage() const | ||
517 | { | ||
518 | // Major note here: It's possible for sections to exist with a Virtual Size of 0. | ||
519 | // That's why it's necessary to use std::max(Vsize, RawSize) here. | ||
520 | // An example for such a file is dbeng6.exe (made by Sybase). | ||
521 | // In this file each and every section has a VSize of 0 but it still runs. | ||
522 | |||
523 | std::vector<PELIB_IMAGE_SECTION_HEADER>::const_iterator ishLastSection = std::max_element(m_vIsh.begin(), m_vIsh.end(), std::mem_fun_ref(&PELIB_IMAGE_SECTION_HEADER::biggerVirtualAddress)); | ||
524 | if (ishLastSection->VirtualSize != 0) return ishLastSection->VirtualAddress + ishLastSection->VirtualSize; | ||
525 | return ishLastSection->VirtualAddress + std::max(ishLastSection->VirtualSize, ishLastSection->SizeOfRawData); | ||
526 | } | ||
527 | |||
528 | /** | ||
529 | * Calculates the space between the last byte of the header and the first byte that's used for something | ||
530 | * else (that's either the first section or an image directory). | ||
531 | * @return Unused space after the header. | ||
532 | * \todo There are PE files with sections beginning at offset 0. They | ||
533 | * need to be considered. | ||
534 | **/ | ||
535 | template<int x> | ||
536 | unsigned int PeHeaderT<x>::calcSpaceAfterHeader() const | ||
537 | { | ||
538 | return (calcStartOfCode() > size() + m_uiOffset) ? calcStartOfCode() - (size() + m_uiOffset) : 0; | ||
539 | } | ||
540 | |||
541 | /** | ||
542 | * Returns the first offset of the file that's actually used for something different than the header. | ||
543 | * That something is not necessarily code, it can be a data directory too. | ||
544 | * This offset can be the beginning of a section or the beginning of a directory. | ||
545 | * \todo Some optimizization is surely possible here. | ||
546 | * \todo There are PE files with sections beginning at offset 0. They | ||
547 | * need to be considered. Returning 0 for these files doesn't really make sense. | ||
548 | * So far these sections are disregarded. | ||
549 | **/ | ||
550 | template<int x> | ||
551 | unsigned int PeHeaderT<x>::calcStartOfCode() const | ||
552 | { | ||
553 | unsigned int directories = calcNumberOfRvaAndSizes(); | ||
554 | dword dwMinOffset = 0xFFFFFFFF; | ||
555 | if (directories >= 1 && getIddExportRva() && rvaToOffset(getIddExportRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddExportRva()); | ||
556 | if (directories >= 2 && getIddImportRva() && rvaToOffset(getIddImportRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddImportRva()); | ||
557 | if (directories >= 3 && getIddResourceRva() && rvaToOffset(getIddResourceRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddResourceRva()); | ||
558 | if (directories >= 4 && getIddExceptionRva() && rvaToOffset(getIddExceptionRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddExceptionRva()); | ||
559 | if (directories >= 5 && getIddSecurityRva() && rvaToOffset(getIddSecurityRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddSecurityRva()); | ||
560 | if (directories >= 6 && getIddBaseRelocRva() && rvaToOffset(getIddBaseRelocRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddBaseRelocRva()); | ||
561 | if (directories >= 7 && getIddDebugRva() && rvaToOffset(getIddDebugRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddDebugRva()); | ||
562 | if (directories >= 8 && getIddArchitectureRva() && rvaToOffset(getIddArchitectureRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddArchitectureRva()); | ||
563 | if (directories >= 9 && getIddGlobalPtrRva() && rvaToOffset(getIddGlobalPtrRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddGlobalPtrRva()); | ||
564 | if (directories >= 10 && getIddTlsRva() && rvaToOffset(getIddTlsRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddTlsRva()); | ||
565 | if (directories >= 11 && getIddLoadConfigRva() && rvaToOffset(getIddLoadConfigRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddLoadConfigRva()); | ||
566 | if (directories >= 12 && getIddBoundImportRva() && rvaToOffset(getIddBoundImportRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddBoundImportRva()); | ||
567 | if (directories >= 13 && getIddIatRva() && rvaToOffset(getIddIatRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddIatRva()); | ||
568 | if (directories >= 14 && getIddDelayImportRva() && rvaToOffset(getIddDelayImportRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddDelayImportRva()); | ||
569 | if (directories >= 15 && getIddComHeaderRva() && rvaToOffset(getIddComHeaderRva()) < dwMinOffset) dwMinOffset = rvaToOffset(getIddComHeaderRva()); | ||
570 | |||
571 | for (word i=0;i<calcNumberOfSections();i++) | ||
572 | { | ||
573 | if ((getPointerToRawData(i) < dwMinOffset || dwMinOffset == 0xFFFFFFFF) && getSizeOfRawData(i)) | ||
574 | { | ||
575 | if (getPointerToRawData(i)) dwMinOffset = getPointerToRawData(i); | ||
576 | } | ||
577 | } | ||
578 | return dwMinOffset; | ||
579 | } | ||
580 | |||
581 | /** | ||
582 | * Calculates the file offset for a new section. The file offset will already be aligned to the file's FileAlignment. | ||
583 | * @return Aligned file offset. | ||
584 | * \todo uiSize isn't used yet. Will be used later on to search for caves. | ||
585 | **/ | ||
586 | template<int x> | ||
587 | unsigned int PeHeaderT<x>::calcOffset(/*unsigned int uiSize*/) const | ||
588 | { | ||
589 | unsigned int maxoffset = size(); | ||
590 | |||
591 | for (word i=0;i<calcNumberOfSections();i++) | ||
592 | { | ||
593 | if (getPointerToRawData(i) + getSizeOfRawData(i) > maxoffset) maxoffset = getPointerToRawData(i) + getSizeOfRawData(i); | ||
594 | } | ||
595 | |||
596 | return alignOffset(maxoffset, getFileAlignment()); | ||
597 | } | ||
598 | |||
599 | /** | ||
600 | * Calculates the Rva for a new section. The Rva will already be aligned to the file's SectionAlignment. | ||
601 | * \todo uiSize isn't used yet. Will be used later on to search for caves. | ||
602 | * @return Aligned Rva. | ||
603 | **/ | ||
604 | template<int x> | ||
605 | unsigned int PeHeaderT<x>::calcRva(/*unsigned int uiSize*/) const | ||
606 | { | ||
607 | // Major note here: It's possible for sections to exist with a Virtual Size of 0. | ||
608 | // That's why it's necessary to use std::max(Vsize, RawSize) here. | ||
609 | // An example for such a file is dbeng6.exe (made by Sybase). | ||
610 | // In this file each and every section has a VSize of 0 but it still runs. | ||
611 | |||
612 | unsigned int maxoffset = size(); | ||
613 | for (word i=0;i<calcNumberOfSections();i++) | ||
614 | { | ||
615 | if (getVirtualAddress(i) + std::max(getVirtualSize(i), getSizeOfRawData(i)) > maxoffset) maxoffset = getVirtualAddress(i) + std::max(getVirtualSize(i), getSizeOfRawData(i)); | ||
616 | } | ||
617 | |||
618 | return alignOffset(maxoffset, getSectionAlignment()); | ||
619 | } | ||
620 | |||
621 | /** | ||
622 | * Returns the number of currently defined sections. Note that this value can be different from the number | ||
623 | * of sections according to the header (see #PeLib::PeHeaderT<x>::getNumberOfSections). | ||
624 | * @return Number of currently defined sections. | ||
625 | **/ | ||
626 | template<int x> | ||
627 | word PeHeaderT<x>::calcNumberOfSections() const | ||
628 | { | ||
629 | return static_cast<PeLib::word>(m_vIsh.size()); | ||
630 | } | ||
631 | |||
632 | /** | ||
633 | * Enlarges the physically last section in the file. | ||
634 | * @param uiSize Additional size that's added to the section's size. | ||
635 | **/ | ||
636 | template<int x> | ||
637 | void PeHeaderT<x>::enlargeLastSection(unsigned int uiSize) | ||
638 | { | ||
639 | std::vector<PELIB_IMAGE_SECTION_HEADER>::iterator ishLastSection = std::max_element(m_vIsh.begin(), m_vIsh.end(), std::mem_fun_ref(&PELIB_IMAGE_SECTION_HEADER::biggerFileOffset)); | ||
640 | unsigned int uiRawDataSize = alignOffset(ishLastSection->SizeOfRawData + uiSize, getFileAlignment()); | ||
641 | |||
642 | ishLastSection->SizeOfRawData = uiRawDataSize; | ||
643 | ishLastSection->VirtualSize = ishLastSection->SizeOfRawData; | ||
644 | |||
645 | setSizeOfImage(calcSizeOfImage()); | ||
646 | } | ||
647 | |||
648 | /** | ||
649 | * Determines the section which contains the file offset. | ||
650 | * @param dwOffset File offset. | ||
651 | * @return Section Id of the section which contains the offset. | ||
652 | **/ | ||
653 | template<int x> | ||
654 | word PeHeaderT<x>::getSectionWithOffset(VAR4_8 dwOffset) const | ||
655 | { | ||
656 | // Offset = 0 must be handled explicitly as there are files | ||
657 | // with sections that begin at offset 0, that means the section | ||
658 | // only exists in memory. | ||
659 | |||
660 | if (!dwOffset) return std::numeric_limits<word>::max(); | ||
661 | |||
662 | for (word i=0;i<calcNumberOfSections();i++) | ||
663 | { | ||
664 | // Explicity exclude sections with raw pointer = 0. | ||
665 | dword rawptr = getPointerToRawData(i); | ||
666 | if (rawptr && rawptr <= dwOffset && rawptr + getSizeOfRawData(i) > dwOffset) return i; | ||
667 | } | ||
668 | |||
669 | return std::numeric_limits<word>::max(); | ||
670 | } | ||
671 | |||
672 | /** | ||
673 | * Determines the section which contains the Rva. | ||
674 | * @param dwRva A relative virtual address. | ||
675 | * @return Section Id of the section which contains the Rva. | ||
676 | **/ | ||
677 | template<int x> | ||
678 | word PeHeaderT<x>::getSectionWithRva(VAR4_8 dwRva) const | ||
679 | { | ||
680 | // Major note here: It's possible for sections to exist with a Virtual Size of 0. | ||
681 | // That's why it's necessary to use std::max(Vsize, RawSize) here. | ||
682 | // An example for such a file is dbeng6.exe (made by Sybase). | ||
683 | // In this file each and every section has a VSize of 0 but it still runs. | ||
684 | |||
685 | for (word i=0;i<calcNumberOfSections();i++) | ||
686 | { | ||
687 | // Weird VC++7 error doesn't allow me to use std::max here. | ||
688 | dword max = getVirtualSize(i) >= getSizeOfRawData(i) ? getVirtualSize(i) : getSizeOfRawData(i); | ||
689 | if (getVirtualAddress(i) <= dwRva && getVirtualAddress(i) + max > dwRva) return i; | ||
690 | } | ||
691 | |||
692 | return -1; | ||
693 | } | ||
694 | |||
695 | /** | ||
696 | * Corrects all faulty values of the current PE header. The following values will be corrected: NtSignature, | ||
697 | * NumberOfSections, SizeOfOptionalHeader, FileAlignment (will be aligned to n*0x200), | ||
698 | * SectionAlignment (will be aligned to n*0x1000), NumberOfRvaAndSizes, SizeOfHeaders, SizeOfImage, | ||
699 | * Magic, Characteristics. | ||
700 | * @param dwOffset Beginning of PeHeader (see #PeLib::MzHeader::getAddressOfPeHeader). | ||
701 | * \todo 32bit and 64bit versions. | ||
702 | **/ | ||
703 | template<int x> | ||
704 | void PeHeaderT<x>::makeValid(dword dwOffset) | ||
705 | { | ||
706 | setNtSignature(PELIB_IMAGE_NT_SIGNATURE); // 'PE' | ||
707 | setMachine(PELIB_IMAGE_FILE_MACHINE_I386); | ||
708 | setNumberOfSections(calcNumberOfSections()); | ||
709 | |||
710 | // Check if 64 bits. | ||
711 | setSizeOfOptionalHeader(PELIB_IMAGE_OPTIONAL_HEADER<x>::size() + calcNumberOfRvaAndSizes() * 8); | ||
712 | |||
713 | // Check if 64 bits. | ||
714 | dword dwCharacteristics = PELIB_IMAGE_FILE_EXECUTABLE_IMAGE | PELIB_IMAGE_FILE_32BIT_MACHINE; | ||
715 | setCharacteristics(dwCharacteristics); | ||
716 | |||
717 | // Check if 64 bits. | ||
718 | setMagic(PELIB_IMAGE_NT_OPTIONAL_HDR32_MAGIC); | ||
719 | |||
720 | // setImageBase(0x01000000); | ||
721 | |||
722 | // Align file and section alignment values | ||
723 | unsigned int dwAlignedOffset = alignOffset(getSectionAlignment(), 0x1000); | ||
724 | setSectionAlignment(dwAlignedOffset ? dwAlignedOffset : 0x1000); | ||
725 | |||
726 | dwAlignedOffset = alignOffset(getFileAlignment(), 0x200); | ||
727 | setFileAlignment(dwAlignedOffset ? dwAlignedOffset : 0x200); | ||
728 | |||
729 | // setMajorSubsystemVersion(4); | ||
730 | // setSubsystem(IMAGE_SUBSYSTEM_WINDOWS_GUI); | ||
731 | setNumberOfRvaAndSizes(calcNumberOfRvaAndSizes()); | ||
732 | |||
733 | // Code below depends on code above. Don't change the order. | ||
734 | dword dwSizeOfHeaders = alignOffset(dwOffset + size(), getFileAlignment()); | ||
735 | setSizeOfHeaders(dwSizeOfHeaders); | ||
736 | |||
737 | dword dwSizeOfImage = alignOffset(dwSizeOfHeaders, getSectionAlignment()); | ||
738 | |||
739 | for (int i=0;i<calcNumberOfSections();i++) | ||
740 | { | ||
741 | dwSizeOfImage += alignOffset(getVirtualSize(i), getSectionAlignment()); | ||
742 | } | ||
743 | |||
744 | dwSizeOfImage = alignOffset(dwSizeOfImage, getSectionAlignment()); | ||
745 | setSizeOfImage(dwSizeOfImage); | ||
746 | } | ||
747 | |||
748 | template<int x> | ||
749 | unsigned int PeHeaderT<x>::offsetToRva(VAR4_8 dwOffset) const | ||
750 | { | ||
751 | if (dwOffset < calcStartOfCode()) return dwOffset; | ||
752 | |||
753 | PeLib::word uiSecnr = getSectionWithOffset(dwOffset); | ||
754 | |||
755 | if (uiSecnr == 0xFFFF) return -1; | ||
756 | |||
757 | return getVirtualAddress(uiSecnr) + dwOffset - getPointerToRawData(uiSecnr); | ||
758 | } | ||
759 | |||
760 | /** | ||
761 | * Converts a file offset to a virtual address. | ||
762 | * @param dwOffset File offset. | ||
763 | * @return Virtual Address. | ||
764 | **/ | ||
765 | template<int x> | ||
766 | unsigned int PeHeaderT<x>::offsetToVa(VAR4_8 dwOffset) const | ||
767 | { | ||
768 | if (dwOffset < calcStartOfCode()) return getImageBase() + dwOffset; | ||
769 | |||
770 | PeLib::word uiSecnr = getSectionWithOffset(dwOffset); | ||
771 | |||
772 | if (uiSecnr == 0xFFFF) return -1; | ||
773 | |||
774 | return getImageBase() + getVirtualAddress(uiSecnr) + dwOffset - getPointerToRawData(uiSecnr); | ||
775 | } | ||
776 | |||
777 | template<int x> | ||
778 | void PeHeaderT<x>::readHeader(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const | ||
779 | { | ||
780 | ibBuffer >> header.Signature; | ||
781 | |||
782 | ibBuffer >> header.FileHeader.Machine; | ||
783 | ibBuffer >> header.FileHeader.NumberOfSections; | ||
784 | ibBuffer >> header.FileHeader.TimeDateStamp; | ||
785 | ibBuffer >> header.FileHeader.PointerToSymbolTable; | ||
786 | ibBuffer >> header.FileHeader.NumberOfSymbols; | ||
787 | ibBuffer >> header.FileHeader.SizeOfOptionalHeader; | ||
788 | ibBuffer >> header.FileHeader.Characteristics; | ||
789 | ibBuffer >> header.OptionalHeader.Magic; | ||
790 | |||
791 | ibBuffer >> header.OptionalHeader.MajorLinkerVersion; | ||
792 | ibBuffer >> header.OptionalHeader.MinorLinkerVersion; | ||
793 | ibBuffer >> header.OptionalHeader.SizeOfCode; | ||
794 | ibBuffer >> header.OptionalHeader.SizeOfInitializedData; | ||
795 | ibBuffer >> header.OptionalHeader.SizeOfUninitializedData; | ||
796 | ibBuffer >> header.OptionalHeader.AddressOfEntryPoint; | ||
797 | ibBuffer >> header.OptionalHeader.BaseOfCode; | ||
798 | readBaseOfData(ibBuffer, header); | ||
799 | ibBuffer >> header.OptionalHeader.ImageBase; | ||
800 | ibBuffer >> header.OptionalHeader.SectionAlignment; | ||
801 | ibBuffer >> header.OptionalHeader.FileAlignment; | ||
802 | ibBuffer >> header.OptionalHeader.MajorOperatingSystemVersion; | ||
803 | ibBuffer >> header.OptionalHeader.MinorOperatingSystemVersion; | ||
804 | ibBuffer >> header.OptionalHeader.MajorImageVersion; | ||
805 | ibBuffer >> header.OptionalHeader.MinorImageVersion; | ||
806 | ibBuffer >> header.OptionalHeader.MajorSubsystemVersion; | ||
807 | ibBuffer >> header.OptionalHeader.MinorSubsystemVersion; | ||
808 | ibBuffer >> header.OptionalHeader.Win32VersionValue; | ||
809 | ibBuffer >> header.OptionalHeader.SizeOfImage; | ||
810 | ibBuffer >> header.OptionalHeader.SizeOfHeaders; | ||
811 | ibBuffer >> header.OptionalHeader.CheckSum; | ||
812 | ibBuffer >> header.OptionalHeader.Subsystem; | ||
813 | ibBuffer >> header.OptionalHeader.DllCharacteristics; | ||
814 | ibBuffer >> header.OptionalHeader.SizeOfStackReserve; | ||
815 | ibBuffer >> header.OptionalHeader.SizeOfStackCommit; | ||
816 | ibBuffer >> header.OptionalHeader.SizeOfHeapReserve; | ||
817 | ibBuffer >> header.OptionalHeader.SizeOfHeapCommit; | ||
818 | ibBuffer >> header.OptionalHeader.LoaderFlags; | ||
819 | ibBuffer >> header.OptionalHeader.NumberOfRvaAndSizes; | ||
820 | } | ||
821 | |||
822 | template<int x> | ||
823 | void PeHeaderT<x>::readDataDirectories(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const | ||
824 | { | ||
825 | PELIB_IMAGE_DATA_DIRECTORY idd; | ||
826 | |||
827 | for (unsigned int i=0;i<header.OptionalHeader.NumberOfRvaAndSizes;i++) | ||
828 | { | ||
829 | ibBuffer >> idd.VirtualAddress; | ||
830 | ibBuffer >> idd.Size; | ||
831 | header.dataDirectories.push_back(idd); | ||
832 | } | ||
833 | } | ||
834 | |||
835 | template<int x> | ||
836 | std::vector<PELIB_IMAGE_SECTION_HEADER> PeHeaderT<x>::readSections(InputBuffer& ibBuffer, PELIB_IMAGE_NT_HEADERS<x>& header) const | ||
837 | { | ||
838 | const unsigned int nrSections = header.FileHeader.NumberOfSections; | ||
839 | PELIB_IMAGE_SECTION_HEADER ishCurr; | ||
840 | |||
841 | std::vector<PELIB_IMAGE_SECTION_HEADER> vIshdCurr; | ||
842 | |||
843 | for (unsigned int i=0;i<nrSections;i++) | ||
844 | { | ||
845 | ibBuffer.read(reinterpret_cast<char*>(ishCurr.Name), 8); | ||
846 | ibBuffer >> ishCurr.VirtualSize; | ||
847 | ibBuffer >> ishCurr.VirtualAddress; | ||
848 | ibBuffer >> ishCurr.SizeOfRawData; | ||
849 | ibBuffer >> ishCurr.PointerToRawData; | ||
850 | ibBuffer >> ishCurr.PointerToRelocations; | ||
851 | ibBuffer >> ishCurr.PointerToLinenumbers; | ||
852 | ibBuffer >> ishCurr.NumberOfRelocations; | ||
853 | ibBuffer >> ishCurr.NumberOfLinenumbers; | ||
854 | ibBuffer >> ishCurr.Characteristics; | ||
855 | vIshdCurr.push_back(ishCurr); | ||
856 | } | ||
857 | |||
858 | return vIshdCurr; | ||
859 | } | ||
860 | |||
861 | template<int x> | ||
862 | int PeHeaderT<x>::read(const unsigned char* pcBuffer, unsigned int uiSize, unsigned int uiOffset) | ||
863 | { | ||
864 | if (uiSize < m_inthHeader.size()) | ||
865 | { | ||
866 | return ERROR_INVALID_FILE; | ||
867 | } | ||
868 | |||
869 | std::vector<unsigned char> vBuffer(pcBuffer, pcBuffer + m_inthHeader.size()); | ||
870 | |||
871 | InputBuffer ibBuffer(vBuffer); | ||
872 | PELIB_IMAGE_NT_HEADERS<x> header; | ||
873 | |||
874 | readHeader(ibBuffer, header); | ||
875 | |||
876 | if (uiSize < m_inthHeader.size() + header.OptionalHeader.NumberOfRvaAndSizes * 8 + header.FileHeader.NumberOfSections * 0x28) | ||
877 | { | ||
878 | return ERROR_INVALID_FILE; | ||
879 | } | ||
880 | |||
881 | vBuffer.resize(header.OptionalHeader.NumberOfRvaAndSizes * 8 + header.FileHeader.NumberOfSections * 0x28); | ||
882 | vBuffer.assign(pcBuffer + m_inthHeader.size(), pcBuffer + m_inthHeader.size() + header.OptionalHeader.NumberOfRvaAndSizes * 8 + header.FileHeader.NumberOfSections * 0x28); | ||
883 | |||
884 | ibBuffer.setBuffer(vBuffer); | ||
885 | |||
886 | readDataDirectories(ibBuffer, header); | ||
887 | |||
888 | m_vIsh = readSections(ibBuffer, header); | ||
889 | |||
890 | std::swap(m_inthHeader, header); | ||
891 | |||
892 | m_uiOffset = uiOffset; | ||
893 | |||
894 | return NO_ERROR; | ||
895 | } | ||
896 | |||
897 | /** | ||
898 | * Reads the PE header from a file Note that this function does not verify if a file is actually a MZ file. | ||
899 | * For this purpose see #PeLib::PeHeaderT<x>::isValid. The only check this function makes is a check to see if | ||
900 | * the file is large enough to be a PE header. If the data is valid doesn't matter. | ||
901 | * @param strFilename Name of the file which will be read. | ||
902 | * @param uiOffset File offset of PE header (see #PeLib::MzHeader::getAddressOfPeHeader). | ||
903 | **/ | ||
904 | template<int x> | ||
905 | int PeHeaderT<x>::read(std::string strFilename, unsigned int uiOffset) | ||
906 | { | ||
907 | std::ifstream ifFile(strFilename.c_str(), std::ios::binary); | ||
908 | |||
909 | if (!ifFile) | ||
910 | { | ||
911 | return ERROR_OPENING_FILE; | ||
912 | } | ||
913 | |||
914 | // File too small | ||
915 | if (fileSize(ifFile) < uiOffset + m_inthHeader.size()) | ||
916 | { | ||
917 | return ERROR_INVALID_FILE; | ||
918 | } | ||
919 | |||
920 | std::vector<unsigned char> vBuffer(m_inthHeader.size()); | ||
921 | |||
922 | ifFile.seekg(uiOffset, std::ios::beg); | ||
923 | ifFile.read(reinterpret_cast<char*>(&vBuffer[0]), static_cast<std::streamsize>(vBuffer.size())); | ||
924 | |||
925 | InputBuffer ibBuffer(vBuffer); | ||
926 | PELIB_IMAGE_NT_HEADERS<x> header; | ||
927 | |||
928 | readHeader(ibBuffer, header); | ||
929 | |||
930 | vBuffer.resize(header.OptionalHeader.NumberOfRvaAndSizes * 8 + header.FileHeader.NumberOfSections * 0x28); | ||
931 | |||
932 | ifFile.read(reinterpret_cast<char*>(&vBuffer[0]), static_cast<std::streamsize>(vBuffer.size())); | ||
933 | if (!ifFile) | ||
934 | { | ||
935 | return ERROR_INVALID_FILE; | ||
936 | } | ||
937 | |||
938 | ibBuffer.setBuffer(vBuffer); | ||
939 | |||
940 | readDataDirectories(ibBuffer, header); | ||
941 | |||
942 | // Sections | ||
943 | // const unsigned int nrSections = header.FileHeader.NumberOfSections; | ||
944 | // if (fileSize(ifFile) < uiOffset + m_inthHeader.size() + nrSections * PELIB_IMAGE_SECTION_HEADER::size()) | ||
945 | // { | ||
946 | // return ERROR_INVALID_FILE; | ||
947 | // } | ||
948 | |||
949 | m_vIsh = readSections(ibBuffer, header); | ||
950 | |||
951 | std::swap(m_inthHeader, header); | ||
952 | |||
953 | m_uiOffset = uiOffset; | ||
954 | |||
955 | ifFile.close(); | ||
956 | |||
957 | return NO_ERROR; | ||
958 | } | ||
959 | |||
960 | /** | ||
961 | * Rebuilds the PE header so that it can be written to a file. It's not guaranteed that the | ||
962 | * header will be valid. If you want to make sure that the header will be valid you | ||
963 | * must call #PeLib::PeHeaderT<x>::makeValid first. | ||
964 | * @param vBuffer Buffer where the rebuilt header will be stored. | ||
965 | **/ | ||
966 | template<int x> | ||
967 | void PeHeaderT<x>::rebuild(std::vector<byte>& vBuffer) const | ||
968 | { | ||
969 | OutputBuffer obBuffer(vBuffer); | ||
970 | |||
971 | obBuffer << m_inthHeader.Signature; | ||
972 | |||
973 | obBuffer << m_inthHeader.FileHeader.Machine; | ||
974 | obBuffer << m_inthHeader.FileHeader.NumberOfSections; | ||
975 | obBuffer << m_inthHeader.FileHeader.TimeDateStamp; | ||
976 | obBuffer << m_inthHeader.FileHeader.PointerToSymbolTable; | ||
977 | obBuffer << m_inthHeader.FileHeader.NumberOfSymbols; | ||
978 | obBuffer << m_inthHeader.FileHeader.SizeOfOptionalHeader; | ||
979 | obBuffer << m_inthHeader.FileHeader.Characteristics; | ||
980 | obBuffer << m_inthHeader.OptionalHeader.Magic; | ||
981 | obBuffer << m_inthHeader.OptionalHeader.MajorLinkerVersion; | ||
982 | obBuffer << m_inthHeader.OptionalHeader.MinorLinkerVersion; | ||
983 | obBuffer << m_inthHeader.OptionalHeader.SizeOfCode; | ||
984 | obBuffer << m_inthHeader.OptionalHeader.SizeOfInitializedData; | ||
985 | obBuffer << m_inthHeader.OptionalHeader.SizeOfUninitializedData; | ||
986 | obBuffer << m_inthHeader.OptionalHeader.AddressOfEntryPoint; | ||
987 | obBuffer << m_inthHeader.OptionalHeader.BaseOfCode; | ||
988 | rebuildBaseOfData(obBuffer); | ||
989 | // obBuffer << m_inthHeader.OptionalHeader.BaseOfData; | ||
990 | obBuffer << m_inthHeader.OptionalHeader.ImageBase; | ||
991 | obBuffer << m_inthHeader.OptionalHeader.SectionAlignment; | ||
992 | obBuffer << m_inthHeader.OptionalHeader.FileAlignment; | ||
993 | obBuffer << m_inthHeader.OptionalHeader.MajorOperatingSystemVersion; | ||
994 | obBuffer << m_inthHeader.OptionalHeader.MinorOperatingSystemVersion; | ||
995 | obBuffer << m_inthHeader.OptionalHeader.MajorImageVersion; | ||
996 | obBuffer << m_inthHeader.OptionalHeader.MinorImageVersion; | ||
997 | obBuffer << m_inthHeader.OptionalHeader.MajorSubsystemVersion; | ||
998 | obBuffer << m_inthHeader.OptionalHeader.MinorSubsystemVersion; | ||
999 | obBuffer << m_inthHeader.OptionalHeader.Win32VersionValue; | ||
1000 | obBuffer << m_inthHeader.OptionalHeader.SizeOfImage; | ||
1001 | obBuffer << m_inthHeader.OptionalHeader.SizeOfHeaders; | ||
1002 | obBuffer << m_inthHeader.OptionalHeader.CheckSum; | ||
1003 | obBuffer << m_inthHeader.OptionalHeader.Subsystem; | ||
1004 | obBuffer << m_inthHeader.OptionalHeader.DllCharacteristics; | ||
1005 | obBuffer << m_inthHeader.OptionalHeader.SizeOfStackReserve; | ||
1006 | obBuffer << m_inthHeader.OptionalHeader.SizeOfStackCommit; | ||
1007 | obBuffer << m_inthHeader.OptionalHeader.SizeOfHeapReserve; | ||
1008 | obBuffer << m_inthHeader.OptionalHeader.SizeOfHeapCommit; | ||
1009 | obBuffer << m_inthHeader.OptionalHeader.LoaderFlags; | ||
1010 | obBuffer << m_inthHeader.OptionalHeader.NumberOfRvaAndSizes; | ||
1011 | |||
1012 | // The 0x10 data directories | ||
1013 | for (unsigned int i=0;i<calcNumberOfRvaAndSizes();i++) | ||
1014 | { | ||
1015 | obBuffer << m_inthHeader.dataDirectories[i].VirtualAddress; | ||
1016 | obBuffer << m_inthHeader.dataDirectories[i].Size; | ||
1017 | } | ||
1018 | |||
1019 | // The section definitions | ||
1020 | const unsigned int nrSections = calcNumberOfSections(); | ||
1021 | for (unsigned int i=0;i<nrSections;i++) | ||
1022 | { | ||
1023 | char temp[9] = {0}; | ||
1024 | strcpy(temp, getSectionName(i).c_str()); | ||
1025 | obBuffer.add(temp, 8); | ||
1026 | obBuffer << m_vIsh[i].VirtualSize; | ||
1027 | obBuffer << m_vIsh[i].VirtualAddress; | ||
1028 | obBuffer << m_vIsh[i].SizeOfRawData; | ||
1029 | obBuffer << m_vIsh[i].PointerToRawData; | ||
1030 | obBuffer << m_vIsh[i].PointerToRelocations; | ||
1031 | obBuffer << m_vIsh[i].PointerToLinenumbers; | ||
1032 | obBuffer << m_vIsh[i].NumberOfRelocations; | ||
1033 | obBuffer << m_vIsh[i].NumberOfLinenumbers; | ||
1034 | obBuffer << m_vIsh[i].Characteristics; | ||
1035 | } | ||
1036 | } | ||
1037 | |||
1038 | /** | ||
1039 | * Converts a relative virtual offset to a file offset. | ||
1040 | * @param dwRva A relative virtual offset. | ||
1041 | * @return A file offset. | ||
1042 | * \todo It's not always 0x1000. | ||
1043 | **/ | ||
1044 | template<int x> | ||
1045 | typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::rvaToOffset(VAR4_8 dwRva) const | ||
1046 | { | ||
1047 | // XXX: Not correct | ||
1048 | if (dwRva < 0x1000) return dwRva; | ||
1049 | |||
1050 | PeLib::word uiSecnr = getSectionWithRva(dwRva); | ||
1051 | if (uiSecnr == 0xFFFF || dwRva > getVirtualAddress(uiSecnr) + getSizeOfRawData(uiSecnr)) | ||
1052 | { | ||
1053 | return std::numeric_limits<VAR4_8>::max(); | ||
1054 | } | ||
1055 | |||
1056 | return getPointerToRawData(uiSecnr) + dwRva - getVirtualAddress(uiSecnr); | ||
1057 | } | ||
1058 | |||
1059 | /** | ||
1060 | * Converts a relative virtual offset to a virtual offset. | ||
1061 | * @param dwRva A relative virtual offset. | ||
1062 | * @return A virtual offset. | ||
1063 | **/ | ||
1064 | template<int x> | ||
1065 | typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::rvaToVa(VAR4_8 dwRva) const | ||
1066 | { | ||
1067 | return getImageBase() + dwRva; | ||
1068 | } | ||
1069 | |||
1070 | /** | ||
1071 | * Calculates the size of the current PE header. This includes the actual header and the section definitions. | ||
1072 | * @return Size of the current PE header. | ||
1073 | * \todo Better handling of files with less than 0x10 directories. | ||
1074 | **/ | ||
1075 | template<int x> | ||
1076 | unsigned int PeHeaderT<x>::size() const | ||
1077 | { | ||
1078 | return m_inthHeader.size() + getNumberOfSections() * PELIB_IMAGE_SECTION_HEADER::size(); | ||
1079 | } | ||
1080 | |||
1081 | // \todo Not sure if this works. | ||
1082 | template<int x> | ||
1083 | typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::vaToRva(VAR4_8 dwRva) const | ||
1084 | { | ||
1085 | if (dwRva - getImageBase() < calcStartOfCode()) return dwRva - getImageBase(); | ||
1086 | |||
1087 | if (getSectionWithRva(dwRva - getImageBase()) == 0xFFFF) return -1; | ||
1088 | |||
1089 | return dwRva - getImageBase(); | ||
1090 | } | ||
1091 | |||
1092 | template<int x> | ||
1093 | typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::vaToOffset(VAR4_8 dwRva) const | ||
1094 | { | ||
1095 | return rvaToOffset(dwRva - getImageBase()); | ||
1096 | } | ||
1097 | |||
1098 | /** | ||
1099 | * Saves the PE header to a file. Note that this only saves the header information, if you have added sections | ||
1100 | * and want to save these to the file you have to call #PeLib::PeHeaderT<x>::saveSections too. This function also | ||
1101 | * does not verify if the PE header is correct. If you want to make sure that the current PE header is valid, | ||
1102 | * call #PeLib::PeHeaderT<x>::isValid and #PeLib::PeHeaderT<x>::makeValid first. | ||
1103 | * @param strFilename Filename of the file the header will be written to. | ||
1104 | * @param uiOffset File offset the header will be written to. | ||
1105 | **/ | ||
1106 | template<int x> | ||
1107 | int PeHeaderT<x>::write(std::string strFilename, unsigned int uiOffset) const | ||
1108 | { | ||
1109 | std::fstream ofFile(strFilename.c_str(), std::ios_base::in); | ||
1110 | |||
1111 | if (!ofFile) | ||
1112 | { | ||
1113 | ofFile.clear(); | ||
1114 | ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); | ||
1115 | } | ||
1116 | else | ||
1117 | { | ||
1118 | ofFile.close(); | ||
1119 | ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); | ||
1120 | } | ||
1121 | |||
1122 | if (!ofFile) | ||
1123 | { | ||
1124 | return ERROR_OPENING_FILE; | ||
1125 | } | ||
1126 | |||
1127 | ofFile.seekp(uiOffset, std::ios::beg); | ||
1128 | |||
1129 | std::vector<unsigned char> vBuffer; | ||
1130 | |||
1131 | rebuild(vBuffer); | ||
1132 | |||
1133 | ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size())); | ||
1134 | |||
1135 | ofFile.close(); | ||
1136 | |||
1137 | return NO_ERROR; | ||
1138 | } | ||
1139 | |||
1140 | |||
1141 | /** | ||
1142 | * Overwrites a section's data. | ||
1143 | * @param wSecnr Number of the section which will be overwritten. | ||
1144 | * @param strFilename Name of the file where the section will be written to. | ||
1145 | * @param wSecnr Number of the section that will be written. | ||
1146 | * @param vBuffer New data of the section. | ||
1147 | **/ | ||
1148 | template<int x> | ||
1149 | int PeHeaderT<x>::writeSectionData(const std::string& strFilename, word wSecnr, const std::vector<byte>& vBuffer) const | ||
1150 | { | ||
1151 | std::fstream ofFile(strFilename.c_str(), std::ios_base::in); | ||
1152 | |||
1153 | if (!ofFile) | ||
1154 | { | ||
1155 | ofFile.clear(); | ||
1156 | ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); | ||
1157 | } | ||
1158 | else | ||
1159 | { | ||
1160 | ofFile.close(); | ||
1161 | ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); | ||
1162 | } | ||
1163 | |||
1164 | if (!ofFile) | ||
1165 | { | ||
1166 | ofFile.clear(); | ||
1167 | |||
1168 | return ERROR_OPENING_FILE; | ||
1169 | } | ||
1170 | |||
1171 | ofFile.seekp(getPointerToRawData(wSecnr), std::ios::beg); | ||
1172 | |||
1173 | ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), std::min(static_cast<unsigned int>(vBuffer.size()), getSizeOfRawData(wSecnr))); | ||
1174 | |||
1175 | ofFile.close(); | ||
1176 | |||
1177 | return NO_ERROR; | ||
1178 | } | ||
1179 | |||
1180 | template<int x> | ||
1181 | int PeHeaderT<x>::writeSections(const std::string& strFilename) const | ||
1182 | { | ||
1183 | std::fstream ofFile(strFilename.c_str(), std::ios_base::in); | ||
1184 | |||
1185 | if (!ofFile) | ||
1186 | { | ||
1187 | ofFile.clear(); | ||
1188 | ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); | ||
1189 | } | ||
1190 | else | ||
1191 | { | ||
1192 | ofFile.close(); | ||
1193 | ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); | ||
1194 | } | ||
1195 | |||
1196 | if (!ofFile) | ||
1197 | { | ||
1198 | return ERROR_OPENING_FILE; | ||
1199 | } | ||
1200 | |||
1201 | unsigned int uiFilesize = fileSize(ofFile); | ||
1202 | |||
1203 | for (int i=0;i<calcNumberOfSections();i++) | ||
1204 | { | ||
1205 | if (uiFilesize < getPointerToRawData(i) + getSizeOfRawData(i)) | ||
1206 | { | ||
1207 | unsigned int uiToWrite = getPointerToRawData(i) + getSizeOfRawData(i) - uiFilesize; | ||
1208 | std::vector<char> vBuffer(uiToWrite); | ||
1209 | ofFile.seekp(0, std::ios::end); | ||
1210 | ofFile.write(&vBuffer[0], static_cast<unsigned int>(vBuffer.size())); | ||
1211 | uiFilesize = getPointerToRawData(i) + getSizeOfRawData(i); | ||
1212 | } | ||
1213 | } | ||
1214 | |||
1215 | ofFile.close(); | ||
1216 | |||
1217 | return NO_ERROR; | ||
1218 | } | ||
1219 | |||
1220 | /** | ||
1221 | * Returns the file's Nt signature. | ||
1222 | * @return The Nt signature value from the PE header. | ||
1223 | **/ | ||
1224 | template<int x> | ||
1225 | dword PeHeaderT<x>::getNtSignature() const | ||
1226 | { | ||
1227 | return m_inthHeader.Signature; | ||
1228 | } | ||
1229 | |||
1230 | /** | ||
1231 | * Returns the file's machine. | ||
1232 | * @return The Machine value from the PE header. | ||
1233 | **/ | ||
1234 | template<int x> | ||
1235 | word PeHeaderT<x>::getMachine() const | ||
1236 | { | ||
1237 | return m_inthHeader.FileHeader.Machine; | ||
1238 | } | ||
1239 | |||
1240 | |||
1241 | /** | ||
1242 | * Returns the file's number of sections as defined in the header. Note that this value can be different | ||
1243 | * from the number of defined sections (#see PeLib::PeHeaderT<x>::getNumberOfSections). | ||
1244 | * @return The NumberOfSections value from the PE header. | ||
1245 | **/ | ||
1246 | template<int x> | ||
1247 | word PeHeaderT<x>::getNumberOfSections() const | ||
1248 | { | ||
1249 | return m_inthHeader.FileHeader.NumberOfSections; | ||
1250 | } | ||
1251 | |||
1252 | /** | ||
1253 | * Returns the file's TimeDateStamp. | ||
1254 | * @return The TimeDateStamp value from the PE header. | ||
1255 | **/ | ||
1256 | template<int x> | ||
1257 | dword PeHeaderT<x>::getTimeDateStamp() const | ||
1258 | { | ||
1259 | return m_inthHeader.FileHeader.TimeDateStamp; | ||
1260 | } | ||
1261 | |||
1262 | /** | ||
1263 | * Returns the relative virtual address of the file's symbol table. | ||
1264 | * @return The PointerToSymbolTable value from the PE header. | ||
1265 | **/ | ||
1266 | template<int x> | ||
1267 | dword PeHeaderT<x>::getPointerToSymbolTable() const | ||
1268 | { | ||
1269 | return m_inthHeader.FileHeader.PointerToSymbolTable; | ||
1270 | } | ||
1271 | |||
1272 | /** | ||
1273 | * Returns the number of symbols of the file's symbol table. | ||
1274 | * @return The NumberOfSymbols value from the PE header. | ||
1275 | **/ | ||
1276 | template<int x> | ||
1277 | dword PeHeaderT<x>::getNumberOfSymbols() const | ||
1278 | { | ||
1279 | return m_inthHeader.FileHeader.NumberOfSymbols; | ||
1280 | } | ||
1281 | |||
1282 | /** | ||
1283 | * Returns the size of optional header of the file. | ||
1284 | * @return The SizeOfOptionalHeader value from the PE header. | ||
1285 | **/ | ||
1286 | template<int x> | ||
1287 | word PeHeaderT<x>::getSizeOfOptionalHeader() const | ||
1288 | { | ||
1289 | return m_inthHeader.FileHeader.SizeOfOptionalHeader; | ||
1290 | } | ||
1291 | |||
1292 | /** | ||
1293 | * @return The Characteristics value from the PE header. | ||
1294 | **/ | ||
1295 | template<int x> | ||
1296 | word PeHeaderT<x>::getCharacteristics() const | ||
1297 | { | ||
1298 | return m_inthHeader.FileHeader.Characteristics; | ||
1299 | } | ||
1300 | |||
1301 | /** | ||
1302 | * @return The Magic value from the PE header. | ||
1303 | **/ | ||
1304 | template<int x> | ||
1305 | word PeHeaderT<x>::getMagic() const | ||
1306 | { | ||
1307 | return m_inthHeader.OptionalHeader.Magic; | ||
1308 | } | ||
1309 | |||
1310 | /** | ||
1311 | * @return The MajorLinkerVersion value from the PE header. | ||
1312 | **/ | ||
1313 | template<int x> | ||
1314 | byte PeHeaderT<x>::getMajorLinkerVersion() const | ||
1315 | { | ||
1316 | return m_inthHeader.OptionalHeader.MajorLinkerVersion; | ||
1317 | } | ||
1318 | |||
1319 | /** | ||
1320 | * @return The MinorLinkerVersion value from the PE header. | ||
1321 | **/ | ||
1322 | template<int x> | ||
1323 | byte PeHeaderT<x>::getMinorLinkerVersion() const | ||
1324 | { | ||
1325 | return m_inthHeader.OptionalHeader.MinorLinkerVersion; | ||
1326 | } | ||
1327 | |||
1328 | /** | ||
1329 | * @return The SizeOfCode value from the PE header. | ||
1330 | **/ | ||
1331 | template<int x> | ||
1332 | dword PeHeaderT<x>::getSizeOfCode() const | ||
1333 | { | ||
1334 | return m_inthHeader.OptionalHeader.SizeOfCode; | ||
1335 | } | ||
1336 | |||
1337 | /** | ||
1338 | * @return The SizeOfInitializedData value from the PE header. | ||
1339 | **/ | ||
1340 | template<int x> | ||
1341 | dword PeHeaderT<x>::getSizeOfInitializedData() const | ||
1342 | { | ||
1343 | return m_inthHeader.OptionalHeader.SizeOfInitializedData; | ||
1344 | } | ||
1345 | |||
1346 | /** | ||
1347 | * @return The SizeOfUninitializedData value from the PE header. | ||
1348 | **/ | ||
1349 | template<int x> | ||
1350 | dword PeHeaderT<x>::getSizeOfUninitializedData() const | ||
1351 | { | ||
1352 | return m_inthHeader.OptionalHeader.SizeOfUninitializedData; | ||
1353 | } | ||
1354 | |||
1355 | /** | ||
1356 | * @return The AddressOfEntryPoint value from the PE header. | ||
1357 | **/ | ||
1358 | template<int x> | ||
1359 | dword PeHeaderT<x>::getAddressOfEntryPoint() const | ||
1360 | { | ||
1361 | return m_inthHeader.OptionalHeader.AddressOfEntryPoint; | ||
1362 | } | ||
1363 | |||
1364 | /** | ||
1365 | * @return The BaseOfCode value from the PE header. | ||
1366 | **/ | ||
1367 | template<int x> | ||
1368 | dword PeHeaderT<x>::getBaseOfCode() const | ||
1369 | { | ||
1370 | return m_inthHeader.OptionalHeader.BaseOfCode; | ||
1371 | } | ||
1372 | |||
1373 | /** | ||
1374 | * @return The ImageBase value from the PE header. | ||
1375 | **/ | ||
1376 | template<int x> | ||
1377 | typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getImageBase() const | ||
1378 | { | ||
1379 | return m_inthHeader.OptionalHeader.ImageBase; | ||
1380 | } | ||
1381 | |||
1382 | /** | ||
1383 | * @return The SectionAlignment value from the PE header. | ||
1384 | **/ | ||
1385 | template<int x> | ||
1386 | dword PeHeaderT<x>::getSectionAlignment() const | ||
1387 | { | ||
1388 | return m_inthHeader.OptionalHeader.SectionAlignment; | ||
1389 | } | ||
1390 | |||
1391 | /** | ||
1392 | * @return The FileAlignment value from the PE header. | ||
1393 | **/ | ||
1394 | template<int x> | ||
1395 | dword PeHeaderT<x>::getFileAlignment() const | ||
1396 | { | ||
1397 | return m_inthHeader.OptionalHeader.FileAlignment; | ||
1398 | } | ||
1399 | |||
1400 | /** | ||
1401 | * @return The MajorOperatingSystemVersion value from the PE header. | ||
1402 | **/ | ||
1403 | template<int x> | ||
1404 | word PeHeaderT<x>::getMajorOperatingSystemVersion() const | ||
1405 | { | ||
1406 | return m_inthHeader.OptionalHeader.MajorOperatingSystemVersion; | ||
1407 | } | ||
1408 | |||
1409 | /** | ||
1410 | * @return The MinorOperatingSystemVersion value from the PE header. | ||
1411 | **/ | ||
1412 | template<int x> | ||
1413 | word PeHeaderT<x>::getMinorOperatingSystemVersion() const | ||
1414 | { | ||
1415 | return m_inthHeader.OptionalHeader.MinorOperatingSystemVersion; | ||
1416 | } | ||
1417 | |||
1418 | /** | ||
1419 | * @return The MajorImageVersion value from the PE header. | ||
1420 | **/ | ||
1421 | template<int x> | ||
1422 | word PeHeaderT<x>::getMajorImageVersion() const | ||
1423 | { | ||
1424 | return m_inthHeader.OptionalHeader.MajorImageVersion; | ||
1425 | } | ||
1426 | |||
1427 | /** | ||
1428 | * @return The MinorImageVersion value from the PE header. | ||
1429 | **/ | ||
1430 | template<int x> | ||
1431 | word PeHeaderT<x>::getMinorImageVersion() const | ||
1432 | { | ||
1433 | return m_inthHeader.OptionalHeader.MinorImageVersion; | ||
1434 | } | ||
1435 | |||
1436 | /** | ||
1437 | * @return The MajorSubsystemVersion value from the PE header. | ||
1438 | **/ | ||
1439 | template<int x> | ||
1440 | word PeHeaderT<x>::getMajorSubsystemVersion() const | ||
1441 | { | ||
1442 | return m_inthHeader.OptionalHeader.MajorSubsystemVersion; | ||
1443 | } | ||
1444 | |||
1445 | /** | ||
1446 | * @return The MinorSubsystemVersion value from the PE header. | ||
1447 | **/ | ||
1448 | template<int x> | ||
1449 | word PeHeaderT<x>::getMinorSubsystemVersion() const | ||
1450 | { | ||
1451 | return m_inthHeader.OptionalHeader.MinorSubsystemVersion; | ||
1452 | } | ||
1453 | |||
1454 | /** | ||
1455 | * @return The WinVersionValue value from the PE header. | ||
1456 | **/ | ||
1457 | template<int x> | ||
1458 | dword PeHeaderT<x>::getWin32VersionValue() const | ||
1459 | { | ||
1460 | return m_inthHeader.OptionalHeader.Win32VersionValue; | ||
1461 | } | ||
1462 | |||
1463 | /** | ||
1464 | * @return The SizeOfImage value from the PE header. | ||
1465 | **/ | ||
1466 | template<int x> | ||
1467 | dword PeHeaderT<x>::getSizeOfImage() const | ||
1468 | { | ||
1469 | return m_inthHeader.OptionalHeader.SizeOfImage; | ||
1470 | } | ||
1471 | |||
1472 | /** | ||
1473 | * @return The SizeOfHeaders value from the PE header. | ||
1474 | **/ | ||
1475 | template<int x> | ||
1476 | dword PeHeaderT<x>::getSizeOfHeaders() const | ||
1477 | { | ||
1478 | return m_inthHeader.OptionalHeader.SizeOfHeaders; | ||
1479 | } | ||
1480 | |||
1481 | /** | ||
1482 | * @return The CheckSums value from the PE header. | ||
1483 | **/ | ||
1484 | template<int x> | ||
1485 | dword PeHeaderT<x>::getCheckSum() const | ||
1486 | { | ||
1487 | return m_inthHeader.OptionalHeader.CheckSum; | ||
1488 | } | ||
1489 | |||
1490 | /** | ||
1491 | * @return The Subsystem value from the PE header. | ||
1492 | **/ | ||
1493 | template<int x> | ||
1494 | word PeHeaderT<x>::getSubsystem() const | ||
1495 | { | ||
1496 | return m_inthHeader.OptionalHeader.Subsystem; | ||
1497 | } | ||
1498 | |||
1499 | /** | ||
1500 | * @return The DllCharacteristics value from the PE header. | ||
1501 | **/ | ||
1502 | template<int x> | ||
1503 | word PeHeaderT<x>::getDllCharacteristics() const | ||
1504 | { | ||
1505 | return m_inthHeader.OptionalHeader.DllCharacteristics; | ||
1506 | } | ||
1507 | |||
1508 | /** | ||
1509 | * @return The SizeOfStackReserve value from the PE header. | ||
1510 | **/ | ||
1511 | template<int x> | ||
1512 | typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getSizeOfStackReserve() const | ||
1513 | { | ||
1514 | return m_inthHeader.OptionalHeader.SizeOfStackReserve; | ||
1515 | } | ||
1516 | |||
1517 | /** | ||
1518 | * @return The SizeOfStackCommit value from the PE header. | ||
1519 | **/ | ||
1520 | template<int x> | ||
1521 | typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getSizeOfStackCommit() const | ||
1522 | { | ||
1523 | return m_inthHeader.OptionalHeader.SizeOfStackCommit; | ||
1524 | } | ||
1525 | |||
1526 | /** | ||
1527 | * @return The SizeOfHeapReserve value from the PE header. | ||
1528 | **/ | ||
1529 | template<int x> | ||
1530 | typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getSizeOfHeapReserve() const | ||
1531 | { | ||
1532 | return m_inthHeader.OptionalHeader.SizeOfHeapReserve; | ||
1533 | } | ||
1534 | |||
1535 | /** | ||
1536 | * @return The SizeOfHeapCommit value from the PE header. | ||
1537 | **/ | ||
1538 | template<int x> | ||
1539 | typename FieldSizes<x>::VAR4_8 PeHeaderT<x>::getSizeOfHeapCommit() const | ||
1540 | { | ||
1541 | return m_inthHeader.OptionalHeader.SizeOfHeapCommit; | ||
1542 | } | ||
1543 | |||
1544 | /** | ||
1545 | * @return The LoaderFlags value from the PE header. | ||
1546 | **/ | ||
1547 | template<int x> | ||
1548 | dword PeHeaderT<x>::getLoaderFlags() const | ||
1549 | { | ||
1550 | return m_inthHeader.OptionalHeader.LoaderFlags; | ||
1551 | } | ||
1552 | |||
1553 | /** | ||
1554 | * @return The NumberOfRvaAndSizes value from the PE header. | ||
1555 | **/ | ||
1556 | template<int x> | ||
1557 | dword PeHeaderT<x>::getNumberOfRvaAndSizes() const | ||
1558 | { | ||
1559 | return m_inthHeader.OptionalHeader.NumberOfRvaAndSizes; | ||
1560 | } | ||
1561 | |||
1562 | template<int x> | ||
1563 | dword PeHeaderT<x>::calcNumberOfRvaAndSizes() const | ||
1564 | { | ||
1565 | return static_cast<dword>(m_inthHeader.dataDirectories.size()); | ||
1566 | } | ||
1567 | |||
1568 | /** | ||
1569 | * Returns the relative virtual address of the current file's export directory. | ||
1570 | * @return The Rva of the Export directory. | ||
1571 | **/ | ||
1572 | template<int x> | ||
1573 | dword PeHeaderT<x>::getIddExportRva() const | ||
1574 | { | ||
1575 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; | ||
1576 | } | ||
1577 | |||
1578 | /** | ||
1579 | * Returns the size of the current file's export directory. | ||
1580 | * @return The sizeof the Export directory. | ||
1581 | **/ | ||
1582 | template<int x> | ||
1583 | dword PeHeaderT<x>::getIddExportSize() const | ||
1584 | { | ||
1585 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXPORT].Size; | ||
1586 | } | ||
1587 | |||
1588 | /** | ||
1589 | * Returns the relative virtual address of the current file's import directory. | ||
1590 | * @return The Rva of the Import directory. | ||
1591 | **/ | ||
1592 | template<int x> | ||
1593 | dword PeHeaderT<x>::getIddImportRva() const | ||
1594 | { | ||
1595 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress; | ||
1596 | } | ||
1597 | |||
1598 | /** | ||
1599 | * Returns the size of the current file's import directory. | ||
1600 | * @return The size of the Import directory. | ||
1601 | **/ | ||
1602 | template<int x> | ||
1603 | dword PeHeaderT<x>::getIddImportSize() const | ||
1604 | { | ||
1605 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IMPORT].Size; | ||
1606 | } | ||
1607 | |||
1608 | /** | ||
1609 | * Returns the relative virtual address of the current file's resource directory. | ||
1610 | * @return The Rva of the Resource directory. | ||
1611 | **/ | ||
1612 | template<int x> | ||
1613 | dword PeHeaderT<x>::getIddResourceRva() const | ||
1614 | { | ||
1615 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress; | ||
1616 | } | ||
1617 | |||
1618 | /** | ||
1619 | * Returns the size of the current file'resource resource directory. | ||
1620 | * @return The size of the Resource directory. | ||
1621 | **/ | ||
1622 | template<int x> | ||
1623 | dword PeHeaderT<x>::getIddResourceSize() const | ||
1624 | { | ||
1625 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE].Size; | ||
1626 | } | ||
1627 | |||
1628 | /** | ||
1629 | * Returns the relative virtual address of the current file's exception directory. | ||
1630 | * @return The Rva of the Exception directory. | ||
1631 | **/ | ||
1632 | template<int x> | ||
1633 | dword PeHeaderT<x>::getIddExceptionRva() const | ||
1634 | { | ||
1635 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXCEPTION].VirtualAddress; | ||
1636 | } | ||
1637 | |||
1638 | /** | ||
1639 | * Returns the size of the current file's exception directory. | ||
1640 | * @return The size of the Exception directory. | ||
1641 | **/ | ||
1642 | template<int x> | ||
1643 | dword PeHeaderT<x>::getIddExceptionSize() const | ||
1644 | { | ||
1645 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXCEPTION].Size; | ||
1646 | } | ||
1647 | |||
1648 | /** | ||
1649 | * Returns the relative virtual address of the current file's security directory. | ||
1650 | * @return The Rva of the Security directory. | ||
1651 | **/ | ||
1652 | template<int x> | ||
1653 | dword PeHeaderT<x>::getIddSecurityRva() const | ||
1654 | { | ||
1655 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress; | ||
1656 | } | ||
1657 | |||
1658 | /** | ||
1659 | * Returns the size of the current file's security directory. | ||
1660 | * @return The size of the Security directory. | ||
1661 | **/ | ||
1662 | template<int x> | ||
1663 | dword PeHeaderT<x>::getIddSecuritySize() const | ||
1664 | { | ||
1665 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY].Size; | ||
1666 | } | ||
1667 | |||
1668 | /** | ||
1669 | * Returns the relative virtual address of the current file's base reloc directory. | ||
1670 | * @return The Rva of the Base Reloc directory. | ||
1671 | **/ | ||
1672 | template<int x> | ||
1673 | dword PeHeaderT<x>::getIddBaseRelocRva() const | ||
1674 | { | ||
1675 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress; | ||
1676 | } | ||
1677 | |||
1678 | /** | ||
1679 | * Returns the size of the current file's base reloc directory. | ||
1680 | * @return The size of the Base Reloc directory. | ||
1681 | **/ | ||
1682 | template<int x> | ||
1683 | dword PeHeaderT<x>::getIddBaseRelocSize() const | ||
1684 | { | ||
1685 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size; | ||
1686 | } | ||
1687 | |||
1688 | /** | ||
1689 | * Returns the relative virtual address of the current file's debug directory. | ||
1690 | * @return The Rva of the Debug directory. | ||
1691 | **/ | ||
1692 | template<int x> | ||
1693 | dword PeHeaderT<x>::getIddDebugRva() const | ||
1694 | { | ||
1695 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress; | ||
1696 | } | ||
1697 | |||
1698 | /** | ||
1699 | * Returns the size of the current file's debug directory. | ||
1700 | * @return The size of the Debug directory. | ||
1701 | **/ | ||
1702 | template<int x> | ||
1703 | dword PeHeaderT<x>::getIddDebugSize() const | ||
1704 | { | ||
1705 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DEBUG].Size; | ||
1706 | } | ||
1707 | |||
1708 | /** | ||
1709 | * Returns the relative virtual address of the current file's Architecture directory. | ||
1710 | * @return The Rva of the Architecture directory. | ||
1711 | **/ | ||
1712 | template<int x> | ||
1713 | dword PeHeaderT<x>::getIddArchitectureRva() const | ||
1714 | { | ||
1715 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_ARCHITECTURE].VirtualAddress; | ||
1716 | } | ||
1717 | |||
1718 | /** | ||
1719 | * Returns the size of the current file's Architecture directory. | ||
1720 | * @return The size of the Architecture directory. | ||
1721 | **/ | ||
1722 | template<int x> | ||
1723 | dword PeHeaderT<x>::getIddArchitectureSize() const | ||
1724 | { | ||
1725 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_ARCHITECTURE].Size; | ||
1726 | } | ||
1727 | |||
1728 | /** | ||
1729 | * Returns the relative virtual address of the current file's global ptr directory. | ||
1730 | * @return The Rva of the GlobalPtr directory. | ||
1731 | **/ | ||
1732 | template<int x> | ||
1733 | dword PeHeaderT<x>::getIddGlobalPtrRva() const | ||
1734 | { | ||
1735 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_GLOBALPTR].VirtualAddress; | ||
1736 | } | ||
1737 | |||
1738 | /** | ||
1739 | * Returns the size of the current file's global ptr directory. | ||
1740 | * @return The size of the GlobalPtr directory. | ||
1741 | **/ | ||
1742 | template<int x> | ||
1743 | dword PeHeaderT<x>::getIddGlobalPtrSize() const | ||
1744 | { | ||
1745 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_GLOBALPTR].Size; | ||
1746 | } | ||
1747 | |||
1748 | /** | ||
1749 | * Returns the relative virtual address of the current file's TLS directory. | ||
1750 | * @return The Rva of the Tls directory. | ||
1751 | **/ | ||
1752 | template<int x> | ||
1753 | dword PeHeaderT<x>::getIddTlsRva() const | ||
1754 | { | ||
1755 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress; | ||
1756 | } | ||
1757 | |||
1758 | /** | ||
1759 | * Returns the size of the current file's TLS directory. | ||
1760 | * @return The size of the Tls directory. | ||
1761 | **/ | ||
1762 | template<int x> | ||
1763 | dword PeHeaderT<x>::getIddTlsSize() const | ||
1764 | { | ||
1765 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_TLS].Size; | ||
1766 | } | ||
1767 | |||
1768 | /** | ||
1769 | * Returns the relative virtual address of the current file's load config directory. | ||
1770 | * @return The Rva of the LoadConfig directory. | ||
1771 | **/ | ||
1772 | template<int x> | ||
1773 | dword PeHeaderT<x>::getIddLoadConfigRva() const | ||
1774 | { | ||
1775 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].VirtualAddress; | ||
1776 | } | ||
1777 | |||
1778 | /** | ||
1779 | * Returns the size of the current file's load config directory. | ||
1780 | * @return The size of the LoadConfig directory. | ||
1781 | **/ | ||
1782 | template<int x> | ||
1783 | dword PeHeaderT<x>::getIddLoadConfigSize() const | ||
1784 | { | ||
1785 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].Size; | ||
1786 | } | ||
1787 | |||
1788 | /** | ||
1789 | * Returns the relative virtual address of the current file's bound import directory. | ||
1790 | * @return The Rva of the BoundImport directory. | ||
1791 | **/ | ||
1792 | template<int x> | ||
1793 | dword PeHeaderT<x>::getIddBoundImportRva() const | ||
1794 | { | ||
1795 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].VirtualAddress; | ||
1796 | } | ||
1797 | |||
1798 | /** | ||
1799 | * Returns the size of the current file's bound import directory. | ||
1800 | * @return The size of the BoundImport directory. | ||
1801 | **/ | ||
1802 | template<int x> | ||
1803 | dword PeHeaderT<x>::getIddBoundImportSize() const | ||
1804 | { | ||
1805 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].Size; | ||
1806 | } | ||
1807 | |||
1808 | /** | ||
1809 | * Returns the relative virtual address of the current file's IAT directory. | ||
1810 | * @return The Rva of the IAT directory. | ||
1811 | **/ | ||
1812 | template<int x> | ||
1813 | dword PeHeaderT<x>::getIddIatRva() const | ||
1814 | { | ||
1815 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress; | ||
1816 | } | ||
1817 | |||
1818 | /** | ||
1819 | * Returns the size of the current file's IAT directory. | ||
1820 | * @return The size of the IAT directory. | ||
1821 | **/ | ||
1822 | template<int x> | ||
1823 | dword PeHeaderT<x>::getIddIatSize() const | ||
1824 | { | ||
1825 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IAT].Size; | ||
1826 | } | ||
1827 | |||
1828 | /** | ||
1829 | * Returns the relative virtual address of the current file's Delay Import directory. | ||
1830 | * @return The Rva of the DelayImport directory. | ||
1831 | **/ | ||
1832 | template<int x> | ||
1833 | dword PeHeaderT<x>::getIddDelayImportRva() const | ||
1834 | { | ||
1835 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress; | ||
1836 | } | ||
1837 | |||
1838 | /** | ||
1839 | * Returns the size of the current file's Delay Import directory. | ||
1840 | * @return The size of the DelayImport directory. | ||
1841 | **/ | ||
1842 | template<int x> | ||
1843 | dword PeHeaderT<x>::getIddDelayImportSize() const | ||
1844 | { | ||
1845 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].Size; | ||
1846 | } | ||
1847 | |||
1848 | /** | ||
1849 | * Returns the relative virtual address of the current file's COM Descriptor directory. | ||
1850 | * @return The Rva of the COM Descriptor directory. | ||
1851 | **/ | ||
1852 | template<int x> | ||
1853 | dword PeHeaderT<x>::getIddComHeaderRva() const | ||
1854 | { | ||
1855 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress; | ||
1856 | } | ||
1857 | |||
1858 | /** | ||
1859 | * Returns the size of the current file's COM Descriptor directory. | ||
1860 | * @return The Rva of the COM Descriptor directory. | ||
1861 | **/ | ||
1862 | template<int x> | ||
1863 | dword PeHeaderT<x>::getIddComHeaderSize() const | ||
1864 | { | ||
1865 | return m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size; | ||
1866 | } | ||
1867 | |||
1868 | /** | ||
1869 | * Returns the relative virtual address of an image directory. | ||
1870 | * @param dwDirectory The identifier of an image directory. | ||
1871 | * @return The Rva of the image directory. | ||
1872 | **/ | ||
1873 | template<int x> | ||
1874 | dword PeHeaderT<x>::getImageDataDirectoryRva(dword dwDirectory) const | ||
1875 | { | ||
1876 | return m_inthHeader.dataDirectories[dwDirectory].VirtualAddress; | ||
1877 | } | ||
1878 | |||
1879 | template<int x> | ||
1880 | void PeHeaderT<x>::setImageDataDirectoryRva(dword dwDirectory, dword value) | ||
1881 | { | ||
1882 | m_inthHeader.dataDirectories[dwDirectory].VirtualAddress = value; | ||
1883 | } | ||
1884 | |||
1885 | /** | ||
1886 | * Returns the size of an image directory. | ||
1887 | * @param dwDirectory The identifier of an image directory. | ||
1888 | * @return The size of the image directory. | ||
1889 | **/ | ||
1890 | template<int x> | ||
1891 | dword PeHeaderT<x>::getImageDataDirectorySize(dword dwDirectory) const | ||
1892 | { | ||
1893 | return m_inthHeader.dataDirectories[dwDirectory].Size; | ||
1894 | } | ||
1895 | |||
1896 | template<int x> | ||
1897 | void PeHeaderT<x>::setImageDataDirectorySize(dword dwDirectory, dword value) | ||
1898 | { | ||
1899 | m_inthHeader.dataDirectories[dwDirectory].Size = value; | ||
1900 | } | ||
1901 | |||
1902 | /** | ||
1903 | * Returns the name of the section which is specified by the parameter wSectionnr. | ||
1904 | * @param wSectionnr Index of the section. | ||
1905 | * @return The name of the section. | ||
1906 | **/ | ||
1907 | template<int x> | ||
1908 | std::string PeHeaderT<x>::getSectionName(word wSectionnr) const | ||
1909 | { | ||
1910 | std::string sectionName = ""; | ||
1911 | |||
1912 | for (unsigned int i=0;i<sizeof(m_vIsh[wSectionnr].Name);i++) | ||
1913 | { | ||
1914 | if (m_vIsh[wSectionnr].Name[i]) sectionName += m_vIsh[wSectionnr].Name[i]; | ||
1915 | } | ||
1916 | |||
1917 | return sectionName; | ||
1918 | } | ||
1919 | |||
1920 | /** | ||
1921 | * Returns the virtual size of the section which is specified by the parameter wSectionnr. | ||
1922 | * @param wSectionnr Index of the section. | ||
1923 | * @return The virtual size of the section. | ||
1924 | **/ | ||
1925 | template<int x> | ||
1926 | dword PeHeaderT<x>::getVirtualSize(word wSectionnr) const | ||
1927 | { | ||
1928 | return m_vIsh[wSectionnr].VirtualSize; | ||
1929 | } | ||
1930 | |||
1931 | /** | ||
1932 | * Returns the relative virtual address of the section which is specified by the parameter wSectionnr. | ||
1933 | * @param wSectionnr Index of the section. | ||
1934 | * @return The Rva of the section. | ||
1935 | **/ | ||
1936 | template<int x> | ||
1937 | dword PeHeaderT<x>::getVirtualAddress(word wSectionnr) const | ||
1938 | { | ||
1939 | return m_vIsh[wSectionnr].VirtualAddress; | ||
1940 | } | ||
1941 | |||
1942 | /** | ||
1943 | * Returns the size of raw data of the section which is specified by the parameter wSectionnr. | ||
1944 | * @param wSectionnr Index of the section. | ||
1945 | * @return The size of raw data of the section. | ||
1946 | **/ | ||
1947 | template<int x> | ||
1948 | dword PeHeaderT<x>::getSizeOfRawData(word wSectionnr) const | ||
1949 | { | ||
1950 | return m_vIsh[wSectionnr].SizeOfRawData; | ||
1951 | } | ||
1952 | |||
1953 | /** | ||
1954 | * Returns the file offset of the section which is specified by the parameter wSectionnr. | ||
1955 | * @param wSectionnr Index of the section. | ||
1956 | * @return The file offset of the section. | ||
1957 | **/ | ||
1958 | template<int x> | ||
1959 | dword PeHeaderT<x>::getPointerToRawData(word wSectionnr) const | ||
1960 | { | ||
1961 | return m_vIsh[wSectionnr].PointerToRawData; | ||
1962 | } | ||
1963 | |||
1964 | /** | ||
1965 | * Returns the pointer to relocations of the section which is specified by the parameter wSectionnr. | ||
1966 | * @param wSectionnr Index of the section. | ||
1967 | * @return The pointer to relocations of the section. | ||
1968 | **/ | ||
1969 | template<int x> | ||
1970 | dword PeHeaderT<x>::getPointerToRelocations(word wSectionnr) const | ||
1971 | { | ||
1972 | return m_vIsh[wSectionnr].PointerToRelocations; | ||
1973 | } | ||
1974 | |||
1975 | /** | ||
1976 | * Returns the poiner to line numbers of the section which is specified by the parameter wSectionnr. | ||
1977 | * @param wSectionnr Index of the section. | ||
1978 | * @return The pointer to line numbers of the section. | ||
1979 | **/ | ||
1980 | template<int x> | ||
1981 | dword PeHeaderT<x>::getPointerToLinenumbers(word wSectionnr) const | ||
1982 | { | ||
1983 | return m_vIsh[wSectionnr].PointerToLinenumbers; | ||
1984 | } | ||
1985 | |||
1986 | /** | ||
1987 | * Returns the number of relocations of the section which is specified by the parameter wSectionnr. | ||
1988 | * @param wSectionnr Index of the section. | ||
1989 | * @return The number of relocations of the section. | ||
1990 | **/ | ||
1991 | template<int x> | ||
1992 | dword PeHeaderT<x>::getNumberOfRelocations(word wSectionnr) const | ||
1993 | { | ||
1994 | return m_vIsh[wSectionnr].NumberOfRelocations; | ||
1995 | } | ||
1996 | |||
1997 | /** | ||
1998 | * Returns the number of line numbers of the section which is specified by the parameter wSectionnr. | ||
1999 | * @param wSectionnr Index of the section. | ||
2000 | * @return The number of line numbers of the section. | ||
2001 | **/ | ||
2002 | template<int x> | ||
2003 | dword PeHeaderT<x>::getNumberOfLinenumbers(word wSectionnr) const | ||
2004 | { | ||
2005 | return m_vIsh[wSectionnr].NumberOfLinenumbers; | ||
2006 | } | ||
2007 | |||
2008 | /** | ||
2009 | * Returns the characteristics of the section which is specified by the parameter wSectionnr. | ||
2010 | * @param wSectionnr Index of the section. | ||
2011 | * @return The characteristics of the section. | ||
2012 | **/ | ||
2013 | template<int x> | ||
2014 | dword PeHeaderT<x>::getCharacteristics(word wSectionnr) const | ||
2015 | { | ||
2016 | return m_vIsh[wSectionnr].Characteristics; | ||
2017 | } | ||
2018 | |||
2019 | /** | ||
2020 | * Changes the file's Nt signature. | ||
2021 | * @param dwValue New value. | ||
2022 | **/ | ||
2023 | template<int x> | ||
2024 | void PeHeaderT<x>::setNtSignature(dword dwValue) | ||
2025 | { | ||
2026 | m_inthHeader.Signature = dwValue; | ||
2027 | } | ||
2028 | |||
2029 | /** | ||
2030 | * Changes the file's Machine. | ||
2031 | * @param wValue New value. | ||
2032 | **/ | ||
2033 | template<int x> | ||
2034 | void PeHeaderT<x>::setMachine(word wValue) | ||
2035 | { | ||
2036 | m_inthHeader.FileHeader.Machine = wValue; | ||
2037 | } | ||
2038 | |||
2039 | /** | ||
2040 | * Changes the number of sections. | ||
2041 | * @param wValue New value. | ||
2042 | **/ | ||
2043 | template<int x> | ||
2044 | void PeHeaderT<x>::setNumberOfSections(word wValue) | ||
2045 | { | ||
2046 | m_inthHeader.FileHeader.NumberOfSections = wValue; | ||
2047 | } | ||
2048 | |||
2049 | /** | ||
2050 | * Changes the file's TimeDateStamp. | ||
2051 | * @param dwValue New value. | ||
2052 | **/ | ||
2053 | template<int x> | ||
2054 | void PeHeaderT<x>::setTimeDateStamp(dword dwValue) | ||
2055 | { | ||
2056 | m_inthHeader.FileHeader.TimeDateStamp = dwValue; | ||
2057 | } | ||
2058 | |||
2059 | /** | ||
2060 | * Changes the file's PointerToSymbolTable. | ||
2061 | * @param dwValue New value. | ||
2062 | **/ | ||
2063 | template<int x> | ||
2064 | void PeHeaderT<x>::setPointerToSymbolTable(dword dwValue) | ||
2065 | { | ||
2066 | m_inthHeader.FileHeader.PointerToSymbolTable = dwValue; | ||
2067 | } | ||
2068 | |||
2069 | /** | ||
2070 | * Changes the file's NumberOfSymbols. | ||
2071 | * @param dwValue New value. | ||
2072 | **/ | ||
2073 | template<int x> | ||
2074 | void PeHeaderT<x>::setNumberOfSymbols(dword dwValue) | ||
2075 | { | ||
2076 | m_inthHeader.FileHeader.NumberOfSymbols = dwValue; | ||
2077 | } | ||
2078 | |||
2079 | /** | ||
2080 | * Changes the file's SizeOfOptionalHeader. | ||
2081 | * @param wValue New value. | ||
2082 | **/ | ||
2083 | template<int x> | ||
2084 | void PeHeaderT<x>::setSizeOfOptionalHeader(word wValue) | ||
2085 | { | ||
2086 | m_inthHeader.FileHeader.SizeOfOptionalHeader = wValue; | ||
2087 | } | ||
2088 | |||
2089 | /** | ||
2090 | * Changes the file's Characteristics. | ||
2091 | * @param wValue New value. | ||
2092 | **/ | ||
2093 | template<int x> | ||
2094 | void PeHeaderT<x>::setCharacteristics(word wValue) | ||
2095 | { | ||
2096 | m_inthHeader.FileHeader.Characteristics = wValue; | ||
2097 | } | ||
2098 | |||
2099 | /** | ||
2100 | * Changes the file's Magic. | ||
2101 | * @param wValue New value. | ||
2102 | **/ | ||
2103 | template<int x> | ||
2104 | void PeHeaderT<x>::setMagic(word wValue) | ||
2105 | { | ||
2106 | m_inthHeader.OptionalHeader.Magic = wValue; | ||
2107 | } | ||
2108 | |||
2109 | /** | ||
2110 | * Changes the file's MajorLinkerVersion. | ||
2111 | * @param bValue New value. | ||
2112 | **/ | ||
2113 | template<int x> | ||
2114 | void PeHeaderT<x>::setMajorLinkerVersion(byte bValue) | ||
2115 | { | ||
2116 | m_inthHeader.OptionalHeader.MajorLinkerVersion = bValue; | ||
2117 | } | ||
2118 | |||
2119 | /** | ||
2120 | * Changes the file's MinorLinkerVersion. | ||
2121 | * @param bValue New value. | ||
2122 | **/ | ||
2123 | template<int x> | ||
2124 | void PeHeaderT<x>::setMinorLinkerVersion(byte bValue) | ||
2125 | { | ||
2126 | m_inthHeader.OptionalHeader.MinorLinkerVersion = bValue; | ||
2127 | } | ||
2128 | |||
2129 | /** | ||
2130 | * Changes the file's SizeOfCode. | ||
2131 | * @param dwValue New value. | ||
2132 | **/ | ||
2133 | template<int x> | ||
2134 | void PeHeaderT<x>::setSizeOfCode(dword dwValue) | ||
2135 | { | ||
2136 | m_inthHeader.OptionalHeader.SizeOfCode = dwValue; | ||
2137 | } | ||
2138 | |||
2139 | /** | ||
2140 | * Changes the file's SizeOfInitializedData. | ||
2141 | * @param dwValue New value. | ||
2142 | **/ | ||
2143 | template<int x> | ||
2144 | void PeHeaderT<x>::setSizeOfInitializedData(dword dwValue) | ||
2145 | { | ||
2146 | m_inthHeader.OptionalHeader.SizeOfInitializedData = dwValue; | ||
2147 | } | ||
2148 | |||
2149 | /** | ||
2150 | * Changes the file's SizeOfUninitializedData. | ||
2151 | * @param dwValue New value. | ||
2152 | **/ | ||
2153 | template<int x> | ||
2154 | void PeHeaderT<x>::setSizeOfUninitializedData(dword dwValue) | ||
2155 | { | ||
2156 | m_inthHeader.OptionalHeader.SizeOfUninitializedData = dwValue; | ||
2157 | } | ||
2158 | |||
2159 | /** | ||
2160 | * Changes the file's AddressOfEntryPoint. | ||
2161 | * @param dwValue New value. | ||
2162 | **/ | ||
2163 | template<int x> | ||
2164 | void PeHeaderT<x>::setAddressOfEntryPoint(dword dwValue) | ||
2165 | { | ||
2166 | m_inthHeader.OptionalHeader.AddressOfEntryPoint = dwValue; | ||
2167 | } | ||
2168 | |||
2169 | /** | ||
2170 | * Changes the file's BaseOfCode. | ||
2171 | * @param dwValue New value. | ||
2172 | **/ | ||
2173 | template<int x> | ||
2174 | void PeHeaderT<x>::setBaseOfCode(dword dwValue) | ||
2175 | { | ||
2176 | m_inthHeader.OptionalHeader.BaseOfCode = dwValue; | ||
2177 | } | ||
2178 | |||
2179 | /** | ||
2180 | * Changes the file's ImageBase. | ||
2181 | * @param dwValue New value. | ||
2182 | **/ | ||
2183 | template<int x> | ||
2184 | void PeHeaderT<x>::setImageBase(typename FieldSizes<x>::VAR4_8 dwValue) | ||
2185 | { | ||
2186 | m_inthHeader.OptionalHeader.ImageBase = dwValue; | ||
2187 | } | ||
2188 | |||
2189 | /** | ||
2190 | * Changes the file's SectionAlignment. | ||
2191 | * @param dwValue New value. | ||
2192 | **/ | ||
2193 | template<int x> | ||
2194 | void PeHeaderT<x>::setSectionAlignment(dword dwValue) | ||
2195 | { | ||
2196 | m_inthHeader.OptionalHeader.SectionAlignment = dwValue; | ||
2197 | } | ||
2198 | |||
2199 | /** | ||
2200 | * Changes the file's FileAlignment. | ||
2201 | * @param dwValue New value. | ||
2202 | **/ | ||
2203 | template<int x> | ||
2204 | void PeHeaderT<x>::setFileAlignment(dword dwValue) | ||
2205 | { | ||
2206 | m_inthHeader.OptionalHeader.FileAlignment = dwValue; | ||
2207 | } | ||
2208 | |||
2209 | /** | ||
2210 | * Changes the file's MajorOperatingSystemVersion. | ||
2211 | * @param wValue New value. | ||
2212 | **/ | ||
2213 | template<int x> | ||
2214 | void PeHeaderT<x>::setMajorOperatingSystemVersion(word wValue) | ||
2215 | { | ||
2216 | m_inthHeader.OptionalHeader.MajorOperatingSystemVersion = wValue; | ||
2217 | } | ||
2218 | |||
2219 | /** | ||
2220 | * Changes the file's MinorOperatingSystemVersion. | ||
2221 | * @param wValue New value. | ||
2222 | **/ | ||
2223 | template<int x> | ||
2224 | void PeHeaderT<x>::setMinorOperatingSystemVersion(word wValue) | ||
2225 | { | ||
2226 | m_inthHeader.OptionalHeader.MinorOperatingSystemVersion = wValue; | ||
2227 | } | ||
2228 | |||
2229 | /** | ||
2230 | * Changes the file's MajorImageVersion. | ||
2231 | * @param wValue New value. | ||
2232 | **/ | ||
2233 | template<int x> | ||
2234 | void PeHeaderT<x>::setMajorImageVersion(word wValue) | ||
2235 | { | ||
2236 | m_inthHeader.OptionalHeader.MajorImageVersion = wValue; | ||
2237 | } | ||
2238 | |||
2239 | /** | ||
2240 | * Changes the file's MinorImageVersion. | ||
2241 | * @param wValue New value. | ||
2242 | **/ | ||
2243 | template<int x> | ||
2244 | void PeHeaderT<x>::setMinorImageVersion(word wValue) | ||
2245 | { | ||
2246 | m_inthHeader.OptionalHeader.MinorImageVersion = wValue; | ||
2247 | } | ||
2248 | |||
2249 | /** | ||
2250 | * Changes the file's MajorSubsystemVersion. | ||
2251 | * @param wValue New value. | ||
2252 | **/ | ||
2253 | template<int x> | ||
2254 | void PeHeaderT<x>::setMajorSubsystemVersion(word wValue) | ||
2255 | { | ||
2256 | m_inthHeader.OptionalHeader.MajorSubsystemVersion = wValue; | ||
2257 | } | ||
2258 | |||
2259 | /** | ||
2260 | * Changes the file's MinorSubsystemVersion. | ||
2261 | * @param wValue New value. | ||
2262 | **/ | ||
2263 | template<int x> | ||
2264 | void PeHeaderT<x>::setMinorSubsystemVersion(word wValue) | ||
2265 | { | ||
2266 | m_inthHeader.OptionalHeader.MinorSubsystemVersion = wValue; | ||
2267 | } | ||
2268 | |||
2269 | /** | ||
2270 | * Changes the file's Win32VersionValue. | ||
2271 | * @param dwValue New value. | ||
2272 | **/ | ||
2273 | template<int x> | ||
2274 | void PeHeaderT<x>::setWin32VersionValue(dword dwValue) | ||
2275 | { | ||
2276 | m_inthHeader.OptionalHeader.Win32VersionValue = dwValue; | ||
2277 | } | ||
2278 | |||
2279 | /** | ||
2280 | * Changes the file's SizeOfImage. | ||
2281 | * @param dwValue New value. | ||
2282 | **/ | ||
2283 | template<int x> | ||
2284 | void PeHeaderT<x>::setSizeOfImage(dword dwValue) | ||
2285 | { | ||
2286 | m_inthHeader.OptionalHeader.SizeOfImage = dwValue; | ||
2287 | } | ||
2288 | |||
2289 | /** | ||
2290 | * Changes the file's SizeOfHeaders. | ||
2291 | * @param dwValue New value. | ||
2292 | **/ | ||
2293 | template<int x> | ||
2294 | void PeHeaderT<x>::setSizeOfHeaders(dword dwValue) | ||
2295 | { | ||
2296 | m_inthHeader.OptionalHeader.SizeOfHeaders = dwValue; | ||
2297 | } | ||
2298 | |||
2299 | /** | ||
2300 | * Changes the file's CheckSum. | ||
2301 | * @param dwValue New value. | ||
2302 | **/ | ||
2303 | template<int x> | ||
2304 | void PeHeaderT<x>::setCheckSum(dword dwValue) | ||
2305 | { | ||
2306 | m_inthHeader.OptionalHeader.CheckSum = dwValue; | ||
2307 | } | ||
2308 | |||
2309 | /** | ||
2310 | * Changes the file's Subsystem. | ||
2311 | * @param wValue New value. | ||
2312 | **/ | ||
2313 | template<int x> | ||
2314 | void PeHeaderT<x>::setSubsystem(word wValue) | ||
2315 | { | ||
2316 | m_inthHeader.OptionalHeader.Subsystem = wValue; | ||
2317 | } | ||
2318 | |||
2319 | /** | ||
2320 | * Changes the file's DllCharacteristics. | ||
2321 | * @param wValue New value. | ||
2322 | **/ | ||
2323 | template<int x> | ||
2324 | void PeHeaderT<x>::setDllCharacteristics(word wValue) | ||
2325 | { | ||
2326 | m_inthHeader.OptionalHeader.DllCharacteristics = wValue; | ||
2327 | } | ||
2328 | |||
2329 | /** | ||
2330 | * Changes the file's SizeOfStackReserve. | ||
2331 | * @param dwValue New value. | ||
2332 | **/ | ||
2333 | template<int x> | ||
2334 | void PeHeaderT<x>::setSizeOfStackReserve(typename FieldSizes<x>::VAR4_8 dwValue) | ||
2335 | { | ||
2336 | m_inthHeader.OptionalHeader.SizeOfStackReserve = dwValue; | ||
2337 | } | ||
2338 | |||
2339 | /** | ||
2340 | * Changes the file's SizeOfStackCommit. | ||
2341 | * @param dwValue New value. | ||
2342 | **/ | ||
2343 | template<int x> | ||
2344 | void PeHeaderT<x>::setSizeOfStackCommit(typename FieldSizes<x>::VAR4_8 dwValue) | ||
2345 | { | ||
2346 | m_inthHeader.OptionalHeader.SizeOfStackCommit = dwValue; | ||
2347 | } | ||
2348 | |||
2349 | /** | ||
2350 | * Changes the file's SizeOfHeapReserve. | ||
2351 | * @param dwValue New value. | ||
2352 | **/ | ||
2353 | template<int x> | ||
2354 | void PeHeaderT<x>::setSizeOfHeapReserve(typename FieldSizes<x>::VAR4_8 dwValue) | ||
2355 | { | ||
2356 | m_inthHeader.OptionalHeader.SizeOfHeapReserve = dwValue; | ||
2357 | } | ||
2358 | |||
2359 | /** | ||
2360 | * Changes the file's SizeOfHeapCommit. | ||
2361 | * @param dwValue New value. | ||
2362 | **/ | ||
2363 | template<int x> | ||
2364 | void PeHeaderT<x>::setSizeOfHeapCommit(typename FieldSizes<x>::VAR4_8 dwValue) | ||
2365 | { | ||
2366 | m_inthHeader.OptionalHeader.SizeOfHeapCommit = dwValue; | ||
2367 | } | ||
2368 | |||
2369 | /** | ||
2370 | * Changes the file's LoaderFlags. | ||
2371 | * @param dwValue New value. | ||
2372 | **/ | ||
2373 | template<int x> | ||
2374 | void PeHeaderT<x>::setLoaderFlags(dword dwValue) | ||
2375 | { | ||
2376 | m_inthHeader.OptionalHeader.LoaderFlags = dwValue; | ||
2377 | } | ||
2378 | |||
2379 | /** | ||
2380 | * Changes the file's NumberOfRvaAndSizes. | ||
2381 | * @param dwValue New value. | ||
2382 | **/ | ||
2383 | template<int x> | ||
2384 | void PeHeaderT<x>::setNumberOfRvaAndSizes(dword dwValue) | ||
2385 | { | ||
2386 | m_inthHeader.OptionalHeader.NumberOfRvaAndSizes = dwValue; | ||
2387 | } | ||
2388 | |||
2389 | template<int x> | ||
2390 | void PeHeaderT<x>::setIddDebugRva(dword dwValue) | ||
2391 | { | ||
2392 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress = dwValue; | ||
2393 | } | ||
2394 | |||
2395 | template<int x> | ||
2396 | void PeHeaderT<x>::setIddDebugSize(dword dwValue) | ||
2397 | { | ||
2398 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DEBUG].Size = dwValue; | ||
2399 | } | ||
2400 | |||
2401 | template<int x> | ||
2402 | void PeHeaderT<x>::setIddDelayImportRva(dword dwValue) | ||
2403 | { | ||
2404 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress = dwValue; | ||
2405 | } | ||
2406 | |||
2407 | template<int x> | ||
2408 | void PeHeaderT<x>::setIddDelayImportSize(dword dwValue) | ||
2409 | { | ||
2410 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].Size = dwValue; | ||
2411 | } | ||
2412 | |||
2413 | template<int x> | ||
2414 | void PeHeaderT<x>::setIddExceptionRva(dword dwValue) | ||
2415 | { | ||
2416 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXCEPTION].VirtualAddress = dwValue; | ||
2417 | } | ||
2418 | |||
2419 | template<int x> | ||
2420 | void PeHeaderT<x>::setIddExceptionSize(dword dwValue) | ||
2421 | { | ||
2422 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXCEPTION].Size = dwValue; | ||
2423 | } | ||
2424 | |||
2425 | template<int x> | ||
2426 | void PeHeaderT<x>::setIddGlobalPtrRva(dword dwValue) | ||
2427 | { | ||
2428 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_GLOBALPTR].VirtualAddress = dwValue; | ||
2429 | } | ||
2430 | |||
2431 | template<int x> | ||
2432 | void PeHeaderT<x>::setIddGlobalPtrSize(dword dwValue) | ||
2433 | { | ||
2434 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_GLOBALPTR].Size = dwValue; | ||
2435 | } | ||
2436 | |||
2437 | template<int x> | ||
2438 | void PeHeaderT<x>::setIddIatRva(dword dwValue) | ||
2439 | { | ||
2440 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress = dwValue; | ||
2441 | } | ||
2442 | |||
2443 | template<int x> | ||
2444 | void PeHeaderT<x>::setIddIatSize(dword dwValue) | ||
2445 | { | ||
2446 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IAT].Size = dwValue; | ||
2447 | } | ||
2448 | |||
2449 | template<int x> | ||
2450 | void PeHeaderT<x>::setIddLoadConfigRva(dword dwValue) | ||
2451 | { | ||
2452 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].VirtualAddress = dwValue; | ||
2453 | } | ||
2454 | |||
2455 | template<int x> | ||
2456 | void PeHeaderT<x>::setIddLoadConfigSize(dword dwValue) | ||
2457 | { | ||
2458 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].Size = dwValue; | ||
2459 | } | ||
2460 | |||
2461 | template<int x> | ||
2462 | void PeHeaderT<x>::setIddResourceRva(dword dwValue) | ||
2463 | { | ||
2464 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress = dwValue; | ||
2465 | } | ||
2466 | |||
2467 | template<int x> | ||
2468 | void PeHeaderT<x>::setIddResourceSize(dword dwValue) | ||
2469 | { | ||
2470 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE].Size = dwValue; | ||
2471 | } | ||
2472 | |||
2473 | template<int x> | ||
2474 | void PeHeaderT<x>::setIddSecurityRva(dword dwValue) | ||
2475 | { | ||
2476 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress = dwValue; | ||
2477 | } | ||
2478 | |||
2479 | template<int x> | ||
2480 | void PeHeaderT<x>::setIddSecuritySize(dword dwValue) | ||
2481 | { | ||
2482 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY].Size = dwValue; | ||
2483 | } | ||
2484 | |||
2485 | template<int x> | ||
2486 | void PeHeaderT<x>::setIddTlsRva(dword dwValue) | ||
2487 | { | ||
2488 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress = dwValue; | ||
2489 | } | ||
2490 | |||
2491 | template<int x> | ||
2492 | void PeHeaderT<x>::setIddTlsSize(dword dwValue) | ||
2493 | { | ||
2494 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_TLS].Size = dwValue; | ||
2495 | } | ||
2496 | |||
2497 | /** | ||
2498 | * Changes the rva of the file's export directory. | ||
2499 | * @param dwValue New value. | ||
2500 | **/ | ||
2501 | template<int x> | ||
2502 | void PeHeaderT<x>::setIddExportRva(dword dwValue) | ||
2503 | { | ||
2504 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress = dwValue; | ||
2505 | } | ||
2506 | |||
2507 | /** | ||
2508 | * Changes the size of the file's export directory. | ||
2509 | * @param dwValue New value. | ||
2510 | **/ | ||
2511 | template<int x> | ||
2512 | void PeHeaderT<x>::setIddExportSize(dword dwValue) | ||
2513 | { | ||
2514 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_EXPORT].Size = dwValue; | ||
2515 | } | ||
2516 | |||
2517 | template<int x> | ||
2518 | void PeHeaderT<x>::setIddBaseRelocRva(dword value) | ||
2519 | { | ||
2520 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress = value; | ||
2521 | } | ||
2522 | |||
2523 | template<int x> | ||
2524 | void PeHeaderT<x>::setIddBaseRelocSize(dword value) | ||
2525 | { | ||
2526 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size = value; | ||
2527 | } | ||
2528 | |||
2529 | template<int x> | ||
2530 | void PeHeaderT<x>::setIddArchitectureRva(dword value) | ||
2531 | { | ||
2532 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_ARCHITECTURE].VirtualAddress = value; | ||
2533 | } | ||
2534 | |||
2535 | template<int x> | ||
2536 | void PeHeaderT<x>::setIddArchitectureSize(dword value) | ||
2537 | { | ||
2538 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_ARCHITECTURE].Size = value; | ||
2539 | } | ||
2540 | |||
2541 | template<int x> | ||
2542 | void PeHeaderT<x>::setIddComHeaderRva(dword value) | ||
2543 | { | ||
2544 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress = value; | ||
2545 | } | ||
2546 | |||
2547 | template<int x> | ||
2548 | void PeHeaderT<x>::setIddComHeaderSize(dword value) | ||
2549 | { | ||
2550 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size = value; | ||
2551 | } | ||
2552 | |||
2553 | /** | ||
2554 | * Changes the rva of the file's import directory. | ||
2555 | * @param dwValue New value. | ||
2556 | **/ | ||
2557 | template<int x> | ||
2558 | void PeHeaderT<x>::setIddImportRva(dword dwValue) | ||
2559 | { | ||
2560 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress = dwValue; | ||
2561 | } | ||
2562 | |||
2563 | /** | ||
2564 | * Changes the size of the file's import directory. | ||
2565 | * @param dwValue New value. | ||
2566 | **/ | ||
2567 | template<int x> | ||
2568 | void PeHeaderT<x>::setIddImportSize(dword dwValue) | ||
2569 | { | ||
2570 | m_inthHeader.dataDirectories[PELIB_IMAGE_DIRECTORY_ENTRY_IMPORT].Size = dwValue; | ||
2571 | } | ||
2572 | |||
2573 | /** | ||
2574 | * Changes the name of a section. | ||
2575 | * @param wSectionnr Identifier of the section | ||
2576 | * @param strName New name. | ||
2577 | **/ | ||
2578 | template<int x> | ||
2579 | void PeHeaderT<x>::setSectionName(word wSectionnr, std::string strName) | ||
2580 | { | ||
2581 | strncpy(reinterpret_cast<char*>(m_vIsh[wSectionnr].Name), strName.c_str(), sizeof(m_vIsh[wSectionnr].Name)); | ||
2582 | } | ||
2583 | |||
2584 | /** | ||
2585 | * Changes the virtual size of a section. | ||
2586 | * @param wSectionnr Identifier of the section | ||
2587 | * @param dwValue New value. | ||
2588 | **/ | ||
2589 | template<int x> | ||
2590 | void PeHeaderT<x>::setVirtualSize(word wSectionnr, dword dwValue) | ||
2591 | { | ||
2592 | m_vIsh[wSectionnr].VirtualSize = dwValue; | ||
2593 | } | ||
2594 | |||
2595 | /** | ||
2596 | * Changes the virtual address of a section. | ||
2597 | * @param wSectionnr Identifier of the section | ||
2598 | * @param dwValue New value. | ||
2599 | **/ | ||
2600 | template<int x> | ||
2601 | void PeHeaderT<x>::setVirtualAddress(word wSectionnr, dword dwValue) | ||
2602 | { | ||
2603 | m_vIsh[wSectionnr].VirtualAddress = dwValue; | ||
2604 | } | ||
2605 | |||
2606 | /** | ||
2607 | * Changes the size of raw data of a section. | ||
2608 | * @param wSectionnr Identifier of the section | ||
2609 | * @param dwValue New value. | ||
2610 | **/ | ||
2611 | template<int x> | ||
2612 | void PeHeaderT<x>::setSizeOfRawData(word wSectionnr, dword dwValue) | ||
2613 | { | ||
2614 | m_vIsh[wSectionnr].SizeOfRawData = dwValue; | ||
2615 | } | ||
2616 | |||
2617 | /** | ||
2618 | * Changes the size of raw data of a section. | ||
2619 | * @param wSectionnr Identifier of the section | ||
2620 | * @param dwValue New value. | ||
2621 | **/ | ||
2622 | template<int x> | ||
2623 | void PeHeaderT<x>::setPointerToRawData(word wSectionnr, dword dwValue) | ||
2624 | { | ||
2625 | m_vIsh[wSectionnr].PointerToRawData = dwValue; | ||
2626 | } | ||
2627 | |||
2628 | /** | ||
2629 | * Changes the pointer to relocations of a section. | ||
2630 | * @param wSectionnr Identifier of the section | ||
2631 | * @param dwValue New value. | ||
2632 | **/ | ||
2633 | template<int x> | ||
2634 | void PeHeaderT<x>::setPointerToRelocations(word wSectionnr, dword dwValue) | ||
2635 | { | ||
2636 | m_vIsh[wSectionnr].PointerToRelocations = dwValue; | ||
2637 | } | ||
2638 | |||
2639 | /** | ||
2640 | * Changes the pointer to line numbers of a section. | ||
2641 | * @param wSectionnr Identifier of the section | ||
2642 | * @param dwValue New value. | ||
2643 | **/ | ||
2644 | template<int x> | ||
2645 | void PeHeaderT<x>::setPointerToLinenumbers(word wSectionnr, dword dwValue) | ||
2646 | { | ||
2647 | m_vIsh[wSectionnr].PointerToLinenumbers = dwValue; | ||
2648 | } | ||
2649 | |||
2650 | /** | ||
2651 | * Changes the number of relocations of a section. | ||
2652 | * @param wSectionnr Identifier of the section | ||
2653 | * @param dwValue New value. | ||
2654 | **/ | ||
2655 | template<int x> | ||
2656 | void PeHeaderT<x>::setNumberOfRelocations(word wSectionnr, dword dwValue) | ||
2657 | { | ||
2658 | m_vIsh[wSectionnr].NumberOfRelocations = dwValue; | ||
2659 | } | ||
2660 | |||
2661 | /** | ||
2662 | * Changes the number of line numbers of a section. | ||
2663 | * @param wSectionnr Identifier of the section | ||
2664 | * @param dwValue New value. | ||
2665 | **/ | ||
2666 | template<int x> | ||
2667 | void PeHeaderT<x>::setNumberOfLinenumbers(word wSectionnr, dword dwValue) | ||
2668 | { | ||
2669 | m_vIsh[wSectionnr].NumberOfLinenumbers = dwValue; | ||
2670 | } | ||
2671 | |||
2672 | /** | ||
2673 | * Changes the characteristics of a section. | ||
2674 | * @param wSectionnr Identifier of the section | ||
2675 | * @param dwValue New value. | ||
2676 | **/ | ||
2677 | template<int x> | ||
2678 | void PeHeaderT<x>::setCharacteristics(word wSectionnr, dword dwValue) | ||
2679 | { | ||
2680 | m_vIsh[wSectionnr].Characteristics = dwValue; | ||
2681 | } | ||
2682 | |||
2683 | } | ||
2684 | |||
2685 | #endif | ||