retdec
Public Member Functions | Private Attributes | List of all members
retdec::loader::Segment Class Reference

#include <segment.h>

Collaboration diagram for retdec::loader::Segment:
Collaboration graph
[legend]

Public Member Functions

 Segment (const retdec::fileformat::SecSeg *secSeg, std::uint64_t address, std::uint64_t size, std::unique_ptr< SegmentDataSource > &&dataSource)
 
 Segment (const Segment &segment)
 
const retdec::fileformat::SecSeggetSecSeg () const
 
bool containsAddress (std::uint64_t address) const
 
std::uint64_t getAddress () const
 
std::uint64_t getEndAddress () const
 
std::uint64_t getPhysicalEndAddress () const
 
std::uint64_t getSize () const
 
std::uint64_t getPhysicalSize () const
 
retdec::common::Range< std::uint64_t > getAddressRange () const
 
retdec::common::Range< std::uint64_t > getPhysicalAddressRange () const
 
const retdec::common::RangeContainer< std::uint64_t > & getNonDecodableAddressRanges () const
 
std::pair< const std::uint8_t *, std::uint64_t > getRawData () const
 
bool hasName () const
 
const std::string & getName () const
 
void setName (const std::string &name)
 
bool getBytes (std::vector< unsigned char > &result) const
 
bool getBytes (std::vector< unsigned char > &result, std::uint64_t addressOffset, std::uint64_t size) const
 
bool getBits (std::string &result) const
 
bool getBits (std::string &result, std::uint64_t addressOffset, std::uint64_t bytesCount) const
 
bool setBytes (const std::vector< unsigned char > &value, std::uint64_t addressOffset)
 
void resize (std::uint64_t newSize)
 
void shrink (std::uint64_t shrinkOffset, std::uint64_t newSize)
 
void addNonDecodableRange (retdec::common::Range< std::uint64_t > range)
 

Private Attributes

const retdec::fileformat::SecSeg_secSeg
 
std::uint64_t _address
 
std::uint64_t _size
 
std::unique_ptr< SegmentDataSource_dataSource
 
std::string _name
 
retdec::common::RangeContainer< std::uint64_t > _nonDecodableRanges
 

Constructor & Destructor Documentation

◆ Segment() [1/2]

retdec::loader::Segment::Segment ( const retdec::fileformat::SecSeg secSeg,
std::uint64_t  address,
std::uint64_t  size,
std::unique_ptr< SegmentDataSource > &&  dataSource 
)

◆ Segment() [2/2]

retdec::loader::Segment::Segment ( const Segment segment)

Member Function Documentation

◆ addNonDecodableRange()

void retdec::loader::Segment::addNonDecodableRange ( retdec::common::Range< std::uint64_t >  range)

Adds address range which should be ignored during the instruction decoding.

Parameters
rangeRange to add.

◆ containsAddress()

bool retdec::loader::Segment::containsAddress ( std::uint64_t  address) const

Returns whether the segment contains specified address.

Parameters
addressThe address to check.
Returns
True if contains, otherwise false.

◆ getAddress()

std::uint64_t retdec::loader::Segment::getAddress ( ) const

Returns an address the segment is loaded at.

Returns
Address of the segment.

◆ getAddressRange()

retdec::common::Range< std::uint64_t > retdec::loader::Segment::getAddressRange ( ) const

Returns the address range. Range goes <getAddress(), getEndAddress()>.

Returns
Address range.

◆ getBits() [1/2]

bool retdec::loader::Segment::getBits ( std::string &  result) const

Get content of segment as bits in string representation.

Parameters
resultBits in string representation.
Returns
True if read was successful, otherwise false.

◆ getBits() [2/2]

bool retdec::loader::Segment::getBits ( std::string &  result,
std::uint64_t  addressOffset,
std::uint64_t  bytesCount 
) const

Get content of segment as bits in string representation.

Parameters
resultBits in string representation.
addressOffsetFirst byte of the segment to be read (0 means first byte of segment).
bytesCountNumber of bytes for read.
Returns
True if read was successful, otherwise false.

◆ getBytes() [1/2]

bool retdec::loader::Segment::getBytes ( std::vector< unsigned char > &  result) const

