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

#include <decoder.h>

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

Public Member Functions

 Decoder ()
 
 ~Decoder ()
 
virtual bool runOnModule (llvm::Module &m) override
 
bool runOnModuleCustom (llvm::Module &m, Config *c, FileImage *o, DebugFormat *d, NameContainer *n, Abi *a)
 

Static Public Attributes

static char ID = 0
 

Private Types

using ByteData = typename std::pair< const std::uint8_t *, std::size_t >
 

Private Member Functions

bool runCatcher ()
 
bool run ()
 
void initTranslator ()
 
void initDryRunCsInstruction ()
 
void initEnvironment ()
 
void initEnvironmentAsm2LlvmMapping ()
 
void initEnvironmentPseudoFunctions ()
 
void initEnvironmentRegisters ()
 
void initRanges ()
 
void initAllowedRangesWithSegments ()
 
void initAllowedRangesWithConfig ()
 
void initJumpTargets ()
 
void initJumpTargetsConfig ()
 
void initJumpTargetsEntryPoint ()
 
void initJumpTargetsExterns ()
 
void initJumpTargetsImports ()
 
void initJumpTargetsExports ()
 
void initJumpTargetsDebug ()
 
void initJumpTargetsSymbols ()
 
void initConfigFunctions ()
 
void initStaticCode ()
 
void initVtables ()
 
void decode ()
 
bool getJumpTarget (JumpTarget &jt)
 
void decodeJumpTarget (const JumpTarget &jt)
 
std::size_t decodeJumpTargetDryRun (const JumpTarget &jt, ByteData bytes, bool strict=false)
 
cs_mode determineMode (cs_insn *insn, common::Address &target)
 
capstone2llvmir::Capstone2LlvmIrTranslator::TranslationResultOne translate (ByteData &bytes, common::Address &addr, llvm::IRBuilder<> &irb)
 
bool getJumpTargetsFromInstruction (common::Address addr, capstone2llvmir::Capstone2LlvmIrTranslator::TranslationResultOne &tr, std::size_t &rangeSize)
 
common::Address getJumpTarget (common::Address addr, llvm::CallInst *branchCall, llvm::Value *val)
 
bool getJumpTargetSwitch (common::Address addr, llvm::CallInst *branchCall, llvm::Value *val, SymbolicTree &st)
 
bool instructionBreaksBasicBlock (common::Address addr, capstone2llvmir::Capstone2LlvmIrTranslator::TranslationResultOne &tr)
 
void handleDelaySlotTypical (common::Address &addr, capstone2llvmir::Capstone2LlvmIrTranslator::TranslationResultOne &res, ByteData &bytes, llvm::IRBuilder<> &irb)
 
void handleDelaySlotLikely (common::Address &addr, capstone2llvmir::Capstone2LlvmIrTranslator::TranslationResultOne &res, ByteData &bytes, llvm::IRBuilder<> &irb)
 
void resolvePseudoCalls ()
 
void finalizePseudoCalls ()
 
common::Address getBasicBlockAddress (llvm::BasicBlock *b)
 
common::Address getBasicBlockEndAddress (llvm::BasicBlock *b)
 
common::Address getBasicBlockAddressAfter (common::Address a)
 
llvm::BasicBlock * getBasicBlockAtAddress (common::Address a)
 
llvm::BasicBlock * getBasicBlockBeforeAddress (common::Address a)
 
llvm::BasicBlock * getBasicBlockAfterAddress (common::Address a)
 
llvm::BasicBlock * getBasicBlockContainingAddress (common::Address a)
 
llvm::BasicBlock * createBasicBlock (common::Address a, llvm::Function *f, llvm::BasicBlock *insertAfter=nullptr)
 
void addBasicBlock (common::Address a, llvm::BasicBlock *b)
 
common::Address getFunctionAddress (llvm::Function *f)
 
common::Address getFunctionEndAddress (llvm::Function *f)
 
common::Address getFunctionAddressAfter (common::Address a)
 
