-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.c
74 lines (65 loc) · 1.55 KB
/
1.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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define SIZE 0x100
char motd[SIZE] = "> > > D-d-d-DROP the ROP! < < <";
void clean_stdin()
{
while (1)
{
char c = getchar();
if (c == '\n') break;
if (c == EOF) exit(1);
}
}
int getnum()
{
int choice = ~0;
scanf("%d", &choice);
clean_stdin();
return choice;
}
void read_motd(char* motd) {
printf("Type in the new message of the day please:\n> ");
char buf[SIZE] = {0};
gets(buf);
memcpy(motd, buf, SIZE);
}
int done = 0;
void main()
{
setvbuf(stdout, NULL, _IONBF, 0);
/* setvbuf(stdin, NULL, _IONBF, 0); */ // Breaks direct ret2libc
printf("motd daemon v0.1 (c) 2019 BetterSoft\n");
fflush(stdout);
system("date"); // [bill] This is easier than manipulating time and makes our code cleaner.
while (!done)
{
printf("\n");
printf("=> How may I help you today?\n");
printf(" 1 - View message of the day\n");
printf(" 2 - Change message of the day\n");
printf(" 3 - Exit\n");
printf("> ");
int choice = getnum();
printf("\n");
switch (choice)
{
case 1:
puts(motd);
break;
case 2:
{
read_motd(motd);
break;
}
case 3:
done = 1;
break;
default:
printf("I don't recognize that option.\n");
break;
}
}
printf("Bye!\n");
}