Skip to content

Commit

Permalink
v1.5 [H2HC Edition]
Browse files Browse the repository at this point in the history
Better Type Reconstruction:
- Improvements for parsing citem_t objects with PTR and ASG statements
- Recursive traversal of Ctree to reconstruct Types hierarchy

Navigate from Pseudocode window to Disassembly line

Hints for Ctree elements which point to Disassembly line

Some bug fixes by user requests
  • Loading branch information
matrosov committed Nov 10, 2014
1 parent a4808b6 commit d9c1c44
Show file tree
Hide file tree
Showing 18 changed files with 303 additions and 746 deletions.
Binary file not shown.
Binary file removed src/HexRaysCodeXplorer.suo
Binary file not shown.
Binary file added src/HexRaysCodeXplorer.v12.suo
Binary file not shown.
104 changes: 95 additions & 9 deletions src/HexRaysCodeXplorer/CodeXplorer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2013
/* Copyright (c) 2014
REhints <info@rehints.com>
All rights reserved.
Expand Down Expand Up @@ -45,6 +45,9 @@ static ushort hotcode_ce;
static const char hotkey_rt[] = "R";
static ushort hotcode_rt;

static const char hotkey_gd[] = "D";
static ushort hotcode_gd;



//--------------------------------------------------------------------------
Expand Down Expand Up @@ -116,7 +119,7 @@ static int idaapi gr_callback(void *ud, int code, va_list va)
switch ( code )
{
// refresh user-defined graph nodes and edges
case grcode_user_refresh:
case grcode_user_refresh:
// in: mutable_graph_t *g
// out: success
{
Expand All @@ -126,7 +129,6 @@ static int idaapi gr_callback(void *ud, int code, va_list va)
break;

graph_builder_t gb(*fg); // Graph builder helper class
//fg->walk_func(f);
gb.apply_to(&gi->vu->cfunc->body, NULL);

mutable_graph_t *mg = va_arg(va, mutable_graph_t *);
Expand Down Expand Up @@ -172,6 +174,39 @@ static int idaapi gr_callback(void *ud, int code, va_list va)
}
}
break;

case grcode_user_hint:
{
DECLARE_GI_VARS;
va_arg(va, mutable_graph_t *);
int mousenode = va_argi(va, int);
int to = va_argi(va, int);
int from = va_argi(va, int);
char **hint = va_arg(va, char **);

callgraph_t::nodeinfo_t *ni = fg->get_info(mousenode);
result = ni != NULL;
if (result && ni->ea != 0xFFFFFFFF)
{
qstring s = get_text_disasm(ni->ea);
*hint = qstrdup(s.c_str());
}
}
break;

case grcode_dblclicked:
{
DECLARE_GI_VARS;
graph_viewer_t *v = va_arg(va, graph_viewer_t *);
selection_item_t *s = va_arg(va, selection_item_t *);

callgraph_t::nodeinfo_t *ni = fg->get_info(s->node);
result = ni != NULL;
if (result && s->is_node && ni->ea != 0xFFFFFFFF)
jumpto(ni->ea);
}
break;

}
return (int)result;
}
Expand All @@ -184,7 +219,6 @@ static bool idaapi display_graph(void *ud)
// Determine the ctree item to highlight
vu.get_current_item(USE_KEYBOARD);
citem_t *highlight = vu.item.is_citem() ? vu.item.e : NULL;

graph_info_t *gi = graph_info_t::create(vu.cfunc->entry_ea, highlight);

netnode id;
Expand All @@ -194,16 +228,23 @@ static bool idaapi display_graph(void *ud)

HWND hwnd = NULL;
TForm *form = create_tform(title.c_str(), &hwnd);
if (hwnd == NULL)
{
warning("Ctree Graph window already open. Switching to it.");
form = find_tform(title.c_str());
if (form != NULL)
switchto_tform(form, true);
return true;
}

if (hwnd != NULL)
{
gi->vu = (vdui_t *)ud;
gi->form = form;
gi->gv = create_graph_viewer(form, id, gr_callback, gi, 0);
open_tform(form, FORM_TAB | FORM_MENU | FORM_QWIDGET);

if (gi->gv != NULL)
viewer_fit_window(gi->gv);

viewer_fit_window(gi->gv);
}

return true;
Expand Down Expand Up @@ -238,6 +279,7 @@ func_t * get_func_by_name(const char *func_name)
return result_func;
}


static bool idaapi decompile_func(vdui_t &vu)
{
// Determine the ctree item to highlight
Expand Down Expand Up @@ -273,7 +315,49 @@ static bool idaapi decompile_func(vdui_t &vu)
return true;
}

//display Object Explorer

// extract ctree custom view
static bool idaapi ctree_into_custom_view(void *ud) // TODO
{
vdui_t &vu = *(vdui_t *)ud;


vu.get_current_item(USE_KEYBOARD);
citem_t *highlight = vu.item.is_citem() ? vu.item.e : NULL;

if (highlight != NULL)
{
// if it is an expression
if (highlight->is_expr())
{
cexpr_t *e = (cexpr_t *)highlight;

// retrieve the name of the routine
char tmp[1024];
memset(tmp, 0x00, sizeof(tmp));
e->print1(tmp, sizeof(tmp), NULL);
tag_remove(tmp, tmp, sizeof(tmp));
}
}

return true;
}


// show disassembly line for ctree->item
static bool idaapi decompiled_line_to_disasm(void *ud)
{
vdui_t &vu = *(vdui_t *)ud;
vu.ctree_to_disasm();

vu.get_current_item(USE_KEYBOARD);
citem_t *highlight = vu.item.is_citem() ? vu.item.e : NULL;

return true;
}


// display Object Explorer
static bool idaapi display_objects(void *ud)
{
vdui_t &vu = *(vdui_t *)ud;
Expand All @@ -296,6 +380,7 @@ static int idaapi callback(void *, hexrays_event_t event, va_list va)
add_custom_viewer_popup_item(vu.ct, "Display Graph", hotkey_dg, display_graph, &vu);
add_custom_viewer_popup_item(vu.ct, "Object Explorer", hotkey_ce, display_objects, &vu);
add_custom_viewer_popup_item(vu.ct, "REconstruct Type", hotkey_rt, reconstruct_type, &vu);
add_custom_viewer_popup_item(vu.ct, "Goto Disasm", hotkey_gd, decompiled_line_to_disasm, &vu);
}
break;

Expand All @@ -307,12 +392,13 @@ static int idaapi callback(void *, hexrays_event_t event, va_list va)
// check for the hotkey
if ( lookup_key_code(keycode, shift, true) == hotcode_dg && shift == 0 )
return display_graph(&vu);
if ( lookup_key_code(keycode, shift, true) == hotcode_dg && shift == 0 )
if ( lookup_key_code(keycode, shift, true) == hotcode_ce && shift == 0 )
return display_objects(&vu);
if ( lookup_key_code(keycode, shift, true) == hotcode_rt && shift == 0 )
return reconstruct_type(&vu);
}
break;

case hxe_double_click:
{
vdui_t &vu = *va_arg(va, vdui_t *);
Expand Down
2 changes: 1 addition & 1 deletion src/HexRaysCodeXplorer/Common.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2013
/* Copyright (c) 2014
REhints <info@rehints.com>
All rights reserved.
Expand Down
Loading

0 comments on commit d9c1c44

Please sign in to comment.