llvm::Function * getFunctionAtAddress (common::Address a)
 
llvm::Function * getFunctionBeforeAddress (common::Address a)
 
llvm::Function * getFunctionAfterAddress (common::Address a)
 
llvm::Function * getFunctionContainingAddress (common::Address a)
 
llvm::Function * createFunction (common::Address a, bool declaration=false)
 
void addFunction (common::Address a, llvm::Function *f)
 
void addFunctionSize (llvm::Function *f, std::optional< std::size_t > sz)
 
bool patternsRecognize ()
 
bool patternTerminatingCalls ()
 
bool patternStaticallyLinked ()
 
std::size_t decodeJumpTargetDryRun_x86 (const JumpTarget &jt, ByteData bytes, bool strict=false)
 
std::size_t decodeJumpTargetDryRun_arm (const JumpTarget &jt, ByteData bytes, bool strict=false)
 
std::size_t decodeJumpTargetDryRun_arm (const JumpTarget &jt, ByteData bytes, cs_mode mode, std::size_t &decodedSz, bool strict=false)
 
void patternsPseudoCall_arm (llvm::CallInst *&call, AsmInstruction &pAi)
 
cs_mode determineMode_arm (cs_insn *insn, common::Address &target)
 
std::size_t decodeJumpTargetDryRun_arm64 (const JumpTarget &jt, ByteData bytes, bool strict=false)
 
void patternsPseudoCall_arm64 (llvm::CallInst *&call, AsmInstruction &pAi)
 
bool disasm_mips (csh ce, cs_mode m, ByteData &bytes, uint64_t &a, cs_insn *i)
 
std::size_t decodeJumpTargetDryRun_mips (const JumpTarget &jt, ByteData bytes, bool strict=false)
 
void initializeGpReg_mips ()
 
std::size_t decodeJumpTargetDryRun_ppc (const JumpTarget &jt, ByteData bytes, bool strict=false)
 
llvm::CallInst * transformToCall (llvm::CallInst *pseudo, llvm::Function *callee)
 
llvm::CallInst * transformToCondCall (llvm::CallInst *pseudo, llvm::Value *cond, llvm::Function *callee, llvm::BasicBlock *falseBb)
 
llvm::ReturnInst * transformToReturn (llvm::CallInst *pseudo)
 
llvm::BranchInst * transformToBranch (llvm::CallInst *pseudo, llvm::BasicBlock *branchee)
 
llvm::BranchInst * transformToCondBranch (llvm::CallInst *pseudo, llvm::Value *cond, llvm::BasicBlock *trueBb, llvm::BasicBlock *falseBb)
 
llvm::SwitchInst * transformToSwitch (llvm::CallInst *pseudo, llvm::Value *val, llvm::BasicBlock *defaultBb, const std::vector< llvm::BasicBlock * > &cases)
 
llvm::GlobalVariable * getCallReturnObject ()
 
void getOrCreateCallTarget (common::Address addr, llvm::Function *&tFnc, llvm::BasicBlock *&tBb)
 
void getOrCreateBranchTarget (common::Address addr, llvm::BasicBlock *&tBb, llvm::Function *&tFnc, llvm::Instruction *from)
 
bool canSplitFunctionOn (llvm::BasicBlock *bb)
 
bool canSplitFunctionOn (common::Address addr, llvm::BasicBlock *bb, std::set< llvm::BasicBlock * > &newFncStarts)
 
llvm::Function * splitFunctionOn (common::Address addr)
 
llvm::Function * splitFunctionOn (common::Address addr, llvm::BasicBlock *bb)
 

Private Attributes

std::map< common::Address, llvm::BasicBlock * > _addr2bb
 
std::map< llvm::BasicBlock *, common::Address_bb2addr
 
std::map< common::Address, llvm::Function * > _addr2fnc
 
std::map< llvm::Function *, common::Address_fnc2addr
 
std::map< llvm::Function *, std::size_t > _fnc2sz
 
