IDA C++ SDK 9.2
|
Array of micro blocks representing microcode for a decompiled function. More...
#include <hexrays.hpp>
Public Member Functions | |
bool | precise_defeas () const |
bool | optimized () const |
bool | short_display () const |
bool | show_reduction () const |
bool | graph_insns () const |
bool | loaded_gdl () const |
bool | should_beautify () const |
bool | rtype_refined () const |
bool | may_refine_rettype () const |
bool | use_wingraph32 () const |
bool | display_numaddrs () const |
bool | display_valnums () const |
bool | is_pattern () const |
bool | is_thunk () const |
bool | saverest_done () const |
bool | callinfo_built () const |
bool | really_alloc () const |
bool | lvars_allocated () const |
bool | chain_varnums_ok () const |
bool | returns_fpval () const |
bool | has_passregs () const |
bool | generated_asserts () const |
bool | propagated_asserts () const |
bool | deleted_pairs () const |
bool | common_stkvars_stkargs () const |
bool | lvar_names_ok () const |
bool | lvars_renamed () const |
bool | has_over_chains () const |
bool | valranges_done () const |
bool | argidx_ok () const |
bool | argidx_sorted () const |
bool | code16_bit_removed () const |
bool | has_stack_retval () const |
bool | has_outlines () const |
bool | is_ctr () const |
bool | is_dtr () const |
bool | is_cdtr () const |
bool | prop_complex () const |
int | get_mba_flags () const |
int | get_mba_flags2 () 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 () |
int | calc_shins_flags () const |
sval_t hexapi | stkoff_vd2ida (sval_t off) const |
sval_t hexapi | stkoff_ida2vd (sval_t off) const |
sval_t | argbase () const |
vdloc_t hexapi | idaloc2vd (const argloc_t &loc, int width) const |
argloc_t hexapi | vd2idaloc (const vdloc_t &loc, int width) const |
bool | is_stkarg (const lvar_t &v) const |
ssize_t | get_stkvar (udm_t *udm, sval_t vd_stkoff, uval_t *p_idaoff=nullptr, tinfo_t *p_frame=nullptr) const |
argloc_t | get_ida_argloc (const lvar_t &v) const |
bool | write_to_const_detected () const |
bool | bad_call_sp_detected () const |
bool | regargs_is_not_aligned () const |
bool | has_bad_sp () const |
mba_t () | |
~mba_t () | |
HEXRAYS_MEMORY_ALLOCATION_FUNCS () void hexapi term() | |
func_t *hexapi | get_curfunc () const |
bool | use_frame () const |
bool | range_contains (ea_t ea) const |
bool | is_snippet () const |
merror_t hexapi | set_maturity (mba_maturity_t mat) |
Set maturity level. | |
int hexapi | optimize_local (int locopt_bits) |
Optimize each basic block locally. | |
merror_t hexapi | build_graph () |
Build control flow graph. | |
mbl_graph_t *hexapi | get_graph () |
Get control graph. | |
int hexapi | analyze_calls (int acflags) |
Analyze calls and determine calling conventions. | |
merror_t hexapi | optimize_global () |
Optimize microcode globally. | |
void hexapi | alloc_lvars () |
Allocate local variables. | |
void hexapi | dump () const |
Dump microcode to a file. | |
AS_PRINTF (3, 0) void hexapi vdump_mba(bool _verify | |
AS_PRINTF (3, 4) void dump_mba(bool _verify | |
va_start (va, title) | |
vdump_mba (_verify, title, va) | |
va_end (va) | |
void hexapi | print (vd_printer_t &vp) const |
Print microcode to any destination. | |
void hexapi | verify (bool always) const |
Verify microcode consistency. | |
void hexapi | mark_chains_dirty () |
Mark the microcode use-def chains dirty. | |
const mblock_t * | get_mblock (uint n) const |
Get basic block by its serial number. | |
mblock_t * | get_mblock (uint n) |
mblock_t *hexapi | insert_block (int bblk) |
Insert a block in the middle of the mbl array. | |
mblock_t *hexapi | split_block (mblock_t *blk, minsn_t *start_insn) |
Split a block: insert a new one after the block, move some instructions to new block. | |
bool hexapi | remove_block (mblock_t *blk) |
Delete a block. | |
bool hexapi | remove_blocks (int start_blk, int end_blk) |
mblock_t *hexapi | copy_block (mblock_t *blk, int new_serial, int cpblk_flags=3) |
Make a copy of a block. | |
bool hexapi | remove_empty_and_unreachable_blocks () |
Delete all empty and unreachable blocks. | |
bool hexapi | merge_blocks () |
Merge blocks. | |
int hexapi | for_all_ops (mop_visitor_t &mv) |
Visit all operands of all instructions. | |
int hexapi | for_all_insns (minsn_visitor_t &mv) |
Visit all instructions. | |
int hexapi | for_all_topinsns (minsn_visitor_t &mv) |
Visit all top level instructions. | |
mop_t *hexapi | find_mop (op_parent_info_t *ctx, ea_t ea, bool is_dest, const mlist_t &list) |
Find an operand in the microcode. | |
minsn_t *hexapi | create_helper_call (ea_t ea, const char *helper, const tinfo_t *rettype=nullptr, const mcallargs_t *callargs=nullptr, const mop_t *out=nullptr) |
Create a call of a helper function. | |
void hexapi | get_func_output_lists (mlist_t *return_regs, mlist_t *spoiled, const tinfo_t &type, ea_t call_ea=BADADDR, bool tail_call=false) |
Prepare the lists of registers & memory that are defined/killed by a function. | |
lvar_t &hexapi | arg (int n) |
Get input argument of the decompiled function. | |
const lvar_t & | arg (int n) const |
ea_t hexapi | alloc_fict_ea (ea_t real_ea) |
Allocate a fictional address. | |
ea_t hexapi | map_fict_ea (ea_t fict_ea) const |
Resolve a fictional address. | |
const ivl_t & | get_std_region (memreg_index_t idx) const |
Get information about various memory regions. | |
const ivl_t & | get_lvars_region () const |
const ivl_t & | get_shadow_region () const |
const ivl_t & | get_args_region () const |
ivl_t | get_stack_region () const |
void hexapi | serialize (bytevec_t &vout) const |
Serialize mbl array into a sequence of bytes. | |
void hexapi | save_snapshot (const char *description) |
Create and save microcode snapshot. | |
mreg_t hexapi | alloc_kreg (size_t size, bool check_size=true) |
Allocate a kernel register. | |
void hexapi | free_kreg (mreg_t reg, size_t size) |
Free a kernel register. | |
merror_t hexapi | inline_func (codegen_t &cdg, int blknum, mba_ranges_t &ranges, int decomp_flags=0, int inline_flags=0) |
Inline a range. | |
const stkpnt_t *hexapi | locate_stkpnt (ea_t ea) const |
bool hexapi | set_lvar_name (lvar_t &v, const char *name, int flagbits) |
bool | set_nice_lvar_name (lvar_t &v, const char *name) |
bool | set_user_lvar_name (lvar_t &v, const char *name) |
Static Public Member Functions | |
static vdloc_t hexapi | idaloc2vd (const argloc_t &loc, int width, sval_t spd) |
static argloc_t hexapi | vd2idaloc (const vdloc_t &loc, int width, sval_t spd) |
static WARN_UNUSED_RESULT mba_t *hexapi | deserialize (const uchar *bytes, size_t nbytes) |
Deserialize a byte sequence into mbl array. |
Public Attributes | |
mba_ranges_t | mbr |
ea_t | entry_ea = BADADDR |
ea_t | last_prolog_ea = BADADDR |
ea_t | first_epilog_ea = BADADDR |
int | qty = 0 |
number of basic blocks | |
int | npurged = -1 |
-1 - unknown | |
callcnv_t | cc = CM_CC_UNKNOWN |
calling convention | |
sval_t | tmpstk_size = 0 |
size of the temporary stack part (which dynamically changes with push/pops) | |
sval_t | frsize = 0 |
size of local stkvars range in the stack frame | |
sval_t | frregs = 0 |
size of saved registers range in the stack frame | |
sval_t | fpd = 0 |
frame pointer delta | |
int | pfn_flags = 0 |
copy of func_t::flags | |
int | retsize = 0 |
size of return address in the stack frame | |
int | shadow_args = 0 |
size of shadow argument area | |
sval_t | fullsize = 0 |
Full stack size including incoming args. | |
sval_t | stacksize = 0 |
The maximal size of the function stack including bytes allocated for outgoing call arguments (up to retaddr) | |
sval_t | inargoff = 0 |
offset of the first stack argument; after fix_scattered_movs() INARGOFF may be less than STACKSIZE | |
sval_t | minstkref = 0 |
The lowest stack location whose address was taken. | |
ea_t | minstkref_ea = BADADDR |
address with lowest minstkref (for debugging) | |
sval_t | minargref = 0 |
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 = 0 |
If sp>0, the max positive sp value. | |
ivlset_t | gotoff_stkvars |
stkvars that hold .got offsets. considered to be unaliasable | |
ivlset_t | restricted_memory |
ivlset_t | aliased_memory = ALLMEM |
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 = MMAT_ZERO |
current maturity level | |
mba_maturity_t | reqmat = MMAT_ZERO |
required maturity level | |
bool | final_type = false |
is the function type final? (specified by the user) | |
tinfo_t | idb_type |
function type as retrieved from the database | |
reginfovec_t | idb_spoiled |
MBA_SPLINFO && final_type: info in ida format. | |
mlist_t | spoiled_list |
MBA_SPLINFO && !final_type: info in vd format. | |
int | fti_flags = 0 |
FTI_... constants for the current function. | |
qstring | label |
name of the function or pattern (colored) | |
lvars_t | vars |
local variables | |
intvec_t | argidx |
input arguments (indexes into 'vars') | |
int | retvaridx = -1 |
index of variable holding the return value -1 means none | |
ea_t | error_ea = BADADDR |
during microcode generation holds ins.ea | |
qstring | error_strarg |
mblock_t * | blocks = nullptr |
double linked list of blocks | |
mblock_t ** | natural = nullptr |
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 [] |
const char * | title |
const char va_list va | const |
const char | const |
Array of micro blocks representing microcode for a decompiled function.
The first micro block is the entry point, the last one is the exit point. The entry and exit blocks are always empty. The exit block is generated at MMAT_LOCOPT maturity level.
mba_t::mba_t | ( | ) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
ssize_t mba_t::get_stkvar | ( | udm_t * | udm, |
sval_t | vd_stkoff, | ||
uval_t * | p_idaoff = nullptr, | ||
tinfo_t * | p_frame = nullptr ) const |
|
inline |
|
inline |
|
inline |
|
inline |
mba_t::HEXRAYS_MEMORY_ALLOCATION_FUNCS | ( | ) |
|
inline |
|
inline |
|
inline |
|
inline |
Set maturity level.
mat | new maturity level |
|
inline |
Optimize each basic block locally.
locopt_bits | combination of Bits for optimize_local() bits |
|
inline |
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.
|
inline |
Get control graph.
Call build_graph() if you need the graph before MMAT_LOCOPT.
|
inline |
Analyze calls and determine calling conventions.
acflags | permitted actions that are necessary for successful detection of calling conventions. See Bits for analyze_calls() |
|
inline |
Optimize microcode globally.
This function applies various optimization methods until we reach the fixed point. After that it preallocates lvars unless reqmat forbids it.
|
inline |
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.
|
inline |
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.
mba_t::AS_PRINTF | ( | 3 | , |
0 | ) |
mba_t::AS_PRINTF | ( | 3 | , |
4 | ) |
mba_t::va_end | ( | va | ) |
void hexapi mba_t::print | ( | vd_printer_t & | vp | ) | const |
Print microcode to any destination.
vp | print sink |
Verify microcode consistency.
always | if 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. If the microcode is inconsistent, this function will generate an internal error. We provide the source code of this function in the plugins/hexrays_sdk/verifier directory for your reference. |
void hexapi mba_t::mark_chains_dirty | ( | ) |
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.
|
inline |
Insert a block in the middle of the mbl array.
The very first block of microcode must be empty, it is the entry block. The very last block of microcode must be BLT_STOP, it is the exit block. Therefore inserting a new block before the entry point or after the exit block is not a good idea.
bblk | the new block will be inserted before BBLK |
Split a block: insert a new one after the block, move some instructions to new block.
blk | block to be split |
start_insn | all instructions to be moved to new block: starting with this one up to the end |
Delete a block.
blk | block to delete |
|
inline |
Make a copy of a block.
This function makes a simple copy of the block. It does not fix the predecessor and successor lists, they must be fixed if necessary.
blk | block to copy |
new_serial | position of the copied block |
cpblk_flags | combination of Batch decompilation bits... bits |
|
inline |
Delete all empty and unreachable blocks.
Blocks marked with MBL_KEEP won't be deleted.
|
inline |
Merge blocks.
This function merges blocks constituting linear flow. It calls remove_empty_and_unreachable_blocks() as well.
|
inline |
Visit all operands of all instructions.
mv | operand visitor |
|
inline |
Visit all instructions.
This function visits all instruction and subinstructions.
mv | instruction visitor |
|
inline |
Visit all top level instructions.
mv | instruction visitor |
|
inline |
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.
[out] | ctx | context information for the result |
ea | desired address of the operand. BADADDR means to accept any address. | |
is_dest | search for destination operand? this argument may be ignored if the exact match could not be found | |
list | list of locations the correspond to the operand |
|
inline |
Create a call of a helper function.
ea | The desired address of the instruction |
helper | The helper name |
rettype | The return type (nullptr or empty type means 'void') |
callargs | The helper arguments (nullptr-no arguments) |
out | The operand where the call result should be stored. If this argument is not nullptr, "mov helper_call(), out" will be generated. Otherwise "call helper()" will be generated. Note: the size of this operand must be equal to the RETTYPE size |
|
inline |
Prepare the lists of registers & memory that are defined/killed by a function.
[out] | return_regs | defined regs to return (eax,edx) |
[out] | spoiled | spoiled regs (flags,ecx,mem) |
type | the function type | |
call_ea | the call insn address (if known) | |
tail_call | is it the tail call? |
|
inline |
Get input argument of the decompiled function.
n | argument number (0..nargs-1) |
Allocate a fictional address.
This function can be used to allocate a new unique address for a new instruction, if re-using any existing address leads to conflicts. For example, if the last instruction of the function modifies R0 and falls through to the next function, it will be a tail call: LDM R0!, {R4,R7} end of the function start of another function In this case R0 generates two different lvars at the same address:
Another example: a third-party plugin makes a copy of an instruction. This may lead to the generation of two variables at the same address. Example 3: fictional addresses can be used for new instructions created while modifying the microcode. This function can be used to allocate a new unique address for a new instruction or a variable. The fictional address is selected from an unallocated address range.
real_ea | real instruction address (BADADDR is ok too) |
Resolve a fictional address.
This function provides a reverse of the mapping made by alloc_fict_ea().
fict_ea | fictional definition address |
|
inline |
Get information about various memory regions.
We map the stack frame to the global memory, to some unused range.
|
inline |
Serialize mbl array into a sequence of bytes.
Deserialize a byte sequence into mbl array.
bytes | pointer to the beginning of the byte sequence. |
nbytes | number of bytes in the byte sequence. |
Allocate a kernel register.
size | size of the register in bytes |
check_size | if true, only the sizes that correspond to a size of a basic type will be accepted. |
Free a kernel register.
If wrong arguments are passed, this function will generate an internal error.
reg | a previously allocated kernel register |
size | size of the register in bytes |
|
inline |
Inline a range.
This function may be called only during the initial microcode generation phase.
cdg | the codegenerator object |
blknum | the block contaning the call/jump instruction to inline |
ranges | the set of ranges to inline. in the case of multiple calls to inline_func(), ranges will be compared using their start addresses. if two ranges have the same address, they will be considered the same. |
decomp_flags | combination of decompile() flags bits |
inline_flags | combination of inline_func() flags bits |
mba_ranges_t mba_t::mbr |
ea_t mba_t::entry_ea = BADADDR |
ea_t mba_t::last_prolog_ea = BADADDR |
ea_t mba_t::first_epilog_ea = BADADDR |
int mba_t::qty = 0 |
number of basic blocks
int mba_t::npurged = -1 |
-1 - unknown
callcnv_t mba_t::cc = CM_CC_UNKNOWN |
calling convention
sval_t mba_t::tmpstk_size = 0 |
size of the temporary stack part (which dynamically changes with push/pops)
sval_t mba_t::frsize = 0 |
size of local stkvars range in the stack frame
sval_t mba_t::frregs = 0 |
size of saved registers range in the stack frame
sval_t mba_t::fpd = 0 |
frame pointer delta
int mba_t::pfn_flags = 0 |
copy of func_t::flags
int mba_t::retsize = 0 |
size of return address in the stack frame
int mba_t::shadow_args = 0 |
size of shadow argument area
sval_t mba_t::fullsize = 0 |
Full stack size including incoming args.
sval_t mba_t::stacksize = 0 |
The maximal size of the function stack including bytes allocated for outgoing call arguments (up to retaddr)
sval_t mba_t::inargoff = 0 |
offset of the first stack argument; after fix_scattered_movs() INARGOFF may be less than STACKSIZE
sval_t mba_t::minstkref = 0 |
The lowest stack location whose address was taken.
ea_t mba_t::minstkref_ea = BADADDR |
address with lowest minstkref (for debugging)
sval_t mba_t::minargref = 0 |
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 mba_t::spd_adjust = 0 |
If sp>0, the max positive sp value.
ivlset_t mba_t::gotoff_stkvars |
stkvars that hold .got offsets. considered to be unaliasable
ivlset_t mba_t::restricted_memory |
ivlset_t mba_t::aliased_memory = ALLMEM |
aliased_memory+restricted_memory=ALLMEM
mlist_t mba_t::nodel_memory |
global dead elimination may not delete references to this area
rlist_t mba_t::consumed_argregs |
registers converted into stack arguments, should not be used as arguments
mba_maturity_t mba_t::maturity = MMAT_ZERO |
current maturity level
mba_maturity_t mba_t::reqmat = MMAT_ZERO |
required maturity level
bool mba_t::final_type = false |
is the function type final? (specified by the user)
tinfo_t mba_t::idb_type |
function type as retrieved from the database
reginfovec_t mba_t::idb_spoiled |
MBA_SPLINFO && final_type: info in ida format.
mlist_t mba_t::spoiled_list |
MBA_SPLINFO && !final_type: info in vd format.
int mba_t::fti_flags = 0 |
FTI_... constants for the current function.
qstring mba_t::label |
name of the function or pattern (colored)
lvars_t mba_t::vars |
local variables
intvec_t mba_t::argidx |
input arguments (indexes into 'vars')
int mba_t::retvaridx = -1 |
index of variable holding the return value -1 means none
ea_t mba_t::error_ea = BADADDR |
during microcode generation holds ins.ea
qstring mba_t::error_strarg |
mblock_t* mba_t::blocks = nullptr |
double linked list of blocks
mblock_t** mba_t::natural = nullptr |
natural order of blocks
ivl_with_name_t mba_t::std_ivls[6] |
we treat memory as consisting of 6 parts see memreg_index_t
|
mutable |
|
mutable |
char mba_t::reserved[] |
const char * mba_t::title |
const char va_list va mba_t::const |
const char mba_t::const |