FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
patchdiff2/system.cpp at master · idkwim/patchdiff2 · GitHub
idkwim
/
patchdiff2
Public
forked from
filcab/patchdiff2
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
patchdiff2
/
system.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
280 lines (206 loc) · 6.28 KB
Breadcrumbs
patchdiff2
/
system.cpp
Copy path
File metadata and controls
280 lines (206 loc) · 6.28 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
Patchdiff2
Portions (C) 2010 - 2011 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
"
precomp.hpp
"
#
include
"
sig.hpp
"
#
include
"
system.hpp
"
#
include
"
options.hpp
"
#
include
"
os.hpp
"
//
global variable to keep IPC state
ipc_config_t
ipcc;
/*
------------------------------------------------
*/
/*
function : generate_idc_file
*/
/*
description: generates an idc file to launch
*/
/*
second plugin instance in batch
*/
/*
mode
*/
/*
------------------------------------------------
*/
static
int
generate_idc_file
(
char
* file)
{
FILE
* fp;
fp =
qfopen
(file,
"
w+
"
);
if
(!fp)
return
-
1
;
qfwrite
(fp,
PATCHDIFF_IDC
,
strlen
(
PATCHDIFF_IDC
));
qfclose
(fp);
return
0
;
}
/*
------------------------------------------------
*/
/*
function : system_execute_second_instance
*/
/*
description: Executes another IDA instance
*/
/*
------------------------------------------------
*/
static
int
system_execute_second_instance
(
char
* idc,
ea_t
ea,
char
* file,
bool
close,
long
id,
void
* data)
{
char
path[
QMAXPATH
*
4
];
char
cmd[
QMAXPATH
*
4
];
if
(!
getsysfile
(path,
sizeof
(path),
IDA_EXEC
,
NULL
))
return
-
1
;
if
(
generate_idc_file
(idc))
return
-
1
;
qsnprintf
(cmd,
sizeof
(cmd),
"
\"
%s
\"
-A -S
\"
%s
\"
-Opatchdiff2:%ld:%
"
PRIea_t
"
:%u:
\"
%s
\"
\"
%s
\"
"
,
path,
idc,
id,
ea,
dto.
graph
.
s_showpref
,
idc,
file
);
return
os_execute_command
(cmd, close, data);
}
/*
------------------------------------------------
*/
/*
function : ipc_init
*/
/*
description: Inits interprocess communication
*/
/*
between 2 IDA instances
*/
/*
------------------------------------------------
*/
bool
ipc_init
(
char
* file,
int
type,
long
id)
{
bool
ret;
long
pid;
char
tmpname[
QMAXPATH
];
if
(type ==
0
)
{
ipcc.
init
=
false
;
ipcc.
data
=
NULL
;
}
else
if
(!ipcc.
init
)
{
if
(type ==
1
)
{
pid =
os_get_pid
();
ret =
os_ipc_init
(&ipcc.
data
, pid,
IPC_SERVER
);
if
(!ret)
return
false
;
os_tempnam
(tmpname,
sizeof
(tmpname),
"
.idc
"
);
if
(
system_execute_second_instance
(tmpname,
BADADDR
, file,
false
, pid, ipcc.
data
) !=
0
)
{
ipc_close
();
return
false
;
}
}
else
{
ret =
os_ipc_init
(&ipcc.
data
, id,
IPC_CLIENT
);
if
(!ret)
return
false
;
}
ipcc.
init
=
true
;
}
return
true
;
}
/*
------------------------------------------------
*/
/*
function : ipc_close
*/
/*
description: Closes interprocess communication
*/
/*
between 2 IDA instances
*/
/*
------------------------------------------------
*/
void
ipc_close
()
{
if
(!ipcc.
init
)
return
;
os_ipc_close
(ipcc.
data
);
ipcc.
data
=
NULL
;
ipcc.
init
=
false
;
}
/*
------------------------------------------------
*/
/*
function : ipc_send_cmd
*/
/*
description: Executes command on the remote
*/
/*
IDA instance
*/
/*
------------------------------------------------
*/
static
bool
ipc_send_cmd
(
char
* cmd)
{
idata_t
d;
d.
cmd
=
IPC_DATA
;
qstrncpy
(d.
data
, cmd,
sizeof
(d.
data
));
if
(!
os_ipc_send
(ipcc.
data
,
IPC_SERVER
, &d))
return
false
;
if
(!
os_ipc_recv
(ipcc.
data
,
IPC_SERVER
, &d) || d.
cmd
!=
IPC_DONE
)
return
false
;
return
true
;
}
/*
------------------------------------------------
*/
/*
function : ipc_recv_cmd
*/
/*
description: Receives command to execute
*/
/*
------------------------------------------------
*/
bool
ipc_recv_cmd
(
char
* buf,
size_t
blen)
{
bool
ret;
idata_t
d;
size_t
len;
memset
(d.
data
,
'
\0
'
,
sizeof
(d.
data
));
ret =
os_ipc_recv
(ipcc.
data
,
IPC_CLIENT
, &d);
if
(!ret)
return
false
;
if
(d.
cmd
!=
IPC_DATA
)
return
false
;
len =
strlen
(d.
data
) +
1
;
if
(len > blen)
len = blen;
memcpy
(buf, d.
data
, len);
return
true
;
}
/*
------------------------------------------------
*/
/*
function : ipc_recv_cmd_end
*/
/*
description: Acknowledges end of command
*/
/*
------------------------------------------------
*/
bool
ipc_recv_cmd_end
()
{
idata_t
d;
d.
cmd
=
IPC_DONE
;
return
os_ipc_send
(ipcc.
data
,
IPC_CLIENT
, &d);
}
/*
------------------------------------------------
*/
/*
function : ipc_execute_second_instance
*/
/*
description: Sends command to the second IDA
*/
/*
instance
*/
/*
------------------------------------------------
*/
static
void
ipc_execute_second_instance
(
char
* idc,
ea_t
ea,
char
* file)
{
char
cmd[
QMAXPATH
*
4
];
if
(!
ipc_init
(file,
1
,
0
))
return
;
qsnprintf
(cmd,
sizeof
(cmd),
"
%u:%
"
PRIea_t
"
:%u:%s
"
,
0
,
ea,
dto.
graph
.
s_showpref
,
idc
);
ipc_send_cmd
(cmd);
}
/*
------------------------------------------------
*/
/*
function : system_parse_idb
*/
/*
description: generates a list of signatures for
*/
/*
another idb
*/
/*
------------------------------------------------
*/
slist_t
*
system_parse_idb
(
ea_t
ea,
char
* file,
options_t
* opt)
{
slist_t
* sl =
NULL
;
char
tmpname[
QMAXPATH
];
os_tempnam
(tmpname,
sizeof
(tmpname),
"
.idc
"
);
if
(!
options_use_ipc
(opt))
system_execute_second_instance
(tmpname, ea, file,
true
,
0
,
NULL
);
else
ipc_execute_second_instance
(tmpname, ea, file);
sl =
siglist_load
(tmpname);
os_unlink
(tmpname);
return
sl;
}
/*
------------------------------------------------
*/
/*
function : system_get_pref
*/
/*
description: Gets global system preference
*/
/*
------------------------------------------------
*/
bool
system_get_pref
(
const
char
*name,
void
* data,
int
type)
{
if
(type ==
SPREF_INT
)
{
return
os_get_pref_int
(name, (
int
*)data);
}
return
false
;
}
Back
|
FazBrowse Home
|
New Git URL