33 unsigned FormatAdditionalSectionFlags(std::string section_name)
const override;
44 system_type system = system_type(0);
46 enum program_flag_type
51 GLOBAL_INITIALIZATION = 4,
52 PROTECTED_MODE_ONLY = 8,
58 program_flag_type program_flags = program_flag_type(0);
60 enum application_flag_type
65 FAMILY_APPLICATION = 8,
66 ERROR_IN_IMAGE = 0x20,
69 application_flag_type application_flags = application_flag_type(0);
71 bool IsLibrary()
const;
73 enum additional_flag_type
75 SUPPORT_LONGFILENAME = 1,
76 WIN20_PROTECTED_MODE = 2,
77 WIN20_PROPORTIONAL_FONTS = 4,
80 additional_flag_type additional_flags = additional_flag_type(0);
82 enum compatibility_type
89 compatibility_type compatibility = CompatibleNone;
91 NEFormat(system_type system,
unsigned program_flags,
unsigned application_flags)
92 : system(system), program_flags(program_flag_type(program_flags)), application_flags(application_flag_type(application_flags)),
93 fast_load_area_offset(0), fast_load_area_length(0)
97 std::shared_ptr<NEFormat> SimulateLinker(compatibility_type compatibility);
99 static std::shared_ptr<NEFormat> CreateConsoleApplication(system_type system = Windows);
101 static std::shared_ptr<NEFormat> CreateGUIApplication(system_type system = Windows);
103 static std::shared_ptr<NEFormat> CreateLibraryModule(system_type system = Windows);
114 entry_type type = Unused;
121 flag_type flags = flag_type(0);
135 Entry(
unsigned type, uint8_t segment,
unsigned flags, uint16_t offset)
136 : type((entry_type)type), segment(segment), flags((flag_type)flags), offset(offset)
140 offset_t GetEntrySize()
const;
142 uint8_t GetIndicatorByte()
const;
150 std::shared_ptr<Linker::Segment> image;
151 offset_t data_offset = 0;
158 Movable = 0x10, Fixed = 0,
160 Preload = 0x40, LoadOnCall = 0,
161 ExecuteOnly = 0x80, ReadOnly = 0x80|Data,
162 Relocations = 0x0100,
164 Discardable = 0x1000,
167 uint16_t movable_entry_index = 0;
169 Segment(std::shared_ptr<Linker::Segment> segment,
unsigned flags)
170 : image(segment), flags((flag_type)flags)
176 PrivilegeLevelShift = 10,
191 source_type type = source_type(0);
200 flag_type flags = flag_type(0);
209 FIARQQ = 1, FJARQQ = 1,
210 FISRQQ = 2, FJSRQQ = 2,
211 FICRQQ = 3, FJCRQQ = 3,
222 Relocation(
unsigned type,
unsigned flags, uint16_t offset, uint16_t module, uint16_t target)
223 : type((source_type)type), flags((flag_type)flags), offset(offset), module(module), target(target)
229 std::map<uint16_t, Relocation> relocations;
238 uint16_t ordinal = 0;
250 uint8_t major, minor;
252 version linker_version{1, 0}, windows_version{0, 0};
254 uint16_t automatic_data = 0;
255 uint16_t heap_size = 0, stack_size = 0;
256 uint16_t ss = 0, sp = 0, cs = 0, ip = 0;
257 uint16_t sector_shift = 9;
259 uint32_t segment_table_offset = 0;
260 uint32_t resource_table_offset = 0;
261 uint32_t resident_name_table_offset = 0;
262 uint32_t module_reference_table_offset = 0;
263 uint32_t imported_names_table_offset = 0;
264 uint32_t entry_table_offset = 0;
265 uint32_t entry_table_length = 0;
266 uint16_t movable_entry_count = 0;
267 uint32_t nonresident_name_table_length = 0;
268 uint32_t nonresident_name_table_offset = 0;
272 uint16_t fast_load_area_offset;
274 uint16_t return_thunks_offset;
279 uint16_t fast_load_area_length;
281 uint16_t segment_reference_thunks_offset;
283 uint16_t code_swap_area_length = 0;
285 std::shared_ptr<Linker::Segment> stack, heap;
286 std::vector<Segment> segments;
287 std::map<std::shared_ptr<Linker::Segment>,
size_t> segment_index;
288 std::vector<Resource> resources;
289 std::vector<Name> resident_names, nonresident_names;
290 std::vector<uint16_t> module_references;
291 std::map<std::string, uint16_t> module_reference_offsets;
292 std::vector<std::string> imported_names;
293 std::map<std::string, uint16_t> imported_name_offsets;
294 uint16_t imported_names_length = 0;
296 std::vector<Entry> entries;
299 std::string module_name;
300 std::string program_name;
302 bool option_capitalize_names =
false;
308 memory_model_t memory_model = MODEL_SMALL;
310 unsigned GetCodeSegmentFlags()
const;
311 unsigned GetDataSegmentFlags()
const;
312 void AddSegment(
const Segment& segment);
313 uint16_t FetchModule(std::string name);
314 uint16_t FetchImportedName(std::string name);
315 std::string MakeProcedureName(std::string name);
318 uint8_t CountBundles(
size_t entry_index);
320 using LinkerManager::SetLinkScript;
321 void SetModel(std::string model)
override;
322 void SetOptions(std::map<std::string, std::string>& options)
override;
323 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;