llvm::Module * _module = nullptr
 
Config_config = nullptr
 
FileImage_image = nullptr
 
DebugFormat_debug = nullptr
 
NameContainer_names = nullptr
 
Llvm2CapstoneInsnMap_llvm2capstone = nullptr
 
Abi_abi = nullptr
 
std::unique_ptr< capstone2llvmir::Capstone2LlvmIrTranslator_c2l
 
cs_insn * _dryCsInsn = nullptr
 
llvm::IRBuilder * _irb
 
RangesToDecode _ranges
 
JumpTargets _jumpTargets
 
std::set< std::string > _externs
 Name of all extern functions gathered from object files. More...
 
std::set< common::Address_imports
 
std::set< common::Address_exports
 
std::set< common::Address_symbols
 
std::map< common::Address, const common::Function * > _debugFncs
 
std::set< common::Address_staticFncs
 
std::set< common::Address_vtableFncs
 
std::set< llvm::Function * > _terminatingFncs
 
llvm::Function * _entryPointFunction = nullptr
 
std::map< common::Address, std::set< llvm::SwitchInst * > > _switchTableStarts
 
std::map< llvm::BasicBlock *, llvm::BasicBlock * > _likelyBb2Target
 
bool _switchGenerated = false
 
bool _somethingDecoded = false
 

Member Typedef Documentation

◆ ByteData

using retdec::bin2llvmir::Decoder::ByteData = typename std::pair<const std::uint8_t*, std::size_t>
private

Constructor & Destructor Documentation

◆ Decoder()

retdec::bin2llvmir::Decoder::Decoder ( )

◆ ~Decoder()

retdec::bin2llvmir::Decoder::~Decoder ( )

Member Function Documentation

◆ addBasicBlock()

void retdec::bin2llvmir::Decoder::addBasicBlock ( common::Address  a,
llvm::BasicBlock *  b 
)
private

◆ addFunction()

void retdec::bin2llvmir::Decoder::addFunction ( common::Address  a,
llvm::Function *  f 
)
private

◆ addFunctionSize()

void retdec::bin2llvmir::Decoder::addFunctionSize ( llvm::Function *  f,
std::optional< std::size_t >  sz 
)
private

Size sz is added only if function's f size was not set so far. Use this function in more reliable, higher priority sources first.

◆ canSplitFunctionOn() [1/2]

bool retdec::bin2llvmir::Decoder::canSplitFunctionOn ( common::Address  addr,
llvm::BasicBlock *  splitBb,
std::set< llvm::BasicBlock * > &  newFncStarts 
)
private
Returns
True if it is allowed to split function on basic block bb.

TODO: The problem here is, that function may became unsplittable after it was split. What then? Merge them back together and transform calls to JUMP_OUTs? Or defer splits/calls/etc only after basic decoding of all functions is done? E.g. fnc1(): ... b lab_in_2 ...

fnc2(): (nothing decoded yet) ... // should not be split here, but it can, because flow from fnc2() // start does not exist yet. lab_in_2: ... fnc2 end

◆ canSplitFunctionOn() [2/2]

bool retdec::bin2llvmir::Decoder::canSplitFunctionOn ( llvm::BasicBlock *  bb)
private
Returns
True if it is allowed to split function on basic block bb.

◆ createBasicBlock()

llvm::BasicBlock * retdec::bin2llvmir::Decoder::createBasicBlock ( common::Address  a,
llvm::Function *  f,
llvm::BasicBlock *  insertAfter = nullptr 
)
private

Create basic block at address a in function f right after basic block insertAfter.

Returns
Created function.

◆ createFunction()

llvm::Function * retdec::bin2llvmir::Decoder::createFunction ( common::Address  a,
bool  declaration = false 
)
private

Create function at address a.

Returns
Created function.

◆ decode()

void retdec::bin2llvmir::Decoder::decode ( )
private

◆ decodeJumpTarget()

void retdec::bin2llvmir::Decoder::decodeJumpTarget ( const JumpTarget jt)
private

