forked from yegord/snowman
-
Notifications
You must be signed in to change notification settings - Fork 15
/
IdaPlugin.cpp
131 lines (106 loc) · 4.23 KB
/
IdaPlugin.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
127
128
129
130
131
/* The file is part of Snowman decompiler. */
/* See doc/licenses.asciidoc for the licensing information. */
//
// SmartDec decompiler - SmartDec is a native code to C/C++ decompiler
// Copyright (C) 2015 Alexander Chernov, Katerina Troshina, Yegor Derevenets,
// Alexander Fokin, Sergey Levin, Leonid Tsvetkov
//
// This file is part of SmartDec decompiler.
//
// SmartDec decompiler is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// SmartDec decompiler is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SmartDec decompiler. If not, see <http://www.gnu.org/licenses/>.
//
#include "IdaPlugin.h"
#include <cassert>
#include <memory> /* std::unique_ptr */
#include <vector>
#include <nc/common/Foreach.h>
#include "IdaWorkaroundStart.h"
#include <ida.hpp>
#include <bytes.hpp>
#include <auto.hpp>
#include <ua.hpp>
#include <idp.hpp> /* For IDP_INTERFACE_VERSION. */
#include <loader.hpp> /* For PLUGIN_KEEP. */
#include "IdaWorkaroundEnd.h"
namespace nc { namespace ida { namespace detail {
namespace {
struct IdaPluginStorage {
std::vector<IdaPluginRegistrator::PluginFactory> pluginFactories;
std::vector<std::unique_ptr<IdaPlugin>> plugins;
};
IdaPluginStorage *storage = NULL;
} // namespace `anonymous-namespace`
bool IdaPluginRegistrator::registerPlugin(const PluginFactory &pluginFactory) {
assert(!pluginFactory.empty());
if(storage == NULL)
storage = new IdaPluginStorage(); /* No locking since it will be called at application startup time. */
storage->pluginFactories.push_back(pluginFactory);
return true;
}
namespace {
// -------------------------------------------------------------------------- //
// Plugin interface
// -------------------------------------------------------------------------- //
char name[] = "Snowman";
char help[] = "";
char hotkey[] = "";
char comment[] = "";
int idaapi init() {
/* Documentation says:
*
* Do checks here to ensure your plug-in is being used within
* an environment it was written for. Return PLUGIN_SKIP if the
* checks fail, otherwise return PLUGIN_KEEP. */
foreach (const IdaPluginRegistrator::PluginFactory &pluginFactory, storage->pluginFactories)
storage->plugins.push_back(std::unique_ptr<IdaPlugin>(pluginFactory()));
return PLUGIN_KEEP;
}
void idaapi run(int /*arg*/) {
/* Documentation says:
*
* The plugin can be passed an integer argument from the plugins.cfg
* file. This can be useful when you want the one plug-in to do
* something different depending on the hot-key pressed or menu
* item selected. */
foreach (auto &plugin, storage->plugins) {
(*plugin)();
}
}
void idaapi terminate() {
/* Documentation says:
*
* Stuff to do when exiting, generally you'd put any sort
* of clean-up jobs here. */
/* Perform destruction in the reverse order. */
while (!storage->plugins.empty()) {
storage->plugins.pop_back();
}
}
} // namespace `anonymous-namespace`
}}} // namespace nc::ida::detail
#ifdef Q_OS_WIN
__declspec(dllexport)
#endif
plugin_t PLUGIN = {
IDP_INTERFACE_VERSION, /**< IDA version plug-in is written for. */
0, /**< Flags. */
nc::ida::detail::init, /**< Initialization function. */
nc::ida::detail::terminate, /**< Clean-up function. */
nc::ida::detail::run, /**< Main plug-in body. */
nc::ida::detail::comment, /**< Comment. */
nc::ida::detail::help, /**< Help multi-line string. */
nc::ida::detail::name, /**< Plug-in name shown in Edit->Plugins menu. */
nc::ida::detail::hotkey /**< Hot key to run the plug-in */
};
/* vim:set et sts=4 sw=4: */