mbl_array_t Class Reference

Micro block array (internal representation of the decompiled code). More...

Public Member Functions

bool precise_defeas (void) const
 
bool optimized (void) const
 
bool short_display (void) const
 
bool show_reduction (void) const
 
bool graph_insns (void) const
 
bool loaded_gdl (void) const
 
bool should_beautify (void) const
 
bool rtype_refined (void) const
 
bool may_refine_rettype (void) const
 
bool may_del_asserts (void) const
 
bool use_wingraph32 (void) const
 
bool display_numaddrs (void) const
 
bool display_valnums (void) const
 
bool is_pattern (void) const
 
bool is_thunk (void) const
 
bool saverest_done (void) const
 
bool callinfo_built (void) const
 
bool has_overvars (void) const
 
bool really_alloc (void) const
 
bool lvars_allocated (void) const
 
bool chain_varnums_ok (void) const
 
bool returns_fpval (void) const
 
bool has_passregs (void) const
 
bool generated_asserts (void) const
 
bool propagated_asserts (void) const
 
bool deleted_pairs (void) const
 
bool common_stkvars_stkargs (void) const
 
bool lvar_names_ok (void) const
 
bool lvars_renamed (void) const
 
bool has_over_chains (void) const
 
bool valranges_done (void) const
 
bool is_ctr (void) const
 
bool is_dtr (void) const
 
bool is_cdtr (void) const
 
int get_mba_flags (void) const
 
void set_mba_flags (int f)
 
void clr_mba_flags (int f)
 
void set_mba_flags2 (int f)
 
void clr_mba_flags2 (int f)
 
void clr_cdtr (void)
 
int calc_shins_flags (void) const
 
sval_t stkoff_vd2ida (sval_t off) const
 
sval_t stkoff_ida2vd (sval_t off) const
 
sval_t argbase () const
 
vdloc_t idaloc2vd (const argloc_t &loc, int width) const
 
argloc_t vd2idaloc (const vdloc_t &loc, int width) const
 
bool is_stkarg (const lvar_t &v) const
 
member_t * get_stkvar (sval_t vd_stkoff, uval_t *poff) const
 
argloc_t get_ida_argloc (const lvar_t &v) const
 
bool write_to_const_detected (void) const
 
bool bad_call_sp_detected (void) const
 
bool regargs_is_not_aligned (void) const
 
bool has_bad_sp (void) const
 
void term (void)
 
func_t * get_curfunc (void) const
 
bool use_frame (void) const
 
bool range_contains (ea_t ea) const
 
bool is_snippet (void) const
 
int optimize_local (int locopt_bits)
 Optimize each basic block locally. More...
 
merror_t build_graph (void)
 Build control flow graph. More...
 
mbl_graph_tget_graph (void)
 Get control graph. More...
 
int analyze_calls (int acflags)
 Analyze calls and determine calling conventions. More...
 
merror_t optimize_global (void)
 Optimize microcode globally. More...
 
void alloc_lvars (void)
 Allocate local variables. More...
 
void dump (void) const
 Dump microcode to a file. More...
 
void vdump_mba (bool _verify, const char *title, va_list va) const
 
void dump_mba (bool _verify, const char *title,...) const
 
void print (vd_printer_t &vp) const
 Print microcode to any destination. More...
 
void verify (bool always) const
 Verify microcode consistency. More...
 
void mark_chains_dirty (void)
 Mark the microcode use-def chains dirty. More...
 
const mblock_tget_mblock (int n) const
 Get basic block by its serial number.
 
mblock_tget_mblock (int n)
 
mblock_tinsert_block (int bblk)
 Insert a block in the middle of the mbl array. More...
 
bool remove_block (mblock_t *blk)
 Delete a block. More...
 
bool remove_empty_blocks (void)
 Delete all empty blocks.
 
bool combine_blocks (void)
 Combine blocks. More...
 
int for_all_ops (mop_visitor_t &mv)
 Visit all operands of all instructions. More...
 
int for_all_insns (minsn_visitor_t &mv)
 Visit all instructions. More...
 
