1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COURGETTE_TYPES_WIN_PE_H_
6 #define COURGETTE_TYPES_WIN_PE_H_
13 // PE file section header. This struct has the same layout as the
14 // IMAGE_SECTION_HEADER structure from WINNT.H
15 // http://msdn.microsoft.com/en-us/library/ms680341(VS.85).aspx
17 #pragma pack(push, 1) // Supported by MSVC and GCC. Ensures no gaps in packing.
20 uint32_t virtual_size;
21 uint32_t virtual_address;
22 uint32_t size_of_raw_data;
23 uint32_t file_offset_of_raw_data;
24 uint32_t pointer_to_relocations; // Always zero in an image.
25 uint32_t pointer_to_line_numbers; // Always zero in an image.
26 uint16_t number_of_relocations; // Always zero in an image.
27 uint16_t number_of_line_numbers; // Always zero in an image.
28 uint32_t characteristics;
32 static_assert(sizeof(Section) == 40, "section size is 40 bytes");
34 // ImageDataDirectory has same layout as IMAGE_DATA_DIRECTORY structure from
36 // http://msdn.microsoft.com/en-us/library/ms680305(VS.85).aspx
38 class ImageDataDirectory {
40 ImageDataDirectory() : address_(0), size_(0) {}
45 static_assert(sizeof(ImageDataDirectory) == 8,
46 "image data directory size is 8 bytes");
49 ////////////////////////////////////////////////////////////////////////////////
51 // Constants and offsets gleaned from WINNT.H and various articles on the
52 // format of Windows PE executables.
54 // This is FIELD_OFFSET(IMAGE_DOS_HEADER, e_lfanew):
55 const size_t kOffsetOfFileAddressOfNewExeHeader = 0x3c;
57 const uint16_t kImageNtOptionalHdr32Magic = 0x10b;
58 const uint16_t kImageNtOptionalHdr64Magic = 0x20b;
60 const size_t kSizeOfCoffHeader = 20;
61 const size_t kMinPeHeaderSize = 4 /*signature*/ + kSizeOfCoffHeader;
62 const size_t kOffsetOfDataDirectoryFromImageOptionalHeader32 = 96;
63 const size_t kOffsetOfDataDirectoryFromImageOptionalHeader64 = 112;
65 } // namespace courgette
67 #endif // COURGETTE_TYPES_WIN_PE_H_