134 std::variant<std::string, uint16_t> resource_id = uint16_t(0);
156 static std::shared_ptr<Section> ReadFromFile(
Reader& rd, offset_t count, std::string
name,
int flags =
Readable);
159 void AlterFlags(
bool state,
unsigned flags_mask);
167 void SetFlag(
unsigned newflags);
169 unsigned GetFlags()
const;
171 bool IsReadable()
const;
173 void SetReadable(
bool state);
175 bool IsWritable()
const;
177 void SetWritable(
bool state);
179 bool IsExecable()
const;
181 void SetExecable(
bool state);
183 bool IsMergeable()
const;
185 void SetMergeable(
bool state);
187 bool IsFixed()
const;
189 bool IsZeroFilled()
const;
191 offset_t SetZeroFilled(
bool is_zero_filled);
193 offset_t GetAlign()
const;
195 void SetAlign(offset_t new_align);
197 offset_t GetStartAddress()
const;
215 offset_t Size()
const;
223 offset_t
Expand(offset_t new_size);
230 int GetByte(offset_t offset)
override;
232 uint64_t ReadUnsigned(
size_t bytes, offset_t offset, EndianType endiantype)
const;
234 uint64_t ReadUnsigned(
size_t bytes, offset_t offset)
const;
236 int64_t ReadSigned(
size_t bytes, offset_t offset, EndianType endiantype)
const;
238 uint64_t ReadSigned(
size_t bytes, offset_t offset)
const;
240 void WriteWord(
size_t bytes, offset_t offset, uint64_t value, EndianType endiantype);
242 void WriteWord(
size_t bytes, offset_t offset, uint64_t value);
247 void WriteWord(
size_t bytes, uint64_t value, EndianType endiantype);
252 void WriteWord(
size_t bytes, uint64_t value);
257 offset_t
Append(
const void * new_data,
size_t length);
262 offset_t
Append(
const char * new_data);
286 using Linker::Buffer::ReadFile;
310 offset_t
WriteFile(std::ostream& out, offset_t size, offset_t offset = 0)
const;
320 offset_t
WriteFile(std::ostream& out)
const;
328 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
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:25
void Reset()
Clear the section.
Definition section.cc:360
offset_t SetAddress(offset_t new_address)
For non-fixed segments, sets the starting address and makes the fixed.
Definition section.cc:141
Position Start() const
Retrieves the address of the first byte of the section.
Definition section.cc:320
Position Base() const
Retrieves the address of the start of the segment of the section.
Definition section.cc:328
void ReadFile(std::istream &in)
Overwrites section data with contents of input stream.
Definition section.cc:334
offset_t Expand(offset_t new_size)
Increases the size of the section by the specified amount.
Definition section.cc:173
void ResetAddress(offset_t new_address)
Forcibly alters the starting address.
Definition section.cc:159
std::string name
Name of the section.
Definition section.h:30
std::weak_ptr< Segment > segment
The segment a section belongs to.
Definition section.h:141
void SetFlag(unsigned newflags)
Sets the flags of the section.
Definition section.cc:28
offset_t bias
Difference between the first byte of the section and the zero address associated with the section.
Definition section.h:125
std::string collection_name
Section name that collects sections.
Definition section.h:145
int GetByte(offset_t offset) override
Retrieve byte at a certain offset (optional, might not be defined)
Definition section.cc:206
offset_t RealignEnd(offset_t align)
Expands the section to a size such that its end is at a specified alignment.
Definition section.cc:193
offset_t Append(const void *new_data, size_t length)
Appends data at the end of a section.
Definition section.cc:258
section_flags
Possible flags for the section.
Definition section.h:40
@ Mergeable
Sections of the same name with this flag are overlayed instead of appended.
Definition section.h:63
@ Stack
Stack section.
Definition section.h:93
@ Heap
Heap section.
Definition section.h:97
@ Resource
Section data represents a resource that has to be handled differently.
Definition section.h:83
@ Fixed
Section resides at a fixed address and cannot be moved.
Definition section.h:76
@ Execable
The section data can be used as instruction.
Definition section.h:52
@ Readable
The data in the section can be read at runtime.
Definition section.h:44
@ ZeroFilled
Section is filled with zeros.
Definition section.h:70
@ Optional
Section data may be unallocated if necessary.
Definition section.h:89
@ CustomFlag
Other flags.
Definition section.h:101
section_flags flags
The type of the section.
Definition section.h:106
std::variant< std::string, uint16_t > resource_type
The resource type and ID for a resource section.
Definition section.h:133
offset_t WriteFile(std::ostream &out, offset_t size, offset_t offset=0) const
Writes data into file.
Definition section.cc:346
Represents an abstract interface whose data can be written to a file.
Definition writable.h:15