retdec
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
retdec::loader::Image Class Referenceabstract

#include <image.h>

Inheritance diagram for retdec::loader::Image:
Inheritance graph
[legend]
Collaboration diagram for retdec::loader::Image:
Collaboration graph
[legend]

Public Member Functions

 Image (const std::shared_ptr< retdec::fileformat::FileFormat > &fileFormat)
 
virtual bool load ()=0
 
virtual retdec::utils::Endianness getEndianness () const override
 
virtual std::size_t getNibbleLength () const override
 
virtual std::size_t getByteLength () const override
 
virtual std::size_t getWordLength () const override
 
virtual std::size_t getBytesPerWord () const override
 
virtual std::size_t getNumberOfNibblesInByte () const override
 
virtual bool hasMixedEndianForDouble () const override
 
virtual bool getXByte (std::uint64_t address, std::uint64_t x, std::uint64_t &res, retdec::utils::Endianness e=retdec::utils::Endianness::UNKNOWN) const override
 
virtual bool getXBytes (std::uint64_t address, std::uint64_t x, std::vector< std::uint8_t > &res) const override
 
virtual bool setXByte (std::uint64_t address, std::uint64_t x, std::uint64_t val, retdec::utils::Endianness e=retdec::utils::Endianness::UNKNOWN) override
 
virtual bool setXBytes (std::uint64_t address, const std::vector< std::uint8_t > &res) override
 
retdec::fileformat::FileFormatgetFileFormat ()
 
const retdec::fileformat::FileFormatgetFileFormat () const
 
std::weak_ptr< retdec::fileformat::FileFormatgetFileFormatWptr () const
 
std::size_t getNumberOfSegments () const
 
const std::vector< std::unique_ptr< Segment > > & getSegments () const
 
std::uint64_t getBaseAddress () const
 
void setBaseAddress (std::uint64_t baseAddress)
 
bool hasDataOnAddress (std::uint64_t address) const
 
bool hasDataInitializedOnAddress (std::uint64_t address) const
 
bool hasReadOnlyDataOnAddress (std::uint64_t address) const
 Test if there are some read-only data on provided address – address belongs to some read-only section or segment. More...
 
bool hasSegmentOnAddress (std::uint64_t address) const
 
bool isPointer (std::uint64_t address, std::uint64_t *pointer=nullptr) const
 
SegmentgetSegment (std::size_t index)
 
SegmentgetSegment (const std::string &name)
 
SegmentgetSegmentWithIndex (std::size_t index)
 
SegmentgetSegmentFromAddress (std::uint64_t address)
 
const SegmentgetSegment (std::size_t index) const
 
const SegmentgetSegment (const std::string &name) const
 
const SegmentgetSegmentWithIndex (std::size_t index) const
 
const SegmentgetSegmentFromAddress (std::uint64_t address) const
 
const SegmentgetEpSegment ()
 
std::pair< const std::uint8_t *, std::uint64_t > getRawSegmentData (std::uint64_t address) const
 
const std::string & getStatusMessage () const
 
const retdec::fileformat::LoaderErrorInfogetLoaderErrorInfo () const
 
- Public Member Functions inherited from retdec::utils::ByteValueStorage
 ByteValueStorage ()=default
 
virtual ~ByteValueStorage ()=default
 
Endianness getInverseEndianness () const
 
bool isLittleEndian () const
 
bool isBigEndian () const
 
bool isUnknownEndian () const
 
bool hexToBig (std::string &str) const
 
bool hexToLittle (std::string &str) const
 
bool bitsToBig (std::string &str) const
 
bool bitsToLittle (std::string &str) const
 
bool bitsToBig (std::vector< unsigned char > &values) const
 
bool bitsToLittle (std::vector< unsigned char > &values) const
 
bool get1Byte (std::uint64_t address, std::uint64_t &res, Endianness e=Endianness::UNKNOWN) const
 
bool get2Byte (std::uint64_t address, std::uint64_t &res, Endianness e=Endianness::UNKNOWN) const
 