◆ decodeJumpTargetDryRun()

std::size_t retdec::bin2llvmir::Decoder::decodeJumpTargetDryRun ( const JumpTarget jt,
ByteData  bytes,
bool  strict = false 
)
private

Check if the given jump targets and bytes can/should be decoded.

Returns
The number of bytes to skip from decoding. If zero, then dry run was ok and decoding of this chunk can proceed. If non-zero, remove the number of bytes from ranges to decode.

◆ decodeJumpTargetDryRun_arm() [1/2]

std::size_t retdec::bin2llvmir::Decoder::decodeJumpTargetDryRun_arm ( const JumpTarget jt,
ByteData  bytes,
bool  strict = false 
)
private

◆ decodeJumpTargetDryRun_arm() [2/2]

std::size_t retdec::bin2llvmir::Decoder::decodeJumpTargetDryRun_arm ( const JumpTarget jt,
ByteData  bytes,
cs_mode  mode,
std::size_t &  decodedSz,
bool  strict = false 
)
private

◆ decodeJumpTargetDryRun_arm64()

std::size_t retdec::bin2llvmir::Decoder::decodeJumpTargetDryRun_arm64 ( const JumpTarget jt,
ByteData  bytes,
bool  strict = false 
)
private

◆ decodeJumpTargetDryRun_mips()

std::size_t retdec::bin2llvmir::Decoder::decodeJumpTargetDryRun_mips ( const JumpTarget jt,
ByteData  bytes,
bool  strict = false 
)
private

◆ decodeJumpTargetDryRun_ppc()

std::size_t retdec::bin2llvmir::Decoder::decodeJumpTargetDryRun_ppc ( const JumpTarget jt,
ByteData  bytes,
bool  strict = false 
)
private

◆ decodeJumpTargetDryRun_x86()

std::size_t retdec::bin2llvmir::Decoder::decodeJumpTargetDryRun_x86 ( const JumpTarget jt,
ByteData  bytes,
bool  strict = false 
)
private

◆ determineMode()

cs_mode retdec::bin2llvmir::Decoder::determineMode ( cs_insn *  insn,
common::Address target 
)
private

◆ determineMode_arm()

cs_mode retdec::bin2llvmir::Decoder::determineMode_arm ( cs_insn *  insn,
common::Address target 
)
private

◆ disasm_mips()

bool retdec::bin2llvmir::Decoder::disasm_mips ( csh  ce,
cs_mode  m,
ByteData bytes,
uint64_t &  a,
cs_insn *  i 
)
private

◆ finalizePseudoCalls()

void retdec::bin2llvmir::Decoder::finalizePseudoCalls ( )
private

◆ getBasicBlockAddress()

common::Address retdec::bin2llvmir::Decoder::getBasicBlockAddress ( llvm::BasicBlock *  b)
private
Returns
Start address for basic block f.

◆ getBasicBlockAddressAfter()

common::Address retdec::bin2llvmir::Decoder::getBasicBlockAddressAfter ( common::Address  a)
private
Returns
Address of the first basic block after address a.

◆ getBasicBlockAfterAddress()

llvm::BasicBlock * retdec::bin2llvmir::Decoder::getBasicBlockAfterAddress ( common::Address  a)
private
Returns
The first basic block after address a.

◆ getBasicBlockAtAddress()

llvm::BasicBlock * retdec::bin2llvmir::Decoder::getBasicBlockAtAddress ( common::Address  a)
private
Returns
Basic block exactly at address a.

◆ getBasicBlockBeforeAddress()

llvm::BasicBlock * retdec::bin2llvmir::Decoder::getBasicBlockBeforeAddress ( common::Address  a)
private
Returns
The first basic block before or at address a.

◆ getBasicBlockContainingAddress()

llvm::BasicBlock * retdec::bin2llvmir::Decoder::getBasicBlockContainingAddress ( common::Address  a)
private
Returns
Basic block that contains the address a. I.e. a is between basic blocks's start and end address.

