FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
patchdiff2/clist.cpp at master · clayne/patchdiff2 · GitHub
clayne
/
patchdiff2
Public
forked from
cseagle/patchdiff2
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
patchdiff2
/
clist.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
295 lines (244 loc) · 6.35 KB
Breadcrumbs
patchdiff2
/
clist.cpp
Copy path
File metadata and controls
295 lines (244 loc) · 6.35 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
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.h
"
#
include
"
sig.h
"
#
include
"
hash.h
"
/*
------------------------------------------------
*/
/*
function : clist_t::clist_t
*/
/*
description: Initializes a chained list of
*/
/*
signatures
*/
/*
------------------------------------------------
*/
clist_t
::
clist_t
(
slist_t
*l) {
dpsig_t
*ds;
dpsig_t
*prev;
size_t
i;
num = l->
num
;
sigs =
NULL
;
nmatch =
0
;
msigs =
NULL
;
prev =
NULL
;
for
(i =
0
; i < l->
num
; i++) {
ds =
new
dpsig_t
();
ds->
prev
= prev;
ds->
next
=
NULL
;
ds->
removed
=
false
;
ds->
sig
= l->
sigs
[i];
if
(prev) {
prev->
next
= ds;
}
else
{
sigs = ds;
}
prev = ds;
}
pos = sigs;
}
/*
------------------------------------------------
*/
/*
function : clist_t::insert
*/
/*
description: Inserts sig in sorted list
*/
/*
------------------------------------------------
*/
int
clist_t::insert
(
sig_t
*s) {
dpsig_t
*ds;
dpsig_t
*prev;
dpsig_t
*cur;
int
ret;
ds =
new
dpsig_t
();
if
(!ds) {
return
-
1
;
}
ds->
sig
= s;
ds->
prev
=
NULL
;
ds->
next
=
NULL
;
ds->
removed
=
false
;
prev =
NULL
;
cur = sigs;
while
(cur) {
//
sig_compare is reversed
ret =
sig_compare
(&s, &cur->
sig
) ;
if
(!ret && cur->
sig
->
startEA
== s->
startEA
) {
return
-
1
;
}
if
(ret <=
0
) {
break
;
}
prev = cur;
cur = cur->
next
;
}
ds->
prev
= prev;
ds->
next
= cur;
if
(!prev) {
sigs = ds;
}
else
{
prev->
next
= ds;
}
if
(cur) {
cur->
prev
= ds;
}
num++;
return
0
;
}
/*
------------------------------------------------
*/
/*
function : clist_t_::insert_dsig
*/
/*
description: Inserts dsig in matched list
*/
/*
------------------------------------------------
*/
int
clist_t::insert_dsig
(
dpsig_t
*ds) {
dpsig_t
*prev;
dpsig_t
*cur;
int
ret;
ds->
prev
=
NULL
;
ds->
next
=
NULL
;
ds->
removed
=
true
;
prev =
NULL
;
cur = msigs;
while
(cur) {
//
sig_compare is reversed
ret =
sig_compare
(&ds->
sig
, &cur->
sig
) ;
if
(!ret && cur->
sig
->
startEA
== ds->
sig
->
startEA
) {
return
-
1
;
}
if
(ret <=
0
) {
break
;
}
prev = cur;
cur = cur->
next
;
}
ds->
prev
= prev;
ds->
next
= cur;
if
(!prev) {
msigs= ds;
}
else
{
prev->
next
= ds;
}
if
(cur) {
cur->
prev
= ds;
}
nmatch++;
return
0
;
}
/*
------------------------------------------------
*/
/*
function : clist_t::clist_t
*/
/*
description: Initializes a chained list of
*/
/*
signatures with a list of xrefs
*/
/*
------------------------------------------------
*/
clist_t
::
clist_t
(
hpsig_t
*hsig,
frefs_t
*refs) {
fref_t
*fl;
sig_t
*sig;
num =
0
;
nmatch =
0
;
sigs =
NULL
;
pos =
NULL
;
msigs =
NULL
;
if
(!refs) {
return
;
}
fl = refs->
list
;
while
(fl) {
sig =
hash_find_ea
(hsig, fl->
ea
);
if
(sig && sig->
get_matched_type
() ==
DIFF_UNMATCHED
) {
insert
(sig);
}
fl = fl->
next
;
}
pos = sigs;
}
/*
------------------------------------------------
*/
/*
function : clist_t::remove
*/
/*
description: Removes element from list
*/
/*
------------------------------------------------
*/
void
clist_t::remove
(
dpsig_t
*ds) {
if
(ds->
removed
==
true
)
return
;
if
(ds->
prev
==
NULL
) {
sigs = ds->
next
;
}
else
{
ds->
prev
->
next
= ds->
next
;
}
if
(ds->
next
!=
NULL
) {
ds->
next
->
prev
= ds->
prev
;
}
insert_dsig
(ds);
}
/*
------------------------------------------------
*/
/*
function : clist_t::reset
*/
/*
description: Resets list position
*/
/*
------------------------------------------------
*/
void
clist_t::reset
() {
pos = sigs;
}
/*
------------------------------------------------
*/
/*
function : clist_t::~clist_t
*/
/*
description: Frees clist_t structure
*/
/*
------------------------------------------------
*/
clist_t
::
~clist_t
() {
delete
sigs;
sigs =
NULL
;
delete
msigs;
msigs =
NULL
;
}
/*
------------------------------------------------
*/
/*
function : clist_t::equal_match
*/
/*
description: Checks if all the elements of a
*/
/*
clist match
*/
/*
------------------------------------------------
*/
bool
clist_t::equal_match
(
const
clist_t
&cl2) {
dpsig_t
*s1, *s2;
size_t
i;
if
(nmatch ==
0
|| cl2.
nmatch
==
0
) {
return
false
;
}
if
(nmatch != cl2.
nmatch
) {
return
false
;
}
s1 = msigs;
s2 = cl2.
msigs
;
for
(i =
0
; i < nmatch; i++) {
if
((s1->
sig
->
get_matched_type
() ==
DIFF_UNMATCHED
) || (s1->
sig
->
msig
->
startEA
!= s2->
sig
->
startEA
)) {
return
false
;
}
s1 = s1->
next
;
s2 = s2->
next
;
}
return
true
;
}
/*
------------------------------------------------
*/
/*
function : clist_almost_equal_match
*/
/*
description: Checks if at lest one element of a
*/
/*
clist match
*/
/*
------------------------------------------------
*/
bool
clist_t::almost_equal_match
(
const
clist_t
&cl2) {
dpsig_t
*s1, *s2;
size_t
i, k;
if
(nmatch ==
0
|| cl2.
nmatch
==
0
) {
return
false
;
}
if
(nmatch != cl2.
nmatch
) {
return
false
;
}
s1 = msigs;
for
(i =
0
; i < nmatch; i++) {
s2 = cl2.
msigs
;
for
(k =
0
; k < cl2.
nmatch
; k++) {
if
(s1->
sig
->
msig
->
startEA
== s2->
sig
->
startEA
) {
return
true
;
}
s2 = s2->
next
;
}
s1 = s1->
next
;
}
return
false
;
}
Back
|
FazBrowse Home
|
New Git URL