forked from Ramaguru-Forks/ssdeep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cycles.cpp
179 lines (138 loc) · 3.19 KB
/
cycles.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
/* MD5DEEP
*
* By Jesse Kornblum
*
* This is a work of the US Government. In accordance with 17 USC 105,
* copyright protection is not available for any work of the US Government.
*
* 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.
*
*/
// $Id$
#include "ssdeep.h"
typedef struct dir_table {
TCHAR *name;
struct dir_table *next;
} dir_table;
dir_table *my_table = NULL;
/* This function was used in the dark ages for debugging
static void dump_table(void)
{
struct dir_table *t = my_table;
while (t != NULL)
{
print_status (_TEXT("* %s"), t->name);
t = t->next;
}
print_status ("-- end of table --");
}
*/
int done_processing_dir(TCHAR *fn)
{
dir_table *last, *temp;
TCHAR *d_name = (TCHAR *)malloc(sizeof(TCHAR) * SSDEEP_PATH_MAX);
#ifdef _WIN32
_wfullpath(d_name,fn,SSDEEP_PATH_MAX);
#else
realpath(fn,d_name);
#endif
if (my_table == NULL)
{
internal_error("Table is NULL in done_processing_dir");
// This code never gets executed...
free(d_name);
return FALSE;
}
temp = my_table;
if (!_tcsncmp(d_name,temp->name,SSDEEP_PATH_MAX))
{
my_table = my_table->next;
free(temp->name);
free(temp);
free(d_name);
return TRUE;
}
while (temp->next != NULL)
{
last = temp;
temp = temp->next;
if (!_tcsncmp(d_name,temp->name,SSDEEP_PATH_MAX))
{
last->next = temp->next;
free(temp->name);
free(temp);
free(d_name);
return TRUE;
}
}
internal_error("%s: Directory %s not found in done_processing_dir",
__progname, d_name);
// This code never gets executed...
// free (d_name);
return FALSE;
}
int processing_dir(TCHAR *fn)
{
dir_table *new_dir, *temp;
TCHAR *d_name = (TCHAR *)malloc(sizeof(TCHAR) * SSDEEP_PATH_MAX);
#ifdef _WIN32
_wfullpath(d_name,fn,SSDEEP_PATH_MAX);
#else
realpath(fn,d_name);
#endif
if (my_table == NULL)
{
my_table = (dir_table*)malloc(sizeof(dir_table));
my_table->name = _tcsdup(d_name);
my_table->next = NULL;
free(d_name);
return TRUE;
}
temp = my_table;
while (temp->next != NULL)
{
/* We should never be adding a directory that is already here */
if (!_tcsncmp(temp->name,d_name,SSDEEP_PATH_MAX))
{
internal_error("%s: Attempt to add existing %s in processing_dir",
__progname, d_name);
// Does not execute
free(d_name);
return FALSE;
}
temp = temp->next;
}
new_dir = (dir_table*)malloc(sizeof(dir_table));
new_dir->name = _tcsdup(d_name);
new_dir->next = NULL;
temp->next = new_dir;
free(d_name);
return TRUE;
}
int have_processed_dir(TCHAR *fn)
{
dir_table *temp;
TCHAR *d_name;
if (my_table == NULL)
return FALSE;
d_name = (TCHAR *)malloc(sizeof(TCHAR) * SSDEEP_PATH_MAX);
#ifdef _WIN32
_wfullpath(d_name,fn,SSDEEP_PATH_MAX);
#else
realpath(fn,d_name);
#endif
temp = my_table;
while (temp != NULL)
{
if (!_tcsncmp(temp->name,d_name,SSDEEP_PATH_MAX))
{
free(d_name);
return TRUE;
}
temp = temp->next;
}
free(d_name);
return FALSE;
}