void
*(*old_luaL_loadbuffer)(
void
*L,
const
char
*buff,
size_t
size,
const
char
*name);
void
*new_luaL_loadbuffer(
void
*L,
const
char
*buff,
size_t
size,
const
char
*name) {
std::string s(name);
if
(s.length() < 128) {
replace_all(s,
"/"
,
"."
);
string path(
"/sdcard/lua/"
);
path.append(s);
FILE
*file =
fopen
(path.c_str(),
"r"
);
if
(file != NULL) {
fseek
(file, 0, SEEK_END);
size_t
new_size =
ftell
(file);
fseek
(file, 0, SEEK_SET);
LOGI(
"[-]file=%s"
, s.c_str());
char
*new_buff = (
char
*) alloca(new_size + 1);
fread
(new_buff, new_size, 1, file);
fclose
(file);
return
old_luaL_loadbuffer(L, new_buff, new_size, name);
}
}
void
*ret = old_luaL_loadbuffer(L, buff, size, name);
return
ret;
}