forked from cseagle/sk3wldbg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sk3wldbg_plugin.cpp
182 lines (161 loc) · 4.95 KB
/
sk3wldbg_plugin.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
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
/*
Source for Sk3wlDbg IdaPro plugin
Copyright (c) 2016 Chris Eagle
This program 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 2 of the License, or (at your option)
any later version.
This program 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
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* This is the Sk3wlDbg plugin module
*
* It is known to compile with
*
* - Visual Studio 2010, Linux g++, OS X - clang
*
*/
#ifdef PACKED
#undef PACKED
#endif
#include <unicorn/unicorn.h>
#include <ida.hpp>
#include <idp.hpp>
#include <bytes.hpp>
#include <auto.hpp>
#include <loader.hpp>
#include <kernwin.hpp>
#include <typeinf.hpp>
#include <nalt.hpp>
#include <segment.hpp>
#include <srarea.hpp>
#include <typeinf.hpp>
#include <struct.hpp>
#include <entry.hpp>
#include <dbg.hpp>
#include <idd.hpp>
#include <ua.hpp>
#include "sk3wldbg_x86.h"
#include "sk3wldbg_arm.h"
#include "sk3wldbg_mips.h"
#include "sk3wldbg_sparc.h"
#include "sk3wldbg_ppc.h"
#include "sk3wldbg_m68k.h"
//--------------------------------------------------------------------------
//
// Initialize.
//
// IDA will call this function only once.
// If this function returns PLGUIN_SKIP, IDA will never load it again.
// If this function returns PLUGIN_OK, IDA will unload the plugin but
// remember that the plugin agreed to work with the database.
// The plugin will be loaded again if the user invokes it by
// pressing the hotkey or selecting it from the menu.
// After the second load the plugin will stay on memory.
// If this function returns PLUGIN_KEEP, IDA will keep the plugin
// in the memory. In this case the initialization function can hook
// into the processor module and user interface notification points.
// See the hook_to_notification_point() function.
//
int idaapi plugin_init(void) {
msg("sk3wldbg trying to init\n");
int debug_mode = UC_MODE_32;
if (inf.lflags & LFLG_64BIT) {
debug_mode = UC_MODE_64;
}
else if (inf.lflags & LFLG_PC_FLAT) {
debug_mode = UC_MODE_32;
}
else {
return PLUGIN_SKIP;
}
switch (ph.id) {
case PLFM_386:
if (debug_mode == UC_MODE_32) {
dbg = new sk3wldbg_x86_32();
}
else {
dbg = new sk3wldbg_x86_64();
}
break;
case PLFM_68K:
dbg = new sk3wldbg_m68k();
break;
case PLFM_ARM:
if (debug_mode == UC_MODE_32) {
dbg = new sk3wldbg_arm();
}
else {
dbg = new sk3wldbg_aarch64();
}
break;
case PLFM_MIPS:
if (debug_mode == UC_MODE_32) {
dbg = new sk3wldbg_mips();
}
else {
dbg = new sk3wldbg_mips64();
}
break;
case PLFM_SPARC:
if (debug_mode == UC_MODE_32) {
dbg = new sk3wldbg_sparc();
}
else {
dbg = new sk3wldbg_sparc64();
}
break;
case PLFM_PPC:
if (debug_mode == UC_MODE_32) {
dbg = new sk3wldbg_ppc();
}
else {
dbg = new sk3wldbg_ppc64();
}
break;
default:
return PLUGIN_SKIP;
}
msg(PLUGIN_NAME" keeping sk3wldbg\n");
return PLUGIN_KEEP;
}
//--------------------------------------------------------------------------
// Terminate.
//
// IDA will call this function when the user asks to exit.
// This function won't be called in the case of emergency exits.
void idaapi plugin_term(void) {
#ifdef DEBUG
msg(PLUGIN_NAME": term entered\n");
#endif
#ifdef DEBUG
msg(PLUGIN_NAME": term exiting\n");
#endif
}
void idaapi plugin_run(int /*arg*/) {
return;
}
//--------------------------------------------------------------------------
//
// PLUGIN DESCRIPTION BLOCK
//
//--------------------------------------------------------------------------
plugin_t PLUGIN = {
IDP_INTERFACE_VERSION,
PLUGIN_DBG | PLUGIN_HIDE, // plugin flags
plugin_init, // initialize
plugin_term, // terminate. this pointer may be NULL.
plugin_run, // invoke plugin
"Sk3wlDbg", // long comment about the plugin
// it could appear in the status line
// or as a hint
"Sk3wlDbg", // multiline help about the plugin
"Sk3wlDbg", // the preferred short name of the plugin
"" // the preferred hotkey to run the plugin
};