int for_all_topinsns (minsn_visitor_t &mv)
 Visit all top level instructions. More...
 
mop_tfind_mop (op_parent_info_t *ctx, ea_t ea, bool is_dest, const mlist_t &list)
 Find an operand in the microcode. More...
 
lvar_targ (int n)
 Get input argument of the decompiled function. More...
 
const lvar_targ (int n) const
 
const ivl_tget_std_region (memreg_index_t idx) const
 Get information about various memory regions. More...
 
const ivl_tget_lvars_region (void) const
 
const ivl_tget_shadow_region (void) const
 
const ivl_tget_args_region (void) const
 
ivl_t get_stack_region (void) const
 
void serialize (bytevec_t &b) const
 Serialize mbl array into a sequence of bytes.
 

Static Public Member Functions

static vdloc_t idaloc2vd (const argloc_t &loc, int width, sval_t spd)
 
static vdloc_t idaloc2vd (const mbl_array_t *mba, const argloc_t &loc, int width)
 
static argloc_t vd2idaloc (const vdloc_t &loc, int width, sval_t spd)
 
static mbl_array_tdeserialize (const uchar *bytes, size_t nbytes)
 Deserialize a byte sequence into mbl array. More...
 

Public Attributes

mba_ranges_t mbr
 
ea_t entry_ea
 
ea_t last_prolog_ea
 
ea_t first_epilog_ea
 
int qty
 number of basic blocks
 
int npurged
 -1 - unknown
 
cm_t cc
 calling convention
 
sval_t tmpstk_size
 size of the temporary stack part (which dynamically changes with push/pops)
 
sval_t frsize
 size of local stkvars range in the stack frame
 
sval_t frregs
 size of saved registers range in the stack frame
 
sval_t fpd
 frame pointer delta
 
int pfn_flags
 copy of func_t::flags
 
int retsize
 size of return address in the stack frame
 
int shadow_args
 size of shadow argument area
 
sval_t fullsize
 Full stack size including incoming args.
 
sval_t stacksize
 The maximal size of the function stack including bytes allocated for outgoing call arguments (up to retaddr)
 
sval_t inargoff
 offset of the first stack argument
 
sval_t minstkref
 The lowest stack location whose address was taken.
 
ea_t minstkref_ea
 address with lowest minstkref (for debugging)
 
sval_t minargref
 The lowest stack argument location whose address was taken This location and locations above it can be aliased It controls locations >= inargoff-shadow_args.
 
sval_t spd_adjust
 If sp>0, the max positive sp value.
 
ivl_t aliased_vars
 Aliased stkvar locations.
 
ivl_t aliased_args
 Aliased stkarg locations.
 
ivlset_t gotoff_stkvars
 stkvars that hold .got offsets. considered to be unaliasable
 
ivlset_t restricted_memory
 
ivlset_t aliased_memory
 aliased_memory+restricted_memory=ALLMEM
 
mlist_t nodel_memory
 global dead elimination may not delete references to this area
 
rlist_t consumed_argregs
 registers converted into stack arguments, should not be used as arguments
 
mba_maturity_t maturity
 current maturity level
 
mba_maturity_t reqmat
 required maturity level
 
bool final_type
 is the function type final? (specified by the user)
 
tinfo_t idb_type
 function type as retrieved from the database
 
reginfovec_t idb_spoiled
 MBL_SPLINFO && final_type: info in ida format.
 
mlist_t spoiled_list
 MBL_SPLINFO && !final_type: info in vd format.
 
int fti_flags
 FTI_... constants for the current function.
 
netnode idb_node
 
qstring label
 name of the function or pattern (colored)
 
lvars_t vars
 local variables
 
intvec_t argidx
 input arguments (indexes into 'vars')
 
int retvaridx
 index of variable holding the return value -1 means none
 
ea_t error_ea
 during microcode generation holds ins.ea
 
qstring error_strarg
 
mblock_tblocks
 double linked list of blocks
 
mblock_t ** natural
 natural order of blocks
 
