miasm
Reverse engineering framework
miasm.jitter.codegen.CGen Class Reference
Inheritance diagram for miasm.jitter.codegen.CGen:
Collaboration diagram for miasm.jitter.codegen.CGen:

Public Member Functions

def __init__ (self, ir_arch)
 
def init_arch_C (self)
 
def dst_to_c (self, src)
 
def patch_c_id (self, expr)
 
def id_to_c (self, expr)
 
def add_label_index (self, dst2index, loc_key)
 
def assignblk_to_irbloc (self, instr, assignblk)
 
def block2assignblks (self, block)
 
def add_local_var (self, dst_var, dst_index, expr)
 
def get_mem_prefetch (self, assignblk)
 
def gen_c_assignments (self, assignblk)
 
def gen_check_memory_exception (self, address)
 
def gen_check_cpu_exception (self, address)
 
def traverse_expr_dst (self, expr, dst2index)
 
def gen_assignblk_dst (self, dst)
 
def gen_post_instr_checks (self, attrib)
 
def gen_pre_code (self, instr_attrib)
 
def gen_post_code (self, attrib, pc_value)
 
def gen_goto_code (self, attrib, instr_offsets, dst)
 
def gen_dst_goto (self, attrib, instr_offsets, dst2index)
 
def gen_c_code (self, attrib, c_dst, c_assignmnts)
 
def get_caracteristics (self, assignblk, attrib)
 
def get_attributes (self, instr, irblocks, log_mn=False, log_regs=False)
 
def gen_bad_block (self)
 
def get_block_post_label (self, block)
 
def gen_init (self, block)
 
def gen_irblock (self, instr_attrib, attributes, instr_offsets, irblock)
 
def gen_finalize (self, block)
 
def gen_c (self, block, log_mn=False, log_regs=False)
 

Public Attributes

 ir_arch
 
 PC
 
 translator
 
 id_to_c_id
 
 C_PC
 

Static Public Attributes

string CODE_EXCEPTION_MEM_AT_INSTR
 
string CODE_EXCEPTION_AT_INSTR
 
string CODE_RETURN_EXCEPTION
 
string CODE_RETURN_NO_EXCEPTION
 
string CODE_CPU_EXCEPTION_POST_INSTR
 
string CODE_VM_EXCEPTION_POST_INSTR
 
string CODE_INIT
 
string CODE_BAD_BLOCK
 

Detailed Description

Helper to generate C code for a given AsmBlock
Translate native assembly block to C

Constructor & Destructor Documentation

◆ __init__()

def miasm.jitter.codegen.CGen.__init__ (   self,
  ir_arch 
)

Member Function Documentation

◆ add_label_index()

def miasm.jitter.codegen.CGen.add_label_index (   self,
  dst2index,
  loc_key 
)
Insert @lbl to the dictionary @dst2index with a uniq value
@dst2index: LocKey -> uniq value
@loc_key: LocKey instance
Here is the caller graph for this function:

◆ add_local_var()

def miasm.jitter.codegen.CGen.add_local_var (   self,
  dst_var,
  dst_index,
  expr 
)
Add local variable used to store temporary result
@dst_var: dictionary of Expr -> local_var_expr
@dst_index : dictionary of size -> local var count
@expr: Expression source
Here is the caller graph for this function:

◆ assignblk_to_irbloc()

def miasm.jitter.codegen.CGen.assignblk_to_irbloc (   self,
  instr,
  assignblk 
)
Ensure IRDst is always set in the head @assignblk of the @instr
@instr: an instruction instance
@assignblk: Assignblk instance
Here is the caller graph for this function:

◆ block2assignblks()

def miasm.jitter.codegen.CGen.block2assignblks (   self,
  block 
)
Return the list of irblocks for a native @block
@block: AsmBlock

Reimplemented in miasm.arch.mips32.jit.mipsCGen, and miasm.arch.arm.jit.arm_CGen.

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

◆ dst_to_c()

def miasm.jitter.codegen.CGen.dst_to_c (   self,
  src 
)
Translate Expr @src into C code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_assignblk_dst()

def miasm.jitter.codegen.CGen.gen_assignblk_dst (   self,
  dst 
)
Generate C code to handle instruction destination
@dst: instruction destination Expr
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_bad_block()

