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,
44 extern const std::map<offset_t, std::string> resource_type_id_descriptions;
62 RT_ACCELERATOR = 0x0008,
67 RT_DLGINCLUDE = 0x000B,
71 RT_DISPLAYINFO = 0x000F,
75 RT_HELPTABLE = 0x0012,
76 RT_HELPSUBTABLE = 0x0013,
81 extern const std::map<offset_t, std::string> resource_type_id_descriptions;
103 uint16_t ordinal = 0;
110 std::shared_ptr<Linker::Contents> image;
111 offset_t data_offset = 0;
114 enum flag_type : uint16_t
120 Movable = 0x10, Fixed = 0,
122 Preload = 0x40, LoadOnCall = 0,
123 ExecuteOnly = 0x80|Code, ReadOnly = 0x80|Data,
124 Relocations = 0x0100,
126 Discardable = 0x1000,
128 flag_type flags = flag_type(0);
141 Segment(std::shared_ptr<Linker::Segment> segment,
unsigned flags)
142 : image(segment), flags(flag_type(flags))
148 PrivilegeLevelShift = 10,
202 FIARQQ = 1, FJARQQ = 1,
203 FISRQQ = 2, FJSRQQ = 2,
204 FICRQQ = 3, FJCRQQ = 3,
230 size_t GetSize()
const;
232 std::vector<Relocation> relocations;
237 void Dump(
Dumper::Dumper& dump,
unsigned index,
bool isos2)
const;
247 typedef std::variant<std::string, uint16_t> Identifier;
249 static Identifier ConvertIdentifier(Linker::ResourceIdentifier identifier);
272 Resource(
const Identifier& type,
const Identifier& name, std::shared_ptr<Linker::Segment> segment,
unsigned flags)
275 if(
auto name_p = std::get_if<std::string>(&type))
279 else if(
auto id_p = std::get_if<uint16_t>(&type))
284 if(
auto name_p = std::get_if<std::string>(&name))
288 else if(
auto id_p = std::get_if<uint16_t>(&name))
294 Resource(
const Linker::ResourceIdentifier& type,
const Linker::ResourceIdentifier& name, std::shared_ptr<Linker::Segment> segment,
unsigned flags)
295 :
Resource(ConvertIdentifier(type), ConvertIdentifier(name), segment, flags)
299 Identifier GetTypeIdentifier()
const
307 return Identifier(uint16_t(
type_id & 0x7FFF));
311 Identifier GetNameIdentifier()
const
315 return Identifier(
id_name.value());
319 return Identifier(uint16_t(
id & 0x7FFF));
323 void Dump(
Dumper::Dumper& dump,
unsigned index,
bool isos2)
const;
332 uint16_t type_id = 0;
333 std::optional<std::string> type_id_name;
334 std::vector<std::shared_ptr<Resource>> resources;
340 if(
auto name_p = std::get_if<std::string>(&type))
342 type_id_name = *name_p;
344 else if(
auto id_p = std::get_if<uint16_t>(&type))
449 uint8_t major, minor;
471 GLOBAL_INITIALIZATION = 4,
472 PROTECTED_MODE_ONLY = 8,
496 FAMILY_APPLICATION = 8,
497 ERROR_IN_IMAGE = 0x20,
513 uint16_t ip = 0, cs = 0, sp = 0, ss = 0;
523 std::vector<std::shared_ptr<Segment>> segments;
531 uint16_t resource_count = 0;
551 std::vector<Name> resident_names;
559 std::vector<ModuleReference> module_references;
567 std::vector<std::string> imported_names;
574 uint32_t nonresident_name_table_length = 0;
576 std::vector<Name> nonresident_names;
590 std::vector<Entry> entries;
609 enum additional_flag_type : uint8_t
611 SUPPORT_LONGFILENAME = 1,
612 WIN20_PROTECTED_MODE = 2,
613 WIN20_PROPORTIONAL_FONTS = 4,
616 additional_flag_type additional_flags = additional_flag_type(0);
621 uint16_t fast_load_area_offset;
623 uint16_t return_thunks_offset;
628 uint16_t fast_load_area_length;
630 uint16_t segment_reference_thunks_offset;
632 uint16_t code_swap_area_length = 0;
634 version windows_version{0, 0};
636 offset_t file_size = offset_t(-1);
638 bool IsLibrary()
const;
672 : system(system), fast_load_area_offset(0), fast_load_area_length(0), output(output)
708 "WIN386", Windows386,
709 "WINDOWS386", Windows386,
711 "BORLAND", BorlandOSS,
716 {
OS2,
"OS/2 1.0 - 1.3" },
717 {
Windows,
"Windows 1.0 - 3.11" },
718 {
MSDOS4,
"Multitasking MS-DOS 4.0" },
719 { Windows386,
"Windows 386 (not supported)" },
720 { BorlandOSS,
"Borland Operating System Services (not supported)" },
721 {
system_type(
OS2 + PharLap),
"Phar Lap 286|DOS-Extender, OS/2 personality (not supported)" },
722 {
system_type(
Windows + PharLap),
"Phar Lap 286|DOS-Extender, Windows personality (not supported)" },
739 {
OUTPUT_GUI,
"creates a graphical executable (for Windows, or Presentation Manager for OS/2)" },
740 {
OUTPUT_CON,
"creates a console (text mode) executable (for OS/2 or Multitasking MS-DOS 4.0)" },
741 {
OUTPUT_DLL,
"creates a dynamic linking library (DLL)" },
776 InitializeFields(stub, system, type, compat, stack);
780 mutable MZStubWriter stub;
781 std::shared_ptr<Linker::Segment> stack, heap;
782 std::map<std::shared_ptr<Linker::Segment>,
size_t> segment_index;
783 std::map<std::string, uint16_t> module_reference_offsets;
784 std::map<std::string, uint16_t> imported_name_offsets;
785 uint16_t imported_names_length = 0;
786 std::map<std::string, uint16_t> resource_name_offsets;
787 uint16_t resource_table_size = 4;
790 std::string module_name;
791 std::string program_name;
793 bool option_capitalize_names =
false;
799 memory_model_t memory_model = MODEL_SMALL;
811 unsigned FormatAdditionalSectionFlags(std::string section_name)
const override;
815 static std::shared_ptr<NEFormat> CreateConsoleApplication(
system_type system =
Windows);
822 std::map<std::tuple<Resource::Identifier, Resource::Identifier>, std::shared_ptr<Resource>>
resources_map;
824 unsigned GetCodeSegmentFlags()
const;
825 unsigned GetDataSegmentFlags()
const;
826 unsigned GetResourceFlags()
const;
827 void AddResource(std::shared_ptr<Resource> resource);
828 void AddSegment(std::shared_ptr<Segment> segment);
829 uint16_t FetchModule(std::string name);
830 uint16_t FetchImportedName(std::string name);
831 uint16_t FetchResourceName(std::string name);
832 std::string MakeProcedureName(std::string name);
835 uint8_t CountBundles(
size_t entry_index)
const;
837 void SetModel(std::string model)
override;
838 std::shared_ptr<Linker::OptionCollector>
GetOptions()
override;
839 void SetOptions(std::map<std::string, std::string>& options)
override;
840 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;
868 typedef std::variant<uint16_t, std::string> Identifier;
871 static void WriteIdentifier(
Linker::Writer& wr,
const Identifier&
id);
872 static offset_t GetIdentifierSize(
const Identifier&
id);
880 std::shared_ptr<Linker::Contents> image;
883 offset_t file_offset;
884 std::vector<Resource> resources;
895 std::map<offset_t, std::string> names;
901 IdDisplay(
const std::map<offset_t, std::string>& names)
906 void DisplayValue(
Dumper::Dumper& dump, std::tuple<Identifier> values)
override;
907 static std::shared_ptr<IdDisplay> Make();
908 static std::shared_ptr<IdDisplay> Make(
const std::map<offset_t, std::string>& names);
This class represents an entry that can be displayed in a file dump.
Definition dumper.h:92
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:773
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 neexe.h:353
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:333
uint8_t segment
The number of the segment, 1 based.
Definition neexe.h:368
void WriteEntry(Linker::Writer &wr) const
Writes an entry within a bundle.
Definition neexe.cc:389
flag_type
Flags present in an entry.
Definition neexe.h:373
@ Exported
Set if the entry is exported.
Definition neexe.h:375
@ SharedData
Set if the data segment used by the entry is global, used in SINGLEDATA modules (libraries)
Definition neexe.h:377
bool same_bundle
Convenience field to signify this entry is part of the same bundle as the previous one.
Definition neexe.h:407
uint16_t offset
Offset within the segment.
Definition neexe.h:381
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:394
static Entry ReadEntry(Linker::Reader &rd, uint8_t indicator_byte)
Reads an entry within a bundle.
Definition neexe.cc:364
uint8_t GetIndicatorByte() const
Retrieves the segment indicator byte. For Fixed entries, this the same as the segment number.
Definition neexe.cc:349
export_type
Definition neexe.h:385
@ NotExported
The entry is not exported, the Exported bit is not set.
Definition neexe.h:387
@ ExportByOrdinal
The entry is exported by ordinal, it is referenced in the nonresident name table.
Definition neexe.h:391
@ ExportByName
The entry is exported by name, it is referenced in the resident name table.
Definition neexe.h:389
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:396
@ INT_3Fh
Byte code for interrupt call that must be placed in the entry field.
Definition neexe.h:403
entry_type
This field represents the type of the entry.
Definition neexe.h:357
@ Fixed
The entry references a fixed segment.
Definition neexe.h:361
@ Movable
The entry references a movable segment.
Definition neexe.h:363
@ Unused
The entry is unused, the other fields are meaningless.
Definition neexe.h:359
static constexpr uint8_t CONSTANT_VALUE
Segment value to represent a constant in the module.
Definition neexe.h:370
entry_type type
The type of entry, based on the first byte in an entry bundle.
Definition neexe.h:366
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition neexe.cc:2460
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition neexe.cc:2474
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition neexe.cc:2452