retdec
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
retdec::fileformat::SecSeg Class Reference

#include <sec_seg.h>

Inheritance diagram for retdec::fileformat::SecSeg:
Inheritance graph
[legend]
Collaboration diagram for retdec::fileformat::SecSeg:
Collaboration graph
[legend]

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...
 

Detailed Description

Base class for section and segment

Member Enumeration Documentation

◆ Type

Enumerator
UNDEFINED_SEC_SEG 

undefined

CODE 

code

DATA 

data

CODE_DATA 

code and (or) data

CONST_DATA 

constant data

BSS 

uninitialized data

DEBUG 

debug information

INFO 

auxiliary information

Constructor & Destructor Documentation

◆ ~SecSeg()

virtual retdec::fileformat::SecSeg::~SecSeg ( )
virtualdefault

Member Function Documentation

◆ belong()

bool retdec::fileformat::SecSeg::belong ( unsigned long long  sAddress) const
Returns
true if the provided address sAddress belongs to this section or segment, false otherwise.

◆ computeEntropy()

void retdec::fileformat::SecSeg::computeEntropy ( )

Compute entropy of section data in <0,1>

◆ computeHashes()

void retdec::fileformat::SecSeg::computeHashes ( )
private

Compute all supported hashes

◆ dump()

void retdec::fileformat::SecSeg::dump ( std::string &  sDump) const

Dump information about instance

Parameters
sDumpInto this parameter is stored dump of instance in an LLVM style

◆ getAddress()

unsigned long long retdec::fileformat::SecSeg::getAddress ( ) const

Get address

Returns
Address

◆ getBits()

bool retdec::fileformat::SecSeg::getBits ( std::string &  sResult) const

Get content of section or segment as bits

Parameters
sResultRead bits in string representation
Returns
true if operation went OK, false otherwise

◆ getBytes() [1/2]

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

Parameters
sResultRead bytes in integer representation
sOffsetFirst byte of the section or segment to be loaded (0 means first byte of section or segment)
sSizeNumber of bytes for read. If this parameter is set to zero, method will read all bytes from sOffset until end of section or segment.
Returns
true if operation went OK, false otherwise

◆ getBytes() [2/2]

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

Parameters
sOffsetFirst byte of the section or segment data to get (0 means first byte of section or segment data)
sSizeNumber of bytes to get. If this parameter is set to zero, method returns all bytes from sOffset until end of section or segment data.
Returns
Section or segment content as reference to string

◆ getBytesAtOffsetAsNumber()

template<typename NumberType >
NumberType retdec::fileformat::SecSeg::getBytesAtOffsetAsNumber ( unsigned long long  sOffset) const
inline

Read bytes from the given offset as a number of the given type.

Parameters
sOffsetIndex from which the number should be read.
Returns
The read number. Returns zero if the offset is out-of-bounds or if there are not enough bytes to read.
Template Parameters
NumberTypeType of the number to read and return.

◆ getCrc32()

std::string retdec::fileformat::SecSeg::getCrc32 ( ) const

Get CRC32

Returns
CRC32 of section content

◆ getEndAddress()

unsigned long long retdec::fileformat::SecSeg::getEndAddress ( ) const

Get end address

Returns
End address of section or segment in memory

◆ getEndOffset()

unsigned long long retdec::fileformat::SecSeg::getEndOffset ( ) const

Get end offset

Returns
End offset of section or segment in file

◆ getEntropy()

bool retdec::fileformat::SecSeg::getEntropy ( double &  res) const

Get entropy of section data

Parameters
resVariable to store result to
Returns
true if entropy is valid, otherwise false

◆ getHexBytes()

bool retdec::fileformat::SecSeg::getHexBytes ( std::string &  sResult) const

Get content of section or segment as bytes

Parameters
sResultRead bytes in hexadecimal string representation
Returns
true if operation went OK, false otherwise

◆ getIndex()

unsigned long long retdec::fileformat::SecSeg::getIndex ( ) const

Get index

Returns
Index

◆ getLoadedSize()

unsigned long long retdec::fileformat::SecSeg::getLoadedSize ( ) const

Get real file size of section or segment

Returns
Real file size of section or segment

◆ getMd5()

std::string retdec::fileformat::SecSeg::getMd5 ( ) const

Get MD5

Returns
MD5 of section content

◆ getMemory()

bool retdec::fileformat::SecSeg::getMemory ( ) const

Return true if the section or segment will appear in the memory image of a process, false otherwise

