retdec
Classes | Public Member Functions | Private Attributes | List of all members
retdec::cpdetect::Search Class Reference

#include <search.h>

Collaboration diagram for retdec::cpdetect::Search:
Collaboration graph
[legend]

Classes

class  RelativeJump
 

Public Member Functions

 Search (retdec::fileformat::FileFormat &fileParser)
 
Status methods
bool isFileLoaded () const
 
bool isFileSupported () const
 
Getters
const std::string & getNibbles () const
 
const std::string & getPlainString () const
 
Jump methods
const RelativeJumpgetRelativeJump (std::size_t fileOffset, std::size_t shift, std::int64_t &moveSize) const
 
Search methods based on signatures
unsigned long long countImpNibbles (const std::string &signPattern) const
 
unsigned long long findUnslashedSignature (const std::string &signPattern, std::size_t startOffset, std::size_t stopOffset) const
 
unsigned long long findSlashedSignature (const std::string &signPattern, std::size_t startOffset, std::size_t stopOffset) const
 
unsigned long long exactComparison (const std::string &signPattern, std::size_t fileOffset, std::size_t shift=0) const
 
bool countSimilarity (const std::string &signPattern, Similarity &sim, std::size_t fileOffset, std::size_t shift=0) const
 
bool areaSimilarity (const std::string &signPattern, Similarity &sim, std::size_t startOffset, std::size_t stopOffset) const
 
Search methods based on plain-string comparison
bool hasString (const std::string &str) const
 
bool hasString (const std::string &str, std::size_t fileOffset) const
 
bool hasString (const std::string &str, std::size_t startOffset, std::size_t stopOffset) const
 
bool hasStringInSection (const std::string &str, const retdec::fileformat::Section *section) const
 
bool hasStringInSection (const std::string &str, std::size_t sectionIndex) const
 
bool hasStringInSection (const std::string &str, const std::string &sectionName) const
 
Signature methods
bool createSignature (std::string &pattern, std::size_t fileOffset, std::size_t size) const
 

Private Member Functions

Auxiliary methods
bool haveSlashes () const
 
std::size_t nibblesFromBytes (std::size_t nBytes) const
 
std::size_t bytesFromNibbles (std::size_t nNibbles) const
 

Private Attributes

retdec::fileformat::FileFormatparser
 
std::string nibbles
 content of file in hexadecimal string representation More...
 
std::string plain
 content of file as plain string More...
 
std::vector< RelativeJumpjumps
 representation of supported relative jumps More...
 
std::size_t averageSlashLen
 average length of one slash representation More...
 
bool fileLoaded
 true if file was successfully loaded, false otherwise More...
 
bool fileSupported
 

Detailed Description

Class for search in file

Constructor & Destructor Documentation

◆ Search()

retdec::cpdetect::Search::Search ( retdec::fileformat::FileFormat fileParser)

Constructor

Parameters
fileParserParser of input file

Member Function Documentation

◆ areaSimilarity()

bool retdec::cpdetect::Search::areaSimilarity ( const std::string &  signPattern,
Similarity sim,
std::size_t  startOffset,
std::size_t  stopOffset 
) const

Count the most similar similarity in area

Parameters
signPatternSignature pattern
simStructure for save similarity
startOffsetStart offset in file (in bytes)
stopOffsetStop offset in file (in bytes)
Returns
true if function went OK, false otherwise

If function return false, sim is left unchanged

◆ bytesFromNibbles()

std::size_t retdec::cpdetect::Search::bytesFromNibbles ( std::size_t  nNibbles) const
private

Count number of bytes from number of nibbles

Parameters
nNibblesNumber of nibbles
Returns
Number of bytes

◆ countImpNibbles()

unsigned long long retdec::cpdetect::Search::countImpNibbles ( const std::string &  signPattern) const

Count number of significant nibbles in signature pattern

Parameters
signPatternSignature pattern
Returns
Number of significant nibbles in signature pattern

◆ countSimilarity()

bool retdec::cpdetect::Search::countSimilarity ( const std::string &  signPattern,
Similarity sim,
std::size_t  fileOffset,
std::size_t  shift = 0 
) const

Count similarity as count of agree nibbles and count of valuable nibbles in signature

Parameters
signPatternSignature pattern
simStructure for save similarity
fileOffsetOffset in file
shiftRelative shift in nibbles from fileOffset
Returns
true if function went OK, false otherwise

If function return false, sim is left unchanged

◆ createSignature()

bool retdec::cpdetect::Search::createSignature ( std::string &  pattern,
std::size_t  fileOffset,
std::size_t  size 
) const

Create signature from specified offset

Parameters
patternInto this parameter is stored resulted signature
fileOffsetStart offset in file (in bytes)
sizeDesired length of signature (in bytes, slashes are also considered as one byte during creation of signature)
Returns
true if signature was successfully created, false otherwise

◆ exactComparison()

unsigned long long retdec::cpdetect::Search::exactComparison ( const std::string &  signPattern,
std::size_t  fileOffset,
std::size_t  shift = 0 
) const

Try find signature signPattern at specified offset

Parameters
signPatternSignature pattern
fileOffsetOffset in file
shiftRelative shift in nibbles from fileOffset
Returns
Number of significant nibbles of signature or 0 if content of file and signature are different

◆ findSlashedSignature()

