-
Notifications
You must be signed in to change notification settings - Fork 0
/
lima.c
44 lines (35 loc) · 780 Bytes
/
lima.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
// Reads characters from a given file
void succeed() {
printf("Access granted!\n");
exit(0);
}
void fail() {
printf("Access denied.\n");
exit(1);
}
int main(int argc, char** argv) {
if (argc != 2) {
printf("Usage: lima.exe <file>\n");
return -1;
}
char* filename = argv[1];
FILE* f = fopen(filename, "r");
if (errno != 0) {
perror("PANIC! Aborting due to");
return -1;
}
char buffer[16];
int read = fread(buffer, 16, 1, f);
if (errno != 0) {
perror("PANIC! Aborting due to");
return -1;
}
if (strncmp("hi saya nak flag", buffer, 16) != 0) {
fail();
}
succeed();
}