Debian Codegraph @

src/ntproba/ioMarkov.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) 2013 Philippe Oechslin, Cedric Tissieres,
10 * Bertrand Mesot, Pierre Lestringant
11 *
12 * Ophcrack is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * Ophcrack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with Ophcrack; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * This program is released under the GPL with the additional exemption
27 * that compiling, linking, and/or using OpenSSL is allowed.
28 *
29 *
30 *
31 *
32 */
33 /* WARNING: this file is a NOT copy from implCPU/v6 */
34
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <sys/mman.h>
38 #include <sys/stat.h>
39 #include <sys/types.h>
40 #include <fcntl.h>
41 #include <unistd.h>
42 #include <string.h>
43
44 #include "ioMarkov.h"
45
46
47 char readImprobaStructFromBinFile(markovImprobaStruct** mis, char* path, char* fileName){
48 struct stat sb;
49 int binFile;
50 char buffer[256];
51
52 if (fileName != NULL){
53 sprintf(buffer, "%s/%s", path, fileName);
54 binFile = open(buffer, O_RDONLY);
55 }
56 else{
57 sprintf(buffer, "%s/%s", path, DEFAULT_MARKOV_FILE_NAME);
58 binFile = open(buffer, O_RDONLY);
59 }
60
61 if (binFile == -1){
62 return 0;
63 }
64
65 if (fstat(binFile, &sb) == -1){
66 close(binFile);
67 return 0;
68 }
69
70
71 if (sb.st_size != sizeof(markovImprobaStruct)){
72 close(binFile);
73 return 0;
74 }
75
76 *mis = (markovImprobaStruct*)mmap(NULL, sizeof(markovImprobaStruct), PROT_READ, MAP_PRIVATE, binFile, 0);
77 if (*mis == MAP_FAILED){
78 close(binFile);
79 return 0;
80 }
81 close(binFile);
82 return 1;
83 }
84
85 markovType fromStringMarkovType(const char* word, const int length){
86 if (!memcmp(word, "NO_MARK", length)){
87 return NO_MARK;
88 }
89 if (!memcmp(word, "MARK0", length)){
90 return MARK0;
91 }
92 if (!memcmp(word, "MARK1", length)){
93 return MARK1;
94 }
95 if (!memcmp(word, "MARK2", length)){
96 return MARK2;
97 }
98 return NO_MARK;
99 }