forked from fjqisba/E-Decompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.h
71 lines (66 loc) · 1.8 KB
/
plugin.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
#pragma once
#include <idp.hpp>
#include "GhidraDecompiler.h"
#include "common\public.h"
class Plugin;
struct ActHandler_EmitGhidraPCode :public action_handler_t
{
public:
static qstring ActHandler_EmitGhidraPCode::actionName;
static qstring ActHandler_EmitGhidraPCode::actionLabel;
ActHandler_EmitGhidraPCode(GhidraDecompiler* d)
{
actionName = "E-Decompiler:GeneratePCode";
actionLabel = getUTF8String("Éú³ÉGhidra P-code");
decompiler = d;
}
int idaapi activate(action_activation_ctx_t* ctx)
{
if (!decompiler || !decompiler->m_architecture) {
return 1;
}
TWidget* currentViewer = get_current_viewer();
if (!currentViewer) {
return 1;
}
ea_t StartEA = 0;
ea_t EndEA;
std::string result;
if (!read_range_selection(currentViewer, &StartEA, &EndEA)) {
StartEA = get_screen_ea();
result = decompiler->GetPcode(StartEA, StartEA + 1);
}
else {
result = decompiler->GetPcode(StartEA, EndEA);
}
msg(result.c_str());
return 1;
}
action_state_t idaapi update(action_update_ctx_t* ctx)
{
return AST_ENABLE_ALWAYS;
}
private:
GhidraDecompiler* decompiler;
};
class Plugin :public plugmod_t
{
public:
explicit Plugin(std::unique_ptr<GhidraDecompiler> decompiler);
~Plugin();
void view(const std::string& name, const DecompilerResult& code) const;
protected:
virtual bool idaapi run(size_t) override;
private:
std::unique_ptr<GhidraDecompiler> m_decompiler;
ActHandler_EmitGhidraPCode actHandler_EmitGhidraPCode = ActHandler_EmitGhidraPCode(m_decompiler.get());
const action_desc_t act_emitGhidraPCode_desc = ACTION_DESC_LITERAL_PLUGMOD(
ActHandler_EmitGhidraPCode::actionName.c_str(),
ActHandler_EmitGhidraPCode::actionLabel.c_str(),
&actHandler_EmitGhidraPCode,
this,
nullptr,
nullptr,
-1
);
};