-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
99 lines (80 loc) · 2.6 KB
/
main.c
File metadata and controls
99 lines (80 loc) · 2.6 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include "basicTreatment.h"
#include "brutforceFile.h"
#include <sys/stat.h>
#define MAX_ZIPNAME_LENGTH 256
#define MAX_PASSWORD_LENGTH 256
int main(int argc, char *argv[]) {
// Créer le dossier
char *password = malloc(sizeof(char) * MAX_PASSWORD_LENGTH);
char *zipName = malloc(sizeof(char) * MAX_ZIPNAME_LENGTH);
//check if the user has entered a zipName in 1st argument and a password in 2nd argument
if (checkIfFileExist(argv[1])) {
strcpy(zipName, argv[1]);
} else {
printf("Veuillez saisir un fichier compressé\n\n\n\n");
printHelp();
exit(1);
}
//for --args parsing (getopt) and their equibalent with -h
struct option longopts[] = {
{"help", no_argument, NULL, 'h'},
{"test", no_argument, NULL, 't'},
{"extract", no_argument, NULL, 'e'},
{"password", required_argument, NULL, 'p'}, //{"password", required_argument, NULL, 'p
{"include", required_argument, NULL, 'i'},
{"output", required_argument, NULL, 'o'},
{"show", no_argument, NULL, 's'},
{NULL, 0, NULL, 0}
};
char *outputName = malloc(sizeof(char) * MAX_ZIPNAME_LENGTH);
strcpy(outputName, "NULL");
//Merge ces 2 trucs ?
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-o") == 0 || strcmp(argv[i], "-output") == 0) {
if (i + 1 < argc) {
strcpy(outputName, argv[i + 1]);
break;
}
}
}for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-p") == 0 || strcmp(argv[i], "--password") == 0) {
if (i + 1 < argc) {
strcpy(password, argv[i + 1]);
break;
}
}
}
int c;
int index = 0;
while ((c = getopt_long(argc, argv, "he:i:st", longopts, &index)) != -1) {
switch (c) {
case 't':
isZipPasswordEncrypted(zipName, password,0);
break;
case 'h':
printHelp();
break;
case 'e':
extractFile(zipName, optarg, password);
break;
case 'i':
Add_OverwriteFile(zipName, optarg, outputName);
break;
case 's':
printZipFolder(zipName);
break;
case 'p':
break;
default:
printf("Option inconnu\n");
break;
}
}
free(password);
free(zipName);
return 0;
}