retdec
|
A representation of a complete module. More...
#include <module.h>
Public Types | |
using | global_var_iterator = GlobalVarDefVector::const_iterator |
Global variable iterator. More... | |
using | func_iterator = FuncVector::const_iterator |
Function iterator. More... | |
using | func_filter_iterator = retdec::utils::FilterIterator< func_iterator > |
Iterator over filtered functions (definitions, declarations, etc.). More... | |
Public Member Functions | |
Module (const llvm::Module *llvmModule, const std::string &identifier, ShPtr< Semantics > semantics, ShPtr< Config > config) | |
Constructs a new module. More... | |
const llvm::Module * | getLLVMModule () const |
Returns the underlying LLVM module of the module. More... | |
std::string | getIdentifier (bool stripDirs=true) const |
Returns the identifier of the module. More... | |
ShPtr< Semantics > | getSemantics () const |
Returns the semantics of the module. More... | |
ShPtr< Config > | getConfig () const |
Global Variables Accessors | |
void | addGlobalVar (ShPtr< Variable > var, ShPtr< Expression > init=nullptr) |
Adds a new global variable to the module. More... | |
void | removeGlobalVar (ShPtr< Variable > var) |
Removes the given variable from the module. More... | |
bool | isGlobalVar (ShPtr< Variable > var) const |
Returns true if var is a global variable, false otherwise. More... | |
bool | isGlobalVarStoringStringLiteral (const std::string &varName) const |
Is a variable with the given name global and stores a string literal? More... | |
ShPtr< Expression > | getInitForGlobalVar (ShPtr< Variable > var) const |
Returns the initializer for the given global variable var. More... | |
ShPtr< Variable > | getGlobalVarByName (const std::string &varName) const |
Returns the global variable named varName. More... | |
bool | hasGlobalVars () const |
Returns true if the module contains at least one global variable, false otherwise. More... | |
bool | hasGlobalVar (const std::string &name) const |
Checks if the module contains a global variable with the given name. More... | |
VarSet | getGlobalVars () const |
Returns all global variables (without their initializer). More... | |
VarSet | getExternalGlobalVars () const |
Returns the set of external global variables. More... | |
std::string | getRegisterForGlobalVar (ShPtr< Variable > var) const |
Returns the name of the register corresponding to the given global variable. More... | |
std::string | getDetectedCryptoPatternForGlobalVar (ShPtr< Variable > var) const |
Returns a description of the detected cryptographic pattern for the given global variable. More... | |
global_var_iterator | global_var_begin () const |
Returns a constant iterator to the first global variable. More... | |
global_var_iterator | global_var_end () const |
Returns a constant iterator past the last global variable. More... | |
Functions Accessors | |
void | addFunc (ShPtr< Function > func) |
Adds the given function to the module. More... | |
void | removeFunc (ShPtr< Function > func) |
Removes the given function from the module. More... | |
bool | funcExists (ShPtr< Function > func) const |
Returns true if func exists in the module, false otherwise. More... | |
ShPtr< Function > | getFuncByName (const std::string &funcName) const |
Returns the function named funcName. More... | |
bool | hasFuncWithName (const std::string &funcName) const |
Returns true if there is a function named funcName, false otherwise. More... | |
bool | correspondsToFunc (ShPtr< Variable > var) const |
Does the given variable correspond to a function? More... | |
bool | hasMainFunc () const |
Returns true if there is a main function in the module, false otherwise. More... | |
bool | isMainFunc (ShPtr< Function > func) const |
Returns true if the given function is the main function, false otherwise. More... | |
VarSet | getVarsForFuncs () const |
Returns variables that correspond to functions in the module. More... | |
std::size_t | getNumOfFuncDefinitions () const |
Returns the number of defined functions in the module. More... | |
bool | hasFuncDefinitions () const |
Returns true if the module contains at least one function definition, false otherwise. More... | |
bool | hasDecompilerDefinedFuncs () const |
Are there any decompiler-defined functions in the module? More... | |
FuncSet | getDecompilerDefinedFuncs () const |
Returns all decompiler-defined functions in the module. More... | |
bool | hasUserDefinedFuncs () const |
Are there any user-defied functions in the module? More... | |
FuncSet | getUserDefinedFuncs () const |
Returns all user-defined functions in the module. More... | |
bool | hasStaticallyLinkedFuncs () const |
Are there any statically linked functions in the module? More... | |
FuncSet | getStaticallyLinkedFuncs () const |
Returns all statically linked functions in the module. More... | |
void | markFuncAsStaticallyLinked (ShPtr< Function > func) |
Marks the given function as statically linked. More... | |
bool | hasDynamicallyLinkedFuncs () const |
Are there any dynamically linked functions in the module? More... | |
FuncSet | getDynamicallyLinkedFuncs () const |
Returns all dynamically linked functions in the module. More... | |
bool | hasSyscallFuncs () const |
Are there any syscall functions in the module? More... | |
FuncSet | getSyscallFuncs () const |
Returns all syscall functions in the module. More... | |
bool | hasInstructionIdiomFuncs () const |
Are there any syscall functions in the module? More... | |
FuncSet | getInstructionIdiomFuncs () const |
Returns all syscall functions in the module. More... | |
bool | isExportedFunc (ShPtr< Function > func) const |
Is the given function exported? More... | |
std::string | getRealNameForFunc (ShPtr< Function > func) const |
Returns the real name of the given function. More... | |
std::string | getDeclarationStringForFunc (ShPtr< Function > func) const |
Returns a C declaration string for the given function. More... | |
std::string | getCommentForFunc (ShPtr< Function > func) const |
Returns a comment for func. More... | |
StringSet | getDetectedCryptoPatternsForFunc (ShPtr< Function > func) const |
Returns a set of names of detected cryptographic patterns that the given function uses. More... | |
std::string | getWrappedFuncName (ShPtr< Function > func) const |
Returns the name of a function that func wraps. More... | |
std::string | getDemangledNameOfFunc (ShPtr< Function > func) const |
Returns the demangled name of func. More... | |
AddressRange | getAddressRangeForFunc (ShPtr< const Function > func) const |
Returns the address range for the given function. More... | |
bool | hasAddressRange (ShPtr< Function > func) const |
Has the given function an address range? More... | |
bool | allFuncDefinitionsHaveAddressRange () const |
Checks if all function definitions have an address range. More... | |
LineRange | getLineRangeForFunc (ShPtr< Function > func) const |
Returns the line range for the given function. More... | |
bool | hasLineRange (ShPtr< Function > func) const |
Has the given function a line range? More... | |
bool | allFuncDefinitionsHaveLineRange () const |
Checks if all function definitions have a line range. More... | |
func_iterator | func_begin () const |
Returns a constant iterator to the first function. More... | |
func_iterator | func_end () const |
Returns a constant iterator past the last function. More... | |
func_filter_iterator | func_definition_begin () const |
Returns a constant iterator to the first function definition. More... | |
func_filter_iterator | func_definition_end () const |
Returns a constant iterator past the last function definition. More... | |
func_filter_iterator | func_declaration_begin () const |
Returns a constant iterator to the first function declaration. More... | |
func_filter_iterator | func_declaration_end () const |
Returns a constant iterator past the last function declaration. More... | |
Local Variables Accessors | |
std::string | comesFromGlobalVar (ShPtr< Function > func, ShPtr< Variable > var) const |
Returns the name of a global variable from which the given local variable comes from. More... | |
Classes Accessors | |
bool | hasClasses () const |
Have any classes been found? More... | |
StringSet | getClassNames () const |
Returns the set of found class names. More... | |
std::string | getClassForFunc (ShPtr< Function > func) const |
Returns the name of a class to which the given function belongs. More... | |
std::string | getTypeOfFuncInClass (ShPtr< Function > func, const std::string &cl) const |
Returns the type of the given function in the given class. More... | |
StringVector | getBaseClassNames (const std::string &cl) const |
Returns the names of base classes of the given class. More... | |
std::string | getDemangledNameOfClass (const std::string &cl) const |
Returns the demangled named of the given class. More... | |
Debug Info Accessors | |
bool | isDebugInfoAvailable () const |
Is debugging information available? More... | |
std::string | getDebugModuleNameForFunc (ShPtr< Function > func) const |
Returns the module name for the given function using debug information. More... | |
bool | hasAssignedDebugModuleName (ShPtr< Function > func) const |
Has the given function assigned a module name from debug information? More... | |
StringSet | getDebugModuleNames () const |
Returns the set of all module names for all functions. More... | |
std::string | getDebugNameForGlobalVar (ShPtr< Variable > var) const |
Returns the name for the given global variable using debug information. More... | |
std::string | getDebugNameForLocalVar (ShPtr< Function > func, ShPtr< Variable > var) const |
Returns the name for the given local variable using debug information. More... | |
std::string | getDebugNameForVar (ShPtr< Variable > var) const |
Returns the name for the given variable using debug information. More... | |
bool | hasAssignedDebugName (ShPtr< Variable > var) const |
Returns true if the given variable has assigned a name from debug information, false otherwise. More... | |
void | addDebugNameForVar (ShPtr< Variable > var, const std::string &name) |
Adds a name for the given variable using debug information. More... | |
Meta Information | |
std::size_t | getNumberOfFuncsDetectedInFrontend () const |
Returns the number of functions detected in the front-end. More... | |
std::string | getDetectedCompilerOrPacker () const |
Returns the detected compiler/packer. More... | |
std::string | getDetectedLanguage () const |
Returns the detected language. More... | |
StringSet | getSelectedButNotFoundFuncs () const |
Returns a set of functions that were selected to be decompiled but were not found. More... | |
Private Types | |
using | FuncAddressRangeMap = std::map< ShPtr< Function >, AddressRange > |
Mapping of a function into an address range. More... | |
Private Member Functions | |
bool | hasFuncSatisfyingPredicate (std::function< bool(ShPtr< Function >)> pred) const |
Is there a function satisfying the given predicate? More... | |
FuncSet | getFuncsSatisfyingPredicate (std::function< bool(ShPtr< Function >)> pred) const |
Returns a set of functions satisfying the given predicate. More... | |
![]() | |
NonCopyable (const NonCopyable &)=delete | |
NonCopyable & | operator= (const NonCopyable &)=delete |
NonCopyable ()=default | |
~NonCopyable ()=default | |
Private Attributes | |
const llvm::Module * | llvmModule |
Original module from which this module has been created. More... | |
std::string | identifier |
Identifier of the module. More... | |
ShPtr< Semantics > | semantics |
The used semantics. More... | |
ShPtr< Config > | config |
The used config. More... | |
GlobalVarDefVector | globalVars |
Global variables. More... | |
FuncVector | funcs |
Functions. More... | |
VarStringMap | debugVarNameMap |
Mapping of a variable into its name in the debug information. More... | |
A representation of a complete module.
Instances of this class have reference object semantics. This class is not meant to be subclassed.
using retdec::llvmir2hll::Module::func_filter_iterator = retdec::utils::FilterIterator<func_iterator> |
Iterator over filtered functions (definitions, declarations, etc.).
using retdec::llvmir2hll::Module::func_iterator = FuncVector::const_iterator |
Function iterator.
|
private |
Mapping of a function into an address range.
using retdec::llvmir2hll::Module::global_var_iterator = GlobalVarDefVector::const_iterator |
Global variable iterator.
retdec::llvmir2hll::Module::Module | ( | const llvm::Module * | llvmModule, |
const std::string & | identifier, | ||
ShPtr< Semantics > | semantics, | ||
ShPtr< Config > | config | ||
) |
Constructs a new module.
[in] | llvmModule | Original module from which this module has been created. |
[in] | identifier | Identifier of the module. |
[in] | semantics | The used semantics. |
[in] | config | Configuration for the module. |
void retdec::llvmir2hll::Module::addDebugNameForVar | ( | ShPtr< Variable > | var, |
const std::string & | name | ||
) |
Adds a name for the given variable using debug information.
The new name overwrites any name that has already been set for var.
Adds the given function to the module.
[in] | func | Function to be added. |
If the function already exists in the module, nothing is done.
void retdec::llvmir2hll::Module::addGlobalVar | ( | ShPtr< Variable > | var, |
ShPtr< Expression > | init = nullptr |
||
) |
Adds a new global variable to the module.
[in] | var | Variable to be added. |
[in] | init | Initializer of var. |
If the global variable already exists, it replaces its initializer with init.
Time complexity: O(n)
, where n
is the number of global variables in the module.
bool retdec::llvmir2hll::Module::allFuncDefinitionsHaveAddressRange | ( | ) | const |
Checks if all function definitions have an address range.
bool retdec::llvmir2hll::Module::allFuncDefinitionsHaveLineRange | ( | ) | const |
Checks if all function definitions have a line range.
std::string retdec::llvmir2hll::Module::comesFromGlobalVar | ( | ShPtr< Function > | func, |
ShPtr< Variable > | var | ||
) | const |
Returns the name of a global variable from which the given local variable comes from.
If the given variable does not come from a global variable, the empty string is returned.
Does the given variable correspond to a function?
Module::func_iterator retdec::llvmir2hll::Module::func_begin | ( | ) | const |
Returns a constant iterator to the first function.
Module::func_filter_iterator retdec::llvmir2hll::Module::func_declaration_begin | ( | ) | const |
Returns a constant iterator to the first function declaration.
Module::func_filter_iterator retdec::llvmir2hll::Module::func_declaration_end | ( | ) | const |
Returns a constant iterator past the last function declaration.
Module::func_filter_iterator retdec::llvmir2hll::Module::func_definition_begin | ( | ) | const |
Returns a constant iterator to the first function definition.
Module::func_filter_iterator retdec::llvmir2hll::Module::func_definition_end | ( | ) | const |
Returns a constant iterator past the last function definition.
Module::func_iterator retdec::llvmir2hll::Module::func_end | ( | ) | const |
Returns a constant iterator past the last function.
Returns true
if func exists in the module, false
otherwise.
func may be either a function definition or a function declaration.
AddressRange retdec::llvmir2hll::Module::getAddressRangeForFunc | ( | ShPtr< const Function > | func | ) | const |
Returns the address range for the given function.
If there is no address range for func, NO_ADDRESS_RANGE
is returned.
StringVector retdec::llvmir2hll::Module::getBaseClassNames | ( | const std::string & | cl | ) | const |
Returns the names of base classes of the given class.
Returns the name of a class to which the given function belongs.
If func does not belong to any class, the empty string is returned.
StringSet retdec::llvmir2hll::Module::getClassNames | ( | ) | const |
Returns the set of found class names.
Returns a comment for func.
Returns the module name for the given function using debug information.
If there is no module name assigned to the given function, the empty string is returned.
StringSet retdec::llvmir2hll::Module::getDebugModuleNames | ( | ) | const |
Returns the set of all module names for all functions.
If debug info is not available or there are no functions, the empty set is returned.
Returns the name for the given global variable using debug information.
If there is no name assigned to the given variable, the empty string is returned.
std::string retdec::llvmir2hll::Module::getDebugNameForLocalVar | ( | ShPtr< Function > | func, |
ShPtr< Variable > | var | ||
) | const |
Returns the name for the given local variable using debug information.
If there is no name assigned to the given variable, the empty string is returned.
Returns the name for the given variable using debug information.
If there is no name assigned to the given variable, the empty string is returned.
Returns a C declaration string for the given function.
If there is no declaration string attached to the given function, it returns the empty string.
FuncSet retdec::llvmir2hll::Module::getDecompilerDefinedFuncs | ( | ) | const |
Returns all decompiler-defined functions in the module.
std::string retdec::llvmir2hll::Module::getDemangledNameOfClass | ( | const std::string & | cl | ) | const |
Returns the demangled named of the given class.
Returns the demangled name of func.
std::string retdec::llvmir2hll::Module::getDetectedCompilerOrPacker | ( | ) | const |
Returns the detected compiler/packer.
If there is no detected compiler/packer, it returns the empty string.
std::string retdec::llvmir2hll::Module::getDetectedCryptoPatternForGlobalVar | ( | ShPtr< Variable > | var | ) | const |
Returns a description of the detected cryptographic pattern for the given global variable.
StringSet retdec::llvmir2hll::Module::getDetectedCryptoPatternsForFunc | ( | ShPtr< Function > | func | ) | const |
Returns a set of names of detected cryptographic patterns that the given function uses.
If the given function does not use any cryptographic patterns, the empty set is returned.
std::string retdec::llvmir2hll::Module::getDetectedLanguage | ( | ) | const |
Returns the detected language.
If there is no detected language, it returns the empty string.
FuncSet retdec::llvmir2hll::Module::getDynamicallyLinkedFuncs | ( | ) | const |
Returns all dynamically linked functions in the module.
VarSet retdec::llvmir2hll::Module::getExternalGlobalVars | ( | ) | const |
Returns the set of external global variables.
Returns the function named funcName.
[in] | funcName | Name of the function. |
If there is no function named funcName, it returns the null pointer.
|
private |
Returns a set of functions satisfying the given predicate.
ShPtr< Variable > retdec::llvmir2hll::Module::getGlobalVarByName | ( | const std::string & | varName | ) | const |
Returns the global variable named varName.
[in] | varName | Name of the variable. |
If there is no global variable named varName, it returns the null pointer.
Time complexity: O(n)
, where n
is the number of global variables in the module.
VarSet retdec::llvmir2hll::Module::getGlobalVars | ( | ) | const |
Returns all global variables (without their initializer).
Time complexity: O(n)
, where n
is the number of global variables in the module.
std::string retdec::llvmir2hll::Module::getIdentifier | ( | bool | stripDirs = true | ) | const |
Returns the identifier of the module.
[in] | stripDirs | Strips all directories from the identifier (if any). |
ShPtr< Expression > retdec::llvmir2hll::Module::getInitForGlobalVar | ( | ShPtr< Variable > | var | ) | const |
Returns the initializer for the given global variable var.
If var is not a global variable or if it has no initializer, the null pointer is returned.
Time complexity: O(n)
, where n
is the number of global variables in the module.
FuncSet retdec::llvmir2hll::Module::getInstructionIdiomFuncs | ( | ) | const |
Returns all syscall functions in the module.
Returns the line range for the given function.
If there is no line range for func, NO_LINE_RANGE
is returned.
const llvm::Module * retdec::llvmir2hll::Module::getLLVMModule | ( | ) | const |
Returns the underlying LLVM module of the module.
std::size_t retdec::llvmir2hll::Module::getNumberOfFuncsDetectedInFrontend | ( | ) | const |
Returns the number of functions detected in the front-end.
std::size_t retdec::llvmir2hll::Module::getNumOfFuncDefinitions | ( | ) | const |
Returns the number of defined functions in the module.
Returns the real name of the given function.
If there is no real name attached to the given function, it returns the empty string.
Returns the name of the register corresponding to the given global variable.
StringSet retdec::llvmir2hll::Module::getSelectedButNotFoundFuncs | ( | ) | const |
Returns a set of functions that were selected to be decompiled but were not found.
Returns the semantics of the module.
FuncSet retdec::llvmir2hll::Module::getStaticallyLinkedFuncs | ( | ) | const |
Returns all statically linked functions in the module.
FuncSet retdec::llvmir2hll::Module::getSyscallFuncs | ( | ) | const |
Returns all syscall functions in the module.
std::string retdec::llvmir2hll::Module::getTypeOfFuncInClass | ( | ShPtr< Function > | func, |
const std::string & | cl | ||
) | const |
Returns the type of the given function in the given class.
The returned value is a textual representation, e.g. "constructor" or "virtual member function". If func does not belong to cl
, the empty string is returned.
FuncSet retdec::llvmir2hll::Module::getUserDefinedFuncs | ( | ) | const |
Returns all user-defined functions in the module.
VarSet retdec::llvmir2hll::Module::getVarsForFuncs | ( | ) | const |
Returns variables that correspond to functions in the module.
Returns the name of a function that func wraps.
See the description of Config::getWrappedFunc() for more information.
Module::global_var_iterator retdec::llvmir2hll::Module::global_var_begin | ( | ) | const |
Returns a constant iterator to the first global variable.
Module::global_var_iterator retdec::llvmir2hll::Module::global_var_end | ( | ) | const |
Returns a constant iterator past the last global variable.
Has the given function an address range?
Has the given function assigned a module name from debug information?
Returns true
if the given variable has assigned a name from debug information, false
otherwise.
bool retdec::llvmir2hll::Module::hasClasses | ( | ) | const |
Have any classes been found?
bool retdec::llvmir2hll::Module::hasDecompilerDefinedFuncs | ( | ) | const |
Are there any decompiler-defined functions in the module?
bool retdec::llvmir2hll::Module::hasDynamicallyLinkedFuncs | ( | ) | const |
Are there any dynamically linked functions in the module?
bool retdec::llvmir2hll::Module::hasFuncDefinitions | ( | ) | const |
Returns true
if the module contains at least one function definition, false
otherwise.
|
private |
Is there a function satisfying the given predicate?
bool retdec::llvmir2hll::Module::hasFuncWithName | ( | const std::string & | funcName | ) | const |
Returns true
if there is a function named funcName, false
otherwise.
bool retdec::llvmir2hll::Module::hasGlobalVar | ( | const std::string & | name | ) | const |
Checks if the module contains a global variable with the given name.
bool retdec::llvmir2hll::Module::hasGlobalVars | ( | ) | const |
Returns true
if the module contains at least one global variable, false
otherwise.
bool retdec::llvmir2hll::Module::hasInstructionIdiomFuncs | ( | ) | const |
Are there any syscall functions in the module?
Has the given function a line range?
bool retdec::llvmir2hll::Module::hasMainFunc | ( | ) | const |
Returns true
if there is a main function in the module, false
otherwise.
The name of the main function depends on the used semantics.
bool retdec::llvmir2hll::Module::hasStaticallyLinkedFuncs | ( | ) | const |
Are there any statically linked functions in the module?
bool retdec::llvmir2hll::Module::hasSyscallFuncs | ( | ) | const |
Are there any syscall functions in the module?
bool retdec::llvmir2hll::Module::hasUserDefinedFuncs | ( | ) | const |
Are there any user-defied functions in the module?
bool retdec::llvmir2hll::Module::isDebugInfoAvailable | ( | ) | const |
Is debugging information available?
Is the given function exported?
See the description of Config::isExportedFunc() for more details.
Returns true
if var is a global variable, false
otherwise.
Time complexity: O(n)
, where n
is the number of global variables in the module.
bool retdec::llvmir2hll::Module::isGlobalVarStoringStringLiteral | ( | const std::string & | varName | ) | const |
Is a variable with the given name global and stores a string literal?
Returns true
if the given function is the main function, false
otherwise.
The name of the main function depends on the used semantics.
Marks the given function as statically linked.
Removes the given function from the module.
If there is no matching function, nothing is removed.
Removes the given variable from the module.
If the global variable does not exist, this function does nothing.
Time complexity: O(n)
, where n
is the number of global variables in the module.
|
private |
Mapping of a variable into its name in the debug information.
|
private |
Functions.
|
private |
Global variables.
|
private |
Identifier of the module.
|
private |
Original module from which this module has been created.