miasm
Reverse engineering framework
miasm.jitter.llvmconvert.LLVMFunction Class Reference
Inheritance diagram for miasm.jitter.llvmconvert.LLVMFunction:
Collaboration diagram for miasm.jitter.llvmconvert.LLVMFunction:

Public Member Functions

def __init__ (self, llvm_context, name="fc", new_module=True)
 
def new_branch_name (self)
 
def append_basic_block (self, label, overwrite=True)
 
def CreateEntryBlockAlloca (self, var_type, default_value=None)
 
def get_ptr_by_expr (self, expr)
 
def update_cache (self, name, value)
 
def set_ret (self, var)
 
def get_basic_block_by_loc_key (self, loc_key)
 
def global_constant (self, name, value)
 
def make_bytearray (self, buf)
 
def printf (self, format, *args)
 
def assign (self, src, dst)
 
def init_fc (self)
 
def add_ir (self, expr)
 
def check_memory_exception (self, offset, restricted_exception=False)
 
def check_cpu_exception (self, offset, restricted_exception=False)
 
def gen_pre_code (self, instr_attrib)
 
def gen_post_code (self, attributes, pc_value)
 
def gen_post_instr_checks (self, attrib, next_instr)
 
def expr2cases (self, expr)
 
def gen_jump2dst (self, attrib, instr_offsets, dst)
 
def gen_irblock (self, instr_attrib, attributes, instr_offsets, irblock)
 
def gen_bad_block (self, asmblock)
 
def gen_finalize (self, asmblock, codegen)
 
def from_asmblock (self, asmblock)
 
def __str__ (self)
 
def dot (self)
 
def as_llvm_mod (self)
 
def verify (self)
 
def get_bytecode (self)
 
def get_assembly (self)
 
def optimise (self)
 
def __call__ (self, *args)
 
def get_function_pointer (self)
 

Public Attributes

 llvm_context
 
 mod
 
 my_args
 
 ret_type
 
 builder
 
 entry_bbl
 
 branch_counter
 
 name
 
 local_vars
 
 local_vars_pointers
 
 expr_cache
 
 main_stream
 
 name2bbl
 
 fc
 

Static Public Attributes

bool log_mn = False
 
bool log_regs = True
 
dictionary op_translate
 Basics. More...
 
dictionary op_translate_with_size = {}
 Add the size as first argument. More...
 
dictionary op_translate_with_suffix_size
 Add the size as suffix. More...
 

Detailed Description

Represent a LLVM function

Implementation note:
A new module is created each time to avoid cumulative lag (if @new_module)

Constructor & Destructor Documentation

◆ __init__()

def miasm.jitter.llvmconvert.LLVMFunction.__init__ (   self,
  llvm_context,
  name = "fc",
  new_module = True 
)

Member Function Documentation

◆ __call__()

def miasm.jitter.llvmconvert.LLVMFunction.__call__ (   self,
args 
)

◆ __str__()

def miasm.jitter.llvmconvert.LLVMFunction.__str__ (   self)

◆ add_ir()

