RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
peexe.h
1#ifndef PEEXE_H
2#define PEEXE_H
3
4#include "../common.h"
5#include "../dumper/dumper.h"
6#include "../linker/segment_manager.h"
7#include "coff.h"
8#include "mzexe.h"
9
10/* TODO: unimplemented */
11
12namespace Microsoft
13{
18 {
19 public:
20 char pe_signature[4];
21
23 {
24 public:
25 static constexpr uint16_t ROM32 = 0x0107;
26 static constexpr uint16_t EXE32 = 0x010B;
27 static constexpr uint16_t EXE64 = 0x020B;
28
29 static constexpr offset_t Win32Base = 0x00400000;
30 static constexpr offset_t Dll32Base = 0x10000000;
31 static constexpr offset_t WinCEBase = 0x00010000;
35 offset_t image_base = 0;
39 uint32_t section_align = 0;
43 uint32_t file_align = 0;
46 {
47 uint16_t major, minor;
48 };
64 uint32_t win32_version = 0;
68 uint32_t total_image_size = 0;
72 uint32_t total_headers_size = 0;
76 uint32_t checksum = 0;
78 enum SubsystemType : uint16_t
79 {
80 Unknown = 0,
81 Native = 1,
82 WindowsGUI = 2,
83 WindowsCUI = 3,
84 OS2CUI = 5,
85 POSIXCUI = 7,
86 NativeWin95 = 8,
87 WinCEGUI = 9,
88 EFIApplication = 10,
89 EFIBootServiceDriver = 11,
90 EFIRuntimeDriver = 12,
91 EFIROM = 13,
92 Xbox = 14,
93 WindowsBootApplication = 16,
94 };
102 uint16_t flags = 0;
114 offset_t reserved_heap_size = 0;
122 uint32_t loader_flags = 0;
123
126 {
127 uint32_t address = 0, size = 0;
128 };
129 enum
130 {
131 DirExportTable,
132 DirImportTable,
133 DirResourceTable,
134 DirExceptionTable,
135 DirCertificateTable,
136 DirBaseRelocationTable,
137 DirDebug,
138 DirArchitecture, // reserved
139 DirGlobalPointer,
140 DirTLSTable,
141 DirLoadConfigTable,
142 DirBoundImport,
143 DirIAT,
144 DirDelayImportDescriptor,
145 DirCLRRuntimeHeader,
146 DirReserved,
147 DirTotalCount,
148 };
152 std::vector<DataDirectory> data_directories;
153
154 bool Is64Bit() const;
155
157 : AOutHeader()
158 {
159 }
160
161 uint32_t GetSize() const override;
162
163 void ReadFile(Linker::Reader& rd) override;
164
165 void WriteFile(Linker::Writer& wr) const override;
166
167 offset_t CalculateValues(COFFFormat& coff) override;
168
169 protected:
170 void DumpFields(const COFFFormat& coff, Dumper::Dumper& dump, Dumper::Region& header_region) const override;
171 };
172
173 mutable MZStubWriter stub;
174
175 void ReadFile(Linker::Reader& rd) override;
176 void CalculateValues() override;
178 offset_t WriteFile(Linker::Writer& wr) const override;
179 void Dump(Dumper::Dumper& dump) const override;
180 /* TODO */
181
183 std::string GetDefaultExtension(Linker::Module& module, std::string filename) const override;
184
185 protected:
186 void ReadOptionalHeader(Linker::Reader& rd);
187 };
188}
189
190#endif /* PEEXE_H */
A standard 28 byte a.out optional header, used by DJGPP.
Definition coff.h:635
The UNIX COFF file format.
Definition coff.h:26
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:586
A record that represents a region within the file.
Definition dumper.h:485
offset_t WriteFile(Writer &wr) const override=0
Stores data in memory to file.
Encodes an object module file as a collection of sections, symbols and relocations.
Definition module.h:24
virtual std::string GetDefaultExtension(Module &module, std::string filename) const
Appends a default extension to the filename.
A helper class, encapsulating functionality needed to import binary data.
Definition reader.h:16
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15
Definition mzexe.h:279
version_type image_version
Binary image version.
Definition peexe.h:56
uint16_t flags
DLL flags (in PE terminology, characteristics)
Definition peexe.h:102
version_type os_version
Required operating system version.
Definition peexe.h:52
uint32_t win32_version
Reserved value.
Definition peexe.h:64
uint32_t loader_flags
Reserved.
Definition peexe.h:122
uint32_t section_align
Section alignment.
Definition peexe.h:39
uint32_t file_align
File alignment.
Definition peexe.h:43
uint32_t checksum
Checksum.
Definition peexe.h:76
std::vector< DataDirectory > data_directories
PE specific areas in the file, each one has a specific purpose.
Definition peexe.h:152
offset_t reserved_stack_size
How much of stack should be reserved at launch.
Definition peexe.h:106
uint32_t total_headers_size
Cumulative size of all the headers, including the stub.
Definition peexe.h:72
offset_t committed_stack_size
How many pages of stack are actually available at launch.
Definition peexe.h:110
offset_t image_base
Preferred base address of image, all relative virtual addresses are calculate relative to this value.
Definition peexe.h:35
SubsystemType subsystem
The Windows subsystem this program runs on.
Definition peexe.h:98
offset_t reserved_heap_size
How much of heap should be reserved at launch.
Definition peexe.h:114
uint32_t total_image_size
Size of the entire image, including headers.
Definition peexe.h:68
offset_t committed_heap_size
How many pages of heap are actually available at launch.
Definition peexe.h:118
uint32_t GetSize() const override
Returns size of optional header.
Definition peexe.cc:13
version_type subsystem_version
Version of the subsystem.
Definition peexe.h:60
Microsoft PE .EXE portable executable file format.
Definition peexe.h:18
std::string GetDefaultExtension(Linker::Module &module, std::string filename) const override
Appends a default extension to the filename.
Definition peexe.cc:153
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition peexe.cc:111
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition peexe.cc:120
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition peexe.cc:141
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition peexe.cc:131
A data directory entry.
Definition peexe.h:126
Represents a version entry with major and minor versions.
Definition peexe.h:46