31
32
33
34
35
36
37
38
39
40
41
42
43
44
..
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
..
90
91
92
93
94
95
96
97
98
99
100
|
// load and run our payload
int e = luaL_loadbufferx(l, ct_bytecode, sizeof(ct_bytecode), "cortav", "b");
if (e != LUA_OK) {
printf("some kind of error idk fam\n");
return -1;
}
if (lua_pcall(l, 0, 0, 0) != LUA_OK) {
size_t len;
const char* msg = luaL_tolstring(l, -1, &len);
if (isatty(2)) {
fprintf(stderr, "\33[31;1m(fatal)\33[m %.*s\n", (int)len, msg);
} else {
................................................................................
io.stderr:write('(' .. arg[0]..' fatal) cannot open file '..arg[i])
end
return dflt
end
local src = setfile(1, io.stdin, "rb")
local dest = setfile(2, io.stdout, "w")
local cstr = {}
local strtpl = [[static char ct_bytecode [%u] = {
%s
};]]
local bytes = {}
local bn = 1
local len = 0
while true do
local byte = src:read(1)
................................................................................
bytes[bn] = str
bn = bn + 1
end
local lines = {
includes;
strtpl:format(#bytes, table.concat(bytes));
main;
}
dest:write(table.concat(lines, '\n'))
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
..
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
...
132
133
134
135
136
137
138
139
140
141
142
143
|
// load and run our payload
int e = luaL_loadbufferx(l, ct_bytecode, sizeof(ct_bytecode), "cortav", "b");
if (e != LUA_OK) {
printf("some kind of error idk fam\n");
return -1;
}
// create the native interface table, if nothing
// else to signal that cortav is running under a
// binary shim
lua_pushglobaltable(l);
lua_newtable(l);
_lua_env_setup
lua_setfield(l, -2, "native");
lua_pop(l, 1);
if (lua_pcall(l, 0, 0, 0) != LUA_OK) {
size_t len;
const char* msg = luaL_tolstring(l, -1, &len);
if (isatty(2)) {
fprintf(stderr, "\33[31;1m(fatal)\33[m %.*s\n", (int)len, msg);
} else {
................................................................................
io.stderr:write('(' .. arg[0]..' fatal) cannot open file '..arg[i])
end
return dflt
end
local src = setfile(1, io.stdin, "rb")
local dest = setfile(2, io.stdout, "w")
local binds = {}
for i=3,#arg do
io.stderr:write(string.format("(%s info) including loader for bind %s\n", arg[0], arg[i]))
table.insert(binds, arg[i])
end
local cstr = {}
local strtpl = [[static char ct_bytecode [%u] = {
%s
};]]
local bindfn = [[#define _lua_env_setup]]
if next(binds) then
-- make cpp do our interpolation for us
bindfn = [[#define _lua_env_setup init_binds(l);]]
local calls = {}
local decls = {}
local ctpl = [[
luaopen_bind_%s(l);
lua_setfield(l, -2, "%s");
]]
for n,b in ipairs(binds) do
table.insert(decls, string.format('extern int luaopen_bind_%s(lua_State* l);\n', b))
table.insert(calls, string.format(ctpl, b, b))
end
local hdr = [[
static void init_binds(lua_State* l) {
]]
local foot = [[
}
]]
bindfn = bindfn .. '\n'
.. table.concat(decls)
.. hdr
.. table.concat(calls)
.. foot
end
local bytes = {}
local bn = 1
local len = 0
while true do
local byte = src:read(1)
................................................................................
bytes[bn] = str
bn = bn + 1
end
local lines = {
includes;
strtpl:format(#bytes, table.concat(bytes));
bindfn;
main;
}
dest:write(table.concat(lines, '\n'))
|