retdec
|
#include <byte_value_storage.h>
Public Member Functions | |
ByteValueStorage ()=default | |
virtual | ~ByteValueStorage ()=default |
virtual Endianness | getEndianness () const =0 |
virtual std::size_t | getNibbleLength () const =0 |
virtual std::size_t | getByteLength () const =0 |
virtual std::size_t | getWordLength () const =0 |
virtual std::size_t | getBytesPerWord () const =0 |
virtual std::size_t | getNumberOfNibblesInByte () const =0 |
virtual bool | hasMixedEndianForDouble () const =0 |
virtual bool | getXByte (std::uint64_t address, std::uint64_t x, std::uint64_t &res, Endianness e=Endianness::UNKNOWN) const =0 |
virtual bool | getXBytes (std::uint64_t address, std::uint64_t x, std::vector< std::uint8_t > &res) const =0 |
virtual bool | setXByte (std::uint64_t address, std::uint64_t x, std::uint64_t val, Endianness e=Endianness::UNKNOWN)=0 |
virtual bool | setXBytes (std::uint64_t address, const std::vector< std::uint8_t > &val)=0 |
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 Types | |
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)> |
Protected Member Functions | |
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 |
|
protected |
|
protected |
|
default |
|
virtualdefault |
bool retdec::utils::ByteValueStorage::bitsToBig | ( | std::string & | str | ) | const |
Convert bit string to big endian
str | String which will be converted |
true
if conversion went OK, false
otherwise bool retdec::utils::ByteValueStorage::bitsToBig | ( | std::vector< unsigned char > & | values | ) | const |
Convert bits to big endian
values | Bits for conversion stored as bytes |
true
if conversion went OK, false
otherwise bool retdec::utils::ByteValueStorage::bitsToLittle | ( | std::string & | str | ) | const |
Convert bit string to little endian
str | String which will be converted |
true
if conversion went OK, false
otherwise bool retdec::utils::ByteValueStorage::bitsToLittle | ( | std::vector< unsigned char > & | values | ) | const |
Convert bits to little endian
values | Bits for conversion stored as bytes |
true
if conversion went OK, false
otherwise
|
protected |
Create vector of bytes from integer
data | Integer |
x | Width of integer |
value | Resulted vector of bytes |
endian | Endian - if specified it is forced, otherwise file's endian is used |
true
if conversion went OK, false
otherwise
|
protected |
Create integer from vector of bytes
data | Vector of bytes |
value | Resulted value |
endian | Endian - if specified it is forced, otherwise file's endian is used |
offset | Offset of first byte from data which will be converted (0 means first offset from data) |
size | Number of bytes for conversion (0 means all bytes from offset to end of data) |
true
if conversion went OK, false
otherwise bool retdec::utils::ByteValueStorage::get10Byte | ( | std::uint64_t | address, |
long double & | res | ||
) | const |
Get long double from the specified address. If system has 80-bit (10-byte) long double, copy data directly. Else convert 80-bit (10-byte) long double into 64-bit (8-byte) double.
address | Address to get double from |
res | Result double |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::get10ByteArray | ( | std::uint64_t | address, |
std::vector< long double > & | res, | ||
std::size_t | size | ||
) | const |
Get long double (10B) array located at provided address using the specified array size
address | Address to get long double from |
res | Result long double array |
size | Array size (how many items are to be read) |
true
if all is OK, false
otherwise)
|
protected |
bool retdec::utils::ByteValueStorage::get1Byte | ( | std::uint64_t | address, |
std::uint64_t & | res, | ||
Endianness | e = Endianness::UNKNOWN |
||
) | const |
Get integer (1B) located at provided address using the specified endian or default file endian
address | Address to get integer from |
res | Result integer |
e | Endian - if specified it is forced, otherwise file's endian is used |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::get1ByteArray | ( | std::uint64_t | address, |
std::vector< std::uint64_t > & | res, | ||
std::size_t | size, | ||
Endianness | e = Endianness::UNKNOWN |
||
) | const |
Get integer (1B) array located at provided address using the specified array size and endian (or default file endian)
address | Address to get integer array from |
res | Result integer array |
size | Integer array size (how many items are to be read) |
e | Endian - if specified it is forced, otherwise file's endian is used |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::get2Byte | ( | std::uint64_t | address, |
std::uint64_t & | res, | ||
Endianness | e = Endianness::UNKNOWN |
||
) | const |
Get integer (2B) located at provided address using the specified endian or default file endian
address | Address to get integer from |
res | Result integer |
e | Endian - if specified it is forced, otherwise file's endian is used |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::get2ByteArray | ( | std::uint64_t | address, |
std::vector< std::uint64_t > & | res, | ||
std::size_t | size, | ||
Endianness | e = Endianness::UNKNOWN |
||
) | const |
Get integer (2B) array located at provided address using the specified array size and endian (or default file endian)
address | Address to get integer array from |
res | Result integer array |
size | Integer array size (how many items are to be read) |
e | Endian - if specified it is forced, otherwise file's endian is used |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::get4Byte | ( | std::uint64_t | address, |
std::uint64_t & | res, | ||
Endianness | e = Endianness::UNKNOWN |
||
) | const |
Get integer (4B) located at provided address using the specified endian or default file endian
address | Address to get integer from |
res | Result integer |
e | Endian - if specified it is forced, otherwise file's endian is used |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::get4ByteArray | ( | std::uint64_t | address, |
std::vector< std::uint64_t > & | res, | ||
std::size_t | size, | ||
Endianness | e = Endianness::UNKNOWN |
||
) | const |
Get integer (4B) array located at provided address using the specified array size and endian (or default file endian)
address | Address to get integer array from |
res | Result integer array |
size | Integer array size (how many items are to be read) |
e | Endian - if specified it is forced, otherwise file's endian is used |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::get8Byte | ( | std::uint64_t | address, |
std::uint64_t & | res, | ||
Endianness | e = Endianness::UNKNOWN |
||
) | const |
Get integer (8B) located at provided address using the specified endian or default file endian
address | Address to get integer from |
res | Result integer |
e | Endian - if specified it is forced, otherwise file's endian is used |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::get8ByteArray | ( | std::uint64_t | address, |
std::vector< std::uint64_t > & | res, | ||
std::size_t | size, | ||
Endianness | e = Endianness::UNKNOWN |
||
) | const |
Get integer (8B) array located at provided address using the specified array size and endian (or default file endian)
address | Address to get integer array from |
res | Result integer array |
size | Integer array size (how many items are to be read) |
e | Endian - if specified it is forced, otherwise file's endian is used |
true
if all is OK, false
otherwise)
|
pure virtual |
Implemented in retdec::loader::Image, retdec::fileformat::RawDataFormat, and retdec::fileformat::FileFormat.
|
pure virtual |
bool retdec::utils::ByteValueStorage::getDouble | ( | std::uint64_t | address, |
double & | res | ||
) | const |
Get double from the specified address.
address | Address to get double from |
res | Result double |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::getDoubleArray | ( | std::uint64_t | address, |
std::vector< double > & | res, | ||
std::size_t | size | ||
) | const |
Get double array located at provided address using the specified array size
address | Address to get double from |
res | Result double array |
size | Array size (how many items are to be read) |
true
if all is OK, false
otherwise)
|
protected |
|
pure virtual |
bool retdec::utils::ByteValueStorage::getFloat | ( | std::uint64_t | address, |
float & | res | ||
) | const |
Get float from the specified address.
address | Address to get float from |
res | Result float |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::getFloatArray | ( | std::uint64_t | address, |
std::vector< float > & | res, | ||
std::size_t | size | ||
) | const |
Get float array located at provided address using the specified array size
address | Address to get float from |
res | Result float array |
size | Array size (how many items are to be read) |
true
if all is OK, false
otherwise)
|
protected |
Endianness retdec::utils::ByteValueStorage::getInverseEndianness | ( | ) | const |
Get opposite endianness
Endianness::UNKNOWN | if file endianness is unknown |
|
pure virtual |
Implemented in retdec::loader::Image, and retdec::fileformat::FileFormat.
bool retdec::utils::ByteValueStorage::getNTBS | ( | std::uint64_t | address, |
std::string & | res, | ||
std::size_t | size = 0 |
||
) | const |
Get NTBS (null-terminated byte string) from specified address
address | Address to get string from |
res | Result string |
size | Requested size of string (if size is zero, read until zero byte) |
true
if all is OK, false
otherwise)
|
protected |
bool retdec::utils::ByteValueStorage::getNTWS | ( | std::uint64_t | address, |
std::size_t | width, | ||
std::vector< std::uint64_t > & | res | ||
) | const |
Get NTWS (null-terminated wide string) from the specified address
address | Address to get string from |
width | Byte width of one character |
res | Result character array |
true
if all is OK, false
otherwise)getNTWSNice()
for a faster wide-string-probing method.
|
protected |
bool retdec::utils::ByteValueStorage::getNTWSNice | ( | std::uint64_t | address, |
std::size_t | width, | ||
std::vector< std::uint64_t > & | res | ||
) | const |
Get nice NTWS (null-terminated wide string of ASCII characters) from the
specified address
address | Address to get string from |
width | Byte width of one character |
res | Result character array |
true
if all is OK, false
otherwise)getNTWS()
for a slower wide-string-forcing method.
|
protected |
|
pure virtual |
Implemented in retdec::loader::Image, and retdec::fileformat::FileFormat.
bool retdec::utils::ByteValueStorage::getWord | ( | std::uint64_t | address, |
std::uint64_t & | res, | ||
Endianness | e = Endianness::UNKNOWN |
||
) | const |
Get word located at provided address using the specified endian or default file endian
address | Address to get integer from |
res | Result integer |
e | Endian - if specified it is forced, otherwise file's endian is used |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::getWordArray | ( | std::uint64_t | address, |
std::vector< std::uint64_t > & | res, | ||
std::size_t | size, | ||
Endianness | e = Endianness::UNKNOWN |
||
) | const |
Get word array located at provided address using the specified size and endian (or default file endian)
address | Address to get integer from |
res | Result integer |
size | Word array size (how many items are to be read) |
e | Endian - if specified it is forced, otherwise file's endian is used |
true
if all is OK, false
otherwise)
|
pure virtual |
Implemented in retdec::loader::Image, and retdec::fileformat::FileFormat.
|
pure virtual |
Implemented in retdec::loader::Image, and retdec::fileformat::FileFormat.
bool retdec::utils::ByteValueStorage::getXByteArray | ( | std::uint64_t | address, |
std::uint64_t | x, | ||
std::vector< std::uint64_t > & | res, | ||
std::size_t | size, | ||
Endianness | e = Endianness::UNKNOWN |
||
) | const |
Get integer (x bytes) array located at provided address using the specified array size and endian (or default file endian)
address | Address to get integer array from |
x | Number of bytes for one array item |
res | Result integer array |
size | Integer array size (how many items are to be read) |
e | Endian - if specified it is forced, otherwise file's endian is used |
true
if all is OK, false
otherwise)
|
pure virtual |
Implemented in retdec::loader::Image, and retdec::fileformat::FileFormat.
|
pure virtual |
bool retdec::utils::ByteValueStorage::hexToBig | ( | std::string & | str | ) | const |
Convert hexadecimal string to big endian
str | String which will be converted |
true
if conversion went OK, false
otherwise bool retdec::utils::ByteValueStorage::hexToLittle | ( | std::string & | str | ) | const |
Convert hexadecimal string to little endian
str | String which will be converted |
true
if conversion went OK, false
otherwise bool retdec::utils::ByteValueStorage::isBigEndian | ( | ) | const |
Find out if endianness is big
true
if endianness is big, false
otherwise bool retdec::utils::ByteValueStorage::isLittleEndian | ( | ) | const |
Find out if endianness is little
true
if endianness is little, false
otherwise bool retdec::utils::ByteValueStorage::isUnknownEndian | ( | ) | const |
Find out if endianness is unknown
true
if endianness is unknown, false
otherwise bool retdec::utils::ByteValueStorage::set10Byte | ( | std::uint64_t | address, |
long double | val | ||
) |
Set long double at the specified address. If system has 80-bit (10-byte) long double, copy data directly. Else convert 80-bit (10-byte) long double into 64-bit (8-byte) double.
address | Address to set double at |
val | Double to set |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::set1Byte | ( | std::uint64_t | address, |
std::uint64_t | val, | ||
Endianness | e = Endianness::UNKNOWN |
||
) |
Set integer (1B) located at provided address using the specified endian or default file endian
address | Address to set integer at |
val | Integer to set |
e | Endian - if specified it is forced, otherwise file's endian is used |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::set2Byte | ( | std::uint64_t | address, |
std::uint64_t | val, | ||
Endianness | e = Endianness::UNKNOWN |
||
) |
Set integer (2B) located at provided address using the specified endian or default file endian
address | Address to set integer at |
val | Integer to set |
e | Endian - if specified it is forced, otherwise file's endian is used |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::set4Byte | ( | std::uint64_t | address, |
std::uint64_t | val, | ||
Endianness | e = Endianness::UNKNOWN |
||
) |
Set integer (4B) located at provided address using the specified endian or default file endian
address | Address to set integer at |
val | Integer to set |
e | Endian - if specified it is forced, otherwise file's endian is used |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::set8Byte | ( | std::uint64_t | address, |
std::uint64_t | val, | ||
Endianness | e = Endianness::UNKNOWN |
||
) |
Set integer (8B) located at provided address using the specified endian or default file endian
address | Address to set integer at |
val | Integer to set |
e | Endian - if specified it is forced, otherwise file's endian is used |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::setDouble | ( | std::uint64_t | address, |
double | val | ||
) |
Set double at the specified address.
address | Address to set double at |
val | Double to set |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::setFloat | ( | std::uint64_t | address, |
float | val | ||
) |
Set float at the specified address.
address | Address to set float at |
val | Float to set |
true
if all is OK, false
otherwise) bool retdec::utils::ByteValueStorage::setWord | ( | std::uint64_t | address, |
std::uint64_t | val, | ||
Endianness | e = Endianness::UNKNOWN |
||
) |
Set word located at provided address using the specified endian or default file endian
address | Address to set integer at |
val | Integer to set |
e | Endian - if specified it is forced, otherwise file's endian is used |
true
if all is OK, false
otherwise)
|
pure virtual |
Implemented in retdec::loader::Image, and retdec::fileformat::FileFormat.
|
pure virtual |
Implemented in retdec::fileformat::FileFormat, and retdec::loader::Image.