9#include "../dumper/dumper.h"
10#include "../linker/module.h"
11#include "../linker/options.h"
12#include "../linker/segment.h"
13#include "../linker/segment_manager.h"
14#include "../linker/writer.h"
54 operator uint32_t()
const {
return number; }
64 std::shared_ptr<Linker::Contents> image;
73 PreloadPages = 0x0040,
74 InvalidPages = 0x0080,
75 ZeroFilledPages = 0x0100,
77 ResidentContiguous = 0x0300,
78 ResidentLongLockable = 0x0400,
86 flag_type flags = flag_type(0);
87 uint32_t page_table_index = 0;
88 uint32_t page_entry_count = 0;
89 uint32_t data_pages_offset = 0;
95 Object(std::shared_ptr<Linker::Segment> segment,
unsigned flags)
96 : image(segment), flags(flag_type(flags))
110 std::shared_ptr<LEFormat> file;
111 std::vector<PhysicalPageNumber> pages;
115 PageSet(std::shared_ptr<LEFormat> file)
134 std::shared_ptr<Linker::Contents> image;
138 SegmentPage(std::shared_ptr<Linker::Contents> image, offset_t offset, offset_t size)
139 : image(image), offset(offset), size(size)
146 std::shared_ptr<const Linker::Image>
AsImage()
const override;
158 std::vector<uint8_t> data;
160 std::vector<IterationRecord> records;
164 static std::shared_ptr<IteratedPage> ReadFromFile(
Linker::Reader& rd, uint16_t size);
177 : iterated_page(iterated_page), size(size)
181 size_t ReadData(
size_t bytes, offset_t offset,
void * buffer)
const override;
245 SourceTypeMask = 0x0F,
250 source_type type = source_type(0);
267 flag_type flags = flag_type(0);
270 uint32_t addition = 0;
283 : Writer(::LittleEndian)
287 Relocation(
unsigned type,
unsigned flags, uint16_t
offset, uint16_t module, uint32_t target = 0, uint32_t addition = 0)
288 : Writer(::LittleEndian), type(source_type(type)), flags(flag_type(flags)), module(module), target(target), addition(addition)
295 bool IsExternal()
const;
297 bool IsSelectorOrOffset()
const;
299 bool ComesBefore()
const;
301 size_t GetSourceSize()
const;
330 void DecrementSingleSourceOffset(
size_t amount);
332 bool IsSelector()
const;
333 bool IsSourceList()
const;
334 bool IsAdditive()
const;
335 size_t GetTargetSize()
const;
336 size_t GetAdditiveSize()
const;
337 size_t GetModuleSize()
const;
338 size_t GetOrdinalSize()
const;
340 uint16_t GetFirstSource()
const;
344 size_t GetSize()
const;
349 std::map<uint16_t, Relocation> relocations;
350 uint32_t checksum = 0;
351 std::shared_ptr<Linker::Contents> image;
380 uint16_t type_id = 0, name_id = 0;
387 Resource(uint16_t type_id, uint16_t name_id, uint32_t size, uint16_t
object = 0, uint32_t offset = 0)
388 : type_id(type_id), name_id(name_id), size(size), object(
object), offset(offset)
398 uint16_t ordinal = 0;
413 entry_type type = Unused;
420 ForwarderByOrdinal = 1,
422 flag_type flags = flag_type(0);
445 : Writer(::LittleEndian)
450 : Writer(::LittleEndian), type(entry_type(type))
454 Entry(
unsigned type, uint16_t
object,
unsigned flags, uint32_t offset)
455 : Writer(::LittleEndian), type(entry_type(type)), object(object), flags(flag_type(flags)), offset(offset)
459 mutable bool same_bundle =
false;
461 bool SameBundle(
const Entry& other)
const;
463 offset_t GetEntryHeadSize()
const;
465 offset_t GetEntryBodySize()
const;
468 static Entry ReadEntry(
Linker::Reader& rd, uint8_t type, LEFormat::Entry& head);
479 enum directive_number : uint16_t
481 VerifyRecordDirective = 0x8001,
482 LanguageInformationDirective = 0x0002,
483 CoProcessorRequiredSupportTable = 0x0003,
484 ThreadStateInitializationDirective = 0x0004,
485 CSetBrowseInformation = 0x0005,
487 static constexpr uint16_t ResidentFlagMask = 0x8000;
488 directive_number directive = directive_number(0);
492 bool IsResident()
const;
495 ::EndianType endiantype = ::LittleEndian;
500 bool IsExtendedFormat()
const;
502 uint32_t format_level = 0;
554 uint32_t module_version = 0;
558 PreProcessInitialization = 0x00000004,
559 NoInternalFixup = 0x00000010,
560 NoExternalFixup = 0x00000020,
561 FullScreen = 0x00000100,
562 GUIAware = 0x00000200,
564 ErrorInImage = 0x00002000,
565 Library = 0x00008000,
566 ProtectedMemoryLibrary = 0x00018000,
567 PhysicalDriver = 0x00020000,
568 VirtualDriver = 0x00028000,
569 PerProcessTermination = 0x40000000,
571 uint32_t module_flags = 0;
573 uint32_t page_count = 0, page_size = 0x1000;
574 uint32_t eip_object = 0, eip_value = 0, esp_object = 0, esp_value = 0;
577 uint32_t last_page_size;
578 uint32_t page_offset_shift;
580 uint32_t fixup_section_size = 0, fixup_section_checksum = 0;
581 uint32_t loader_section_size = 0, loader_section_checksum = 0;
582 uint32_t object_table_offset = 0, object_page_table_offset = 0, object_iterated_pages_offset = 0;
583 uint32_t resource_table_offset = 0, resource_table_entry_count = 0, resident_name_table_offset = 0;
584 uint32_t entry_table_offset = 0, module_directives_offset = 0, fixup_page_table_offset = 0, fixup_record_table_offset = 0;
585 uint32_t imported_module_table_offset = 0, imported_procedure_table_offset = 0;
586 uint32_t per_page_checksum_offset = 0;
587 uint32_t data_pages_offset = 0, preload_page_count = 0;
588 uint32_t nonresident_name_table_offset = 0, nonresident_name_table_size = 0, nonresident_name_table_checksum = 0;
589 uint32_t automatic_data = 0;
590 uint32_t debug_info_offset = 0, debug_info_size = 0, instance_preload_page_count = 0, instance_demand_page_count = 0;
591 uint32_t stack_size = 0, heap_size = 0;
593 uint32_t vxd_version_info_resource_offset = 0;
594 uint32_t vxd_version_info_resource_length = 0;
595 ResourceFile vxd_version_info_resource = ResourceFile(ResourceFile::System_Windows_3x);
596 uint16_t vxd_device_id = 0;
597 uint16_t vxd_ddk_version = 0;
599 std::vector<Object> objects;
600 std::vector<ModuleDirective> module_directives;
606 std::vector<Page> pages;
608 typedef std::vector<Page>::iterator iterator;
609 typedef std::vector<Page>::const_iterator const_iterator;
610 typedef std::vector<Page>::reference reference;
611 typedef std::vector<Page>::const_reference const_reference;
618 const_iterator begin()
const;
620 const_iterator end()
const;
623 const_reference front()
const;
625 const_reference back()
const;
627 void push_back(
const Page& page);
644 std::map<std::tuple<uint16_t, uint16_t>,
Resource> resources;
645 std::vector<Name> resident_names, nonresident_names;
646 std::vector<Entry> entries;
647 std::vector<std::string> imported_modules, imported_procedures;
649 offset_t file_size = offset_t(-1);
667 : system(
system_type(system)), output(output), last_page_size(0)
672 : system(
system_type(system)), output(output), last_page_size(0)
678 bool IsLibrary()
const;
680 bool IsDriver()
const;
684 bool MayHaveStack()
const;
694 offset_t GetPageOffset(PhysicalPageNumber physical_page_number)
const;
695 offset_t GetPageSize(PhysicalPageNumber physical_page_number)
const;
718 {
OS2,
"OS/2 2.0+" },
719 {
Windows,
"Reserved for Windows (not supported)" },
720 {
MSDOS4,
"Reserved for Multitasking MS-DOS 4.0 (not supported)" },
721 {
Windows386,
"Windows 386 (virtual device driver only)" },
722 {
Neutral,
"IBM Microkernel Personality Neutral (not supported)" },
723 {
DOS4G,
"Rational Systems (Tenberry Software) DOS/4G or DOS/4GW executable" },
744 {
OUTPUT_GUI,
"creates a graphical executable (Presentation Manager for OS/2)" },
745 {
OUTPUT_CON,
"creates a console (text mode) executable" },
746 {
OUTPUT_DLL,
"creates a dynamic linking library (DLL)" },
747 {
OUTPUT_PDD,
"creates a physical device driver" },
748 {
OUTPUT_VDD,
"creates a virtual device driver" },
785 InitializeFields(stub, system, type, compat, stack, heap, le, lx);
789 static std::shared_ptr<LEFormat> CreateConsoleApplication(
system_type system =
OS2);
791 static std::shared_ptr<LEFormat> CreateGUIApplication(
system_type system =
OS2);
793 static std::shared_ptr<LEFormat> CreateLibraryModule(
system_type system =
OS2);
795 static std::shared_ptr<LEFormat> CreateDeviceDriver(
system_type system =
OS2,
bool virtual_device_driver =
true);
799 mutable MZStubWriter stub;
804 std::string program_name, module_name;
812 unsigned FormatAdditionalSectionFlags(std::string section_name)
const override;
814 Resource& AddResource(Resource resource);
816 void GetRelocationOffset(Object&
object,
size_t offset, PhysicalPageNumber& page_index, uint16_t& page_offset);
817 void AddRelocation(Object&
object,
unsigned type,
unsigned flags,
size_t offset, uint16_t module, uint32_t target = 0, uint32_t addition = 0);
819 std::shared_ptr<Linker::Segment> stack, heap;
820 std::map<std::shared_ptr<Linker::Segment>,
size_t> object_index;
821 std::map<std::string, uint32_t> imported_procedure_name_offsets;
822 offset_t imported_procedure_names_length = 0;
824 unsigned GetDefaultObjectFlags()
const;
825 void AddObject(
const Object&
object);
826 uint16_t FetchImportedModuleName(std::string name);
827 uint16_t FetchImportedProcedureName(std::string name);
830 uint8_t CountBundles(
size_t entry_index)
const;
832 static std::vector<Linker::OptionDescription<void> *> ParameterNames;
834 std::shared_ptr<Linker::OptionCollector>
GetOptions()
override;
835 void SetOptions(std::map<std::string, std::string>& options)
override;
836 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;
A region within a file that can be dumped, decompiled, and it may contain fixups.
Definition dumper.h:705
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:773
A record that represents a region within the file.
Definition dumper.h:666
Represents abstract data contents whose data can be written to a file.
Definition image.h:17
virtual offset_t WriteFile(Writer &wr, offset_t count, offset_t offset=0) const =0
Writes data of non-zero filled sections.
A representation of an enumeration with associated string representations for each value.
Definition options.h:15
std::map< value_type, std::string > descriptions
An empty dictionary that explains the value types in detail.
Definition options.h:20
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:474
Documents and handles command line options.
Definition options.h:306
Stores an absolute address along with the containing segment or address space.
Definition position.h:17
A helper class, encapsulating functionality needed to import binary data.
Definition reader.h:20
A representation of a value within some binary data that has to be fixed up once the exact position o...
Definition relocation.h:27
A helper class to collect sections into segments.
Definition segment_manager.h:32
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15
Represents an entry into the binary, typically DLL exported procedures.
Definition leexe.h:403
export_type export_state
Whether the entry is exported. This is not actually stored in the entry table and its value is ignore...
Definition leexe.h:436
std::string import_name
Convenience field that stores the imported procedure name for a forwarder entry, if imported by name,...
Definition leexe.h:442
std::string entry_name
The name of an exported entry. This is not actually stored in the entry table and its value is ignore...
Definition leexe.h:438
export_type
Definition leexe.h:427
@ NotExported
The entry is not exported, the Exported bit is not set.
Definition leexe.h:429
@ ExportByName
The entry is exported by name, it is referenced in the resident name table.
Definition leexe.h:431
@ ExportByOrdinal
The entry is exported by ordinal, it is referenced in the nonresident name table.
Definition leexe.h:433
std::string module_name
Convenience field that stores the module name for a forwarder entry, not used for generation.
Definition leexe.h:440
An image instance where the iterated page data can be accessed as the series of bytes it generates.
Definition leexe.h:171
offset_t WriteFile(Linker::Writer &wr, offset_t count, offset_t offset=0) const override
Writes data of non-zero filled sections.
Definition leexe.cc:156
size_t ReadData(size_t bytes, offset_t offset, void *buffer) const override
Attempts to fill a buffer with data.
Definition leexe.cc:122
offset_t ImageSize() const override
Retrieves size of stored data.
Definition leexe.cc:151
A data structure to represent an LE/LX iterated page, consisting of data produced from a repetition o...
Definition leexe.h:153
offset_t ImageSize() const override
Retrieves size of stored data.
Definition leexe.cc:85
offset_t WriteFile(Linker::Writer &wr, offset_t count, offset_t offset=0) const override
Writes data of non-zero filled sections.
Definition leexe.cc:116
An image instance that is a collection of other images, conceptually pages.
Definition leexe.h:108
offset_t ImageSize() const override
Retrieves size of stored data.
Definition leexe.cc:11
offset_t WriteFile(Linker::Writer &wr, offset_t count, offset_t offset=0) const override
Writes data of non-zero filled sections.
Definition leexe.cc:21
Represents a relocation record associated to this page.
Definition leexe.h:233
uint16_t actual_object
Convenience field that stores the actual object number for an entry, not used for generation.
Definition leexe.h:278
std::string module_name
Convenience field that stores the module name, not used for generation.
Definition leexe.h:274
uint32_t actual_offset
Convenience field that stores the actual offset for an entry, not used for generation.
Definition leexe.h:280
std::string import_name
Convenience field that stores the imported procedure name, if imported by name, also the name for an ...
Definition leexe.h:276
std::vector< Chain > sources
The sequence of sources corresponding to the same relocation record.
Definition leexe.h:327
Represents a page (usually of 4 KiB) within an LE/LX object.
Definition leexe.h:191
page_type
LX (and presumably LE) page types.
Definition leexe.h:195
uint32_t offset
(LX only) Offset of the page within the file
Definition leexe.h:210
uint32_t fixup_offset
The offset to the first fixup from the fixup record table, as stored in the fixup page table.
Definition leexe.h:229
uint16_t size
(LX only) The size of the page as stored in the file
Definition leexe.h:217
uint16_t type
The type of the page.
Definition leexe.h:224
Typesafe wrapper around std::vector<Page> to only access elements via physical pages.
Definition leexe.h:604
An image instance for a single page within a complete object image.
Definition leexe.h:132
offset_t WriteFile(Linker::Writer &wr, offset_t count, offset_t offset=0) const override
Writes data of non-zero filled sections.
Definition leexe.cc:59
offset_t ImageSize() const override
Retrieves size of stored data.
Definition leexe.cc:54
std::shared_ptr< const Linker::Image > AsImage() const override
Retrieves a randomly accessible image.
Definition leexe.cc:73
For chained relocations, this contains an element of the relocation chain.
Definition leexe.h:305
A source location entry in the relocation record.
Definition leexe.h:317
uint32_t base_address
If the relocations are chained, this contains the base address to which other fields are relocated to...
Definition leexe.h:321
std::vector< ChainLink > chains
If the relocations are chained, this contains the following link entries.
Definition leexe.h:323
uint16_t source
Offset within page where relocation should be applied to.
Definition leexe.h:319
Type safe wrapper for an uint32_t to access physical pages.
Definition leexe.h:50