unsigned long long retdec::cpdetect::Search::findSlashedSignature ( const std::string &  signPattern,
std::size_t  startOffset,
std::size_t  stopOffset 
) const

Search if there is a slash(es) containing pattern in selected area

Parameters
signPatternSignature pattern
startOffsetStart offset in file (in bytes)
stopOffsetStop offset in file (in bytes)
Returns
If pattern is not present in area return 0, else return number of patterns significant nibbles

◆ findUnslashedSignature()

unsigned long long retdec::cpdetect::Search::findUnslashedSignature ( const std::string &  signPattern,
std::size_t  startOffset,
std::size_t  stopOffset 
) const

Method tells if there is the pattern in selected area of file. Unable for slashed signatures

Parameters
signPatternSignature pattern
startOffsetStart offset in file (in bytes)
stopOffsetStop offset in file (in bytes)
Returns
If pattern is present in area return number of patterns significant nibbles, else return 0

◆ getNibbles()

const std::string & retdec::cpdetect::Search::getNibbles ( ) const

Get content of file in hexadecimal string representation

Returns
Content of file in hexadecimal string representation

◆ getPlainString()

const std::string & retdec::cpdetect::Search::getPlainString ( ) const

Get content of file as plain string

Returns
Content of file as plain string

◆ getRelativeJump()

const Search::RelativeJump * retdec::cpdetect::Search::getRelativeJump ( std::size_t  fileOffset,
std::size_t  shift,
std::int64_t &  moveSize 
) const

Check if relative jump is present on offset fileOffset

Parameters
fileOffsetByte offset in file
shiftRelative shift in nibbles from fileOffset
moveSizeInto this parameter is stored number of nibbles of which will jump or zero if nullptr is returned
Returns
Pointer to the description of detected jump of nullptr if jump is not detected

◆ hasString() [1/3]

bool retdec::cpdetect::Search::hasString ( const std::string &  str) const

Check if file contains specified substring

Parameters
strCoveted substring
Returns
true if file contains str, false otherwise

◆ hasString() [2/3]

bool retdec::cpdetect::Search::hasString ( const std::string &  str,
std::size_t  fileOffset 
) const

Check if file has substring str on specified offset

Parameters
strCoveted substring
fileOffsetOffset in file
Returns
true if file has str on offset fileOffset, false otherwise

◆ hasString() [3/3]

bool retdec::cpdetect::Search::hasString ( const std::string &  str,
std::size_t  startOffset,
std::size_t  stopOffset 
) const

Check if file contains string in selected area of file

Parameters
strCoveted string
startOffsetStart offset in file (in bytes)
stopOffsetStop offset in file (in bytes)
Returns
true if string is present in selected area of file, false otherwise

◆ hasStringInSection() [1/3]

bool retdec::cpdetect::Search::hasStringInSection ( const std::string &  str,
const retdec::fileformat::Section section 
) const

Check if file contains string in selected section

Parameters
strCoveted string
sectionSelected section
Returns
true if string is present in selected section, false otherwise

◆ hasStringInSection() [2/3]

bool retdec::cpdetect::Search::hasStringInSection ( const std::string &  str,
const std::string &  sectionName 
) const

Check if file contains string in selected section

Parameters
strCoveted string
sectionNameName of selected section
Returns
true if string is present in selected section, false otherwise

◆ hasStringInSection() [3/3]

bool retdec::cpdetect::Search::hasStringInSection ( const std::string &  str,
std::size_t  sectionIndex 
) const

Check if file contains string in selected section

Parameters
strCoveted string
sectionIndexIndex of selected section (indexed from 0)
Returns
true if string is present in selected section, false otherwise

◆ haveSlashes()

bool retdec::cpdetect::Search::haveSlashes ( ) const
private

Check is some slashes are defined for target architecture of input file

Returns
true if at least one slash pattern is defined for target architecture of input file, false otherwise

◆ isFileLoaded()

bool retdec::cpdetect::Search::isFileLoaded ( ) const

Check if input file was successfully loaded

Returns
true if file was successfully loaded, false otherwise

◆ isFileSupported()

bool retdec::cpdetect::Search::isFileSupported ( ) const

Check if input file is supported for search

Returns
true if input file is supported for search, false otherwise

◆ nibblesFromBytes()

std::size_t retdec::cpdetect::Search::nibblesFromBytes ( std::size_t  nBytes) const
private

Count number of nibbles from number of bytes

Parameters
nBytesNumber of bytes
Returns
Number of nibbles

Member Data Documentation

◆ averageSlashLen

std::size_t retdec::cpdetect::Search::averageSlashLen
private

average length of one slash representation

◆ fileLoaded

bool retdec::cpdetect::Search::fileLoaded
private

true if file was successfully loaded, false otherwise

◆ fileSupported

bool retdec::cpdetect::Search::fileSupported
private

true if search of patterns is supported for input file, false otherwise

◆ jumps

std::vector<RelativeJump> retdec::cpdetect::Search::jumps
private

representation of supported relative jumps

◆ nibbles

std::string retdec::cpdetect::Search::nibbles
private

content of file in hexadecimal string representation

◆ parser

retdec::fileformat::FileFormat& retdec::cpdetect::Search::parser
private

◆ plain

std::string retdec::cpdetect::Search::plain
private

content of file as plain string


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