bool get4Byte (std::uint64_t address, std::uint64_t &res, Endianness e=Endianness::UNKNOWN) const
 
bool get8Byte (std::uint64_t address, std::uint64_t &res, Endianness e=Endianness::UNKNOWN) const
 
bool get10Byte (std::uint64_t address, long double &res) const
 
bool getWord (std::uint64_t address, std::uint64_t &res, Endianness e=Endianness::UNKNOWN) const
 
bool getFloat (std::uint64_t address, float &res) const
 
bool getDouble (std::uint64_t address, double &res) const
 
bool set1Byte (std::uint64_t address, std::uint64_t val, Endianness e=Endianness::UNKNOWN)
 
bool set2Byte (std::uint64_t address, std::uint64_t val, Endianness e=Endianness::UNKNOWN)
 
bool set4Byte (std::uint64_t address, std::uint64_t val, Endianness e=Endianness::UNKNOWN)
 
bool set8Byte (std::uint64_t address, std::uint64_t val, Endianness e=Endianness::UNKNOWN)
 
bool set10Byte (std::uint64_t address, long double val)
 
bool setWord (std::uint64_t address, std::uint64_t val, Endianness e=Endianness::UNKNOWN)
 
bool setFloat (std::uint64_t address, float val)
 
bool setDouble (std::uint64_t address, double val)
 
bool getXByteArray (std::uint64_t address, std::uint64_t x, std::vector< std::uint64_t > &res, std::size_t size, Endianness e=Endianness::UNKNOWN) const
 
bool get1ByteArray (std::uint64_t address, std::vector< std::uint64_t > &res, std::size_t size, Endianness e=Endianness::UNKNOWN) const
 
bool get2ByteArray (std::uint64_t address, std::vector< std::uint64_t > &res, std::size_t size, Endianness e=Endianness::UNKNOWN) const
 
bool get4ByteArray (std::uint64_t address, std::vector< std::uint64_t > &res, std::size_t size, Endianness e=Endianness::UNKNOWN) const
 
bool get8ByteArray (std::uint64_t address, std::vector< std::uint64_t > &res, std::size_t size, Endianness e=Endianness::UNKNOWN) const
 
bool get10ByteArray (std::uint64_t address, std::vector< long double > &res, std::size_t size) const
 
bool getWordArray (std::uint64_t address, std::vector< std::uint64_t > &res, std::size_t, Endianness e=Endianness::UNKNOWN) const
 
bool getFloatArray (std::uint64_t address, std::vector< float > &res, std::size_t size) const
 
bool getDoubleArray (std::uint64_t address, std::vector< double > &res, std::size_t size) const
 
bool getNTBS (std::uint64_t address, std::string &res, std::size_t size=0) const
 
bool getNTWS (std::uint64_t address, std::size_t width, std::vector< std::uint64_t > &res) const
 
bool getNTWSNice (std::uint64_t address, std::size_t width, std::vector< std::uint64_t > &res) const
 

Protected Member Functions

SegmentinsertSegment (std::unique_ptr< Segment > segment)
 
void removeSegment (Segment *segment)
 
void nameSegment (Segment *segment)
 
void sortSegments ()
 
void setStatusMessage (const std::string &message)
 
- Protected Member Functions inherited from retdec::utils::ByteValueStorage
bool createValueFromBytes (const std::vector< std::uint8_t > &data, std::uint64_t &value, Endianness endian, std::uint64_t offset=0, std::uint64_t size=0) const
 
bool createBytesFromValue (std::uint64_t data, std::uint64_t x, std::vector< std::uint8_t > &value, Endianness endian) const
 
bool get10ByteImpl (const std::vector< std::uint8_t > &data, long double &res) const
 
bool getFloatImpl (const std::vector< std::uint8_t > &data, float &res) const
 
bool getDoubleImpl (const std::vector< std::uint8_t > &data, double &res) const
 
bool getNTBSImpl (const GetNByteFn &get1ByteFn, std::uint64_t address, std::string &res, std::size_t size) const
 
