-
Notifications
You must be signed in to change notification settings - Fork 29
/
idaplugin.h
357 lines (322 loc) · 8.78 KB
/
idaplugin.h
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/**
* @file idaplugin/idaplugin.h
* @brief Main idaplugin header.
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/
#ifndef IDAPLUGIN_IDAPLUGIN_H
#define IDAPLUGIN_IDAPLUGIN_H
#include "defs.h"
namespace idaplugin {
class GhidraDec
#if IDA_SDK_VERSION >= 750
: public plugmod_t, public event_listener_t
#endif
{
public:
GhidraDec();
virtual ~GhidraDec();
bool canDecompileInput();
void runSelectiveDecompilation(func_t* fnc2decomp = nullptr, bool force = false);
/**
* General info used by plugin.
*/
RdGlobalInfo* decompInfo;
ea_t globalAddress = 0;
void killDecompilation(bool bTerminate);
void saveIdaDatabase(bool inSitu = false, const std::string& suffix = ".dec-backup");
void generatePluginDatabase();
bool isRelocatable();
void runAllDecompilation();
bool setInputPath();
#if IDA_SDK_VERSION < 750
static
#endif
#ifdef __X64__
bool idaapi run(size_t arg);
#else
void idaapi run(int arg);
#endif
#if IDA_SDK_VERSION >= 750
ssize_t idaapi on_event(ssize_t notification_code, va_list va);
#else
static ssize_t idaapi view_callback(void* ud, int notification_code, va_list va);
#endif
int idaapi init();
void idaapi term();
bool isWordGlobal(const std::string& word, int color);
const retdec::config::Object* getWordGlobal(const std::string& word, int color);
bool isWordFunction(const std::string& word, int color);
const retdec::config::Function* getWordFunction(
const std::string& word,
int color);
func_t* getIdaFunction(const std::string& word, int color);
bool isCurrentFunction(func_t* fnc);
func_t* getCurrentFunction();
bool isWordCurrentParameter(const std::string& word, int color);
void decompileFunction(
TWidget* cv,
const std::string& calledFnc,
bool force = false,
bool forceDec = false);
bool idaapi moveToPrevious();
struct move_backward_ah_t : public action_handler_t
{
move_backward_ah_t(GhidraDec* pm = nullptr) : action_handler_t() {
this->pm = pm;
}
GhidraDec* pm;
static const char* actionName;
static const char* actionLabel;
static const char* actionHotkey;
virtual int idaapi activate(action_activation_ctx_t*)
{
pm->moveToPrevious();
return false;
}
virtual action_state_t idaapi update(action_update_ctx_t*)
{
return AST_ENABLE_ALWAYS;
}
};
move_backward_ah_t move_backward_ah = move_backward_ah_t(this);
const action_desc_t move_backward_ah_desc = ACTION_DESC_LITERAL_PLUGMOD(
move_backward_ah_t::actionName,
move_backward_ah_t::actionLabel,
&move_backward_ah,
this,
nullptr,
move_backward_ah_t::actionHotkey,
-1);
bool idaapi moveToNext();
struct move_forward_ah_t : public action_handler_t
{
move_forward_ah_t(GhidraDec* pm = nullptr) : action_handler_t() {
this->pm = pm;
}
GhidraDec* pm;
static const char* actionName;
static const char* actionLabel;
static const char* actionHotkey;
virtual int idaapi activate(action_activation_ctx_t*)
{
pm->moveToNext();
return false;
}
virtual action_state_t idaapi update(action_update_ctx_t*)
{
return AST_ENABLE_ALWAYS;
}
};
move_forward_ah_t move_forward_ah;
const action_desc_t move_forward_ah_desc = ACTION_DESC_LITERAL_PLUGMOD(
move_forward_ah_t::actionName,
move_forward_ah_t::actionLabel,
&move_forward_ah,
this,
nullptr,
move_forward_ah_t::actionHotkey,
-1);
bool idaapi insertCurrentFunctionComment();
struct change_fnc_comment_ah_t : public action_handler_t
{
change_fnc_comment_ah_t(GhidraDec* pm = nullptr) : action_handler_t() {
this->pm = pm;
}
GhidraDec* pm;
static const char* actionName;
static const char* actionLabel;
static const char* actionHotkey;
virtual int idaapi activate(action_activation_ctx_t*)
{
pm->insertCurrentFunctionComment();
return false;
}
virtual action_state_t idaapi update(action_update_ctx_t*)
{
return AST_ENABLE_ALWAYS;
}
};
change_fnc_comment_ah_t change_fnc_comment_ah;
const action_desc_t change_fnc_comment_ah_desc = ACTION_DESC_LITERAL_PLUGMOD(
change_fnc_comment_ah_t::actionName,
change_fnc_comment_ah_t::actionLabel,
&change_fnc_comment_ah,
this,
nullptr,
change_fnc_comment_ah_t::actionHotkey,
-1);
bool idaapi changeFunctionGlobalName(TWidget* cv);
struct change_fnc_global_name_ah_t : public action_handler_t
{
change_fnc_global_name_ah_t(GhidraDec* pm = nullptr) : action_handler_t() {
this->pm = pm;
}
GhidraDec* pm;
TWidget* view = nullptr;
static const char* actionName;
static const char* actionLabel;
static const char* actionHotkey;
virtual int idaapi activate(action_activation_ctx_t*)
{
pm->changeFunctionGlobalName(view);
return false;
}
virtual action_state_t idaapi update(action_update_ctx_t*)
{
return AST_ENABLE_ALWAYS;
}
void setView(TWidget* v)
{
view = v;
}
};
bool idaapi openXrefsWindow(func_t* fnc);
change_fnc_global_name_ah_t change_fnc_global_name_ah;
const action_desc_t change_fnc_global_name_ah_desc = ACTION_DESC_LITERAL_PLUGMOD(
change_fnc_global_name_ah_t::actionName,
change_fnc_global_name_ah_t::actionLabel,
&change_fnc_global_name_ah,
this,
nullptr,
change_fnc_global_name_ah_t::actionHotkey,
-1);
struct open_xrefs_ah_t : public action_handler_t
{
open_xrefs_ah_t(GhidraDec* pm = nullptr) : action_handler_t() {
this->pm = pm;
}
GhidraDec* pm;
func_t* fnc = nullptr;
static const char* actionName;
static const char* actionLabel;
static const char* actionHotkey;
virtual int idaapi activate(action_activation_ctx_t*)
{
pm->openXrefsWindow(fnc);
return false;
}
virtual action_state_t idaapi update(action_update_ctx_t*)
{
return AST_ENABLE_ALWAYS;
}
void setFunction(func_t* f)
{
fnc = f;
}
};
bool idaapi openCallsWindow(func_t* fnc);
open_xrefs_ah_t open_xrefs_ah;
const action_desc_t open_xrefs_ah_desc = ACTION_DESC_LITERAL_PLUGMOD(
open_xrefs_ah_t::actionName,
open_xrefs_ah_t::actionLabel,
&open_xrefs_ah,
this,
nullptr,
open_xrefs_ah_t::actionHotkey,
-1);
struct open_calls_ah_t : public action_handler_t
{
open_calls_ah_t(GhidraDec* pm = nullptr) : action_handler_t() {
this->pm = pm;
}
GhidraDec* pm;
func_t* fnc = nullptr;
static const char* actionName;
static const char* actionLabel;
static const char* actionHotkey;
virtual int idaapi activate(action_activation_ctx_t*)
{
pm->openCallsWindow(fnc);
return false;
}
virtual action_state_t idaapi update(action_update_ctx_t*)
{
return AST_ENABLE_ALWAYS;
}
void setFunction(func_t* f)
{
fnc = f;
}
};
open_calls_ah_t open_calls_ah;
const action_desc_t open_calls_ah_desc = ACTION_DESC_LITERAL_PLUGMOD(
open_calls_ah_t::actionName,
open_calls_ah_t::actionLabel,
&open_calls_ah,
this,
nullptr,
open_calls_ah_t::actionHotkey,
-1);
bool idaapi changeTypeDeclaration(TWidget* cv);
struct change_fnc_type_ah_t : public action_handler_t
{
change_fnc_type_ah_t(GhidraDec* pm = nullptr) : action_handler_t() {
this->pm = pm;
}
GhidraDec* pm;
TWidget* view = nullptr;
static const char* actionName;
static const char* actionLabel;
static const char* actionHotkey;
virtual int idaapi activate(action_activation_ctx_t*)
{
pm->changeTypeDeclaration(view);
return false;
}
virtual action_state_t idaapi update(action_update_ctx_t*)
{
return AST_ENABLE_ALWAYS;
}
void setView(TWidget* v)
{
view = v;
}
};
bool idaapi jumpToASM(ea_t ea);
change_fnc_type_ah_t change_fnc_type_ah;
const action_desc_t change_fnc_type_ah_desc = ACTION_DESC_LITERAL_PLUGMOD(
change_fnc_type_ah_t::actionName,
change_fnc_type_ah_t::actionLabel,
&change_fnc_type_ah,
this,
nullptr,
change_fnc_type_ah_t::actionHotkey,
-1);
struct jump_to_asm_ah_t : public action_handler_t
{
jump_to_asm_ah_t(GhidraDec* pm = nullptr) : action_handler_t() {
this->pm = pm;
}
GhidraDec* pm;
ea_t addr;
static const char* actionName;
static const char* actionLabel;
static const char* actionHotkey;
virtual int idaapi activate(action_activation_ctx_t*)
{
pm->jumpToASM(addr);
return false;
}
virtual action_state_t idaapi update(action_update_ctx_t*)
{
return AST_ENABLE_ALWAYS;
}
void setAddress(ea_t a)
{
addr = a;
}
};
jump_to_asm_ah_t jump_to_asm_ah;
const action_desc_t jump_to_asm_ah_desc = ACTION_DESC_LITERAL_PLUGMOD(
jump_to_asm_ah_t::actionName,
jump_to_asm_ah_t::actionLabel,
&jump_to_asm_ah,
this,
nullptr,
jump_to_asm_ah_t::actionHotkey,
-1);
static ssize_t idaapi ui_callback(void* ud, int notification_code, va_list va);
void registerPermanentActions();
};
} // namespace idaplugin
#endif