ivl_with_name_t std_ivls [6]
 we treat memory as consisting of 6 parts see memreg_index_t
 
hexwarns_t notes
 
uchar occurred_warns [32]
 
char reserved []
 

Detailed Description

Micro block array (internal representation of the decompiled code).

Array of micro blocks represents microcode for a decompiled function.

Intermediate representation of the decompiled function. The details of this class are not public yet because it will be modified in the near future. We plan to disclose them after porting the decompiler to ARM.

The first micro block is the entry point, the last one if the exit point. The entry and exit blocks are always empty. The exit block is generated at MMAT_LOCOPT maturity level.

Examples:
hexrays_sample11.cpp, hexrays_sample12.cpp, hexrays_sample13.cpp, hexrays_sample15.cpp, and hexrays_sample9.cpp.

Definition at line 63 of file hexrays.dox.

Member Function Documentation

◆ alloc_lvars()

void mbl_array_t::alloc_lvars ( void  )

Allocate local variables.

Must be called only immediately after optimize_global(), with no modifications to the microcode. Converts registers, stack variables, and similar operands into mop_l. This call will not fail because all necessary checks were performed in optimize_global(). After this call the microcode reaches its final state.

Definition at line 10389 of file hexrays.hpp.

References hexdsp.

◆ analyze_calls()

int mbl_array_t::analyze_calls ( int  acflags)

Analyze calls and determine calling conventions.

Parameters
acflagspermitted actions that are necessary for successful detection of calling conventions. See Bits for analyze_calls()
Returns
number of calls. -1 means error.
Examples:
hexrays_sample12.cpp.

Definition at line 10377 of file hexrays.hpp.

References hexdsp.

◆ arg()

lvar_t & mbl_array_t::arg ( int  n)

Get input argument of the decompiled function.

Parameters
nargument number (0..nargs-1)

Definition at line 10473 of file hexrays.hpp.

References hexdsp.

◆ build_graph()

merror_t mbl_array_t::build_graph ( void  )

Build control flow graph.

This function may be called only once. It calculates the type of each basic block and the adjacency list. optimize_local() calls this function if necessary. You need to call this function only before MMAT_LOCOPT.

Returns
error code
Examples:
hexrays_sample12.cpp.

Definition at line 10365 of file hexrays.hpp.

References hexdsp.

◆ combine_blocks()

bool mbl_array_t::combine_blocks ( void  )

Combine blocks.

This function merges blocks constituting linear flow. It calls remove_empty_blocks() as well.

Returns
true if changed any blocks

Definition at line 10443 of file hexrays.hpp.

References hexdsp.

◆ deserialize()

mbl_array_t * mbl_array_t::deserialize ( const uchar *  bytes,
size_t  nbytes 
)
static

Deserialize a byte sequence into mbl array.

Parameters
bytespointer to the beginning of the byte sequence.
nbytesnumber of bytes in the byte sequence.
Returns
new mbl array

Definition at line 10485 of file hexrays.hpp.

References hexdsp.

◆ dump()

void mbl_array_t::dump ( void  ) const

Dump microcode to a file.

The file will be created in the directory pointed by IDA_DUMPDIR envvar. Dump will be created only if IDA is run under debugger.

Definition at line 10395 of file hexrays.hpp.

References hexdsp.

◆ find_mop()

mop_t * mbl_array_t::find_mop ( op_parent_info_t ctx,
ea_t  ea,
bool  is_dest,
const mlist_t list 
)

Find an operand in the microcode.

This function tries to find the operand that matches LIST. Any operand that overlaps with LIST is considered as a match.

Parameters
[out]ctxcontext information for the result
eadesired address of the operand
is_destsearch for destination operand? this argument may be ignored if the exact match could not be found
listlist of locations the correspond to the operand
Returns
pointer to the operand or NULL.
Examples:
hexrays_sample12.cpp, and hexrays_sample15.cpp.

Definition at line 10467 of file hexrays.hpp.

References hexdsp.

◆ for_all_insns()