def miasm.jitter.codegen.CGen.gen_bad_block (   self)
Generate the C code for a bad_block instance
Here is the caller graph for this function:

◆ gen_c()

def miasm.jitter.codegen.CGen.gen_c (   self,
  block,
  log_mn = False,
  log_regs = False 
)
Generate the C code for the @block and return it as a list of lines
@log_mn: log mnemonics
@log_regs: log registers
Here is the call graph for this function:

◆ gen_c_assignments()

def miasm.jitter.codegen.CGen.gen_c_assignments (   self,
  assignblk 
)
Return C information used to generate the C code of the @assignblk
@assignblk: an AssignBlock instance
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_c_code()

def miasm.jitter.codegen.CGen.gen_c_code (   self,
  attrib,
  c_dst,
  c_assignmnts 
)
Generate the C code for assignblk.
@attrib: Attributes instance
@c_dst: irdst C code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_check_cpu_exception()

def miasm.jitter.codegen.CGen.gen_check_cpu_exception (   self,
  address 
)
Generate C code to check cpu exceptions
@address: address of the faulty instruction
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_check_memory_exception()

def miasm.jitter.codegen.CGen.gen_check_memory_exception (   self,
  address 
)
Generate C code to check memory exceptions
@address: address of the faulty instruction
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_dst_goto()

def miasm.jitter.codegen.CGen.gen_dst_goto (   self,
  attrib,
  instr_offsets,
  dst2index 
)
Generate code for possible @dst2index.

@attrib: an Attributes instance
@instr_offsets: list of instructions offsets
@dst2index: link from destination to index
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_finalize()

def miasm.jitter.codegen.CGen.gen_finalize (   self,
  block 
)
Generate the C code for the final block instruction

Reimplemented in miasm.arch.mips32.jit.mipsCGen.

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

◆ gen_goto_code()

def miasm.jitter.codegen.CGen.gen_goto_code (   self,
  attrib,
  instr_offsets,
  dst 
)
Generate C code for a potential destination @dst
@attrib: instruction Attributes
@instr_offsets: instructions offsets list
@dst: potential instruction destination
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_init()

def miasm.jitter.codegen.CGen.gen_init (   self,
  block 
)
Generate the init C code for a @block
@block: an asm_bloc instance
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_irblock()

def miasm.jitter.codegen.CGen.gen_irblock (   self,
  instr_attrib,
  attributes,
  instr_offsets,
  irblock 
)
Generate the C code for an @irblock
@irblock: an irbloc instance
@attributes: an Attributes instance list
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_post_code()

def miasm.jitter.codegen.CGen.gen_post_code (   self,
  attrib,
  pc_value 
)
Callback to generate code AFTER the instruction execution
@attrib: Attributes instance

Reimplemented in miasm.arch.x86.jit.x86_64_CGen, miasm.arch.x86.jit.x86_32_CGen, and miasm.arch.mep.jit.mep_CGen.

Here is the caller graph for this function:

◆ gen_post_instr_checks()

def miasm.jitter.codegen.CGen.gen_post_instr_checks (   self,
  attrib 
)
Generate C code for handling potential exceptions
@attrib: Attributes instance
Here is the caller graph for this function:

◆ gen_pre_code()

def miasm.jitter.codegen.CGen.gen_pre_code (   self,
  instr_attrib 
)
Callback to generate code BEFORE the instruction execution
@instr_attrib: Attributes instance

Reimplemented in miasm.arch.mep.jit.mep_CGen.

Here is the caller graph for this function:

◆ get_attributes()

def miasm.jitter.codegen.CGen.get_attributes (   self,
  instr,
  irblocks,
  log_mn = False,
  log_regs = False 
)
Get the carateristics of each @irblocks. Returns the corresponding
attributes object.
@irblock: a list of irbloc instance
@log_mn: generate code to log instructions
@log_regs: generate code to log registers states
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_block_post_label()

def miasm.jitter.codegen.CGen.get_block_post_label (   self,
  block 
)
Get label next to the @block
@block: AsmBlock instance
Here is the caller graph for this function:

◆ get_caracteristics()

def miasm.jitter.codegen.CGen.get_caracteristics (   self,
  assignblk,
  attrib 
)
Set the carateristics in @attrib according to the @assignblk
@assignblk: an AssignBlock instance
@attrib: an Attributes instance
Here is the caller graph for this function:

