7#include "../dumper/dumper.h"
8#include "../linker/module.h"
9#include "../linker/options.h"
10#include "../linker/segment.h"
11#include "../linker/segment_manager.h"
12#include "../linker/writer.h"
29 RT_ACCELERATOR = 0x0009,
31 RT_MESSAGETABLE = 0x000B,
32 RT_GROUP_CURSOR = 0x000C,
33 RT_GROUP_ICON = 0x000E,
35 RT_DLGINCLUDE = 0x0011,
38 RT_ANICURSOR = 0x0015,
60 RT_ACCELERATOR = 0x0008,
65 RT_DLGINCLUDE = 0x000B,
69 RT_DISPLAYINFO = 0x000F,
73 RT_HELPTABLE = 0x0012,
74 RT_HELPSUBTABLE = 0x0013,
106 std::shared_ptr<Linker::Image> image;
107 offset_t data_offset = 0;
110 enum flag_type : uint16_t
116 Movable = 0x10, Fixed = 0,
118 Preload = 0x40, LoadOnCall = 0,
119 ExecuteOnly = 0x80|Code, ReadOnly = 0x80|Data,
120 Relocations = 0x0100,
122 Discardable = 0x1000,
124 flag_type flags = flag_type(0);
137 Segment(std::shared_ptr<Linker::Segment> segment,
unsigned flags)
138 : image(segment), flags(flag_type(flags))
144 PrivilegeLevelShift = 10,
198 FIARQQ = 1, FJARQQ = 1,
199 FISRQQ = 2, FJSRQQ = 2,
200 FICRQQ = 3, FJCRQQ = 3,
226 size_t GetSize()
const;
228 std::vector<Relocation> relocations;
233 void Dump(
Dumper::Dumper& dump,
unsigned index,
bool isos2)
const;
262 void Dump(
Dumper::Dumper& dump,
unsigned index,
bool isos2)
const;
269 uint16_t type_id = 0;
270 std::string type_id_name;
271 std::vector<Resource> resources;
372 uint8_t major, minor;
394 GLOBAL_INITIALIZATION = 4,
395 PROTECTED_MODE_ONLY = 8,
419 FAMILY_APPLICATION = 8,
420 ERROR_IN_IMAGE = 0x20,
436 uint16_t ip = 0, cs = 0, sp = 0, ss = 0;
446 std::vector<Segment> segments;
454 uint16_t resource_count = 0;
474 std::vector<Name> resident_names;
482 std::vector<ModuleReference> module_references;
490 std::vector<std::string> imported_names;
497 uint32_t nonresident_name_table_length = 0;
499 std::vector<Name> nonresident_names;
513 std::vector<Entry> entries;
532 enum additional_flag_type : uint8_t
534 SUPPORT_LONGFILENAME = 1,
535 WIN20_PROTECTED_MODE = 2,
536 WIN20_PROPORTIONAL_FONTS = 4,
539 additional_flag_type additional_flags = additional_flag_type(0);
544 uint16_t fast_load_area_offset;
546 uint16_t return_thunks_offset;
551 uint16_t fast_load_area_length;
553 uint16_t segment_reference_thunks_offset;
555 uint16_t code_swap_area_length = 0;
557 version windows_version{0, 0};
559 offset_t file_size = offset_t(-1);
561 bool IsLibrary()
const;
580 fast_load_area_offset(0), fast_load_area_length(0)
593 InitializeFields(stub);
598 std::shared_ptr<Linker::Segment> stack, heap;
599 std::map<std::shared_ptr<Linker::Segment>,
size_t> segment_index;
600 std::map<std::string, uint16_t> module_reference_offsets;
601 std::map<std::string, uint16_t> imported_name_offsets;
602 uint16_t imported_names_length = 0;
605 std::string module_name;
606 std::string program_name;
608 bool option_capitalize_names =
false;
614 memory_model_t memory_model = MODEL_SMALL;
624 unsigned FormatAdditionalSectionFlags(std::string section_name)
const override;
626 enum compatibility_type
633 compatibility_type compatibility = CompatibleNone;
635 std::shared_ptr<NEFormat> SimulateLinker(compatibility_type compatibility);
637 static std::shared_ptr<NEFormat> CreateConsoleApplication(
system_type system =
Windows);
643 unsigned GetCodeSegmentFlags()
const;
644 unsigned GetDataSegmentFlags()
const;
645 void AddSegment(
const Segment& segment);
646 uint16_t FetchModule(std::string name);
647 uint16_t FetchImportedName(std::string name);
648 std::string MakeProcedureName(std::string name);
651 uint8_t CountBundles(
size_t entry_index)
const;
653 void SetModel(std::string model)
override;
654 std::shared_ptr<Linker::OptionCollector>
GetOptions()
override;
655 void SetOptions(std::map<std::string, std::string>& options)
override;
656 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
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
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:16
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 neexe.h:276
offset_t GetEntrySize() const
Returns the size of an entry as stored in the file, without the first two bytes of the bundle.
Definition neexe.cc:299
uint8_t segment
The number of the segment, 1 based.
Definition neexe.h:291
void WriteEntry(Linker::Writer &wr) const
Writes an entry within a bundle.
Definition neexe.cc:355
flag_type
Flags present in an entry.
Definition neexe.h:296
@ Exported
Set if the entry is exported.
Definition neexe.h:298
@ SharedData
Set if the data segment used by the entry is global, used in SINGLEDATA modules (libraries)
Definition neexe.h:300
bool same_bundle
Convenience field to signify this entry is part of the same bundle as the previous one.
Definition neexe.h:330
uint16_t offset
Offset within the segment.
Definition neexe.h:304
export_type export_state
Whether the entry is exported. This is not actually stored in the entry table and its value is ignore...
Definition neexe.h:317
static Entry ReadEntry(Linker::Reader &rd, uint8_t indicator_byte)
Reads an entry within a bundle.
Definition neexe.cc:330
uint8_t GetIndicatorByte() const
Retrieves the segment indicator byte. For Fixed entries, this the same as the segment number.
Definition neexe.cc:315
export_type
Definition neexe.h:308
@ NotExported
The entry is not exported, the Exported bit is not set.
Definition neexe.h:310
@ ExportByOrdinal
The entry is exported by ordinal, it is referenced in the nonresident name table.
Definition neexe.h:314
@ ExportByName
The entry is exported by name, it is referenced in the resident name table.
Definition neexe.h:312
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 neexe.h:319
@ INT_3Fh
Byte code for interrupt call that must be placed in the entry field.
Definition neexe.h:326
entry_type
This field represents the type of the entry.
Definition neexe.h:280
@ Fixed
The entry references a fixed segment.
Definition neexe.h:284
@ Movable
The entry references a movable segment.
Definition neexe.h:286
@ Unused
The entry is unused, the other fields are meaningless.
Definition neexe.h:282
static constexpr uint8_t CONSTANT_VALUE
Segment value to represent a constant in the module.
Definition neexe.h:293
entry_type type
The type of entry, based on the first byte in an entry bundle.
Definition neexe.h:289