forked from alexander-pick/patchdiff2_ida6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatchdiff.cpp
233 lines (183 loc) · 4.27 KB
/
patchdiff.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
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
/*
Patchdiff2
Portions (C) 2011 Alexander Pick
Portions (C) 2010 Nicolas Pouvesle
Portions (C) 2007 - 2009 Tenable Network Security, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
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, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <ida.hpp>
#include <loader.hpp>
#include <kernwin.hpp>
#include <idp.hpp>
#include <diskio.hpp>
#include <auto.hpp>
#include "sig.hpp"
#include "parser.hpp"
#include "patchdiff.hpp"
#include "diff.hpp"
#include "backup.hpp"
#include "display.hpp"
#include "options.hpp"
#include "system.hpp"
extern plugin_t PLUGIN;
extern char *exename;
deng_t * d_engine;
cpu_t patchdiff_cpu;
options_t * d_opt;
int idaapi init(void)
{
if (!strcmp(inf.procName, "metapc"))
{
if (inf.is_64bit())
patchdiff_cpu = CPU_X8664;
else
patchdiff_cpu = CPU_X8632;
}
else if (!strcmp(inf.procName, "PPC"))
{
patchdiff_cpu = CPU_PPC;
}
else
patchdiff_cpu = CPU_DEFAULT;
d_engine = NULL;
// handle IPC
ipc_init(NULL, 0, 0);
d_opt = options_init();
if (!d_opt)
return PLUGIN_SKIP;
return PLUGIN_OK;
}
void idaapi term(void)
{
if (d_engine)
{
if (options_save_db(d_opt))
backup_save_results(d_engine);
diff_engine_free(d_engine);
unhook_from_notification_point(HT_UI, ui_callback);
}
ipc_close();
options_close(d_opt);
}
void run_first_instance()
{
char * file;
slist_t * sl1 = NULL;
slist_t * sl2 = NULL;
int ret;
msg ("\n---------------------------------------------------\n"
"PatchDiff Plugin v2.0.9\n"
"Copyright (c) 2011 Alexander Pick\n"
"Copyright (c) 2010, Nicolas Pouvesle\n"
"Copyright (c) 2007-2009, Tenable Network Security, Inc\n"
"---------------------------------------------------\n\n");
ret = backup_load_results(&d_engine, d_opt);
if (ret == 1)
{
display_results(d_engine);
return;
}
else if (ret == -1)
{
return;
}
show_wait_box ("PatchDiff is in progress ...");
msg ("Scanning for functions ...\n");
// value parameter problem
//sl2 = parse_second_idb(file, d_opt);
sl2 = parse_second_idb(&file, d_opt);
//printf("file: %s\n", file);
if (!sl2)
{
msg("Error: IDB2 parsing cancelled or failed.\n");
hide_wait_box();
return;
}
msg ("parsing first idb...\n");
sl1 = parse_idb ();
if (!sl1)
{
msg("Error: IDB1 parsing failed.\n");
siglist_free(sl2);
hide_wait_box();
return;
}
msg ("diffing...\n");
generate_diff(&d_engine, sl1, sl2, file, true, d_opt);
msg ("done!\n");
hide_wait_box();
if (sl1) siglist_partial_free(sl1);
if (sl2) siglist_partial_free(sl2);
}
void run_second_instance(const char * options)
{
slist_t * sl;
char file[QMAXPATH];
ea_t ea = BADADDR;
unsigned int opt = 0;
unsigned int id;
bool cont;
char tmp[QMAXPATH*4];
qsscanf(options, "%u:%"FMT_EA"u:%u:%s", &id, &ea, &opt, file);
if (id)
{
if (ipc_init(file, 2, id))
{
do
{
cont = ipc_recv_cmd(tmp, sizeof(tmp));
if (cont)
{
run_second_instance(tmp);
ipc_recv_cmd_end();
}
}while(cont);
}
}
else
{
if (ea == BADADDR)
sl = parse_idb();
else
sl = parse_fct(ea, opt);
if (!sl) return;
siglist_save(sl, file);
siglist_free(sl);
}
}
void idaapi run(int arg)
{
autoWait();
const char * options = get_plugin_options("patchdiff");
if (options == NULL)
{
run_first_instance();
} else {
run_second_instance(options);
}
}
char comment[] = "w00t";
char help[] = "A Binary Difference Analysis plugin module\n";
char wanted_name[] = "PatchDiff2";
char wanted_hotkey[] = "Ctrl-8";
plugin_t PLUGIN =
{
IDP_INTERFACE_VERSION,
PLUGIN_MOD,
init,
term,
run,
comment,
help,
wanted_name,
wanted_hotkey
};