vds_hooks

summary: react to decompiler events/notifications

description:

Shows how to hook to many notifications sent by the decompiler.

This plugin doesn’t really accomplish anything: it just prints the parameters.

The list of notifications handled below should be exhaustive, and is there to hint at what is possible to accomplish by subclassing ida_hexrays.Hexrays_Hooks

see_also: curpos_details

level: intermediate

Attributes

vds_hooks

Classes

vds_hooks_t

Module Contents

class vds_hooks.vds_hooks_t

Bases: ida_hexrays.Hexrays_Hooks

display_shortened_cfuncs = False
display_vdui_curpos = False
inhibit_log = 0
flowchart(fc, mba, reachable_blocks, decomp_flags)

Flowchart has been generated.

Parameters:
  • fc – (qflow_chart_t *)

  • mba – (mba_t *)

  • reachable_blocks – (bitset_t *)

  • decomp_flags – (int)

Returns:

Microcode error code

stkpnts(mba, stkpnts)

SP change points have been calculated.

Parameters:

mba – (mba_t *)

Returns:

Microcode error code This event is generated for each inlined range as well.

prolog(mba, fc, reachable_blocks, decomp_flags)

Prolog analysis has been finished.

Parameters:
  • mba – (mba_t *)

  • fc – (qflow_chart_t *)

  • reachable_blocks – (const bitset_t *)

  • decomp_flags – (int)

Returns:

Microcode error code This event is generated for each inlined range as well.

mba_maturity(mba, reqmat)

Maturity level of an MBA was changed.

Parameters:
  • mba – (mba_t *)

  • reqmat – (mba_maturity_t) requested maturity level

Returns:

Microcode error code

microcode(mba)

Microcode has been generated.

Parameters:

mba – (mba_t *)

Returns:

Microcode error code

preoptimized(mba)

Microcode has been preoptimized.

Parameters:

mba – (mba_t *)

Returns:

Microcode error code

locopt(mba)

Basic block level optimization has been finished.

Parameters:

mba – (mba_t *)

Returns:

Microcode error code

prealloc(mba)

Local variables: preallocation step begins.

Parameters:

mba – (mba_t *) This event may occur several times. Should return: 1 if modified microcode Negative values are Microcode error code

glbopt(mba)

Global optimization has been finished. If microcode is modified, MERR_LOOP must be returned. It will cause a complete restart of the optimization.

Parameters:

mba – (mba_t *)

Returns:

Microcode error code

begin_structural(out, cfunc, ctrl_graph)
structural(ctrl_graph)

Structural analysis has been finished.

Parameters:

ct – (control_graph_t *)

maturity(cfunc, maturity)

Ctree maturity level is being changed.

Parameters:
  • cfunc – (cfunc_t *)

  • new_maturity – (ctree_maturity_t)

interr(code)

Internal error has occurred.

Parameters:

errcode – (int )

combine(blk, insn)

Trying to combine instructions of basic block.

Parameters:
  • blk – (mblock_t *)

  • insn – (minsn_t *) Should return: 1 if combined the current instruction with a preceding one -1 if the instruction should not be combined 0 else

print_func(cfunc, printer)

Printing ctree and generating text.

Parameters:
  • cfunc – (cfunc_t *)

  • vp – (vc_printer_t *) Returns: 1 if text has been generated by the plugin It is forbidden to modify ctree at this event.

func_printed(cfunc)

Function text has been generated. Plugins may modify the text in cfunc_t::sv. However, it is too late to modify the ctree or microcode. The text uses regular color codes (see lines.hpp) COLOR_ADDR is used to store pointers to ctree items.

Parameters:

cfunc – (cfunc_t *)

resolve_stkaddrs(mba)

The optimizer is about to resolve stack addresses.

Parameters:

mba – (mba_t *)

open_pseudocode(vu)

New pseudocode view has been opened.

Parameters:

vu – (vdui_t *)

switch_pseudocode(vu)

Existing pseudocode view has been reloaded with a new function. Its text has not been refreshed yet, only cfunc and mba pointers are ready.

Parameters:

vu – (vdui_t *)

refresh_pseudocode(vu)

Existing pseudocode text has been refreshed. Adding/removing pseudocode lines is forbidden in this event.

Parameters:

vu – (vdui_t *) See also hxe_text_ready, which happens earlier

close_pseudocode(vu)

Pseudocode view is being closed.

Parameters:

vu – (vdui_t *)

