-
Notifications
You must be signed in to change notification settings - Fork 14
/
learning-the-ropes.c
50 lines (46 loc) · 1.79 KB
/
learning-the-ropes.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
#include <stdio.h> // for snprintf, size_t
#include <stdlib.h> // for exit, atoi, EXIT_FAILURE
#include <string.h> // for strcmp
#include <sys/param.h> // for MIN
#include <unistd.h> // for STDOUT_FILENO, STDIN_FILENO
#include "utils.h" // for write_n, line_buf, line_buf_next, line_buf_re...
static const char ROPES[] = {
#include "learning-the-ropes.h"
};
static const char QUESTION1[] = "Greetings! What's your name?> ";
static const char QUESTION3[] = "Oh yeah? How many bytes can you ROP?> ";
static const char QUESTION4[] = "You'll have to give me 110%!> ";
int main(void)
{
char in_buf[128], out_buf[128];
struct line_buf lb;
size_t i;
line_buf_init(&lb, in_buf, sizeof(in_buf));
write_n(STDOUT_FILENO, CLEAR_HOME, sizeof(CLEAR_HOME) - 1);
write_n(STDOUT_FILENO, ROPES, sizeof(ROPES));
write_n(STDOUT_FILENO, QUESTION1, sizeof(QUESTION1) - 1);
line_buf_read_stdin(&lb);
*lb.newline = 0;
/* This needs to be silly and obvious */
i = MIN(snprintf(out_buf, sizeof(out_buf), lb.buf), sizeof(out_buf));
i += MIN(snprintf(out_buf + i, sizeof(out_buf) - i,
", you coming here means you think you are a pwner.\n"
"But do you even ROP?> "),
sizeof(out_buf) - i);
line_buf_next(&lb);
write_n(STDOUT_FILENO, out_buf, i);
line_buf_read_stdin(&lb);
*lb.newline = 0;
if (strcmp(lb.buf, "HELL YEAH") != 0)
exit(EXIT_FAILURE);
line_buf_next(&lb);
write_n(STDOUT_FILENO, QUESTION3, sizeof(QUESTION3) - 1);
line_buf_read_stdin(&lb);
*lb.newline = 0;
i = atoi(lb.buf);
i += (i + 9) / 10;
line_buf_next(&lb);
write_n(STDOUT_FILENO, QUESTION4, sizeof(QUESTION4) - 1);
read_n(STDIN_FILENO, lb.current, i - (lb.current - lb.buf), "user input");
return EXIT_FAILURE;
}