retdec
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
retdec::bin2llvmir::ValueProtect Class Reference

#include <value_protect.h>

Inheritance diagram for retdec::bin2llvmir::ValueProtect:
Inheritance graph
[legend]
Collaboration diagram for retdec::bin2llvmir::ValueProtect:
Collaboration graph
[legend]

Public Member Functions

 ValueProtect ()
 
virtual bool runOnModule (llvm::Module &M) override
 
bool runOnModuleCustom (llvm::Module &M, Config *c, Abi *abi)
 

Static Public Attributes

static char ID = 0
 

Private Member Functions

bool run ()
 
bool protect ()
 
bool protectStack ()
 
bool protectRegisters (bool skipCalledFunctions=true)
 
bool protectLoadStores ()
 
bool unprotect ()
 
void protectValue (llvm::Value *val, llvm::Type *t, llvm::Instruction *before)
 
llvm::Function * getOrCreateFunction (llvm::Type *t)
 
llvm::Function * createFunction (llvm::Type *t)
 

Private Attributes

llvm::Module * _module = nullptr
 
Config_config = nullptr
 
Abi_abi = nullptr
 

Static Private Attributes

static std::map< llvm::Type *, llvm::Function * > _type2fnc
 

Detailed Description

Generates patterns like this at functions' entry BBs:

%1 = call i32 @__decompiler_undefined_function_X()
store i32 %1, i32* XYZ

Where XYZ are allocated variables (registers, stacks).

This is done to protect these variables from aggressive LLVM optimizations. This way, stacks are not uninitialized, and registers are not equal to their initialization values.

Every even run generates these protections. Every odd run removes them (partially, see https://github.com/avast/retdec/issues/301).

Constructor & Destructor Documentation

◆ ValueProtect()

retdec::bin2llvmir::ValueProtect::ValueProtect ( )

Member Function Documentation

◆ createFunction()

llvm::Function * retdec::bin2llvmir::ValueProtect::createFunction ( llvm::Type *  t)
private

◆ getOrCreateFunction()

llvm::Function * retdec::bin2llvmir::ValueProtect::getOrCreateFunction ( llvm::Type *  t)
private

◆ protect()

bool retdec::bin2llvmir::ValueProtect::protect ( )
private

◆ protectLoadStores()

bool retdec::bin2llvmir::ValueProtect::protectLoadStores ( )
private

Replace loads/stores from/to undef/nullptr values by special intrinsic functions. These loads and stores would be recognized by LLVM optimization passes and they would cause "abort() // UNREACHABLE" pattern in the output C.

◆ protectRegisters()

bool retdec::bin2llvmir::ValueProtect::protectRegisters ( bool  skipCalledFunctions = true)
private

◆ protectStack()

bool retdec::bin2llvmir::ValueProtect::protectStack ( )
private

◆ protectValue()

void retdec::bin2llvmir::ValueProtect::protectValue ( llvm::Value *  val,
llvm::Type *  t,
llvm::Instruction *  before 
)
private

◆ run()

bool retdec::bin2llvmir::ValueProtect::run ( )
private
Returns
True if module _module was modified in any way, false otherwise.

◆ runOnModule()

bool retdec::bin2llvmir::ValueProtect::runOnModule ( llvm::Module &  M)
overridevirtual

◆ runOnModuleCustom()

bool retdec::bin2llvmir::ValueProtect::runOnModuleCustom ( llvm::Module &  M,
Config c,
Abi abi 
)

◆ unprotect()

bool retdec::bin2llvmir::ValueProtect::unprotect ( )
private

Member Data Documentation

◆ _abi

Abi* retdec::bin2llvmir::ValueProtect::_abi = nullptr
private

◆ _config

Config* retdec::bin2llvmir::ValueProtect::_config = nullptr
private

◆ _module

llvm::Module* retdec::bin2llvmir::ValueProtect::_module = nullptr
private

◆ _type2fnc

std::map< llvm::Type *, llvm::Function * > retdec::bin2llvmir::ValueProtect::_type2fnc
staticprivate

◆ ID

char retdec::bin2llvmir::ValueProtect::ID = 0
static

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