int mbl_array_t::for_all_insns ( minsn_visitor_t mv)

Visit all instructions.

This function visits all instruction and subinstructions.

Parameters
mvinstruction visitor
Returns
non-zero value returned by mv.visit_mop() or zero

Definition at line 10455 of file hexrays.hpp.

References hexdsp.

◆ for_all_ops()

int mbl_array_t::for_all_ops ( mop_visitor_t mv)

Visit all operands of all instructions.

Parameters
mvoperand visitor
Returns
non-zero value returned by mv.visit_mop() or zero

Definition at line 10449 of file hexrays.hpp.

References hexdsp.

◆ for_all_topinsns()

int mbl_array_t::for_all_topinsns ( minsn_visitor_t mv)

Visit all top level instructions.

Parameters
mvinstruction visitor
Returns
non-zero value returned by mv.visit_mop() or zero

Definition at line 10461 of file hexrays.hpp.

References hexdsp.

◆ get_graph()

mbl_graph_t * mbl_array_t::get_graph ( void  )

Get control graph.

Call build_graph() if you need the graph before MMAT_LOCOPT.

Examples:
hexrays_sample12.cpp.

Definition at line 10371 of file hexrays.hpp.

References hexdsp.

◆ get_std_region()

const ivl_t & mbl_array_t::get_std_region ( memreg_index_t  idx) const

Get information about various memory regions.

We map the stack frame to the global memory, to some unused range.

Definition at line 4802 of file hexrays.hpp.

References close_pseudocode(), get_hexrays_version(), get_widget_vdui(), hexapi, MMIDX_ARGS, MMIDX_LVARS, MMIDX_SHADOW, and open_pseudocode().

◆ insert_block()

mblock_t * mbl_array_t::insert_block ( int  bblk)

Insert a block in the middle of the mbl array.

Parameters
bblkhe new block will be inserted before BBLK
Returns
ptr to new block

Definition at line 10425 of file hexrays.hpp.

References hexdsp.

◆ mark_chains_dirty()

void mbl_array_t::mark_chains_dirty ( void  )

Mark the microcode use-def chains dirty.

Call this function is any inter-block data dependencies got changed because of your modifications to the microcode. Failing to do so may cause an internal error.

Examples:
hexrays_sample11.cpp.

Definition at line 10419 of file hexrays.hpp.

References hexdsp.

◆ optimize_global()

merror_t mbl_array_t::optimize_global ( void  )

Optimize microcode globally.

This function applies various optimization methods until we reach the fixed point. After that it preallocates lvars unless reqmat forbids it.

Returns
error code

Definition at line 10383 of file hexrays.hpp.

References hexdsp.

◆ optimize_local()

int mbl_array_t::optimize_local ( int  locopt_bits)

Optimize each basic block locally.

Parameters
locopt_bitscombination of Bits for optimize_local() bits
Returns
number of changes. 0 means nothing changed This function is called by the decompiler, usually there is no need to call it explicitly.

Definition at line 10359 of file hexrays.hpp.

References hexdsp.

◆ print()

void mbl_array_t::print ( vd_printer_t vp) const

Print microcode to any destination.

Parameters
vpprint sink
Examples:
hexrays_sample13.cpp, and hexrays_sample9.cpp.

Definition at line 10407 of file hexrays.hpp.

References hexdsp.

◆ remove_block()

bool mbl_array_t::remove_block ( mblock_t blk)

Delete a block.

Parameters
blkblock to delete
Returns
true if at least one of the other blocks became empty or unreachable

Definition at line 10431 of file hexrays.hpp.

References hexdsp.

◆ verify()

void mbl_array_t::verify ( bool  always) const

Verify microcode consistency.

Parameters
alwaysif false, the check will be performed only if ida runs under debugger If any inconsistency is discovered, an internal error will be generated. We strongly recommend you to call this function before returing control to the decompiler from your callbacks, in the case if you modified the microcode.
Examples:
hexrays_sample11.cpp.

Definition at line 10413 of file hexrays.hpp.

References hexdsp.