Debian Codegraph @

src/core/ophtask.c

raw symbols SCIP
1 /*
2 *
3 * Ophcrack is a Lanmanager/NTLM hash cracker based on the faster time-memory
4 * trade-off using rainbow tables.
5 *
6 * Created with the help of: Maxime Mueller, Luca Wullschleger, Claude
7 * Hochreutiner, Andreas Huber and Etienne Dysli.
8 *
9 * Copyright (c) 2008 Philippe Oechslin, Cedric Tissieres, Bertrand Mesot
10 *
11 * Ophcrack is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * Ophcrack is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with Ophcrack; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 * This program is released under the GPL with the additional exemption
26 * that compiling, linking, and/or using OpenSSL is allowed.
27 *
28 *
29 *
30 *
31 */
32 #include <stdlib.h>
33 #include <string.h>
34
35 #include "ophtask.h"
36 #include "original.h"
37 /*-------------------------------------------------------------------------*/
38 ophtask_t *ophtask_alloc(ophkind_t kind) {
39 ophtask_t *task = (ophtask_t*)malloc(sizeof(ophtask_t));
40
41 task->kind = kind;
42 task->data = 0;
43 task->stat = ophstat_alloc();
44
45 switch (kind) {
46 case preload_all: {
47 ophload_t *load = (ophload_t*)malloc(sizeof(ophload_t));
48 task->data = load;
49
50 load->tables = list_alloc();
51 load->tbl = 0;
52 load->preload = preload_none;
53 } break;
54
55 case preload_one:
56 case unload: {
57 ophload_t *load = (ophload_t*)malloc(sizeof(ophload_t));
58 task->data = load;
59
60 load->tables = 0;
61 load->tbl = 0;
62 load->preload = preload_none;
63 } break;
64
65 case find:
66 case lookup_idx:
67 case lookup_end:
68 case lookup_srt:
69 case check: {
70 ophwork_t *work = (ophwork_t*)malloc(sizeof(ophwork_t));
71 task->data = work;
72
73 work->hsh = 0;
74 work->htbl = 0;
75 work->cmin = 0;
76 work->cmax = 0;
77 work->tosearch = 0;
78 } break;
79
80 case bforce_all:
81 case bforce_nt:
82 case bforce_lm:
83 case resolve_nt: {
84 ophbforce_t *force = (ophbforce_t*)malloc(sizeof(ophbforce_t));
85 task->data = force;
86
87 force->nhashes = 0;
88 force->hashes = 0;
89 force->hash = 0;
90 force->found = 0;
91 force->len = 1;
92 force->count = 0;
93
94 memset(force->idx, 0, sizeof(force->idx));
95 memset(force->bloom, 0, sizeof(force->bloom));
96 } break;
97
98 case all:
99 break;
100 }
101
102 return task;
103 }
104 /*-------------------------------------------------------------------------*/
105 void ophtask_free(ophtask_t *task) {
106 int kind = task->kind;
107
108 switch (kind) {
109 case preload_all: {
110 ophload_t *load = task->data;
111
112 list_free(load->tables);
113 free(load);
114 } break;
115
116 case preload_one:
117 case unload: {
118 ophload_t *load = task->data;
119 free(load);
120 } break;
121
122 case find:
123 case lookup_idx:
124 case lookup_end:
125 case lookup_srt:
126 case check: {
127 ophwork_t *work = task->data;
128 ophel_t **tosearch = work->tosearch;
129
130 int cmax = work->cmax;
131 int cmin = work->cmin;
132 int size = cmax-cmin+1;
133 int i;
134
135 if (tosearch) {
136 for (i=0; i<size; ++i)
137 if (tosearch[i]) ophel_free(tosearch[i]);
138
139 free(tosearch);
140 }
141
142 free(work);
143 } break;
144
145 case bforce_all:
146 case bforce_nt:
147 case bforce_lm:
148 case resolve_nt: {
149 ophbforce_t *force = task->data;
150
151 hash_t **hashes = force->hashes;
152 uchar_t **hash = force->hash;
153 int *found = force->found;
154
155 int nhashes = force->nhashes;
156 int i;
157
158 if (hash) {
159 for (i=0; i<nhashes; ++i)
160 if (hash[i]) free(hash[i]);
161
162 free(hash);
163 }
164
165 if (found) free(found);
166 if (hashes) free(hashes);
167
168 free(force);
169 } break;
170
171 case all:
172 break;
173 }
174
175 ophstat_free(task->stat);
176 free(task);
177 }
178 /*-------------------------------------------------------------------------*/
179 void ophtask_convert(ophtask_t *task, ophkind_t from, ophkind_t to) {
180 if (from == find) {
181 ophwork_t *work = task->data;
182
183 int cmin = work->cmin;
184 int cmax = work->cmax;
185 int size = cmax-cmin+1;
186 int i;
187
188 if (to == lookup_idx || to == lookup_end || to == lookup_srt) {
189 task->kind = to;
190 work->tosearch = (ophel_t**)malloc(size*sizeof(ophel_t));
191
192 for (i=0; i<size; ++i)
193 work->tosearch[i] = ophel_alloc();
194 }
195 }
196 }