◆ getBasicBlockEndAddress()

common::Address retdec::bin2llvmir::Decoder::getBasicBlockEndAddress ( llvm::BasicBlock *  b)
private
Returns
End address for basic block b - the end address of the last instruction in the basic block.

◆ getCallReturnObject()

llvm::GlobalVariable * retdec::bin2llvmir::Decoder::getCallReturnObject ( )
private

TODO: We should get registers based on the ABI the function is using, not the same register for all calls on an architecture.

◆ getFunctionAddress()

common::Address retdec::bin2llvmir::Decoder::getFunctionAddress ( llvm::Function *  f)
private
Returns
Start address for function f.

◆ getFunctionAddressAfter()

common::Address retdec::bin2llvmir::Decoder::getFunctionAddressAfter ( common::Address  a)
private

◆ getFunctionAfterAddress()

llvm::Function * retdec::bin2llvmir::Decoder::getFunctionAfterAddress ( common::Address  a)
private

◆ getFunctionAtAddress()

llvm::Function * retdec::bin2llvmir::Decoder::getFunctionAtAddress ( common::Address  a)
private
Returns
Function exactly at address a.

◆ getFunctionBeforeAddress()

llvm::Function * retdec::bin2llvmir::Decoder::getFunctionBeforeAddress ( common::Address  a)
private
Returns
The first function before or at address a.

◆ getFunctionContainingAddress()

llvm::Function * retdec::bin2llvmir::Decoder::getFunctionContainingAddress ( common::Address  a)
private
Returns
Function that contains the address a. I.e. a is between function's start and end address.

◆ getFunctionEndAddress()

common::Address retdec::bin2llvmir::Decoder::getFunctionEndAddress ( llvm::Function *  f)
private
Returns
End address for function f.
Note
End address is one byte beyond the function, i.e. <start, end).

◆ getJumpTarget() [1/2]

common::Address retdec::bin2llvmir::Decoder::getJumpTarget ( common::Address  addr,
llvm::CallInst *  branchCall,
llvm::Value *  val 
)
private

◆ getJumpTarget() [2/2]

bool retdec::bin2llvmir::Decoder::getJumpTarget ( JumpTarget jt)
private

◆ getJumpTargetsFromInstruction()

bool retdec::bin2llvmir::Decoder::getJumpTargetsFromInstruction ( common::Address  addr,
capstone2llvmir::Capstone2LlvmIrTranslator::TranslationResultOne tr,
std::size_t &  rangeSize 
)
private
Returns
True if this instruction ends basic block, false otherwise.

◆ getJumpTargetSwitch()

bool retdec::bin2llvmir::Decoder::getJumpTargetSwitch ( common::Address  addr,
llvm::CallInst *  branchCall,
llvm::Value *  val,
SymbolicTree st 
)
private
Returns
True if switch recognized, false otherwise.

◆ getOrCreateBranchTarget()

void retdec::bin2llvmir::Decoder::getOrCreateBranchTarget ( common::Address  addr,
llvm::BasicBlock *&  tBb,
llvm::Function *&  tFnc,
llvm::Instruction *  from 
)
private

◆ getOrCreateCallTarget()

void retdec::bin2llvmir::Decoder::getOrCreateCallTarget ( common::Address  addr,
llvm::Function *&  tFnc,
llvm::BasicBlock *&  tBb 
)
private

Primary: try to create function for addr target and fill tFnc with the result. If successful, tBb is also filled. Secondary: if function not created, try to create BB for addr target and fill tBb with the result.

◆ handleDelaySlotLikely()

void retdec::bin2llvmir::Decoder::handleDelaySlotLikely ( common::Address addr,
capstone2llvmir::Capstone2LlvmIrTranslator::TranslationResultOne res,
ByteData bytes,
llvm::IRBuilder<> &  irb 
)
private
br cond, target_true, target_false
delay_slot_likely_insn

==>

br cond, ds_likely_bb, target_false

