-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
105 lines (85 loc) · 3.1 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
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "main.h"
#include "ext/ui.h"
#include "ext/dirscan.h"
#include "ext/fileutil.h"
struct FileList {
char **files; // All files in list fileList.files[index]
char **dirs;
size_t count_files; // Files detected in directory
size_t count_dirs; // Files detected in directory
};
struct LinesList {
char **lines;
size_t count;
};
void execop() {
const char *filepath = "./ext/dirscan.c";
if (if_path_exists(filepath)) {
struct LinesList linesList = readLinesfromfile(filepath);
for (size_t i = 0; i < linesList.count; i++) {
printf("%s", linesList.lines[i]);
}
freeLinesList(&linesList);
} else {
printf("File does not exist: %s\n", filepath);
}
}
#define MAX_LINE_LENGTH 128
#define MAX_PATH_LENGTH 2048
void extractInfo(FILE *file, FILE *outputFile) {
char line[MAX_LINE_LENGTH];
char url[MAX_LINE_LENGTH], username[MAX_LINE_LENGTH], password[MAX_LINE_LENGTH], application[MAX_LINE_LENGTH];
while (fgets(line, sizeof(line), file) != NULL) {
if (strstr(line, "URL:") != NULL) {
strcpy(url, line + 5); // Skip "URL: "
url[strcspn(url, "\n")] = '\0'; // Remove newline character
}
else if (strstr(line, "Username:") != NULL) {
strcpy(username, line + 10); // Skip "Username: "
username[strcspn(username, "\n")] = '\0'; // Remove newline character
}
else if (strstr(line, "Password:") != NULL) {
strcpy(password, line + 10); // Skip "Password: "
password[strcspn(password, "\n")] = '\0'; // Remove newline character
}
else if (strstr(line, "Application:") != NULL) {
strcpy(application, line + 13); // Skip "Application: "
application[strcspn(application, "\n")] = '\0'; // Remove newline character
}
}
fprintf(outputFile, "%s:%s@%s:%s\n", username, password, url, application);
}
int main() {
char logs_path[64];
printf("Path to logs folder: ");
scanf("%s", logs_path);
struct FileList fileList = listFiles(logs_path);
FILE *outputFile = fopen("./extracted.txt", "w");
if (outputFile == NULL) {
perror("Error opening output file");
return 1;
}
for (size_t i = 0; i < fileList.count_dirs; ++i) {
if (strcmp(fileList.dirs[i], ".") != 0 && strcmp(fileList.dirs[i], "..") != 0) {
char logs_path_plus_logdir[MAX_PATH_LENGTH];
strcpy(logs_path_plus_logdir, logs_path);
strcat(logs_path_plus_logdir, "/");
strcat(logs_path_plus_logdir, fileList.dirs[i]);
strcat(logs_path_plus_logdir, "/Passwords.txt");
if (if_path_exists(logs_path_plus_logdir) == 1) {
FILE *file = fopen(logs_path_plus_logdir, "r");
if (file == NULL) {
perror("Error opening file");
return 1;
}
extractInfo(file, outputFile);
fclose(file);
}
}
}
fclose(outputFile);
return 0;
}