-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
72 lines (60 loc) · 1.55 KB
/
main.c
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
#include <string.h>
#include <stdio.h>
#include "cracker.h"
#include <getopt.h>
void
usage (void)
{
printf("Usage: [zipcrack [-t | -p ] <NB> <-d DICTINARY> <ZIP_FILE>]\n");
}
void checkParams(char* file, char* pflag, char* tflag, char* dflag){
if(dflag ==NULL){
usage();
exit(-1);
}if(pflag!=NULL && tflag!=NULL){
usage();
exit(-1);
}else if(pflag==NULL && tflag==NULL){
usage();
exit(-1);
}else if(file == NULL){
usage();
exit(-1);
}
}
int
main (int argc, char ** argv)
{
int c;
char* pflag = 0;
char* tflag = 0;
char* dflag = 0;
char* file;
if (argc < 2) {
usage();
return 1;
}
while ((c = getopt (argc, argv, "p:t:d:")) != -1) { /*Parse arguments*/
switch (c){
case 'p':
pflag = (char*)optarg;
break;
case 't':
tflag = (char*)optarg;
break;
case 'd':
dflag = (char*)optarg;
break;
}
}
file = argv[argc-1];
checkParams(file, pflag, tflag,dflag); /*Exits if arguments are wrong*/
if(pflag){
printf("Password cracking of archive %s with dictionary %s started using %d process\n",file,dflag,atoi(pflag));
start_cracking('p',atoi(pflag), file, dflag);
}else{
printf("Password cracking of archive %s with dictionary %s started using %d threads\n",file,dflag,atoi(tflag));
start_cracking('t',atoi(tflag), file, dflag);
}
return 1;
}