ds_likely_bb: delay_slot_likely_insn br target_true target_false: ...

◆ handleDelaySlotTypical()

void retdec::bin2llvmir::Decoder::handleDelaySlotTypical ( common::Address addr,
capstone2llvmir::Capstone2LlvmIrTranslator::TranslationResultOne res,
ByteData bytes,
llvm::IRBuilder<> &  irb 
)
private

; ASM branch insn ; ASM delay slot insn

==>

; ASM branch insn LLVM IR body without branch ; ASM delay slot insn LLVM IR body branch from prev insn

◆ initAllowedRangesWithConfig()

void retdec::bin2llvmir::Decoder::initAllowedRangesWithConfig ( )
private

◆ initAllowedRangesWithSegments()

void retdec::bin2llvmir::Decoder::initAllowedRangesWithSegments ( )
private

Initialize address ranges to decode from image segments/sections.

◆ initConfigFunctions()

void retdec::bin2llvmir::Decoder::initConfigFunctions ( )
private

◆ initDryRunCsInstruction()

void retdec::bin2llvmir::Decoder::initDryRunCsInstruction ( )
private

Initialize instruction used in dry run disassembly.

◆ initEnvironment()

void retdec::bin2llvmir::Decoder::initEnvironment ( )
private

Synchronize metadata between capstone2llvmir and bin2llvmir.

◆ initEnvironmentAsm2LlvmMapping()

void retdec::bin2llvmir::Decoder::initEnvironmentAsm2LlvmMapping ( )
private

Find out from capstone2llvmir which global is used for LLVM IR <-> Capstone ASM mapping.

  1. Set its name.
  2. Set it to config.
  3. Create metadata for it, so it can be quickly recognized without querying config.

◆ initEnvironmentPseudoFunctions()

void retdec::bin2llvmir::Decoder::initEnvironmentPseudoFunctions ( )
private

Set pseudo functions' names in LLVM IR and set them to config.

◆ initEnvironmentRegisters()

void retdec::bin2llvmir::Decoder::initEnvironmentRegisters ( )
private

Create config objects for HW registers. Initialize ABI with registers.

◆ initializeGpReg_mips()

void retdec::bin2llvmir::Decoder::initializeGpReg_mips ( )
private

◆ initJumpTargets()

void retdec::bin2llvmir::Decoder::initJumpTargets ( )
private

Find jump targets to decode.

◆ initJumpTargetsConfig()

void retdec::bin2llvmir::Decoder::initJumpTargetsConfig ( )
private

◆ initJumpTargetsDebug()

void retdec::bin2llvmir::Decoder::initJumpTargetsDebug ( )
private

◆ initJumpTargetsEntryPoint()

void retdec::bin2llvmir::Decoder::initJumpTargetsEntryPoint ( )
private

◆ initJumpTargetsExports()

void retdec::bin2llvmir::Decoder::initJumpTargetsExports ( )
private

◆ initJumpTargetsExterns()

void retdec::bin2llvmir::Decoder::initJumpTargetsExterns ( )
private

◆ initJumpTargetsImports()

void retdec::bin2llvmir::Decoder::initJumpTargetsImports ( )
private

◆ initJumpTargetsSymbols()

void retdec::bin2llvmir::Decoder::initJumpTargetsSymbols ( )
private

◆ initRanges()

void retdec::bin2llvmir::Decoder::initRanges ( )
private

Find address ranges to decode.

◆ initStaticCode()

void retdec::bin2llvmir::Decoder::initStaticCode ( )
private

◆ initTranslator()

void retdec::bin2llvmir::Decoder::initTranslator ( )
private

Initialize capstone2llvmir translator according to the architecture of file to decompile.

Returns
True if error, false otherwise.

◆ initVtables()

void retdec::bin2llvmir::Decoder::initVtables ( )
private

◆ instructionBreaksBasicBlock()

bool retdec::bin2llvmir::Decoder::instructionBreaksBasicBlock ( common::Address  addr,
capstone2llvmir::Capstone2LlvmIrTranslator::TranslationResultOne tr 
)
private

