-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrontend.c
executable file
·60 lines (46 loc) · 1.2 KB
/
frontend.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
#define _(STRING) gettext(STRING)
#define IS_FRONTEND_ENTRY
#include "main.c"
#include <locale.h>
#include <libintl.h>
#include <windham_const.h>
#define INIT_STR \
u8"/bin/sh\xffOpen\xffTAB"
volatile const char init_str[256] __attribute__((section(".windhaminit"))) = u8"WINDHAMINIT:\xff" INIT_STR;
void parse_and_call() {
int argc = 0;
char **argv = NULL;
size_t len = strlen((const char *)init_str + strlen("WINDHAMINIT:\xff"));
char *copy = malloc(len + 1);
memcpy(copy, (const char *)init_str + strlen("WINDHAMINIT:\xff"), len + 1);
for (size_t i = 0; i < len; i++) {
if ((unsigned char)copy[i] == 0xff) {
argc++;
copy[i] = '\0';
}
}
argc++;
argv = malloc(argc * sizeof(char *));
char *ptr = copy;
for (int i = 0; i < argc; i++) {
argv[i] = ptr;
ptr += strlen(ptr) + 1;
}
init_process = argv[0];
main_(argc, argv);
free(argv);
free(copy);
}
int main(int argc, char * argv[argc]) {
is_pid1 = getpid() == 1;
if (is_pid1){
parse_and_call();
exit(0);
}
setlocale(LC_ALL, "");
bindtextdomain("windham", "/usr/share/locale");
textdomain("windham");
tcgetattr(STDIN_FILENO, &oldt);
main_(argc, argv);
return 0;
}