bool getNTWSImpl (const GetXByteFn &getXByteFn, std::uint64_t address, std::size_t width, std::vector< std::uint64_t > &res) const
 
bool getNTWSNiceImpl (const GetXByteFn &getXByteFn, std::uint64_t address, std::size_t width, std::vector< std::uint64_t > &res) const
 

Private Member Functions

const Segment_getSegment (std::size_t index) const
 
const Segment_getSegment (const std::string &name) const
 
const Segment_getSegmentWithIndex (std::size_t index) const
 
const Segment_getSegmentFromAddress (std::uint64_t address) const
 

Private Attributes

std::shared_ptr< retdec::fileformat::FileFormat_fileFormat
 
std::vector< std::unique_ptr< Segment > > _segments
 
std::uint64_t _baseAddress
 
NameGenerator _namelessSegNameGen
 
std::string _statusMessage
 

Additional Inherited Members

- Protected Types inherited from retdec::utils::ByteValueStorage
using GetNByteFn = std::function< bool(std::uint64_t, std::uint64_t &, Endianness)>
 
using GetXByteFn = std::function< bool(std::uint64_t, std::uint64_t, std::uint64_t &, Endianness)>
 

Constructor & Destructor Documentation

◆ Image()

retdec::loader::Image::Image ( const std::shared_ptr< retdec::fileformat::FileFormat > &  fileFormat)

Member Function Documentation

◆ _getSegment() [1/2]

const Segment * retdec::loader::Image::_getSegment ( const std::string &  name) const
private

◆ _getSegment() [2/2]

const Segment * retdec::loader::Image::_getSegment ( std::size_t  index) const
private

◆ _getSegmentFromAddress()

const Segment * retdec::loader::Image::_getSegmentFromAddress ( std::uint64_t  address) const
private

◆ _getSegmentWithIndex()

const Segment * retdec::loader::Image::_getSegmentWithIndex ( std::size_t  index) const
private

◆ getBaseAddress()

std::uint64_t retdec::loader::Image::getBaseAddress ( ) const

Returns a base address where the address space is loaded.

Returns
Base address.

◆ getByteLength()

std::size_t retdec::loader::Image::getByteLength ( ) const
overridevirtual

◆ getBytesPerWord()

std::size_t retdec::loader::Image::getBytesPerWord ( ) const
overridevirtual

◆ getEndianness()

Endianness retdec::loader::Image::getEndianness ( ) const
overridevirtual

◆ getEpSegment()

const Segment * retdec::loader::Image::getEpSegment ( )

Returns the segment into which entry points address falls, if any exists.

Returns
Entry point segment, otherwise nullptr.

◆ getFileFormat() [1/2]

retdec::fileformat::FileFormat * retdec::loader::Image::getFileFormat ( )

Returns the retdec::fileformat::FileFormat object associated with the loaded image, which contains static information about the file.

Returns
File format object.

◆ getFileFormat() [2/2]

const retdec::fileformat::FileFormat * retdec::loader::Image::getFileFormat ( ) const

Returns the retdec::fileformat::FileFormat object associated with the loaded image, which contains static information about the file.

Returns
File format object.

◆ getFileFormatWptr()

std::weak_ptr< retdec::fileformat::FileFormat > retdec::loader::Image::getFileFormatWptr ( ) const

Returns the retdec::fileformat::FileFormat object associated with the loaded image as weak pointer, which containers static information about the file.

Returns
Weak pointer to file format object.

◆ getLoaderErrorInfo()

const retdec::fileformat::LoaderErrorInfo & retdec::loader::Image::getLoaderErrorInfo ( ) const

◆ getNibbleLength()

std::size_t retdec::loader::Image::getNibbleLength ( ) const
overridevirtual

◆ getNumberOfNibblesInByte()

std::size_t retdec::loader::Image::getNumberOfNibblesInByte ( ) const
overridevirtual

◆ getNumberOfSegments()

std::size_t retdec::loader::Image::getNumberOfSegments ( ) const

