retdec
|
#include <sec_seg.h>
Public Types | |
enum class | Type { UNDEFINED_SEC_SEG , CODE , DATA , CODE_DATA , CONST_DATA , BSS , DEBUG , INFO } |
Public Member Functions | |
virtual | ~SecSeg ()=default |
Query methods | |
bool | isUndefined () const |
bool | isCode () const |
bool | isData () const |
bool | isCodeAndData () const |
bool | isConstData () const |
bool | isBss () const |
bool | isDebug () const |
bool | isInfo () const |
bool | isSomeData () const |
bool | isSomeCode () const |
bool | isDataOnly () const |
bool | isReadOnly () const |
Virtual query methods | |
virtual bool | isValid (const FileFormat *sOwner) const |
Getters | |
std::string | getCrc32 () const |
std::string | getMd5 () const |
std::string | getSha256 () const |
std::string | getName () const |
const char * | getNameAsCStr () const |
const llvm::StringRef | getBytes (unsigned long long sOffset=0, unsigned long long sSize=0) const |
SecSeg::Type | getType () const |
unsigned long long | getIndex () const |
unsigned long long | getOffset () const |
unsigned long long | getEndOffset () const |
unsigned long long | getSizeInFile () const |
unsigned long long | getLoadedSize () const |
unsigned long long | getAddress () const |
unsigned long long | getEndAddress () const |
bool | getSizeInMemory (unsigned long long &sMemorySize) const |
bool | getSizeOfOneEntry (unsigned long long &sEntrySize) const |
bool | getMemory () const |
bool | getEntropy (double &res) const |
template<typename NumberType > | |
NumberType | getBytesAtOffsetAsNumber (unsigned long long sOffset) const |
Getters of section or segment content | |
bool | getBits (std::string &sResult) const |
bool | getBytes (std::vector< unsigned char > &sResult, unsigned long long sOffset=0, unsigned long long sSize=0) const |
bool | getString (std::string &sResult, unsigned long long sOffset=0, unsigned long long sSize=0) const |
bool | getHexBytes (std::string &sResult) const |
Setters | |
void | setName (std::string sName) |
void | setType (SecSeg::Type sType) |
void | setIndex (unsigned long long sIndex) |
void | setOffset (unsigned long long sOffset) |
void | setSizeInFile (unsigned long long sFileSize) |
void | setAddress (unsigned long long sAddress) |
void | setSizeInMemory (unsigned long long sMemorySize) |
void | setSizeOfOneEntry (unsigned long long sEntrySize) |
void | setMemory (bool sMemory) |
Other methods | |
void | computeEntropy () |
void | invalidateMemorySize () |
void | invalidateEntrySize () |
void | load (const FileFormat *sOwner) |
void | dump (std::string &sDump) const |
bool | hasCrc32 () const |
bool | hasMd5 () const |
bool | hasSha256 () const |
bool | hasEmptyName () const |
bool | belong (unsigned long long sAddress) const |
bool | operator< (const SecSeg &sOther) const |
Private Member Functions | |
void | computeHashes () |
Private Attributes | |
std::string | crc32 |
CRC32 of section or segment data. More... | |
std::string | md5 |
MD5 of section or segment data. More... | |
std::string | sha256 |
SHA256 of section or segment data. More... | |
std::string | name |
name of section or segment More... | |
llvm::StringRef | bytes |
reference to content of section or segment More... | |
Type | type = Type::UNDEFINED_SEC_SEG |
type More... | |
unsigned long long | index = 0 |
index More... | |
unsigned long long | offset = 0 |
start offset in file More... | |
unsigned long long | fileSize = 0 |
size in file More... | |
unsigned long long | address = 0 |
start address in memory More... | |
unsigned long long | memorySize = 0 |
size in memory More... | |
unsigned long long | entrySize = 0 |
size of one entry in file More... | |
double | entropy = 0.0 |
entropy in <0,8> More... | |
bool | memorySizeIsValid = false |
true if size in memory is valid More... | |
bool | entrySizeIsValid = false |
size of one entry in section or segment More... | |
bool | isInMemory = false |
true if the section or segment will appear in the memory image of a process More... | |
bool | loaded = false |
true if content of section or segment was successfully loaded from input file More... | |
bool | isEntropyValid = false |
true if entropy has been computed More... | |
Base class for section and segment
|
strong |
|
virtualdefault |
bool retdec::fileformat::SecSeg::belong | ( | unsigned long long | sAddress | ) | const |
true
if the provided address sAddress
belongs to this section or segment, false
otherwise. void retdec::fileformat::SecSeg::computeEntropy | ( | ) |
Compute entropy of section data in <0,1>
|
private |
Compute all supported hashes
void retdec::fileformat::SecSeg::dump | ( | std::string & | sDump | ) | const |
Dump information about instance
sDump | Into this parameter is stored dump of instance in an LLVM style |
unsigned long long retdec::fileformat::SecSeg::getAddress | ( | ) | const |
Get address
bool retdec::fileformat::SecSeg::getBits | ( | std::string & | sResult | ) | const |
Get content of section or segment as bits
sResult | Read bits in string representation |
true
if operation went OK, false
otherwise bool retdec::fileformat::SecSeg::getBytes | ( | std::vector< unsigned char > & | sResult, |
unsigned long long | sOffset = 0 , |
||
unsigned long long | sSize = 0 |
||
) | const |
Get content of section or segment as bytes
sResult | Read bytes in integer representation |
sOffset | First byte of the section or segment to be loaded (0 means first byte of section or segment) |
sSize | Number of bytes for read. If this parameter is set to zero, method will read all bytes from sOffset until end of section or segment. |
true
if operation went OK, false
otherwise const llvm::StringRef retdec::fileformat::SecSeg::getBytes | ( | unsigned long long | sOffset = 0 , |
unsigned long long | sSize = 0 |
||
) | const |
Get section or segment content as reference to string
sOffset | First byte of the section or segment data to get (0 means first byte of section or segment data) |
sSize | Number of bytes to get. If this parameter is set to zero, method returns all bytes from sOffset until end of section or segment data. |
|
inline |
Read bytes from the given offset as a number of the given type.
sOffset | Index from which the number should be read. |
NumberType | Type of the number to read and return. |
std::string retdec::fileformat::SecSeg::getCrc32 | ( | ) | const |
Get CRC32
unsigned long long retdec::fileformat::SecSeg::getEndAddress | ( | ) | const |
Get end address
unsigned long long retdec::fileformat::SecSeg::getEndOffset | ( | ) | const |
Get end offset
bool retdec::fileformat::SecSeg::getEntropy | ( | double & | res | ) | const |
Get entropy of section data
res | Variable to store result to |
true
if entropy is valid, otherwise false
bool retdec::fileformat::SecSeg::getHexBytes | ( | std::string & | sResult | ) | const |
Get content of section or segment as bytes
sResult | Read bytes in hexadecimal string representation |
true
if operation went OK, false
otherwise unsigned long long retdec::fileformat::SecSeg::getIndex | ( | ) | const |
Get index
unsigned long long retdec::fileformat::SecSeg::getLoadedSize | ( | ) | const |
Get real file size of section or segment
std::string retdec::fileformat::SecSeg::getMd5 | ( | ) | const |
Get MD5
bool retdec::fileformat::SecSeg::getMemory | ( | ) | const |
Return true
if the section or segment will appear in the memory image of a process, false
otherwise
std::string retdec::fileformat::SecSeg::getName | ( | ) | const |
Get name
const char * retdec::fileformat::SecSeg::getNameAsCStr | ( | ) | const |
Returns the name as a null-terminated C string.
This version of getName() is useful when communicating with C APIs because the following code has undefined behavior (getName() returns a temporary):
Instead, use this function:
The returned pointer is valid as long as (1) the section/segment exists and (2) its name has not been changed.
unsigned long long retdec::fileformat::SecSeg::getOffset | ( | ) | const |
Get offset
std::string retdec::fileformat::SecSeg::getSha256 | ( | ) | const |
Get SHA256
unsigned long long retdec::fileformat::SecSeg::getSizeInFile | ( | ) | const |
Get size in file
bool retdec::fileformat::SecSeg::getSizeInMemory | ( | unsigned long long & | sMemorySize | ) | const |
Get size of section or segment in memory
sMemorySize | Into this parameter is stored section or segment memory size |
true
if memory size is valid, false
otherwiseIf method returns false
, sMemorySize is left unchanged
bool retdec::fileformat::SecSeg::getSizeOfOneEntry | ( | unsigned long long & | sEntrySize | ) | const |
Get size of one entry in section or segment
sEntrySize | Into this parameter is stored section or segment entry size |
true
if section or segment entry size is valid, false
otherwiseIf method returns false
, sEntrySize is left unchanged
bool retdec::fileformat::SecSeg::getString | ( | std::string & | sResult, |
unsigned long long | sOffset = 0 , |
||
unsigned long long | sSize = 0 |
||
) | const |
Get content of section or segment as plain string
sResult | Into this parameter is stored content of section or segment as plain string |
sOffset | First byte of the section or segment to be loaded (0 means first byte of section or segment) |
sSize | Number of bytes for read. If this parameter is set to zero, method will read all bytes from sOffset until end of section or segment. |
true
if operation went OK, false
otherwise SecSeg::Type retdec::fileformat::SecSeg::getType | ( | ) | const |
Get type
bool retdec::fileformat::SecSeg::hasCrc32 | ( | ) | const |
Check if CRC32 was computed
true
if CRC32 was computed, false
otherwise bool retdec::fileformat::SecSeg::hasEmptyName | ( | ) | const |
true
if section or segment has empty name, false
otherwise bool retdec::fileformat::SecSeg::hasMd5 | ( | ) | const |
Check if MD5 was computed
true
if MD5 was computed, false
otherwise bool retdec::fileformat::SecSeg::hasSha256 | ( | ) | const |
Check if SHA256 was computed
true
if SHA256 was computed, false
otherwise void retdec::fileformat::SecSeg::invalidateEntrySize | ( | ) |
Invalidate size of one entry in section or segment
Instance method getSizeOfOneEntry() returns false
after invocation of this method. Size of one entry is possible to revalidate by invocation of method setSizeOfOneEntry().
void retdec::fileformat::SecSeg::invalidateMemorySize | ( | ) |
Invalidate size of section or segment in memory
Instance method getSizeInMemory() returns false
after invocation of this method. Size in memory is possible to revalidate by invocation of method setMemorySize().
bool retdec::fileformat::SecSeg::isBss | ( | ) | const |
Check if section is BSS section
true
if section is BSS section, false
otherwise bool retdec::fileformat::SecSeg::isCode | ( | ) | const |
Check if section is code section
true
if section is code section, false
otherwise bool retdec::fileformat::SecSeg::isCodeAndData | ( | ) | const |
Check if section is code_data section
true
if section is code_data section, false
otherwise bool retdec::fileformat::SecSeg::isConstData | ( | ) | const |
Check if section is const data section
true
if section is const data section, false
otherwise bool retdec::fileformat::SecSeg::isData | ( | ) | const |
Check if section is data section
true
if section is data section, false
otherwise bool retdec::fileformat::SecSeg::isDataOnly | ( | ) | const |
true
if isData() or isConstData(), false
otherwise. bool retdec::fileformat::SecSeg::isDebug | ( | ) | const |
Check if section is debug section
true
if section is debug section, false
otherwise bool retdec::fileformat::SecSeg::isInfo | ( | ) | const |
Check if section is info section
true
if section is info section, false
otherwise bool retdec::fileformat::SecSeg::isReadOnly | ( | ) | const |
true
if isCode() or isConstData(), false
otherwise. bool retdec::fileformat::SecSeg::isSomeCode | ( | ) | const |
true
if isCode() or isCodeAndData(), false
otherwise. bool retdec::fileformat::SecSeg::isSomeData | ( | ) | const |
true
if isData() or isCodeAndData() or isConstData(), false
otherwise. bool retdec::fileformat::SecSeg::isUndefined | ( | ) | const |
Check if section type is undefined
true
if section type is undefined, false
otherwise
|
virtual |
Does this section appear to be valid in the context of the provided input file?
sOwner | Pointer to input file |
true
if section is valid, false
otherwise Reimplemented in retdec::fileformat::ElfSection.
void retdec::fileformat::SecSeg::load | ( | const FileFormat * | sOwner | ) |
Load content of section or segment from input file
sOwner | Pointer to input file |
This method must be called before getters of section or segment content
bool retdec::fileformat::SecSeg::operator< | ( | const SecSeg & | sOther | ) | const |
true
if this section or segment is less than the provided section or segment sOther
, false
otherwise. void retdec::fileformat::SecSeg::setAddress | ( | unsigned long long | sAddress | ) |
Set address
sAddress | Address |
void retdec::fileformat::SecSeg::setIndex | ( | unsigned long long | sIndex | ) |
Set index
sIndex | Index |
void retdec::fileformat::SecSeg::setMemory | ( | bool | sMemory | ) |
Set true
if the section or segment will appear in the memory image of a process, false
otherwise
void retdec::fileformat::SecSeg::setName | ( | std::string | sName | ) |
Set name
sName | Name |
void retdec::fileformat::SecSeg::setOffset | ( | unsigned long long | sOffset | ) |
Set offset
sOffset | Offset |
void retdec::fileformat::SecSeg::setSizeInFile | ( | unsigned long long | sFileSize | ) |
Set size in file
sFileSize | Size in file |
void retdec::fileformat::SecSeg::setSizeInMemory | ( | unsigned long long | sMemorySize | ) |
Set size of section or segment in memory
sMemorySize | Size of section or segment in memory |
void retdec::fileformat::SecSeg::setSizeOfOneEntry | ( | unsigned long long | sEntrySize | ) |
Set size of one entry in section or segment
sEntrySize | Size of one entry in section or segment |
void retdec::fileformat::SecSeg::setType | ( | SecSeg::Type | sType | ) |
Set type
sType | Type |
|
private |
start address in memory
|
private |
reference to content of section or segment
|
private |
CRC32 of section or segment data.
|
private |
entropy in <0,8>
|
private |
size of one entry in file
|
private |
size of one entry in section or segment
|
private |
size in file
|
private |
index
|
private |
true
if entropy has been computed
|
private |
true
if the section or segment will appear in the memory image of a process
|
private |
true
if content of section or segment was successfully loaded from input file
|
private |
MD5 of section or segment data.
|
private |
size in memory
|
private |
true
if size in memory is valid
|
private |
name of section or segment
|
private |
start offset in file
|
private |
SHA256 of section or segment data.
|
private |
type