◆ patternsPseudoCall_arm()

void retdec::bin2llvmir::Decoder::patternsPseudoCall_arm ( llvm::CallInst *&  call,
AsmInstruction ai 
)
private

Recognize some ARM-specific patterns.

◆ patternsPseudoCall_arm64()

void retdec::bin2llvmir::Decoder::patternsPseudoCall_arm64 ( llvm::CallInst *&  call,
AsmInstruction pAi 
)
private

◆ patternsRecognize()

bool retdec::bin2llvmir::Decoder::patternsRecognize ( )
private
Returns
True if function changed something in IR, false otherwise.

◆ patternStaticallyLinked()

bool retdec::bin2llvmir::Decoder::patternStaticallyLinked ( )
private

Sometimes, statically linked code detection does not recognize all statically linked functions. We search for the following patterns:

define <certain_fnc_name>()
...
single function call in the whole body = call to statically linked fnc
...

◆ patternTerminatingCalls()

bool retdec::bin2llvmir::Decoder::patternTerminatingCalls ( )
private
Returns
True if function changed something in IR, false otherwise.

◆ resolvePseudoCalls()

void retdec::bin2llvmir::Decoder::resolvePseudoCalls ( )
private

◆ run()

bool retdec::bin2llvmir::Decoder::run ( )
private

◆ runCatcher()

bool retdec::bin2llvmir::Decoder::runCatcher ( )
private

◆ runOnModule()

bool retdec::bin2llvmir::Decoder::runOnModule ( llvm::Module &  m)
overridevirtual

◆ runOnModuleCustom()

bool retdec::bin2llvmir::Decoder::runOnModuleCustom ( llvm::Module &  m,
Config c,
FileImage o,
DebugFormat d,
NameContainer n,
Abi a 
)

◆ splitFunctionOn() [1/2]

llvm::Function * retdec::bin2llvmir::Decoder::splitFunctionOn ( common::Address  addr)
private

This can create new BB at addr even if it then cannot split function on this new BB. Is this desirable behavior?

◆ splitFunctionOn() [2/2]

llvm::Function * retdec::bin2llvmir::Decoder::splitFunctionOn ( common::Address  addr,
llvm::BasicBlock *  bb 
)
private

◆ transformToBranch()

llvm::BranchInst * retdec::bin2llvmir::Decoder::transformToBranch ( llvm::CallInst *  pseudo,
llvm::BasicBlock *  branchee 
)
private

◆ transformToCall()

llvm::CallInst * retdec::bin2llvmir::Decoder::transformToCall ( llvm::CallInst *  pseudo,
llvm::Function *  callee 
)
private

◆ transformToCondBranch()

llvm::BranchInst * retdec::bin2llvmir::Decoder::transformToCondBranch ( llvm::CallInst *  pseudo,
llvm::Value *  cond,
llvm::BasicBlock *  trueBb,
llvm::BasicBlock *  falseBb 
)
private

◆ transformToCondCall()

llvm::CallInst * retdec::bin2llvmir::Decoder::transformToCondCall ( llvm::CallInst *  pseudo,
llvm::Value *  cond,
llvm::Function *  callee,
llvm::BasicBlock *  falseBb 
)
private

◆ transformToReturn()

llvm::ReturnInst * retdec::bin2llvmir::Decoder::transformToReturn ( llvm::CallInst *  pseudo)
private

◆ transformToSwitch()

llvm::SwitchInst * retdec::bin2llvmir::Decoder::transformToSwitch ( llvm::CallInst *  pseudo,
llvm::Value *  val,
llvm::BasicBlock *  defaultBb,
const std::vector< llvm::BasicBlock * > &  cases 
)
private

◆ translate()

capstone2llvmir::Capstone2LlvmIrTranslator::TranslationResultOne retdec::bin2llvmir::Decoder::translate ( ByteData bytes,
common::Address addr,
llvm::IRBuilder<> &  irb 
)
private

