7#include "../dumper/dumper.h"
8#include "../linker/module.h"
9#include "../linker/segment.h"
10#include "../linker/segment_manager.h"
11#include "../linker/writer.h"
28 RT_ACCELERATOR = 0x0009,
30 RT_MESSAGETABLE = 0x000B,
31 RT_GROUP_CURSOR = 0x000C,
32 RT_GROUP_ICON = 0x000E,
34 RT_DLGINCLUDE = 0x0011,
37 RT_ANICURSOR = 0x0015,
59 RT_ACCELERATOR = 0x0008,
64 RT_DLGINCLUDE = 0x000B,
68 RT_DISPLAYINFO = 0x000F,
72 RT_HELPTABLE = 0x0012,
73 RT_HELPSUBTABLE = 0x0013,
105 std::shared_ptr<Linker::Image> image;
106 offset_t data_offset = 0;
109 enum flag_type : uint16_t
115 Movable = 0x10, Fixed = 0,
117 Preload = 0x40, LoadOnCall = 0,
118 ExecuteOnly = 0x80|Code, ReadOnly = 0x80|Data,
119 Relocations = 0x0100,
121 Discardable = 0x1000,
123 flag_type flags = flag_type(0);
136 Segment(std::shared_ptr<Linker::Segment> segment,
unsigned flags)
137 : image(segment), flags(flag_type(flags))
143 PrivilegeLevelShift = 10,
197 FIARQQ = 1, FJARQQ = 1,
198 FISRQQ = 2, FJSRQQ = 2,
199 FICRQQ = 3, FJCRQQ = 3,
225 size_t GetSize()
const;
227 std::vector<Relocation> relocations;
232 void Dump(
Dumper::Dumper& dump,
unsigned index,
bool isos2)
const;
261 void Dump(
Dumper::Dumper& dump,
unsigned index,
bool isos2)
const;
268 uint16_t type_id = 0;
269 std::string type_id_name;
270 std::vector<Resource> resources;
369 uint8_t major, minor;
391 GLOBAL_INITIALIZATION = 4,
392 PROTECTED_MODE_ONLY = 8,
416 FAMILY_APPLICATION = 8,
417 ERROR_IN_IMAGE = 0x20,
433 uint16_t ip = 0, cs = 0, sp = 0, ss = 0;
443 std::vector<Segment> segments;
451 uint16_t resource_count = 0;
471 std::vector<Name> resident_names;
479 std::vector<ModuleReference> module_references;
487 std::vector<std::string> imported_names;
494 uint32_t nonresident_name_table_length = 0;
496 std::vector<Name> nonresident_names;
510 std::vector<Entry> entries;
529 enum additional_flag_type : uint8_t
531 SUPPORT_LONGFILENAME = 1,
532 WIN20_PROTECTED_MODE = 2,
533 WIN20_PROPORTIONAL_FONTS = 4,
536 additional_flag_type additional_flags = additional_flag_type(0);
541 uint16_t fast_load_area_offset;
543 uint16_t return_thunks_offset;
548 uint16_t fast_load_area_length;
550 uint16_t segment_reference_thunks_offset;
552 uint16_t code_swap_area_length = 0;
554 version windows_version{0, 0};
556 offset_t file_size = offset_t(-1);
558 bool IsLibrary()
const;
577 fast_load_area_offset(0), fast_load_area_length(0)
583 mutable MZStubWriter stub;
584 std::shared_ptr<Linker::Segment> stack, heap;
585 std::map<std::shared_ptr<Linker::Segment>,
size_t> segment_index;
586 std::map<std::string, uint16_t> module_reference_offsets;
587 std::map<std::string, uint16_t> imported_name_offsets;
588 uint16_t imported_names_length = 0;
591 std::string module_name;
592 std::string program_name;
594 bool option_capitalize_names =
false;
600 memory_model_t memory_model = MODEL_SMALL;
608 unsigned FormatAdditionalSectionFlags(std::string section_name)
const override;
610 enum compatibility_type
617 compatibility_type compatibility = CompatibleNone;
619 std::shared_ptr<NEFormat> SimulateLinker(compatibility_type compatibility);
621 static std::shared_ptr<NEFormat> CreateConsoleApplication(
system_type system =
Windows);
627 unsigned GetCodeSegmentFlags()
const;
628 unsigned GetDataSegmentFlags()
const;
629 void AddSegment(
const Segment& segment);
630 uint16_t FetchModule(std::string name);
631 uint16_t FetchImportedName(std::string name);
632 std::string MakeProcedureName(std::string name);
635 uint8_t CountBundles(
size_t entry_index)
const;
637 void SetModel(std::string model)
override;
638 void SetOptions(std::map<std::string, std::string>& options)
override;
639 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
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:275
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:290
uint8_t segment
The number of the segment, 1 based.
Definition neexe.h:290
void WriteEntry(Linker::Writer &wr) const
Writes an entry within a bundle.
Definition neexe.cc:346
flag_type
Flags present in an entry.
Definition neexe.h:293
@ Exported
Set if the entry is exported.
Definition neexe.h:295
@ SharedData
Set if the data segment used by the entry is global, used in SINGLEDATA modules (libraries)
Definition neexe.h:297
bool same_bundle
Convenience field to signify this entry is part of the same bundle as the previous one.
Definition neexe.h:327
uint16_t offset
Offset within the segment.
Definition neexe.h:301
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:314
@ INT_3Fh
Byte code for interrupt call that must be placed in the entry field.
Definition neexe.h:323
static Entry ReadEntry(Linker::Reader &rd, uint8_t indicator_byte)
Reads an entry within a bundle.
Definition neexe.cc:321
uint8_t GetIndicatorByte() const
Retrieves the segment indicator byte. For Fixed entries, this the same as the segment number.
Definition neexe.cc:306
export_type
Definition neexe.h:305
@ NotExported
The entry is not exported, the Exported bit is not set.
Definition neexe.h:307
@ ExportByOrdinal
The entry is exported by ordinal, it is referenced in the nonresident name table.
Definition neexe.h:311
@ ExportByName
The entry is exported by name, it is referenced in the resident name table.
Definition neexe.h:309
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:316
entry_type
This field represents the type of the entry.
Definition neexe.h:279
@ Fixed
The entry references a fixed segment.
Definition neexe.h:283
@ Movable
The entry references a movable segment.
Definition neexe.h:285
@ Unused
The entry is unused, the other fields are meaningless.
Definition neexe.h:281
entry_type type
The type of entry, based on the first byte in an entry bundle.
Definition neexe.h:288