5#include "../dumper/dumper.h"
6#include "../linker/options.h"
7#include "../linker/segment_manager.h"
25 InitializeFields(stub);
31 unsigned FormatAdditionalSectionFlags(std::string section_name)
const override;
35 std::shared_ptr<Linker::Segment> image;
37 static const uint32_t REL32 = 0x80000000;
42 uint32_t offset : 31, rel32 : 1;
47 : offset(offset), rel32(rel32)
56 bool operator ==(
const Relocation& other)
const;
58 bool operator <(
const Relocation& other)
const;
61 offset_t image_size = 0;
62 std::set<Relocation> relocations;
63 offset_t header_size = 0;
64 offset_t bss_pages = 0;
65 offset_t extra_pages = 0;
68 offset_t relocation_offset = 0;
71 MPFormat(
bool has_relocations =
false)
72 : has_relocations(has_relocations)
76 std::shared_ptr<Linker::OptionCollector>
GetOptions()
override;
78 void SetOptions(std::map<std::string, std::string>& options)
override;
80 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;
111 InitializeFields(stub);
124 bool FormatSupportsStackSection()
const override;
127 const bool is_multisegmented;
130 uint16_t header_size = 0;
131 uint32_t file_size = 0;
133 uint32_t runtime_parameters_offset = 0;
134 uint32_t runtime_parameters_size = 0;
135 uint32_t relocation_table_offset = 0;
136 uint32_t relocation_table_size = 0;
137 uint32_t segment_information_table_offset = 0;
138 uint32_t segment_information_table_size = 0;
139 uint16_t segment_information_table_entry_size = 0;
140 uint32_t load_image_offset = 0;
141 uint32_t load_image_size = 0;
142 uint32_t symbol_table_offset = 0;
143 uint32_t symbol_table_size = 0;
144 uint32_t gdt_address = 0;
145 uint32_t gdt_size = 0;
146 uint32_t ldt_address = 0;
147 uint32_t ldt_size = 0;
148 uint32_t idt_address = 0;
149 uint32_t idt_size = 0;
150 uint32_t tss_address = 0;
151 uint32_t tss_size = 0;
152 uint32_t minimum_extra = 0;
153 uint32_t maximum_extra = 0;
154 uint32_t base_load_offset = 0;
162 uint32_t memory_requirements = 0;
163 uint32_t stack_size = 0;
167 P3Format(
bool is_multisegmented,
bool is_32bit =
true)
168 : is_multisegmented(is_multisegmented), is_32bit(is_32bit)
175 uint16_t min_realmode_param = 0, max_realmode_param = 0, min_int_buffer_size_kb = 0, max_int_buffer_size_kb = 0, int_stack_count = 0, int_stack_size_kb = 0;
176 uint32_t realmode_area_end = 0;
177 uint16_t call_buffer_size_kb = 0, flags = 0, ring = 0;
179 void CalculateValues();
186 std::shared_ptr<Linker::OptionCollector>
GetOptions()
override;
188 void SetOptions(std::map<std::string, std::string>& options)
override;
204 Flat(
bool is_32bit =
true)
209 std::shared_ptr<Linker::Segment> image;
211 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;
232 uint32_t address = 0;
234 virtual uint32_t GetStoredSize()
const = 0;
235 virtual uint32_t GetLoadedSize()
const = 0;
242 std::weak_ptr<AbstractSegment> image;
261 Descriptor(uint32_t access, std::weak_ptr<AbstractSegment> image = std::weak_ptr<AbstractSegment>())
262 : image(image), access(access)
266 void CalculateValues();
274 std::vector<Descriptor> descriptors;
276 uint32_t GetStoredSize()
const override;
278 uint32_t GetLoadedSize()
const override;
282 void CalculateValues();
285 std::shared_ptr<DescriptorTable> gdt;
286 std::shared_ptr<DescriptorTable> idt;
287 std::shared_ptr<DescriptorTable> ldt;
294 uint32_t esp0 = 0, esp1 = 0, esp2 = 0;
295 uint32_t cr3 = 0, eip = 0, eflags = 0, eax = 0, ecx = 0, edx = 0, ebx = 0, esp = 0, ebp = 0, esi = 0, edi = 0;
296 uint16_t ss0 = 0, ss1 = 0, ss2 = 0, es = 0, cs = 0, ss = 0, ds = 0, fs = 0, gs = 0, ldtr = 0, iopb = 0;
304 uint32_t GetStoredSize()
const override;
306 uint32_t GetLoadedSize()
const override;
311 std::shared_ptr<TaskStateSegment> tss;
317 std::shared_ptr<Linker::Segment> segment;
322 uint32_t base_offset = 0;
324 Segment(std::shared_ptr<Linker::Segment> segment, uint32_t access, uint16_t selector)
325 : segment(segment), access(access), selector(selector)
329 uint32_t GetStoredSize()
const override;
331 uint32_t GetLoadedSize()
const override;
346 std::shared_ptr<Segment> segment;
349 Relocation(std::shared_ptr<Segment> segment, uint32_t offset)
350 : segment(segment), offset(offset)
354 bool operator ==(
const Relocation& other)
const;
356 bool operator <(
const Relocation& other)
const;
361 std::vector<std::shared_ptr<AbstractSegment>> segments;
362 std::map<std::shared_ptr<Linker::Segment>, std::shared_ptr<Segment>> segment_associations;
363 std::set<Relocation> relocations;
364 std::shared_ptr<Segment> code;
365 std::shared_ptr<Segment> data;
367 void OnNewSegment(std::shared_ptr<Linker::Segment> linker_segment)
override;
388 std::unique_ptr<P3Format> contents;
398 void SetOptions(std::map<std::string, std::string>& options)
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:308
Documents and handles command line options.
Definition options.h:196
A helper class, encapsulating functionality needed to import binary data.
Definition reader.h:16
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