keyboard(vu, key_code, shift_state)

Keyboard has been hit.

Parameters:
  • vu – (vdui_t *)

  • key_code – (int) VK_

  • shift_state – (int) Should return: 1 if the event has been handled

right_click(vu)

Mouse right click. Use hxe_populating_popup instead, in case you want to add items in the popup menu.

Parameters:

vu – (vdui_t *)

double_click(vu, shift_state)

Mouse double click.

Parameters:
  • vu – (vdui_t *)

  • shift_state – (int) Should return: 1 if the event has been handled

curpos(vu)

Current cursor position has been changed. (for example, by left-clicking or using keyboard)

Parameters:

vu – (vdui_t *)

create_hint(vu)

Create a hint for the current item.

Parameters:

vu – (vdui_t *)

Returns:

0: continue collecting hints with other subscribers

Returns:

1: stop collecting hints

text_ready(vu)

Decompiled text is ready.

Parameters:

vu – (vdui_t *) This event can be used to modify the output text (sv). Obsolete. Please use hxe_func_printed instead.

populating_popup(widget, popup, vu)

Populating popup menu. We can add menu items now.

Parameters:
  • widget – (TWidget *)

  • popup_handle – (TPopupMenu *)

  • vu – (vdui_t *)

lvar_name_changed(vu, v, name, is_user_name)

Local variable got renamed.

Parameters:
  • vu – (vdui_t *)

  • v – (lvar_t *)

  • name – (const char *)

  • is_user_name – (bool) Please note that it is possible to read/write user settings for lvars directly from the idb.

lvar_type_changed(vu, v, tif)

Local variable type got changed.

Parameters:
  • vu – (vdui_t *)

  • v – (lvar_t *)

  • tinfo – (const tinfo_t *) Please note that it is possible to read/write user settings for lvars directly from the idb.

lvar_cmt_changed(vu, v, cmt)

Local variable comment got changed.

Parameters:
  • vu – (vdui_t *)

  • v – (lvar_t *)

  • cmt – (const char *) Please note that it is possible to read/write user settings for lvars directly from the idb.

lvar_mapping_changed(vu, _from, to)

Local variable mapping got changed.

Parameters:
  • vu – (vdui_t *)

  • to – (lvar_t *) Please note that it is possible to read/write user settings for lvars directly from the idb.

cmt_changed(cfunc, loc, cmt)

Comment got changed.

Parameters:
  • cfunc – (cfunc_t *)

  • loc – (const treeloc_t *)

  • cmt – (const char *)

build_callinfo(blk, type)

Analyzing a call instruction.

Parameters:
  • blk – (mblock_t *) blk->tail is the call.

  • type – (tinfo_t *) buffer for the output type.

callinfo_built(blk)

A call instruction has been anallyzed.

Parameters:

blk – (mblock_t *) blk->tail is the call.

calls_done(mba)

All calls have been analyzed.

Parameters:

mba – (mba_t *) This event is generated immediately after analyzing all calls, before any optimizitions, call unmerging and block merging.

begin_inlining(cdg, flags)

Starting to inline outlined functions.

Parameters:
  • cdg – (codegen_t *)

  • decomp_flags – (int)

Returns:

Microcode error code This is an opportunity to inline other ranges.

inlining_func(cdg, blk, mbr)

A set of ranges is going to be inlined.

Parameters:
  • cdg – (codegen_t *)

  • blk – (int) the block containing call/jump to inline

  • mbr – (mba_ranges_t *) the range to inline

inlined_func(cdg, blk, mbr, i1, i2)

A set of ranges got inlined.

Parameters:
  • cdg – (codegen_t *)

  • blk – (int) the block containing call/jump to inline

  • mbr – (mba_ranges_t *) the range to inline

  • i1 – (int) blknum of the first inlined block

  • i2 – (int) blknum of the last inlined block (excluded)

pre_structural(ctrl_graph, cfunc, cfg)

Structure analysis is starting.

Parameters:
  • ct – (control_graph_t *) in/out: control graph

  • cfunc – (cfunc_t *) in: the current function

  • g – (const simple_graph_t *) in: control flow graph

Returns:

Microcode error code; MERR_BLOCK means that the analysis has been performed by a plugin

collect_warnings(cfunc)

Collect warning messages from plugins. These warnings will be displayed at the function header, after the user-defined comments.

Parameters:

cfunc – (cfunc_t *)

vds_hooks.vds_hooks