我想知道如何从使用 Lua 的程序中获取 Lua_State 的地址。我对汇编程序并不是很熟悉,但我对 C++ 非常了解。
这就是源代码的样子:
#pragma comment(lib, "lua51.lib")
#pragma comment(lib, "lua5.1.lib")
extern "C" {
#include <lua.h>
#include <lauxlib.h>
}
lua_State* L; // I want to get address of it but I haven't got source for remote program.
// So I could use this state in my DLL injected to remote program.
int main()
{
L = lua_open();
//////loops here and functions registers.
lua_close(L);
return 1;
}
我在 IDA 中自己尝试过,但并不知道如何找到它。在 IDA 中它看起来像这样
.text:00401000 ; =============== S U B R O U T I N E =======================================
.text:00401000
.text:00401000
.text:00401000 ; int __cdecl main(int argc, const char **argv, const char **envp)
.text:00401000 _main proc near ; CODE XREF: __tmainCRTStartup+10Ap
.text:00401000
.text:00401000 argc = dword ptr 4
.text:00401000 argv = dword ptr 8
.text:00401000 envp = dword ptr 0Ch
.text:00401000
.text:00401000 push esi
.text:00401001 call _luaL_newstate
.text:00401006 mov esi, ds:__imp__Sleep@4 ; Sleep(x)
.text:0040100C mov ?L@@3PAUlua_State@@A, eax ; lua_State * L
.text:00401011
.text:00401011 loc_401011: ; CODE XREF: _main+15j
.text:00401011 push 64h ; dwMilliseconds
.text:00401013 call esi ; Sleep(x) ; Sleep(x)
.text:00401015 jmp short loc_401011
.text:00401015 _main endp
.text:00401015
.text:00401015 ; ---------------------------------------------------------------------------
.text:00401017 align 4
.text:00401018 ; =============== S U B R O U T I N E =======================================
.text:00401018
.text:00401018 ; Attributes: thunk
.text:00401018
.text:00401018 _luaL_newstate proc near ; CODE XREF: _main+1p
.text:00401018 jmp ds:__imp__luaL_newstate
.text:00401018 _luaL_newstate endp
.text:00401018
.text:0040101E