Get the whole content of segment as bytes.

Parameters
resultRead bytes in integer representation.
Returns
True if read was successful, otherwise false.

◆ getBytes() [2/2]

bool retdec::loader::Segment::getBytes ( std::vector< unsigned char > &  result,
std::uint64_t  addressOffset,
std::uint64_t  size 
) const

Get content of segment as bytes.

Parameters
resultRead bytes in integer representation.
addressOffsetFirst byte of the segment to be read (0 means first byte of segment).
sizeNumber of bytes for read.
Returns
True if read was successful, otherwise false.

◆ getEndAddress()

std::uint64_t retdec::loader::Segment::getEndAddress ( ) const

Returns the last valid address of the segment.

Returns
End address of the segment.

◆ getName()

const std::string & retdec::loader::Segment::getName ( ) const

Returns the name of the segment, if it has one.

Returns
Name of the segment.

◆ getNonDecodableAddressRanges()

const retdec::common::RangeContainer< std::uint64_t > & retdec::loader::Segment::getNonDecodableAddressRanges ( ) const

Returns the list of address ranges which should be ignored during instruction decoding.

Returns
List of address ranges.

◆ getPhysicalAddressRange()

retdec::common::Range< std::uint64_t > retdec::loader::Segment::getPhysicalAddressRange ( ) const

Returns the address range. Range goes <getAddress(), getEndAddress()>.

Returns
Address range.

◆ getPhysicalEndAddress()

std::uint64_t retdec::loader::Segment::getPhysicalEndAddress ( ) const

Returns the last address of the segment that contains physical data from the file.

Returns
End address of the physical data of the segment.

◆ getPhysicalSize()

std::uint64_t retdec::loader::Segment::getPhysicalSize ( ) const

Returns the size of the physical data that is loaded for the file. If the physical size is greater than virtual, virtual is returned instead.

Returns
The physical size of the segment.

◆ getRawData()

std::pair< const std::uint8_t *, std::uint64_t > retdec::loader::Segment::getRawData ( ) const

Returns the raw data of the segment in its size. Returns null pointer and 0 for segments without any source of phyiscal data.

Returns
Raw data pointer and size.

◆ getSecSeg()

const retdec::fileformat::SecSeg * retdec::loader::Segment::getSecSeg ( ) const

Returns associated section or segment, which was used for loading of this segment.

Returns
Associated section or segment. If no section or segment is associated, returns nullptr.

◆ getSize()

std::uint64_t retdec::loader::Segment::getSize ( ) const

Returns the loaded size of the segment.

Returns
The size of the segment.

◆ hasName()

bool retdec::loader::Segment::hasName ( ) const

Returns whether the segment is named segment.

Returns
True if set, otherwise false.

◆ resize()

void retdec::loader::Segment::resize ( std::uint64_t  newSize)

Resizes segment to a given size.

Parameters
newSizeThe new size of segment.

◆ setBytes()

bool retdec::loader::Segment::setBytes ( const std::vector< unsigned char > &  value,
std::uint64_t  addressOffset 
)

◆ setName()

void retdec::loader::Segment::setName ( const std::string &  name)

Sets the name to the segment.

Parameters
nameNew name of the segment.

◆ shrink()

void retdec::loader::Segment::shrink ( std::uint64_t  newAddress,
std::uint64_t  newSize 
)

Shrinks the segment to start from the new given address and has new given size. The address must already be valid address in the segment and size cannot exceed the current upper bound of the segment.

Parameters
newAddressThe new address of segment.
newSizeThe new size of segment.

Member Data Documentation

◆ _address

std::uint64_t retdec::loader::Segment::_address
private

◆ _dataSource

std::unique_ptr<SegmentDataSource> retdec::loader::Segment::_dataSource
private

◆ _name

std::string retdec::loader::Segment::_name
private

◆ _nonDecodableRanges

retdec::common::RangeContainer<std::uint64_t> retdec::loader::Segment::_nonDecodableRanges
private

◆ _secSeg

const retdec::fileformat::SecSeg* retdec::loader::Segment::_secSeg
private

◆ _size

std::uint64_t retdec::loader::Segment::_size
private

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