18 typedef uint32_t ResourceIdentifier_Integer;
19 typedef std::string ResourceIdentifier_String;
20 typedef std::variant<ResourceIdentifier_String, ResourceIdentifier_Integer> ResourceIdentifier;
138 ResourceIdentifier resource_id = uint16_t(0);
139 ResourceIdentifier resource_language = uint16_t(0);
161 static std::shared_ptr<Section> ReadFromFile(
Reader& rd, offset_t count, std::string
name,
int flags =
Readable);
164 void AlterFlags(
bool state,
unsigned flags_mask);
172 void SetFlag(
unsigned newflags);
174 unsigned GetFlags()
const;
176 bool IsReadable()
const;
178 void SetReadable(
bool state);
180 bool IsWritable()
const;
182 void SetWritable(
bool state);
184 bool IsExecutable()
const;
186 void SetExecutable(
bool state);
188 bool IsMergeable()
const;
190 void SetMergeable(
bool state);
192 bool IsFixed()
const;
194 bool IsZeroFilled()
const;
196 virtual offset_t SetZeroFilled(
bool is_zero_filled);
198 offset_t GetAlign()
const;
200 void SetAlign(offset_t new_align);
202 offset_t GetStartAddress()
const;
225 virtual offset_t Size()
const;
233 offset_t
Expand(offset_t new_size);
240 size_t ReadData(
size_t bytes, offset_t offset,
void * buffer)
const override;
247 offset_t
WriteData(
size_t bytes, offset_t offset,
const void * buffer);
254 offset_t
WriteWord(
size_t bytes, offset_t offset, uint64_t value, EndianType endiantype);
261 offset_t
WriteWord(
size_t bytes, offset_t offset, uint64_t value);
268 offset_t
WriteWord(
size_t bytes, uint64_t value, EndianType endiantype);
275 offset_t
WriteWord(
size_t bytes, uint64_t value);
280 offset_t
Append(
const void * new_data,
size_t length);
285 offset_t
Append(
const char * new_data);
315 virtual void ReadFile(std::istream& in);
335 virtual offset_t
WriteFile(std::ostream& out, offset_t bytes, offset_t offset = 0)
const;
345 offset_t
WriteFile(std::ostream& out)
const;
350 virtual void Reset();
353 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:53
virtual void ReadFile(Reader &rd)
Overwrites buffer data with contents of reader.
Definition buffer.cc:24
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:20
A section of data as read from an object file.
Definition section.h:28
offset_t GetEndAddress() const
Returns end address (GetStartAddress() + Size())
Definition section.cc:144
virtual void Reset()
Clear the section.
Definition section.cc:383
virtual offset_t WriteFile(std::ostream &out, offset_t bytes, offset_t offset=0) const
Writes data into file.
Definition section.cc:369
offset_t SetAddress(offset_t new_address)
For non-fixed segments, sets the starting address and makes the fixed.
Definition section.cc:149
Position Start() const
Retrieves the address of the first byte of the section.
Definition section.cc:343
Position Base() const
Retrieves the address of the start of the segment of the section.
Definition section.cc:351
virtual void ReadFile(std::istream &in)
Overwrites section data with contents of input stream.
Definition section.cc:357
offset_t Expand(offset_t new_size)
Increases the size of the section by the specified amount.
Definition section.cc:181
offset_t WriteData(size_t bytes, offset_t offset, const void *buffer)
Writes data into the section image.
Definition section.cc:236
void ResetAddress(offset_t new_address)
Forcibly alters the starting address.
Definition section.cc:167
std::string name
Name of the section.
Definition section.h:33
ResourceIdentifier resource_type
The resource type, ID and language for a resource section.
Definition section.h:137
std::weak_ptr< Segment > segment
The segment a section belongs to.
Definition section.h:146
void SetFlag(unsigned newflags)
Sets the flags of the section.
Definition section.cc:31
offset_t WriteWord(size_t bytes, offset_t offset, uint64_t value, EndianType endiantype)
Writes a value into the section image.
Definition section.cc:247
offset_t bias
Difference between the first byte of the section and the zero address associated with the section.
Definition section.h:128
std::string collection_name
Section name that collects sections.
Definition section.h:150
size_t ReadData(size_t bytes, offset_t offset, void *buffer) const override
Attempts to fill a buffer with data.
Definition section.cc:216
offset_t RealignEnd(offset_t align)
Expands the section to a size such that its end is at a specified alignment.
Definition section.cc:203
offset_t Append(const void *new_data, size_t length)
Appends data at the end of a section.
Definition section.cc:277
section_flags
Possible flags for the section.
Definition section.h:43
@ Executable
The section data can be used as instruction.
Definition section.h:55
@ Mergeable
Sections of the same name with this flag are overlayed instead of appended.
Definition section.h:66
@ Writable
The section can be written to at runtime.
Definition section.h:51
@ Stack
Stack section.
Definition section.h:96
@ Heap
Heap section.
Definition section.h:100
@ Resource
Section data represents a resource that has to be handled differently.
Definition section.h:86
@ Fixed
Section resides at a fixed address and cannot be moved.
Definition section.h:79
@ Readable
The data in the section can be read at runtime.
Definition section.h:47
@ ZeroFilled
Section is filled with zeros.
Definition section.h:73
@ Optional
Section data may be unallocated if necessary.
Definition section.h:92
@ CustomFlag
Other flags.
Definition section.h:104
section_flags flags
The type of the section.
Definition section.h:109