-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvfs1.c
156 lines (132 loc) · 4.66 KB
/
vfs1.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
__attribute__((constructor)) void flush_buf() {
setbuf(stdin, NULL);
setbuf(stdout, NULL);
setbuf(stderr, NULL);
}
void banner() {
puts("VVVVVVVV VVVVVVVVFFFFFFFFFFFFFFFFFFFFFF SSSSSSSSSSSSSSS ");
puts("V::::::V V::::::VF::::::::::::::::::::F SS:::::::::::::::S");
puts("V::::::V V::::::VF::::::::::::::::::::FS:::::SSSSSS::::::S");
puts("V::::::V V::::::VFF::::::FFFFFFFFF::::FS:::::S SSSSSSS");
puts(" V:::::V V:::::V F:::::F FFFFFFS:::::S ");
puts(" V:::::V V:::::V F:::::F S:::::S ");
puts(" V:::::V V:::::V F::::::FFFFFFFFFF S::::SSSS ");
puts(" V:::::V V:::::V F:::::::::::::::F SS::::::SSSSS ");
puts(" V:::::V V:::::V F:::::::::::::::F SSS::::::::SS ");
puts(" V:::::V V:::::V F::::::FFFFFFFFFF SSSSSS::::S ");
puts(" V:::::V:::::V F:::::F S:::::S");
puts(" V:::::::::V F:::::F S:::::S");
puts(" V:::::::V FF:::::::FF SSSSSSS S:::::S");
puts(" V:::::V F::::::::FF S::::::SSSSSS:::::S");
puts(" V:::V F::::::::FF S:::::::::::::::SS ");
puts(" VVV FFFFFFFFFFF SSSSSSSSSSSSSSS ");
puts("");
puts("");
puts("[+] Welcome to the Virtual File System! Here you can create, delete, and");
puts("modify files. In order to save space, multiple people are using this same");
puts("system. But don't worry! We've implemented a system to prevent people from");
puts("seeing each other's files. Enjoy!\n\n");
}
int menu() {
int choice;
puts("[+] What would you like to do?");
puts("1. Create a file");
puts("2. Delete a file");
puts("3. Modify a file");
puts("4. Read a file");
puts("5. Exit");
printf("> ");
scanf("%d", &choice);
return choice;
}
int main() {
banner();
// INITIALIZATIONS
struct filesystem {
char contents[2880];
char flag[64];
int current_file;
};
// get flag
struct filesystem fs;
char * buffer = 0;
long length;
FILE * f = fopen ("flag.txt", "rb");
if (f) {
fseek (f, 0, SEEK_END);
length = ftell (f);
fseek (f, 0, SEEK_SET);
buffer = malloc (length);
if (buffer) {
fread (buffer, 1, length, f);
}
fclose (f);
}
if (buffer) {
strcpy(fs.flag, buffer);
free(buffer);
}
else {
puts("[-] Error reading flag");
exit(1);
}
fs.current_file = 0;
char filename[32];
char contents[256];
while (1==1) {
int choice = menu();
if (choice == 1) {
if (fs.current_file == 10) {
puts("[-] Sorry, you can't create any more files!");
continue;
}
// create
puts("[+] What would you like to name your file?");
printf("> ");
scanf("%32s", filename);
puts("[+] What would you like to put in your file?");
printf("> ");
scanf("%256s", contents);
// copy filename
memcpy(fs.contents + (fs.current_file*288), filename, 32);
// copy contents
memcpy(fs.contents + (fs.current_file*288) + 32, contents, 256);
printf("[+] File created! (#%d)\n\n", fs.current_file);
fs.current_file++;
}
else if (choice == 2) {
// delete
//delete_file();
printf("Sorry, that hasn't been implemented yet!\n");
}
else if (choice == 3) {
// modify
//modify_file();
printf("Sorry, that hasn't been implemented yet!\n");
}
else if (choice == 4) {
// read
int file_to_read;
puts("[+] Which file # would you like to read?");
printf("> ");
scanf("%d", &file_to_read);
if ((file_to_read >= fs.current_file) || (file_to_read < 0)) {
puts("[-] Invalid file number");
continue;
}
printf("[+] Filename: %s", fs.contents + (file_to_read*288));
printf("[+] Contents: %s", fs.contents + (file_to_read*288) + 32);
}
else if (choice == 5) {
exit(0);
}
else {
puts("[-] Invalid choice");
exit(1);
}
}
}