FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
patchdiff2/hash.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
/
hash.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
147 lines (116 loc) · 3.66 KB
Breadcrumbs
patchdiff2
/
hash.cpp
Copy path
File metadata and controls
147 lines (116 loc) · 3.66 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
/*
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
"
hash.h
"
#
include
"
sig.h
"
/*
------------------------------------------------
*/
/*
function : hash_init
*/
/*
description: Initializes hash table to NULL
*/
/*
------------------------------------------------
*/
hpsig_t
*
hash_init
(
size_t
num) {
unsigned
int
i;
hpsig_t
*hsig;
static
unsigned
int
primes[] = {
67
,
251
,
509
,
1021
,
2039
,
4093
,
8191
,
16381
,
32749
,
65521
,
131071
,
262139
,
524287
,
1048573
,
2097143
};
for
(i =
0
; i < ((
sizeof
(primes) /
sizeof
(
unsigned
int
)) -
1
); i++) {
if
(primes[i] > (num/
3
)) {
break
;
}
}
hsig =
new
hpsig_t
();
if
(!hsig) {
return
NULL
;
}
hsig->
max_hash
= primes[i];
hsig->
table
=
new
hsignature_t
*[hsig->
max_hash
];
if
(!hsig->
table
) {
delete
hsig;
return
NULL
;
}
for
(i =
0
; i < hsig->
max_hash
; i++) {
hsig->
table
[i] =
NULL
;
}
return
hsig;
}
/*
------------------------------------------------
*/
/*
function : hash_mk_ea
*/
/*
description: Creates hash value
*/
/*
------------------------------------------------
*/
unsigned
int
hash_mk_ea
(
hpsig_t
*htable,
ea_t
val) {
char
*ptr;
unsigned
int
h =
0
;
int
i;
ptr = (
char
*) &val;
for
(i =
0
; i <
sizeof
(val); i++) {
h += ptr[i];
h += ( h <<
10
);
h ^= ( h >>
6
);
}
h += ( h <<
3
);
h ^= ( h >>
11
);
h += ( h >>
15
);
return
h % htable->
max_hash
;
}
/*
------------------------------------------------
*/
/*
function : hash_add_ea
*/
/*
description: Adds element to the hash table
*/
/*
------------------------------------------------
*/
int
hash_add_ea
(
hpsig_t
*htable,
sig_t
*sig) {
int
id =
hash_mk_ea
(htable, sig->
startEA
);
hsignature_t
*hsig =
NULL
;
hsig =
new
hsignature_t
();
if
(!hsig) {
return
-
1
;
}
hsig->
sig
= sig;
hsig->
next
= htable->
table
[id];
htable->
table
[id] = hsig;
return
0
;
}
/*
------------------------------------------------
*/
/*
function : hash_find_ea
*/
/*
description: Finds element in the hash table
*/
/*
------------------------------------------------
*/
sig_t
*
hash_find_ea
(
hpsig_t
*htable,
ea_t
ea) {
if
(ea ==
BADADDR
) {
return
NULL
;
}
int
id =
hash_mk_ea
(htable, ea);
hsignature_t
*hsig;
hsig = htable->
table
[id];
while
(hsig !=
NULL
) {
if
(hsig->
sig
->
startEA
== ea) {
return
hsig->
sig
;
}
hsig = hsig->
next
;
}
return
NULL
;
}
/*
------------------------------------------------
*/
/*
function : hash_free
*/
/*
description: Frees hash table
*/
/*
------------------------------------------------
*/
void
hash_free
(
hpsig_t
*htable) {
unsigned
int
i;
hsignature_t
*hsig, *tmp;
for
(i =
0
; i < htable->
max_hash
; i++) {
hsig = htable->
table
[i];
while
(hsig !=
NULL
) {
tmp = hsig->
next
;
delete
hsig;
hsig = tmp;
}
}
delete []
htable;
}
Back
|
FazBrowse Home
|
New Git URL