RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
Linker::Buffer Class Reference

A buffer that can be used to read and store data from a file. More...

#include <buffer.h>

Inheritance diagram for Linker::Buffer:
Linker::Image Linker::Contents Linker::Section Linker::TableSection< GOTEntry > Linker::TableSection< TableEntryType > Linker::GlobalOffsetTable

Public Member Functions

 Buffer (size_t size)
 
 Buffer (const std::vector< uint8_t > &data)
 
offset_t ImageSize () const override
 Retrieves the offset of the byte after the last one belonging to this format from the first one.
 
void Resize (offset_t new_size)
 Resize buffer.
 
virtual offset_t Expand (offset_t new_size)
 Increases the size of the buffer by the specified amount.
 
virtual offset_t WriteData (size_t bytes, offset_t offset, const void *buffer)
 Writes data into the buffer image.
 
virtual offset_t WriteWord (size_t bytes, offset_t offset, uint64_t value, EndianType endiantype)
 Append data to buffer.
 
offset_t WriteWord (size_t bytes, offset_t offset, uint64_t value)
 Writes a value into the buffer image.
 
offset_t WriteWord (size_t bytes, uint64_t value, EndianType endiantype)
 Writes a value at the current end of the buffer.
 
offset_t WriteWord (size_t bytes, uint64_t value)
 Writes value at the current end of the buffer.
 
virtual offset_t Append (const void *new_data, size_t length)
 Appends data at the end of a buffer.
 
offset_t Append (const char *new_data)
 Appends data at the end of a buffer.
 
offset_t Append (std::vector< uint8_t > &additional_data)
 Appends data at the end of a buffer.
 
virtual void ReadFile (const std::shared_ptr< Reader > &rd)
 Overwrites buffer data with contents of reader.
 
void ReadFileRemaining (const std::shared_ptr< Reader > &rd)
 Overwrites buffer data with contents of reader.
 
void ReadFile (const std::shared_ptr< Reader > &rd, offset_t count)
 Overwrites buffer data with contents of reader.
 
offset_t WriteFile (const std::shared_ptr< Writer > &wr, offset_t count, offset_t offset=0) const override
 Writes data of non-zero filled sections.
 
size_t ReadData (size_t bytes, offset_t offset, void *buffer) const override
 Attempts to fill a buffer with data.
 
virtual offset_t WriteFile (const std::shared_ptr< Writer > &wr) const=0
 Writes data of non-zero filled sections.
 
- Public Member Functions inherited from Linker::Image
std::shared_ptr< const Image > AsImage () const override
 Retrieves a randomly accessible image.
 
uint64_t ReadUnsigned (size_t bytes, offset_t offset, EndianType endiantype) const
 Reads an unsigned number at a specific offset.
 
uint64_t ReadUnsigned (size_t bytes, offset_t offset) const
 Reads an unsigned number at a specific offset with the default endianness.
 
int64_t ReadSigned (size_t bytes, offset_t offset, EndianType endiantype) const
 Reads a signed number at a specific offset.
 
int64_t ReadSigned (size_t bytes, offset_t offset) const
 Reads a signed number at a specific offset with the default endianness.
 
int GetByte (offset_t offset) const
 Retrieve byte at a certain offset (optional, might not be defined)
 
offset_t WriteFile (const std::shared_ptr< Writer > &wr) const override
 Writes data of non-zero filled sections.
 
virtual offset_t WriteFile (const std::shared_ptr< Writer > &wr) const=0
 Writes data of non-zero filled sections.
 
- Public Member Functions inherited from Linker::Contents
std::shared_ptr< Image > AsImage ()
 Retrieves a randomly accessible image.
 

Static Public Member Functions

static std::shared_ptr< Buffer > ReadFromFile (const std::shared_ptr< Reader > &rd)
 Creates a buffer containing the remaining data in the reader.
 
static std::shared_ptr< Buffer > ReadFromFile (const std::shared_ptr< Reader > &rd, offset_t count)
 Creates a buffer containing the specified amount of bytes from the reader.
 

Protected Attributes

std::vector< uint8_t > data
 

Friends

class Section
 
class Contents
 

Detailed Description

A buffer that can be used to read and store data from a file.

Member Function Documentation

◆ Append()

