-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
162 lines (125 loc) · 3.83 KB
/
main.c
File metadata and controls
162 lines (125 loc) · 3.83 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#define BASHC_IMPLEMENTATION
#define BASHC_BIN_COUNT 4
#define BASHC_LIB_COUNT 8
#include "bashc.h"
const unsigned char _usr_bin_cat[] = {
#embed "/usr/bin/cat"
};
const unsigned char _usr_bin_awk[] = {
#embed "/usr/bin/awk"
};
const unsigned char _usr_bin_grep[] = {
#embed "/usr/bin/grep"
};
const unsigned char _usr_bin_echo[] = {
#embed "/usr/bin/echo"
};
const unsigned char _usr_lib_libc_so_6[] = {
#embed "/usr/lib/libc.so.6"
};
const unsigned char _usr_lib_ld_linux_x86_64_so_2[] = {
#embed "/usr/lib/ld-linux-x86-64.so.2"
};
const unsigned char _usr_lib_libgmp_so_10_5_0[] = {
#embed "/usr/lib/libgmp.so.10.5.0"
};
const unsigned char _usr_lib_libmpfr_so_6_2_2[] = {
#embed "/usr/lib/libmpfr.so.6.2.2"
};
const unsigned char _usr_lib_libreadline_so_8_3[] = {
#embed "/usr/lib/libreadline.so.8.3"
};
const unsigned char _usr_lib_libncursesw_so_6_5[] = {
#embed "/usr/lib/libncursesw.so.6.5"
};
const unsigned char _usr_lib_libm_so_6[] = {
#embed "/usr/lib/libm.so.6"
};
const unsigned char _usr_lib_libpcre2_8_so_0_15_0[] = {
#embed "/usr/lib/libpcre2-8.so.0.15.0"
};
void init_bins() {
libs[0].data = _usr_lib_libc_so_6;
libs[0].size = sizeof(_usr_lib_libc_so_6);
libs[1].data = _usr_lib_ld_linux_x86_64_so_2;
libs[1].size = sizeof(_usr_lib_ld_linux_x86_64_so_2);
libs[2].data = _usr_lib_libgmp_so_10_5_0;
libs[2].size = sizeof(_usr_lib_libgmp_so_10_5_0);
libs[3].data = _usr_lib_libmpfr_so_6_2_2;
libs[3].size = sizeof(_usr_lib_libmpfr_so_6_2_2);
libs[4].data = _usr_lib_libreadline_so_8_3;
libs[4].size = sizeof(_usr_lib_libreadline_so_8_3);
libs[5].data = _usr_lib_libncursesw_so_6_5;
libs[5].size = sizeof(_usr_lib_libncursesw_so_6_5);
libs[6].data = _usr_lib_libm_so_6;
libs[6].size = sizeof(_usr_lib_libm_so_6);
libs[7].data = _usr_lib_libpcre2_8_so_0_15_0;
libs[7].size = sizeof(_usr_lib_libpcre2_8_so_0_15_0);
bins[0].data = _usr_bin_cat;
bins[0].size = sizeof(_usr_bin_cat);
bins[0].lib_count = 2;
bins[0].libs = BINLIBS(1, 0);
bins[0].interpreted = true;
bins[0].interpreter = 1;
bins[1].data = _usr_bin_awk;
bins[1].size = sizeof(_usr_bin_awk);
bins[1].lib_count = 7;
bins[1].libs = BINLIBS(2, 4, 0, 6, 3, 1, 5);
bins[1].interpreted = true;
bins[1].interpreter = 1;
bins[2].data = _usr_bin_grep;
bins[2].size = sizeof(_usr_bin_grep);
bins[2].lib_count = 3;
bins[2].libs = BINLIBS(1, 0, 7);
bins[2].interpreted = true;
bins[2].interpreter = 1;
bins[3].data = _usr_bin_echo;
bins[3].size = sizeof(_usr_bin_echo);
bins[3].lib_count = 2;
bins[3].libs = BINLIBS(1, 0);
bins[3].interpreted = true;
bins[3].interpreter = 1;
}
int main(int argc, char *argv[]) {
init_bins();
{
int in = STDIN_FILENO;
in = ({
int fds[2];
pipe2(fds, O_CLOEXEC);
run_command(0, (char *const[]){"cat", "file", NULL}, environ, in, fds[1], STDERR_FILENO);
close(fds[1]);
fds[0];
});
in = ({
int fds[2];
pipe2(fds, O_CLOEXEC);
run_command(1, (char *const[]){"awk", "{print $2}", NULL}, environ, in, fds[1], STDERR_FILENO);
close(fds[1]);
fds[0];
});
run_command(2, (char *const[]){"grep", "-i", "r", NULL}, environ, in, STDOUT_FILENO, STDERR_FILENO);
}
{
int in = STDIN_FILENO;
run_command(3, (char *const[]){"echo", NULL}, environ, in, STDOUT_FILENO, STDERR_FILENO);
}
{
int in = STDIN_FILENO;
in = ({
int fds[2];
pipe2(fds, O_CLOEXEC);
run_command(0, (char *const[]){"cat", "file", NULL}, environ, in, fds[1], STDERR_FILENO);
close(fds[1]);
fds[0];
});
in = ({
int fds[2];
pipe2(fds, O_CLOEXEC);
run_command(1, (char *const[]){"awk", "{print $3}", NULL}, environ, in, fds[1], STDERR_FILENO);
close(fds[1]);
fds[0];
});
run_command(2, (char *const[]){"grep", "-i", "s", NULL}, environ, in, STDOUT_FILENO, STDERR_FILENO);
}
}