◆ get_mem_prefetch()

def miasm.jitter.codegen.CGen.get_mem_prefetch (   self,
  assignblk 
)
Generate temporary variables used to fetch memory used in the @assignblk
Return a dictionary: ExprMem -> temporary variable
@assignblk: AssignBlock instance
Here is the caller graph for this function:

◆ id_to_c()

def miasm.jitter.codegen.CGen.id_to_c (   self,
  expr 
)
Translate Expr @expr into corresponding C code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_arch_C()

def miasm.jitter.codegen.CGen.init_arch_C (   self)
Iinitialize jitter internals

◆ patch_c_id()

def miasm.jitter.codegen.CGen.patch_c_id (   self,
  expr 
)
Replace ExprId in @expr with corresponding C variables
Here is the caller graph for this function:

◆ traverse_expr_dst()

def miasm.jitter.codegen.CGen.traverse_expr_dst (   self,
  expr,
  dst2index 
)
Generate the index of the destination label for the @expr
@dst2index: dictionary to link label to its index
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ C_PC

miasm.jitter.codegen.CGen.C_PC

◆ CODE_BAD_BLOCK

string miasm.jitter.codegen.CGen.CODE_BAD_BLOCK
static
Initial value:
= r"""
// Unknown mnemonic
CPU_exception_flag = EXCEPT_UNK_MNEMO;
""" + CODE_RETURN_EXCEPTION

◆ CODE_CPU_EXCEPTION_POST_INSTR

string miasm.jitter.codegen.CGen.CODE_CPU_EXCEPTION_POST_INSTR
static
Initial value:
= r"""
if (CPU_exception_flag) {
%s = DST_value;
BlockDst->address = DST_value;
return JIT_RET_EXCEPTION;
}
"""

◆ CODE_EXCEPTION_AT_INSTR

string miasm.jitter.codegen.CGen.CODE_EXCEPTION_AT_INSTR
static
Initial value:
= r"""
if (CPU_exception_flag_at_instr) {
%s = %s;
BlockDst->address = %s;
return JIT_RET_EXCEPTION;
}
"""

◆ CODE_EXCEPTION_MEM_AT_INSTR

string miasm.jitter.codegen.CGen.CODE_EXCEPTION_MEM_AT_INSTR
static
Initial value:
= r"""
// except fetch mem at instr noauto
if ((VM_exception_flag & ~EXCEPT_CODE_AUTOMOD) & EXCEPT_DO_NOT_UPDATE_PC) {
%s = %s;
BlockDst->address = %s;
return JIT_RET_EXCEPTION;
}
"""

◆ CODE_INIT

string miasm.jitter.codegen.CGen.CODE_INIT
static
Initial value:
= r"""
int DST_case;
uint64_t DST_value;
struct vm_cpu *mycpu = jitcpu->cpu;
goto %s;
"""

◆ CODE_RETURN_EXCEPTION

string miasm.jitter.codegen.CGen.CODE_RETURN_EXCEPTION
static
Initial value:
= r"""
return JIT_RET_EXCEPTION;
"""

◆ CODE_RETURN_NO_EXCEPTION

string miasm.jitter.codegen.CGen.CODE_RETURN_NO_EXCEPTION
static
Initial value:
= r"""
%s:
%s = %s;
BlockDst->address = %s;
return JIT_RET_NO_EXCEPTION;
"""

◆ CODE_VM_EXCEPTION_POST_INSTR

string miasm.jitter.codegen.CGen.CODE_VM_EXCEPTION_POST_INSTR
static
Initial value:
= r"""
check_memory_breakpoint(&(jitcpu->pyvm->vm_mngr));
check_invalid_code_blocs(&(jitcpu->pyvm->vm_mngr));
if (VM_exception_flag) {
%s = DST_value;
BlockDst->address = DST_value;
return JIT_RET_EXCEPTION;
}
"""

◆ id_to_c_id

miasm.jitter.codegen.CGen.id_to_c_id

◆ ir_arch

miasm.jitter.codegen.CGen.ir_arch

◆ PC

miasm.jitter.codegen.CGen.PC

◆ translator

miasm.jitter.codegen.CGen.translator

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