◆ getName()

std::string retdec::fileformat::SecSeg::getName ( ) const

Get name

Returns
Name

◆ getNameAsCStr()

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):

const char *name = sec->getName().c_str();
std::string name
name of section or segment
Definition: sec_seg.h:41

Instead, use this function:

const char *name = sec->getNameAsCStr();

The returned pointer is valid as long as (1) the section/segment exists and (2) its name has not been changed.

◆ getOffset()

unsigned long long retdec::fileformat::SecSeg::getOffset ( ) const

Get offset

Returns
Offset

◆ getSha256()

std::string retdec::fileformat::SecSeg::getSha256 ( ) const

Get SHA256

Returns
SHA256 of section content

◆ getSizeInFile()

unsigned long long retdec::fileformat::SecSeg::getSizeInFile ( ) const

Get size in file

Returns
Size in file

◆ getSizeInMemory()

bool retdec::fileformat::SecSeg::getSizeInMemory ( unsigned long long &  sMemorySize) const

Get size of section or segment in memory

Parameters
sMemorySizeInto this parameter is stored section or segment memory size
Returns
true if memory size is valid, false otherwise

If method returns false, sMemorySize is left unchanged

◆ getSizeOfOneEntry()

bool retdec::fileformat::SecSeg::getSizeOfOneEntry ( unsigned long long &  sEntrySize) const

Get size of one entry in section or segment

Parameters
sEntrySizeInto this parameter is stored section or segment entry size
Returns
true if section or segment entry size is valid, false otherwise

If method returns false, sEntrySize is left unchanged

◆ getString()

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

Parameters
sResultInto this parameter is stored content of section or segment as plain string
sOffsetFirst byte of the section or segment to be loaded (0 means first byte of section or segment)
sSizeNumber of bytes for read. If this parameter is set to zero, method will read all bytes from sOffset until end of section or segment.
Returns
true if operation went OK, false otherwise

◆ getType()

SecSeg::Type retdec::fileformat::SecSeg::getType ( ) const

Get type

Returns
Type

◆ hasCrc32()

bool retdec::fileformat::SecSeg::hasCrc32 ( ) const

Check if CRC32 was computed

Returns
true if CRC32 was computed, false otherwise

◆ hasEmptyName()

bool retdec::fileformat::SecSeg::hasEmptyName ( ) const
Returns
true if section or segment has empty name, false otherwise

◆ hasMd5()

bool retdec::fileformat::SecSeg::hasMd5 ( ) const

Check if MD5 was computed

Returns
true if MD5 was computed, false otherwise

◆ hasSha256()

bool retdec::fileformat::SecSeg::hasSha256 ( ) const

Check if SHA256 was computed

Returns
true if SHA256 was computed, false otherwise

◆ invalidateEntrySize()

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().

◆ invalidateMemorySize()

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().

◆ isBss()

bool retdec::fileformat::SecSeg::isBss ( ) const

Check if section is BSS section

Returns
true if section is BSS section, false otherwise

◆ isCode()

bool retdec::fileformat::SecSeg::isCode ( ) const

Check if section is code section

Returns
true if section is code section, false otherwise

◆ isCodeAndData()

bool retdec::fileformat::SecSeg::isCodeAndData ( ) const

Check if section is code_data section

Returns
true if section is code_data section, false otherwise

◆ isConstData()

bool retdec::fileformat::SecSeg::isConstData ( ) const

Check if section is const data section

Returns
true if section is const data section, false otherwise

◆ isData()

bool retdec::fileformat::SecSeg::isData ( ) const

Check if section is data section

Returns
true if section is data section, false otherwise

◆ isDataOnly()

bool retdec::fileformat::SecSeg::isDataOnly ( ) const
Returns
true if isData() or isConstData(), false otherwise.

◆ isDebug()

bool retdec::fileformat::SecSeg::isDebug ( ) const

Check if section is debug section

Returns
true if section is debug section, false otherwise

◆ isInfo()

bool retdec::fileformat::SecSeg::isInfo ( ) const

Check if section is info section

Returns
true if section is info section, false otherwise

◆ isReadOnly()

bool retdec::fileformat::SecSeg::isReadOnly ( ) const
Returns
true if isCode() or isConstData(), false otherwise.

◆ isSomeCode()

bool retdec::fileformat::SecSeg::isSomeCode ( ) const
Returns
true if isCode() or isCodeAndData(), false otherwise.

◆ isSomeData()

