summaryrefslogtreecommitdiffstats
path: root/misplays.c
blob: 1d200a870acf710cba6861bcad104a6354633d20 (plain) (blame)
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 <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>

#include "console.h"
#include "helpers.h"

static char *const SPLOITCMD[] = {
    "/bin/bash", "-c", "sploit <(echo 'io.interact()') cat",
    NULL
};

static PANEL *left, *right;
static struct console p1, p2;
static int mode = 0;

static void layout(void) {
    int w = COLS/2;
    reset_panel(left, LINES, w, 0, 0);
    reset_panel(right, LINES, COLS-w, 0, w);
    //reset_panel(left, 0, 0, 0, 0);
    //reset_panel(right, 0, 0, 0, 0);
}

static void dofork(struct console *cons) {
    if (fork() == 0) {
        console_configslave(cons);
        close_range(STDERR_FILENO+1, ~0U, CLOSE_RANGE_UNSHARE);
        execvp(SPLOITCMD[0], SPLOITCMD);
        exit(1);
    }
}

int main(void) {
    cursinit();

    left = newpan(0, 0, 0, 0);
    right = newpan(0, 0, 0, 0);
    layout();

    console_init(&p1);
    console_init(&p2);
    dofork(&p1);
    dofork(&p2);

    int quit = 0;
    while (!quit) {
        console_update(&p1, left);
        console_update(&p2, right);
        cursupdate();
        int ch = getch();

        if (mode == 0) {
            switch (ch) {
                case 'q':
                    quit = 1;
                    break;
                case KEY_RESIZE:
                    layout();
                    break;
                case KEY_F(1):
                    mode = 1;
                    console_enter(&p1, left);
                    break;
                case KEY_F(2):
                    mode = 2;
                    console_enter(&p2, right);
                    break;
            }
        } else if (mode == 1) {
            switch (ch) {
                case KEY_RESIZE:
                    layout();
                    break;
                case 0x1b:
                    mode = 0;
                    console_leave(&p1, left);
                    break;
                case ERR:
                    break;
                default:
                    console_input(&p1, ch);
                    break;
            }
        } else {
            switch (ch) {
                case KEY_RESIZE:
                    layout();
                    break;
                case 0x1b:
                    mode = 0;
                    console_leave(&p2, right);
                    break;
                case ERR:
                    break;
                default:
                    console_input(&p2, ch);
                    break;
            }
        }
    }

    endwin();
    return 0;
}