-
Notifications
You must be signed in to change notification settings - Fork 133
/
main.cpp
113 lines (99 loc) · 2.88 KB
/
main.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
/*
* Hex-Rays Decompiler project
* Copyright (c) 2007-2018 by Hex-Rays, support@hex-rays.com
* ALL RIGHTS RESERVED.
*
* Sample plugin for Hex-Rays Decompiler.
* It generates microcode for selection and dumps it to the output window.
*/
#include <set>
#define USE_DANGEROUS_FUNCTIONS
#include <hexrays.hpp>
#include "HexRaysUtil.hpp"
#include "MicrocodeExplorer.hpp"
#include "PatternDeobfuscate.hpp"
#include "AllocaFixer.hpp"
#include "Unflattener.hpp"
#include "Config.hpp"
extern plugin_t PLUGIN;
// Hex-Rays API pointer
hexdsp_t *hexdsp = NULL;
ObfCompilerOptimizer hook;
CFUnflattener cfu;
//--------------------------------------------------------------------------
int idaapi init(void)
{
if (!init_hexrays_plugin())
return PLUGIN_SKIP; // no decompiler
const char *hxver = get_hexrays_version();
msg("Hex-rays version %s has been detected, %s ready to use\n", hxver, PLUGIN.wanted_name);
// Install our block and instruction optimization classes.
#if DO_OPTIMIZATION
install_optinsn_handler(&hook);
install_optblock_handler(&cfu);
#endif
return PLUGIN_KEEP;
}
//--------------------------------------------------------------------------
void idaapi term(void)
{
if (hexdsp != NULL)
{
// Uninstall our block and instruction optimization classes.
#if DO_OPTIMIZATION
remove_optinsn_handler(&hook);
remove_optblock_handler(&cfu);
// I couldn't figure out why, but my plugin would segfault if it tried
// to free mop_t pointers that it had allocated. Maybe hexdsp had been
// set to NULL at that point, so the calls to delete crashed? Anyway,
// cleaning up before we unload solved the issues.
cfu.Clear(true);
#endif
term_hexrays_plugin();
}
}
//--------------------------------------------------------------------------
bool idaapi run(size_t arg)
{
if (arg == 0xbeef)
{
PLUGIN.flags |= PLUGIN_UNL;
return true;
}
if (arg == 2)
{
FixCallsToAllocaProbe();
return true;
}
#if IDA_SDK_VERSION >= 730
if (arg == 0)
#else
if (arg == 3)
#endif
{
ShowMicrocodeExplorer();
return true;
}
return true;
}
//--------------------------------------------------------------------------
static const char comment[] = "Show microcode";
//--------------------------------------------------------------------------
//
// PLUGIN DESCRIPTION BLOCK
//
//--------------------------------------------------------------------------
plugin_t PLUGIN =
{
IDP_INTERFACE_VERSION,
0, // plugin flags
init, // initialize
term, // terminate. this pointer may be NULL.
run, // invoke plugin
comment, // long comment about the plugin
// it could appear in the status line
// or as a hint
"", // multiline help about the plugin
"Microcode explorer", // the preferred short name of the plugin
"" // the preferred hotkey to run the plugin
};