Member Data Documentation

◆ _abi

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

◆ _addr2bb

std::map<common::Address, llvm::BasicBlock*> retdec::bin2llvmir::Decoder::_addr2bb
private

◆ _addr2fnc

std::map<common::Address, llvm::Function*> retdec::bin2llvmir::Decoder::_addr2fnc
private

◆ _bb2addr

std::map<llvm::BasicBlock*, common::Address> retdec::bin2llvmir::Decoder::_bb2addr
private

◆ _c2l

std::unique_ptr<capstone2llvmir::Capstone2LlvmIrTranslator> retdec::bin2llvmir::Decoder::_c2l
private

◆ _config

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

◆ _debug

DebugFormat* retdec::bin2llvmir::Decoder::_debug = nullptr
private

◆ _debugFncs

std::map<common::Address, const common::Function*> retdec::bin2llvmir::Decoder::_debugFncs
private

◆ _dryCsInsn

cs_insn* retdec::bin2llvmir::Decoder::_dryCsInsn = nullptr
private

◆ _entryPointFunction

llvm::Function* retdec::bin2llvmir::Decoder::_entryPointFunction = nullptr
private

◆ _exports

std::set<common::Address> retdec::bin2llvmir::Decoder::_exports
private

◆ _externs

std::set<std::string> retdec::bin2llvmir::Decoder::_externs
private

Name of all extern functions gathered from object files.

◆ _fnc2addr

std::map<llvm::Function*, common::Address> retdec::bin2llvmir::Decoder::_fnc2addr
private

◆ _fnc2sz

std::map<llvm::Function*, std::size_t> retdec::bin2llvmir::Decoder::_fnc2sz
private

◆ _image

FileImage* retdec::bin2llvmir::Decoder::_image = nullptr
private

◆ _imports

std::set<common::Address> retdec::bin2llvmir::Decoder::_imports
private

◆ _irb

llvm::IRBuilder* retdec::bin2llvmir::Decoder::_irb
private

◆ _jumpTargets

JumpTargets retdec::bin2llvmir::Decoder::_jumpTargets
private

◆ _likelyBb2Target

std::map<llvm::BasicBlock*, llvm::BasicBlock*> retdec::bin2llvmir::Decoder::_likelyBb2Target
private

◆ _llvm2capstone

Llvm2CapstoneInsnMap* retdec::bin2llvmir::Decoder::_llvm2capstone = nullptr
private

◆ _module

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

◆ _names

NameContainer* retdec::bin2llvmir::Decoder::_names = nullptr
private

◆ _ranges

RangesToDecode retdec::bin2llvmir::Decoder::_ranges
private

◆ _somethingDecoded

bool retdec::bin2llvmir::Decoder::_somethingDecoded = false
private

◆ _staticFncs

std::set<common::Address> retdec::bin2llvmir::Decoder::_staticFncs
private

◆ _switchGenerated

bool retdec::bin2llvmir::Decoder::_switchGenerated = false
private

◆ _switchTableStarts

std::map<common::Address, std::set<llvm::SwitchInst*> > retdec::bin2llvmir::Decoder::_switchTableStarts
private

Start of all recognized jump tables. TODO: use this to check that one table does not use labels from another. TODO: maybe we should also remove/fix cond branches to default labels before switches (this was done in the original cfg implementation. However, if we do it too soon, it will cause diff problems when comparing to IDA cfg dumps). We could do it after. Btw, we already have diff problem because default label is added to switch -> it has one more succ then cond branch in IDA (if default label is not in jump table).

◆ _symbols

std::set<common::Address> retdec::bin2llvmir::Decoder::_symbols
private

◆ _terminatingFncs

std::set<llvm::Function*> retdec::bin2llvmir::Decoder::_terminatingFncs
private

◆ _vtableFncs

std::set<common::Address> retdec::bin2llvmir::Decoder::_vtableFncs
private

◆ ID

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

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