【发布时间】:2021-01-15 15:11:41
【问题描述】:
现在假设您有两个具有不同 lua 实例的程序。一是主程序,二是你为它编写的dll。
在我的问题中,我将从现在开始将主程序命名为 main, dll i child。我们将子进程加载到主进程中,绕过它并以某种方式访问 lua_State。
我的主要问题是,我们可以在主程序运行时通过我们抓取的 lua_State 执行 lua_pcall 或 dofile 吗?
示例代码
主程序:
#include <lua.hpp>
bool loadFile(lua_State* L) {
// run the Lua script
luaL_dofile(L, "helloworld.lua");
if (lua_pcall(L, 0, 0, eh) != 0)
{
std::string err = luaL_checkstring(L, -1);
lua_pop(L, 1);
}
}
int main()
{
// create new Lua state
lua_State *lua_state;
lua_state = luaL_newstate();
loadFile(lua_state);
}
儿童节目:
#include <lua.hpp>
#include "hookingLibrary.h"
typedef int(__fastcall* main_loadFile_Proto)(lua_State* L);
main_loadFile_Proto main_loadFile_Ptr;
lua_State * L lastState;
uint64_t main_loadFile_Addr = 0x0;
int main_loadFile_Detour(lua_State* L) {
lastState = L;
return main_loadFile_Ptr(L);
}
int main()
{
// detouring etc.
// I do not put detouring codes here. I am just declaring it as an
// opinion.
HookingLibrary::hook((LPVOID)(uintptr_t)main_loadFile_Addr, &main_loadFile_Detour, (LPVOID*)&main_loadFile_Ptr);
do{
Sleep(100);
}while(!lastState);
// create new Lua state
lua_State *lua_state;
lua_state = lastState;
// run the Lua script
luaL_dofile(lua_state, "helloworld.lua");
// close the Lua state
lua_close(lua_state);
}
【问题讨论】:
-
这取决于:“main”是使用 Lua 作为 DLL 还是编译到程序中?