-
Notifications
You must be signed in to change notification settings - Fork 13
/
util.cpp
126 lines (105 loc) · 2.87 KB
/
util.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "util.h"
#include <kernwin.hpp>
#include <prodir.h>
/*--------------------------------------------------------------------------
History
--------
10/23/2013 - eliasb - First version, it comes from refactored
code from the plugin module
10/25/2013 - eliasb - Added jump_to_node()
10/30/2013 - eliasb - moved str2asizet() and skip_spaces() from other modules
10/31/2013 - eliasb - added 'is_ida_gui()'
--------------------------------------------------------------------------*/
//--------------------------------------------------------------------------
char *skip_spaces(char *p)
{
return skipSpaces(p);
}
//--------------------------------------------------------------------------
asize_t str2asizet(const char *str)
{
ea_t v;
qsscanf(str, "%a", &v);
return (asize_t)v;
}
//--------------------------------------------------------------------------
const char *get_screen_function_fn(const char *ext)
{
func_t *fnc = get_func(get_screen_ea());
if (fnc == NULL)
return NULL;
static char buf[QMAXPATH] = { 0 };
// Copy database path global var
set_file_ext(buf, qnumber(buf), database_idb, "");
size_t t = qstrlen(buf);
if (t > 0 && buf[t - 1] == '.')
buf[t - 1] = '\0';
// format as: dir/file/func->startEA . ext
static qstring s;
s = buf;
s.cat_sprnt("-%08a.%s", fnc->startEA, ext);
return s.c_str();
}
//--------------------------------------------------------------------------
/**
* @brief Get the disassembly text into a qstring
*/
void get_disasm_text(
ea_t start,
ea_t end,
qstring *out)
{
// Generate disassembly text
text_t txt;
gen_disasm_text(
start,
end,
txt,
false);
// Append all disasm lines
for (text_t::iterator it=txt.begin(); it != txt.end(); ++it)
{
out->append(it->line);
out->append("\n");
}
}
//--------------------------------------------------------------------------
/**
* @brief Build a function flowchart
*/
bool get_func_flowchart(
ea_t ea,
qflow_chart_t &qf)
{
func_t *f = get_func(ea);
if (f == NULL)
return false;
qstring s;
s.sprnt("$ flowchart of %a()", f->startEA);
qf.create(
s.c_str(),
f,
BADADDR,
BADADDR,
FC_PREDS);
return true;
}
//--------------------------------------------------------------------------
void jump_to_node(graph_viewer_t *gv, int nid)
{
viewer_center_on(gv, nid);
int x, y;
// will return a place only when a node was previously selected
place_t *old_pl = get_custom_viewer_place(gv, false, &x, &y);
if (old_pl == NULL)
return;
user_graph_place_t *new_pl = (user_graph_place_t *) old_pl->clone();
new_pl->node = nid;
jumpto(gv, new_pl, x, y);
delete new_pl;
}
//--------------------------------------------------------------------------
bool is_ida_gui()
{
return callui(ui_get_hwnd).vptr != NULL || is_idaq();
}