133 std::variant<std::string, uint16_t> resource_id = uint16_t(0);
155 static std::shared_ptr<Section> ReadFromFile(
Reader& rd, offset_t count, std::string
name,
int flags =
Readable);
158 void AlterFlags(
bool state,
unsigned flags_mask);
166 void SetFlag(
unsigned newflags);
168 unsigned GetFlags()
const;
170 bool IsReadable()
const;
172 void SetReadable(
bool state);
174 bool IsWritable()
const;
176 void SetWritable(
bool state);
178 bool IsExecutable()
const;
180 void SetExecutable(
bool state);
182 bool IsMergeable()
const;
184 void SetMergeable(
bool state);
186 bool IsFixed()
const;
188 bool IsZeroFilled()
const;
190 offset_t SetZeroFilled(
bool is_zero_filled);
192 offset_t GetAlign()
const;
194 void SetAlign(offset_t new_align);
196 offset_t GetStartAddress()
const;
214 offset_t Size()
const;
222 offset_t
Expand(offset_t new_size);
229 size_t ReadData(
size_t bytes, offset_t offset,
void * buffer)
const override;
231 void WriteWord(
size_t bytes, offset_t offset, uint64_t value, EndianType endiantype);
233 void WriteWord(
size_t bytes, offset_t offset, uint64_t value);
238 void WriteWord(
size_t bytes, uint64_t value, EndianType endiantype);
243 void WriteWord(
size_t bytes, uint64_t value);
248 offset_t
Append(
const void * new_data,
size_t length);
253 offset_t
Append(
const char * new_data);
277 using Buffer::ReadFile;
303 offset_t
WriteFile(std::ostream& out, offset_t size, offset_t offset = 0)
const;
313 offset_t
WriteFile(std::ostream& out)
const;
321 std::ostream& operator<<(std::ostream& out,
const Section& section);
A buffer that can be used to read and store data from a file.
Definition buffer.h:22
offset_t WriteFile(Writer &wr, offset_t count, offset_t offset=0) const override
Writes data of non-zero filled sections.
Definition buffer.cc:43
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 section of data as read from an object file.
Definition section.h:24
void Reset()
Clear the section.
Definition section.cc:352
offset_t SetAddress(offset_t new_address)
For non-fixed segments, sets the starting address and makes the fixed.
Definition section.cc:144
Position Start() const
Retrieves the address of the first byte of the section.
Definition section.cc:312
Position Base() const
Retrieves the address of the start of the segment of the section.
Definition section.cc:320
void ReadFile(std::istream &in)
Overwrites section data with contents of input stream.
Definition section.cc:326
offset_t Expand(offset_t new_size)
Increases the size of the section by the specified amount.
Definition section.cc:176
void ResetAddress(offset_t new_address)
Forcibly alters the starting address.
Definition section.cc:162
std::string name
Name of the section.
Definition section.h:29
std::weak_ptr< Segment > segment
The segment a section belongs to.
Definition section.h:140
void SetFlag(unsigned newflags)
Sets the flags of the section.
Definition section.cc:31
offset_t bias
Difference between the first byte of the section and the zero address associated with the section.
Definition section.h:124
std::string collection_name
Section name that collects sections.
Definition section.h:144
size_t ReadData(size_t bytes, offset_t offset, void *buffer) const override
Attempts to fill a buffer with data.
Definition section.cc:209
offset_t RealignEnd(offset_t align)
Expands the section to a size such that its end is at a specified alignment.
Definition section.cc:196
offset_t Append(const void *new_data, size_t length)
Appends data at the end of a section.
Definition section.cc:250
section_flags
Possible flags for the section.
Definition section.h:39
@ Executable
The section data can be used as instruction.
Definition section.h:51
@ Mergeable
Sections of the same name with this flag are overlayed instead of appended.
Definition section.h:62
@ Writable
The section can be written to at runtime.
Definition section.h:47
@ Stack
Stack section.
Definition section.h:92
@ Heap
Heap section.
Definition section.h:96
@ Resource
Section data represents a resource that has to be handled differently.
Definition section.h:82
@ Fixed
Section resides at a fixed address and cannot be moved.
Definition section.h:75
@ Readable
The data in the section can be read at runtime.
Definition section.h:43
@ ZeroFilled
Section is filled with zeros.
Definition section.h:69
@ Optional
Section data may be unallocated if necessary.
Definition section.h:88
@ CustomFlag
Other flags.
Definition section.h:100
section_flags flags
The type of the section.
Definition section.h:105
std::variant< std::string, uint16_t > resource_type
The resource type and ID for a resource section.
Definition section.h:132
offset_t WriteFile(std::ostream &out, offset_t size, offset_t offset=0) const
Writes data into file.
Definition section.cc:338