OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef TYPES_WIN_PE_H_ | 5 #ifndef TYPES_WIN_PE_H_ |
6 #define TYPES_WIN_PE_H_ | 6 #define TYPES_WIN_PE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include <stddef.h> |
9 | 9 #include <stdint.h> |
10 | 10 |
11 namespace courgette { | 11 namespace courgette { |
12 | 12 |
13 // PE file section header. This struct has the same layout as the | 13 // PE file section header. This struct has the same layout as the |
14 // IMAGE_SECTION_HEADER structure from WINNT.H | 14 // IMAGE_SECTION_HEADER structure from WINNT.H |
15 // http://msdn.microsoft.com/en-us/library/ms680341(VS.85).aspx | 15 // http://msdn.microsoft.com/en-us/library/ms680341(VS.85).aspx |
16 // | 16 // |
17 #pragma pack(push, 1) // Supported by MSVC and GCC. Ensures no gaps in packing. | 17 #pragma pack(push, 1) // Supported by MSVC and GCC. Ensures no gaps in packing. |
18 struct Section { | 18 struct Section { |
19 char name[8]; | 19 char name[8]; |
20 uint32 virtual_size; | 20 uint32_t virtual_size; |
21 uint32 virtual_address; | 21 uint32_t virtual_address; |
22 uint32 size_of_raw_data; | 22 uint32_t size_of_raw_data; |
23 uint32 file_offset_of_raw_data; | 23 uint32_t file_offset_of_raw_data; |
24 uint32 pointer_to_relocations; // Always zero in an image. | 24 uint32_t pointer_to_relocations; // Always zero in an image. |
25 uint32 pointer_to_line_numbers; // Always zero in an image. | 25 uint32_t pointer_to_line_numbers; // Always zero in an image. |
26 uint16 number_of_relocations; // Always zero in an image. | 26 uint16_t number_of_relocations; // Always zero in an image. |
27 uint16 number_of_line_numbers; // Always zero in an image. | 27 uint16_t number_of_line_numbers; // Always zero in an image. |
28 uint32 characteristics; | 28 uint32_t characteristics; |
29 }; | 29 }; |
30 #pragma pack(pop) | 30 #pragma pack(pop) |
31 | 31 |
32 static_assert(sizeof(Section) == 40, "section size is 40 bytes"); | 32 static_assert(sizeof(Section) == 40, "section size is 40 bytes"); |
33 | 33 |
34 // ImageDataDirectory has same layout as IMAGE_DATA_DIRECTORY structure from | 34 // ImageDataDirectory has same layout as IMAGE_DATA_DIRECTORY structure from |
35 // WINNT.H | 35 // WINNT.H |
36 // http://msdn.microsoft.com/en-us/library/ms680305(VS.85).aspx | 36 // http://msdn.microsoft.com/en-us/library/ms680305(VS.85).aspx |
37 // | 37 // |
38 class ImageDataDirectory { | 38 class ImageDataDirectory { |
39 public: | 39 public: |
40 ImageDataDirectory() : address_(0), size_(0) {} | 40 ImageDataDirectory() : address_(0), size_(0) {} |
41 RVA address_; | 41 RVA address_; |
42 uint32 size_; | 42 uint32_t size_; |
43 }; | 43 }; |
44 | 44 |
45 static_assert(sizeof(ImageDataDirectory) == 8, | 45 static_assert(sizeof(ImageDataDirectory) == 8, |
46 "image data directory size is 8 bytes"); | 46 "image data directory size is 8 bytes"); |
47 | 47 |
48 | 48 |
49 //////////////////////////////////////////////////////////////////////////////// | 49 //////////////////////////////////////////////////////////////////////////////// |
50 | 50 |
51 // Constants and offsets gleaned from WINNT.H and various articles on the | 51 // Constants and offsets gleaned from WINNT.H and various articles on the |
52 // format of Windows PE executables. | 52 // format of Windows PE executables. |
53 | 53 |
54 // This is FIELD_OFFSET(IMAGE_DOS_HEADER, e_lfanew): | 54 // This is FIELD_OFFSET(IMAGE_DOS_HEADER, e_lfanew): |
55 const size_t kOffsetOfFileAddressOfNewExeHeader = 0x3c; | 55 const size_t kOffsetOfFileAddressOfNewExeHeader = 0x3c; |
56 | 56 |
57 const uint16 kImageNtOptionalHdr32Magic = 0x10b; | 57 const uint16_t kImageNtOptionalHdr32Magic = 0x10b; |
58 const uint16 kImageNtOptionalHdr64Magic = 0x20b; | 58 const uint16_t kImageNtOptionalHdr64Magic = 0x20b; |
59 | 59 |
60 const size_t kSizeOfCoffHeader = 20; | 60 const size_t kSizeOfCoffHeader = 20; |
61 const size_t kOffsetOfDataDirectoryFromImageOptionalHeader32 = 96; | 61 const size_t kOffsetOfDataDirectoryFromImageOptionalHeader32 = 96; |
62 const size_t kOffsetOfDataDirectoryFromImageOptionalHeader64 = 112; | 62 const size_t kOffsetOfDataDirectoryFromImageOptionalHeader64 = 112; |
63 | 63 |
64 } // namespace | 64 } // namespace |
65 #endif // TYPES_WIN_PE_H_ | 65 #endif // TYPES_WIN_PE_H_ |
OLD | NEW |