bool retdec::fileformat::SecSeg::isSomeData ( ) const
Returns
true if isData() or isCodeAndData() or isConstData(), false otherwise.

◆ isUndefined()

bool retdec::fileformat::SecSeg::isUndefined ( ) const

Check if section type is undefined

Returns
true if section type is undefined, false otherwise

◆ isValid()

bool retdec::fileformat::SecSeg::isValid ( const FileFormat sOwner) const
virtual

Does this section appear to be valid in the context of the provided input file?

Parameters
sOwnerPointer to input file
Returns
true if section is valid, false otherwise

Reimplemented in retdec::fileformat::ElfSection.

◆ load()

void retdec::fileformat::SecSeg::load ( const FileFormat sOwner)

Load content of section or segment from input file

Parameters
sOwnerPointer to input file

This method must be called before getters of section or segment content

◆ operator<()

bool retdec::fileformat::SecSeg::operator< ( const SecSeg sOther) const
Returns
true if this section or segment is less than the provided section or segment sOther, false otherwise.

◆ setAddress()

void retdec::fileformat::SecSeg::setAddress ( unsigned long long  sAddress)

Set address

Parameters
sAddressAddress

◆ setIndex()

void retdec::fileformat::SecSeg::setIndex ( unsigned long long  sIndex)

Set index

Parameters
sIndexIndex

◆ setMemory()

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

◆ setName()

void retdec::fileformat::SecSeg::setName ( std::string  sName)

Set name

Parameters
sNameName

◆ setOffset()

void retdec::fileformat::SecSeg::setOffset ( unsigned long long  sOffset)

Set offset

Parameters
sOffsetOffset

◆ setSizeInFile()

void retdec::fileformat::SecSeg::setSizeInFile ( unsigned long long  sFileSize)

Set size in file

Parameters
sFileSizeSize in file

◆ setSizeInMemory()

void retdec::fileformat::SecSeg::setSizeInMemory ( unsigned long long  sMemorySize)

Set size of section or segment in memory

Parameters
sMemorySizeSize of section or segment in memory

◆ setSizeOfOneEntry()

void retdec::fileformat::SecSeg::setSizeOfOneEntry ( unsigned long long  sEntrySize)

Set size of one entry in section or segment

Parameters
sEntrySizeSize of one entry in section or segment

◆ setType()

void retdec::fileformat::SecSeg::setType ( SecSeg::Type  sType)

Set type

Parameters
sTypeType

Member Data Documentation

◆ address

unsigned long long retdec::fileformat::SecSeg::address = 0
private

start address in memory

◆ bytes

llvm::StringRef retdec::fileformat::SecSeg::bytes
private

reference to content of section or segment

◆ crc32

std::string retdec::fileformat::SecSeg::crc32
private

CRC32 of section or segment data.

◆ entropy

double retdec::fileformat::SecSeg::entropy = 0.0
private

entropy in <0,8>

◆ entrySize

unsigned long long retdec::fileformat::SecSeg::entrySize = 0
private

size of one entry in file

◆ entrySizeIsValid

bool retdec::fileformat::SecSeg::entrySizeIsValid = false
private

size of one entry in section or segment

◆ fileSize

unsigned long long retdec::fileformat::SecSeg::fileSize = 0
private

size in file

◆ index

unsigned long long retdec::fileformat::SecSeg::index = 0
private

index

◆ isEntropyValid

bool retdec::fileformat::SecSeg::isEntropyValid = false
private

true if entropy has been computed

◆ isInMemory

bool retdec::fileformat::SecSeg::isInMemory = false
private

true if the section or segment will appear in the memory image of a process

◆ loaded

bool retdec::fileformat::SecSeg::loaded = false
private

true if content of section or segment was successfully loaded from input file

◆ md5

std::string retdec::fileformat::SecSeg::md5
private

MD5 of section or segment data.

◆ memorySize

unsigned long long retdec::fileformat::SecSeg::memorySize = 0
private

size in memory

◆ memorySizeIsValid

bool retdec::fileformat::SecSeg::memorySizeIsValid = false
private

true if size in memory is valid

◆ name

std::string retdec::fileformat::SecSeg::name
private

name of section or segment

◆ offset

unsigned long long retdec::fileformat::SecSeg::offset = 0
private

start offset in file

◆ sha256

std::string retdec::fileformat::SecSeg::sha256
private

SHA256 of section or segment data.

◆ type

Type retdec::fileformat::SecSeg::type = Type::UNDEFINED_SEC_SEG
private

type


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