Returns the number of the segments in the address space.

Returns
The number of segments.

◆ getRawSegmentData()

std::pair< const std::uint8_t *, std::uint64_t > retdec::loader::Image::getRawSegmentData ( std::uint64_t  address) const

Returns raw segment data together with its size. Caller should never access beyond pointer + size (including). Size is calculated from the physical size of the segment. Returns pair of null pointer and 0 in case of an error.

Parameters
addressAddress to start from.
Returns
Raw data pointer and size.

◆ getSegment() [1/4]

Segment * retdec::loader::Image::getSegment ( const std::string &  name)

Returns the segment with the provided name, if any exists.

Parameters
nameName of the segment.
Returns
Segment with provided name, otherwise nullptr.

◆ getSegment() [2/4]

const Segment * retdec::loader::Image::getSegment ( const std::string &  name) const

Returns the segment with the provided name, if any exists.

Parameters
nameName of the segment.
Returns
Segment with provided name, otherwise nullptr.

◆ getSegment() [3/4]

Segment * retdec::loader::Image::getSegment ( std::size_t  index)

Returns the segment at the given index, if any exists.

Parameters
indexIndex of the segment.
Returns
Segment at given index, otherwise nullptr.

◆ getSegment() [4/4]

const Segment * retdec::loader::Image::getSegment ( std::size_t  index) const

Returns the segment at the given index, if any exists.

Parameters
indexIndex of the segment.
Returns
Segment at given index, otherwise nullptr.

◆ getSegmentFromAddress() [1/2]

Segment * retdec::loader::Image::getSegmentFromAddress ( std::uint64_t  address)

Returns the segment into which provided address falls, if any exists.

Parameters
addressThe address to check.
Returns
Segment, otherwise nullptr.

◆ getSegmentFromAddress() [2/2]

const Segment * retdec::loader::Image::getSegmentFromAddress ( std::uint64_t  address) const

Returns the segment into which provided address falls, if any exists.

Parameters
addressThe address to check.
Returns
Segment, otherwise nullptr.

◆ getSegments()

const std::vector< std::unique_ptr< Segment > > & retdec::loader::Image::getSegments ( ) const

Returns the all loaded segments in the image.

Returns
Vector of loaded segments.

◆ getSegmentWithIndex() [1/2]

Segment * retdec::loader::Image::getSegmentWithIndex ( std::size_t  index)

Returns the segment created from section/segment in section/program headers at specified index, if any exists.

Parameters
indexIndex of the section/segment in section/program headers.
Returns
Segment at the specified index, otherwise nullptr.

◆ getSegmentWithIndex() [2/2]

const Segment * retdec::loader::Image::getSegmentWithIndex ( std::size_t  index) const

Returns the segment created from section/segment in section/program headers at specified index, if any exists.

Parameters
indexIndex of the section/segment in section/program headers.
Returns
Segment at the specified index, otherwise nullptr.

◆ getStatusMessage()

const std::string & retdec::loader::Image::getStatusMessage ( ) const

◆ getWordLength()

std::size_t retdec::loader::Image::getWordLength ( ) const
overridevirtual

◆ getXByte()

bool retdec::loader::Image::getXByte ( std::uint64_t  address,
std::uint64_t  x,
std::uint64_t &  res,
retdec::utils::Endianness  e = retdec::utils::Endianness::UNKNOWN 
) const
overridevirtual

Get integer (x bytes) located at provided address using the specified endian or default file endian

Parameters
addressAddress to get integer from
xNumber of bytes for conversion
resResult integer
eEndian - if specified it is forced, otherwise file's endian is used
Returns
Status of operation (true if all is OK, false otherwise)

Implements retdec::utils::ByteValueStorage.

◆ getXBytes()

bool retdec::loader::Image::getXBytes ( std::uint64_t  address,
std::uint64_t  x,
std::vector< std::uint8_t > &  res 
) const
overridevirtual

Get x bytes long byte array from specified address