offset_t Buffer::Append ( const void *  new_data,
size_t  length 
)
virtual

Appends data at the end of a buffer.

Parameters
new_dataPointer to data to append
lengthNumber of bytes of data to load from pointer and insert into buffer
Returns
The offset of the newly written data within the buffer

Reimplemented in Linker::Section.

◆ Expand()

offset_t Buffer::Expand ( offset_t  new_size)
virtual

Increases the size of the buffer by the specified amount.

Parameters
new_sizeThe new size for the buffer. If it is smaller than the current size, nothing is changed.
Returns
The actual amount of bytes the buffer was increased by.

Reimplemented in Linker::Section.

◆ ImageSize()

offset_t Buffer::ImageSize ( ) const
overridevirtual

Retrieves the offset of the byte after the last one belonging to this format from the first one.

Returns
The size of the image, or offset_t(-1) if it cannot be determined before writing to the file

Implements Linker::Contents.

◆ ReadData()

size_t Buffer::ReadData ( size_t  bytes,
offset_t  offset,
void *  buffer 
) const
overridevirtual

Attempts to fill a buffer with data.

Parameters
bytesThe (maximum) number of bytes to place in buffer
offsetThe offset in the image to start reading the data
bufferA byte buffer
Returns
Actual number of bytes copied into buffer

Implements Linker::Image.

Reimplemented in Linker::Section, Linker::TableSection< TableEntryType >, and Linker::TableSection< GOTEntry >.

◆ ReadFile() [1/2]

void Buffer::ReadFile ( const std::shared_ptr< Reader > &  rd)
virtual

Overwrites buffer data with contents of reader.

Note that only as many bytes are read in as the size of the buffer.

Reimplemented in Linker::Section, Linker::Section, Linker::TableSection< TableEntryType >, and Linker::TableSection< GOTEntry >.

◆ ReadFile() [2/2]

void Buffer::ReadFile ( const std::shared_ptr< Reader > &  rd,
offset_t  count 
)

Overwrites buffer data with contents of reader.

Exactly the specified amount is read, the buffer is expanded if needed but not shrank

◆ ReadFileRemaining()

void Buffer::ReadFileRemaining ( const std::shared_ptr< Reader > &  rd)

Overwrites buffer data with contents of reader.

All the remaining bytes are read, the buffer is expanded if needed but not shrank

◆ ReadFromFile()

std::shared_ptr< Buffer > Buffer::ReadFromFile ( const std::shared_ptr< Reader > &  rd,
offset_t  count 
)
static

Creates a buffer containing the specified amount of bytes from the reader.

If less data is available, the buffer will be shorter

◆ WriteData()

offset_t Buffer::WriteData ( size_t  bytes,
offset_t  offset,
const void *  buffer 
)
virtual

Writes data into the buffer image.

Returns
The amount of bytes the buffer was increased by.

Reimplemented in Linker::Section.

◆ WriteFile() [1/2]

virtual offset_t Linker::Contents::WriteFile ( const std::shared_ptr< Writer > &  wr) const
virtual

◆ WriteFile() [2/2]

offset_t Buffer::WriteFile ( const std::shared_ptr< Writer > &  wr,
offset_t  count,
offset_t  offset = 0 
) const
overridevirtual

◆ WriteWord() [1/4]

offset_t Buffer::WriteWord ( size_t  bytes,
offset_t  offset,
uint64_t  value 
)

Writes a value into the buffer image.

Returns
The amount of bytes the buffer was increased by.

◆ WriteWord() [2/4]

offset_t Buffer::WriteWord ( size_t  bytes,
offset_t  offset,
uint64_t  value,
EndianType  endiantype 
)
virtual

Append data to buffer.

Writes a value into the buffer image

Returns
The amount of bytes the buffer was increased by.

Reimplemented in Linker::Section.

◆ WriteWord() [3/4]

offset_t Buffer::WriteWord ( size_t  bytes,
uint64_t  value 
)

Writes value at the current end of the buffer.

Returns
The amount of bytes the buffer was increased by.

◆ WriteWord() [4/4]

offset_t Buffer::WriteWord ( size_t  bytes,
uint64_t  value,
EndianType  endiantype 
)

Writes a value at the current end of the buffer.

Returns
The amount of bytes the buffer was increased by.

The documentation for this class was generated from the following files: