5#include "../dumper/dumper.h"
6#include "../linker/segment_manager.h"
19 unsigned FormatAdditionalSectionFlags(std::string section_name)
const override;
23 std::shared_ptr<Linker::Segment> image;
25 static const uint32_t REL32 = 0x80000000;
30 uint32_t offset : 31, rel32 : 1;
35 : offset(offset), rel32(rel32)
44 bool operator ==(
const Relocation& other)
const;
46 bool operator <(
const Relocation& other)
const;
49 offset_t image_size = 0;
50 std::set<Relocation> relocations;
51 offset_t header_size = 0;
52 offset_t bss_pages = 0;
53 offset_t extra_pages = 0;
56 offset_t relocation_offset = 0;
59 MPFormat(
bool has_relocations =
false)
60 : has_relocations(has_relocations)
64 void SetOptions(std::map<std::string, std::string>& options)
override;
66 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;
95 bool FormatSupportsStackSection()
const override;
98 const bool is_multisegmented;
101 uint16_t header_size = 0;
102 uint32_t file_size = 0;
104 uint32_t runtime_parameters_offset = 0;
105 uint32_t runtime_parameters_size = 0;
106 uint32_t relocation_table_offset = 0;
107 uint32_t relocation_table_size = 0;
108 uint32_t segment_information_table_offset = 0;
109 uint32_t segment_information_table_size = 0;
110 uint16_t segment_information_table_entry_size = 0;
111 uint32_t load_image_offset = 0;
112 uint32_t load_image_size = 0;
113 uint32_t symbol_table_offset = 0;
114 uint32_t symbol_table_size = 0;
115 uint32_t gdt_address = 0;
116 uint32_t gdt_size = 0;
117 uint32_t ldt_address = 0;
118 uint32_t ldt_size = 0;
119 uint32_t idt_address = 0;
120 uint32_t idt_size = 0;
121 uint32_t tss_address = 0;
122 uint32_t tss_size = 0;
123 uint32_t minimum_extra = 0;
124 uint32_t maximum_extra = 0;
125 uint32_t base_load_offset = 0;
133 uint32_t memory_requirements = 0;
134 uint32_t stack_size = 0;
138 P3Format(
bool is_multisegmented,
bool is_32bit =
true)
139 : is_multisegmented(is_multisegmented), is_32bit(is_32bit)
146 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;
147 uint32_t realmode_area_end = 0;
148 uint16_t call_buffer_size_kb = 0, flags = 0, ring = 0;
150 void CalculateValues();
157 void SetOptions(std::map<std::string, std::string>& options)
override;
173 Flat(
bool is_32bit =
true)
178 std::shared_ptr<Linker::Segment> image;
180 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;
201 uint32_t address = 0;
203 virtual uint32_t GetStoredSize()
const = 0;
204 virtual uint32_t GetLoadedSize()
const = 0;
211 std::weak_ptr<AbstractSegment> image;
230 Descriptor(uint32_t access, std::weak_ptr<AbstractSegment> image = std::weak_ptr<AbstractSegment>())
231 : image(image), access(access)
235 void CalculateValues();
243 std::vector<Descriptor> descriptors;
245 uint32_t GetStoredSize()
const override;
247 uint32_t GetLoadedSize()
const override;
251 void CalculateValues();
254 std::shared_ptr<DescriptorTable> gdt;
255 std::shared_ptr<DescriptorTable> idt;
256 std::shared_ptr<DescriptorTable> ldt;
263 uint32_t esp0 = 0, esp1 = 0, esp2 = 0;
264 uint32_t cr3 = 0, eip = 0, eflags = 0, eax = 0, ecx = 0, edx = 0, ebx = 0, esp = 0, ebp = 0, esi = 0, edi = 0;
265 uint16_t ss0 = 0, ss1 = 0, ss2 = 0, es = 0, cs = 0, ss = 0, ds = 0, fs = 0, gs = 0, ldtr = 0, iopb = 0;
273 uint32_t GetStoredSize()
const override;
275 uint32_t GetLoadedSize()
const override;
280 std::shared_ptr<TaskStateSegment> tss;
286 std::shared_ptr<Linker::Segment> segment;
291 uint32_t base_offset = 0;
293 Segment(std::shared_ptr<Linker::Segment> segment, uint32_t access, uint16_t selector)
294 : segment(segment), access(access), selector(selector)
298 uint32_t GetStoredSize()
const override;
300 uint32_t GetLoadedSize()
const override;
315 std::shared_ptr<Segment> segment;
318 Relocation(std::shared_ptr<Segment> segment, uint32_t offset)
319 : segment(segment), offset(offset)
323 bool operator ==(
const Relocation& other)
const;
325 bool operator <(
const Relocation& other)
const;
330 std::vector<std::shared_ptr<AbstractSegment>> segments;
331 std::map<std::shared_ptr<Linker::Segment>, std::shared_ptr<Segment>> segment_associations;
332 std::set<Relocation> relocations;
333 std::shared_ptr<Segment> code;
334 std::shared_ptr<Segment> data;
336 void OnNewSegment(std::shared_ptr<Linker::Segment> linker_segment)
override;
357 std::unique_ptr<P3Format> contents;
362 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
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