Parameters
addressAddress to get array from
xNumber of bytes for get
resResult array.
Returns
Status of operation (true if all is OK, false otherwise)

Implements retdec::utils::ByteValueStorage.

◆ hasDataInitializedOnAddress()

bool retdec::loader::Image::hasDataInitializedOnAddress ( std::uint64_t  address) const

Checks whether there are data on the provided address – address must belong to some segment and it cannot be BSS segment.

Parameters
addressThe address to check.
Returns
True if data are present on the provided address, otherwise false.

◆ hasDataOnAddress()

bool retdec::loader::Image::hasDataOnAddress ( std::uint64_t  address) const

Checks whether there are data on the provided address – address must belong to some segment.

Parameters
addressThe address to check.
Returns
True if data are present on the provided address, otherwise false.

◆ hasMixedEndianForDouble()

bool retdec::loader::Image::hasMixedEndianForDouble ( ) const
overridevirtual

◆ hasReadOnlyDataOnAddress()

bool retdec::loader::Image::hasReadOnlyDataOnAddress ( std::uint64_t  address) const

Test if there are some read-only data on provided address – address belongs to some read-only section or segment.

Parameters
addressAddress to test
Returns
True if there are read-only data for address, false otherwise
Note
This will return false if address is in BSS or debug section.

◆ hasSegmentOnAddress()

bool retdec::loader::Image::hasSegmentOnAddress ( std::uint64_t  address) const

Checks whether there is segment on the provided address – whether address falls into some of the segments.

Parameters
addressThe address to check.
Returns
True if segment is present, otherwise false.

◆ insertSegment()

Segment * retdec::loader::Image::insertSegment ( std::unique_ptr< Segment segment)
protected

◆ isPointer()

bool retdec::loader::Image::isPointer ( std::uint64_t  address,
std::uint64_t *  pointer = nullptr 
) const

Find out, if there is a pointer (valid address) on the provided address

Parameters
addressAddress to check
pointerIf not nullptr, and there is a pointer on address, then set the pointer value to where this parameter points.
Returns
True if pointer on address, false otherwise

◆ load()

virtual bool retdec::loader::Image::load ( )
pure virtual

Virtual method that should be overriden in every subclass of Image. Performs the logic of loading.

Returns
True if loading was successful, otherwise false.

Implemented in retdec::loader::RawDataImage, retdec::loader::PeImage, retdec::loader::MachOImage, retdec::loader::IntelHexImage, retdec::loader::ElfImage, and retdec::loader::CoffImage.

◆ nameSegment()

void retdec::loader::Image::nameSegment ( Segment segment)
protected

◆ removeSegment()

void retdec::loader::Image::removeSegment ( Segment segment)
protected

◆ setBaseAddress()

void retdec::loader::Image::setBaseAddress ( std::uint64_t  baseAddress)

Sets a base address for the address space.

Parameters
baseAddressAddress to set.

◆ setStatusMessage()

void retdec::loader::Image::setStatusMessage ( const std::string &  message)
protected

◆ setXByte()

bool retdec::loader::Image::setXByte ( std::uint64_t  address,
std::uint64_t  x,
std::uint64_t  val,
retdec::utils::Endianness  e = retdec::utils::Endianness::UNKNOWN 
)
overridevirtual

◆ setXBytes()

bool retdec::loader::Image::setXBytes ( std::uint64_t  address,
const std::vector< std::uint8_t > &  res 
)
overridevirtual

◆ sortSegments()

void retdec::loader::Image::sortSegments ( )
protected

Member Data Documentation

◆ _baseAddress

std::uint64_t retdec::loader::Image::_baseAddress
private

◆ _fileFormat

std::shared_ptr<retdec::fileformat::FileFormat> retdec::loader::Image::_fileFormat
private

◆ _namelessSegNameGen

NameGenerator retdec::loader::Image::_namelessSegNameGen
private

◆ _segments

std::vector<std::unique_ptr<Segment> > retdec::loader::Image::_segments
private

◆ _statusMessage

std::string retdec::loader::Image::_statusMessage
private

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