我有一个应用程序,它使用修改版的Lua 5.2。Lua嵌入在exe中,就我所知(使用Dependency Walker),没有导出其Lua函数的符号。我没有这个应用程序的源代码。我需要为Lua编写C模块,以便与这个应用程序一起使用。
我成功地在这个应用程序处理的Lua文件中进行了require,但是只要我尝试调用任何lua_*函数,应用程序就会崩溃并显示“访问冲突”错误。
有没有办法找到嵌入式Lua函数的地址/名称并调用它们?
我问过应用程序开发人员是否允许我这样做,他们似乎不在意。唯一的问题是禁止修改应用程序本身。
更新:就我所见,我之所以遇到“访问冲突”,是因为我正在尝试使用Lua代理库,并且它无法将调用传递给exe Lua C函数。如果我不使用Proxy DLL,我会收到“检测到多个VMs”的消息。有没有办法解决这个问题?
我的Lua C模块代码:
对于那些问“什么是Lua代理库”的人:
我成功地在这个应用程序处理的Lua文件中进行了require,但是只要我尝试调用任何lua_*函数,应用程序就会崩溃并显示“访问冲突”错误。
有没有办法找到嵌入式Lua函数的地址/名称并调用它们?
我问过应用程序开发人员是否允许我这样做,他们似乎不在意。唯一的问题是禁止修改应用程序本身。
更新:就我所见,我之所以遇到“访问冲突”,是因为我正在尝试使用Lua代理库,并且它无法将调用传递给exe Lua C函数。如果我不使用Proxy DLL,我会收到“检测到多个VMs”的消息。有没有办法解决这个问题?
我的Lua C模块代码:
#if defined(WIN32) || defined(_WIN32)
# define LUA_BUILD_AS_DLL /* for #define LUA_API __declspec(dllimport) */
#endif
#ifdef __cplusplus
extern "C" {
#endif
#include <lua.h>
#include <lauxlib.h>
#ifdef __cplusplus
}
#endif
#if defined(WIN32) || defined(_WIN32)
# ifdef __cplusplus
# define MY_LUA_API extern "C" __declspec(dllexport)
# else
# define MY_LUA_API __declspec(dllexport)
# endif
#else
# define MY_LUA_API extern "C"
#endif
using namespace std;
static int Lmytest_test(lua_State *L) {
// Check the arguments.
int argn = lua_gettop(L);
if (argn != 1 || !lua_isstring(L, 1)) {
lua_pushstring(L, "Give me one string argument please!");
lua_error(L);
}
lua_pushstring(L, "Hello world!");
return 2;
}
static const struct luaL_Reg lib[] = {
{ "test", Lmytest_test },
{ NULL, NULL }
};
MY_LUA_API int luaopen_mytest(lua_State* L) {
printf("Before newlib\n");
#if LUA_VERSION_NUM >= 502
luaL_newlib(L, lib);
#else
lua_createtable(L, 0, sizeof(lib) / sizeof(lib[0]));
luaL_register(L, NULL, lib);
#endif
printf("After newlib\n");
return 1;
}
对于那些问“什么是Lua代理库”的人:
http://lua-users.org/wiki/LuaProxyDll
http://lua-users.org/wiki/LuaProxyDllTwo
int luaopen_hello(lua_State *L) { printf("Hello from C!\n"); return 0; }
然后使用require("hello")
加载它。如果它打印出了Hello from C!
,那么你可能在你的模块中做错了些什么;如果还打印出了“Access violation”,那么程序的作者已禁用了加载模块的功能。 - Henri Menkelua_*
函数,它将崩溃并显示此消息。 - user64675