5#include "../dumper/dumper.h"
6#include "../linker/options.h"
7#include "../linker/segment_manager.h"
24 uint16_t major, minor;
32 static constexpr uint16_t
ROM32 = 0x0107;
34 static constexpr uint16_t
EXE32 = 0x010B;
36 static constexpr uint16_t
EXE64 = 0x020B;
101 EFIBootServiceDriver = 11,
102 EFIRuntimeDriver = 12,
105 WindowsBootApplication = 16,
139 uint32_t address = 0, size = 0;
149 DirBaseRelocationTable,
157 DirDelayImportDescriptor,
176 uint32_t
GetSize()
const override;
187 offset_t
RVAToAddress(uint32_t rva,
bool suppress_on_zero =
false)
const;
204 offset_t
RVAToAddress(uint32_t rva,
bool suppress_on_zero =
false)
const;
214 static constexpr uint32_t
EXECUTE = 0x20000000;
216 static constexpr uint32_t
READ = 0x40000000;
218 static constexpr uint32_t
WRITE = 0x80000000;
230 void ReadSectionData(
Linker::Reader& rd,
const COFFFormat& coff_format)
override;
231 void WriteSectionData(
Linker::Writer& wr,
const COFFFormat& coff_format)
const override;
232 uint32_t
ImageSize(
const COFFFormat& coff_format)
const override;
278 template <
typename Key>
285 std::variant<std::shared_ptr<Resource>, std::shared_ptr<ResourceDirectory>>
content;
292 uint32_t timestamp = 0;
304 void AddResource(std::shared_ptr<Resource>& resource,
size_t level = 0);
317 using Section::ReadSectionData;
318 using Section::WriteSectionData;
319 using Section::ImageSize;
321 bool IsPresent()
const;
330 std::shared_ptr<ResourcesSection>
resources = std::make_shared<ResourcesSection>();
336 typedef uint16_t Ordinal;
362 uint32_t timestamp = 0;
363 uint32_t forwarder_chain = 0;
412 using Section::ReadSectionData;
413 using Section::WriteSectionData;
414 using Section::ImageSize;
416 bool IsPresent()
const;
425 std::shared_ptr<ImportsSection>
imports = std::make_shared<ImportsSection>();
465 std::variant<uint32_t, Forwarder>
value;
485 uint32_t timestamp = 0;
500 std::vector<std::optional<std::shared_ptr<ExportedEntry>>>
entries;
505 void SetEntry(uint32_t ordinal, std::shared_ptr<ExportedEntry> entry);
507 void AddEntry(std::shared_ptr<ExportedEntry> entry);
516 using Section::ReadSectionData;
517 using Section::WriteSectionData;
518 using Section::ImageSize;
520 bool IsPresent()
const;
529 std::shared_ptr<ExportsSection>
exports = std::make_shared<ExportsSection>();
610 std::map<uint32_t, std::shared_ptr<BaseRelocationBlock>>
blocks_map;
618 using Section::ReadSectionData;
619 using Section::WriteSectionData;
620 using Section::ImageSize;
622 bool IsPresent()
const;
631 std::shared_ptr<BaseRelocationsSection>
base_relocations = std::make_shared<BaseRelocationsSection>();
645 ::EndianType GetMachineEndianType()
const;
738 enum subsystem_determination
740 Subsystem_Windows = 1,
745 Subsystem_EFIApplication,
746 Subsystem_EFIBootServiceDriver,
747 Subsystem_EFIRuntimeDriver,
749 Subsystem_BootApplication,
757 "WINDOWS", Subsystem_Windows,
758 "CONSOLE", Subsystem_Console,
759 "NATIVE", Subsystem_Native,
760 "OS2", Subsystem_OS2,
761 "POSIX", Subsystem_POSIX,
762 "EFI_APPLICATION", Subsystem_EFIApplication,
763 "EFI_BOOT_SERVICE_DRIVER", Subsystem_EFIBootServiceDriver,
764 "EFI_RUNTIME_DRIVER", Subsystem_EFIRuntimeDriver,
765 "EFI_ROM", Subsystem_EFI_ROM,
766 "BOOT_APPLICATION", Subsystem_BootApplication)
787 Linker::Option<offset_t> image_base{
"base",
"Base address of image, used for calculating relative virtual addresses"};
792 InitializeFields(stub, target, subsystem, output, image_base, section_align);
798 unsigned FormatAdditionalSectionFlags(std::string section_name)
const override;
800 std::shared_ptr<Resource>& AddResource(std::shared_ptr<Resource>& resource);
802 ImportDirectory& FetchImportLibrary(std::string library_name,
bool create_if_not_present =
false);
803 void AddImportByName(std::string library_name, std::string entry_name, uint16_t hint);
804 void AddImportByOrdinal(std::string library_name, uint16_t ordinal);
806 static std::vector<Linker::OptionDescription<void> *> ParameterNames;
808 std::shared_ptr<Linker::OptionCollector>
GetOptions()
override;
845 void SetOptions(std::map<std::string, std::string>& options)
override;
846 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;
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
A representation of an enumeration with associated string representations for each value.
Definition options.h:15
Encodes an object module file as a collection of sections, symbols and relocations.
Definition module.h:24
Helper class that contains the options interpreted by the format.
Definition options.h:467
Documents and handles command line options.
Definition options.h:303
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
Encompasses the information necessary to encode a forwarder exported reference.
Definition peexe.h:437
std::variant< std::string, uint32_t > reference
The name or ordinal to the entry that is being reexported, this field will not appear directly in the...
Definition peexe.h:442
std::string reference_name
A string representation of the forwarder, to appear in the image.
Definition peexe.h:444
uint32_t rva
The relative virtual address of the reference name.
Definition peexe.h:446
std::string dll_name
The name of the library whose entry is being reexported, this field will not appear directly in the i...
Definition peexe.h:440
Represents a name by which an exported entry is identified.
Definition peexe.h:451
uint32_t rva
The relative virtual address of the name string.
Definition peexe.h:456
std::string name
The name, as a string.
Definition peexe.h:454
Represents a single exported entry in the file.
Definition peexe.h:429
std::optional< Name > name
An optional name by which the exported entry is identified, otherwise its position in the export tabl...
Definition peexe.h:467
std::variant< uint32_t, Forwarder > value
Represents the associated value of the entry: either the relative virtual address of the object being...
Definition peexe.h:465
Represents a single entry in the resource directory.
Definition peexe.h:280
Key identifier
The value that identifiers the resource at the current level.
Definition peexe.h:283
std::variant< std::shared_ptr< Resource >, std::shared_ptr< ResourceDirectory > > content
The contents at this level, either the resource itself, or another level of resource directory.
Definition peexe.h:285
uint32_t content_rva
The relative virtual address of the contents.
Definition peexe.h:287