def miasm.jitter.llvmconvert.LLVMFunction.add_ir (   self,
  expr 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ append_basic_block()

def miasm.jitter.llvmconvert.LLVMFunction.append_basic_block (   self,
  label,
  overwrite = True 
)
Add a new basic block to the current function.
@label: str or asmlabel
@overwrite: if False, do nothing if a bbl with the same name already exists
Return the corresponding LLVM Basic Block
Here is the caller graph for this function:

◆ as_llvm_mod()

def miasm.jitter.llvmconvert.LLVMFunction.as_llvm_mod (   self)
Return a ModuleRef standing for the current function
Here is the caller graph for this function:

◆ assign()

def miasm.jitter.llvmconvert.LLVMFunction.assign (   self,
  src,
  dst 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_cpu_exception()

def miasm.jitter.llvmconvert.LLVMFunction.check_cpu_exception (   self,
  offset,
  restricted_exception = False 
)
Add a check for CPU errors.
@offset: offset of the current exception (int or Instruction)
If restricted_exception, check only for exception which do not
require a pc update
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_memory_exception()

def miasm.jitter.llvmconvert.LLVMFunction.check_memory_exception (   self,
  offset,
  restricted_exception = False 
)
Add a check for memory errors.
@offset: offset of the current exception (int or Instruction)
If restricted_exception, check only for exception which do not
require a pc update, and do not consider automod exception
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateEntryBlockAlloca()

def miasm.jitter.llvmconvert.LLVMFunction.CreateEntryBlockAlloca (   self,
  var_type,
  default_value = None 
)
Create an alloca instruction at the beginning of the current fc
@default_value: if set, store the default_value just after the allocation
Here is the caller graph for this function:

◆ dot()

def miasm.jitter.llvmconvert.LLVMFunction.dot (   self)

◆ expr2cases()

def miasm.jitter.llvmconvert.LLVMFunction.expr2cases (   self,
  expr 
)
Evaluate @expr and return:
- switch value -> dst
- evaluation of the switch value (if any)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ from_asmblock()

def miasm.jitter.llvmconvert.LLVMFunction.from_asmblock (   self,
  asmblock 
)
Build the function from an asmblock (asm_block instance).
Prototype : f(i8* jitcpu, i8* vmcpu, i8* vmmngr, i8* status)
Here is the call graph for this function:

◆ gen_bad_block()

def miasm.jitter.llvmconvert.LLVMFunction.gen_bad_block (   self,
  asmblock 
)
Translate an asm_bad_block into a CPU exception
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_finalize()

def miasm.jitter.llvmconvert.LLVMFunction.gen_finalize (   self,
  asmblock,
  codegen 
)
In case of delayslot, generate a dummy BBL which return on the computed
IRDst or on next_label
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_irblock()

def miasm.jitter.llvmconvert.LLVMFunction.gen_irblock (   self,
  instr_attrib,
  attributes,
  instr_offsets,
  irblock 
)
Generate the code for an @irblock
@instr_attrib: an Attributes instance or the instruction to translate
@attributes: list of Attributes corresponding to irblock assignments
@instr_offsets: offset of all asmblock's instructions
@irblock: an irblock instance
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_jump2dst()

def miasm.jitter.llvmconvert.LLVMFunction.gen_jump2dst (   self,
  attrib,
  instr_offsets,
  dst 
)
Generate the code for a jump to @dst with final check for error

Several cases have to be considered:
 - jump to an offset out of the current ASM BBL (JMP 0x11223344)
 - jump to an offset inside the current ASM BBL (Go to next instruction)
 - jump to an offset back in the current ASM BBL (For max_exec jit
   option on self loops)
 - jump to a generated IR label, which must be jitted in this same
   function (REP MOVSB)
 - jump to a computed offset (CALL @32[0x11223344])

Reimplemented in miasm.jitter.llvmconvert.LLVMFunction_IRCompilation.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_post_code()

def miasm.jitter.llvmconvert.LLVMFunction.gen_post_code (   self,
  attributes,
  pc_value 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_post_instr_checks()

def miasm.jitter.llvmconvert.LLVMFunction.gen_post_instr_checks (   self,
  attrib,
  next_instr 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_pre_code()

def miasm.jitter.llvmconvert.LLVMFunction.gen_pre_code (   self,
  instr_attrib 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_assembly()

def miasm.jitter.llvmconvert.LLVMFunction.get_assembly (   self)
Here is the call graph for this function:

◆ get_basic_block_by_loc_key()

def miasm.jitter.llvmconvert.LLVMFunction.get_basic_block_by_loc_key (   self,
  loc_key 
)
Here is the caller graph for this function:

◆ get_bytecode()

def miasm.jitter.llvmconvert.LLVMFunction.get_bytecode (   self)
Here is the call graph for this function:

◆ get_function_pointer()

def miasm.jitter.llvmconvert.LLVMFunction.get_function_pointer (   self)
Here is the call graph for this function:

◆ get_ptr_by_expr()

def miasm.jitter.llvmconvert.LLVMFunction.get_ptr_by_expr (   self,
  expr 
)
"Return a pointer casted corresponding to ExprId expr. If it is not
already computed, compute it at the end of entry_bloc
Here is the caller graph for this function:

◆ global_constant()

def miasm.jitter.llvmconvert.LLVMFunction.global_constant (   self,
  name,
  value 
)
Inspired from numba/cgutils.py

Get or create a (LLVM module-)global constant with *name* or *value*.
Here is the caller graph for this function:

◆ init_fc()

def miasm.jitter.llvmconvert.LLVMFunction.init_fc (   self)

Reimplemented in miasm.jitter.llvmconvert.LLVMFunction_IRCompilation.

Here is the caller graph for this function:

◆ make_bytearray()

def miasm.jitter.llvmconvert.LLVMFunction.make_bytearray (   self,
  buf 
)
Inspired from numba/cgutils.py

Make a byte array constant from *buf*.
Here is the caller graph for this function:

◆ new_branch_name()

def miasm.jitter.llvmconvert.LLVMFunction.new_branch_name (   self)
Here is the caller graph for this function:

◆ optimise()

def miasm.jitter.llvmconvert.LLVMFunction.optimise (   self)
Here is the call graph for this function:

◆ printf()

def miasm.jitter.llvmconvert.LLVMFunction.printf (   self,
  format,
args 
)
Inspired from numba/cgutils.py

Calls printf().
Argument `format` is expected to be a Python string.
Values to be printed are listed in `args`.

Note: There is no checking to ensure there is correct number of values
in `args` and there type matches the declaration in the format string.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_ret()

def miasm.jitter.llvmconvert.LLVMFunction.set_ret (   self,
  var 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_cache()

def miasm.jitter.llvmconvert.LLVMFunction.update_cache (   self,
  name,
  value 
)
Here is the caller graph for this function:

◆ verify()

def miasm.jitter.llvmconvert.LLVMFunction.verify (   self)
Here is the call graph for this function:

Member Data Documentation

◆ branch_counter

miasm.jitter.llvmconvert.LLVMFunction.branch_counter

◆ builder

miasm.jitter.llvmconvert.LLVMFunction.builder

◆ entry_bbl

miasm.jitter.llvmconvert.LLVMFunction.entry_bbl

◆ expr_cache

miasm.jitter.llvmconvert.LLVMFunction.expr_cache

◆ fc

miasm.jitter.llvmconvert.LLVMFunction.fc

◆ llvm_context

miasm.jitter.llvmconvert.LLVMFunction.llvm_context

◆ local_vars

miasm.jitter.llvmconvert.LLVMFunction.local_vars

◆ local_vars_pointers

miasm.jitter.llvmconvert.LLVMFunction.local_vars_pointers

◆ log_mn

bool miasm.jitter.llvmconvert.LLVMFunction.log_mn = False
static

◆ log_regs

bool miasm.jitter.llvmconvert.LLVMFunction.log_regs = True
static

◆ main_stream

miasm.jitter.llvmconvert.LLVMFunction.main_stream

◆ mod

miasm.jitter.llvmconvert.LLVMFunction.mod

◆ my_args

miasm.jitter.llvmconvert.LLVMFunction.my_args

◆ name

miasm.jitter.llvmconvert.LLVMFunction.name

◆ name2bbl

miasm.jitter.llvmconvert.LLVMFunction.name2bbl

◆ op_translate

dictionary miasm.jitter.llvmconvert.LLVMFunction.op_translate
static
Initial value:
= {'x86_cpuid': 'x86_cpuid',
}

Basics.

◆ op_translate_with_size

dictionary miasm.jitter.llvmconvert.LLVMFunction.op_translate_with_size = {}
static

Add the size as first argument.

◆ op_translate_with_suffix_size

dictionary miasm.jitter.llvmconvert.LLVMFunction.op_translate_with_suffix_size
static
Initial value:
= {
'bcdadd': 'bcdadd',
'bcdadd_cf': 'bcdadd_cf',
}

Add the size as suffix.

◆ ret_type

miasm.jitter.llvmconvert.LLVMFunction.ret_type

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