![](/img/trans.png)
[英]Why does `&*(&*d)` return address of "c" instead of address of "b"?
[英]Why is jumping to the same address working with “technique” A but not with B?
我在這里寫了幾行黑客文:
這是makro luaL_openlib
的定義,它實際上是指向0x0090DE00
的函數指針:
/*
Type definitions for function signatures
*/
typedef int (luaL__openlib) (lua_State *L, const char *libname, const luaL_reg *l, int nup);
/*
Intercepting macros for function calls.
*/
#define luaL_openlib(L, libname, l, nup) ((luaL__openlib*) 0x0090DE00)(L, libname, l, nup)
這就是我所說的:
static int luaAi_helloworld(lua_State *L)
{
MessageBox(NULL, L"Hello World", L"", MB_OK);
return 1;
}
static const luaL_reg ai_funcs[] = {
{ "helloworld", luaAi_helloworld },
{ NULL, NULL }
};
void open_ailib(lua_State *L)
{
luaL_openlib(L, "ai", ai_funcs, 0);
}
上面的代碼被編譯成DLL。 DLL是由我的目標進程加載的,我對此做了一點破解。
但是: 這有效!
結果是我可以在計算機游戲的腳本中調用ai.helloworld()
來顯示“ Hello World”消息框。
現在,代碼看起來有點混亂,但是它做的是完全相同的事情:
static int scse_helloworld (lua_State *L)
{
MessageBox(NULL, L"Hello World", L"", MB_OK);
return 1;
}
static luaL_reg scselib[] = {
{"helloworld", scse_helloworld},
{NULL, NULL}
};
/*
Type definitions for function signatures
*/
typedef int (luaL__openlib)(lua_State *L, const char *libname, const luaL_reg *l, int nup);
/*
Intercepting macros for function calls.
*/
#define luaL_openlib2(L, libname, l, nup) ((luaL__openlib*) 0x0090de00)(L, libname, l, nup)
SCSE_API int luaopen_scse(lua_State *L)
{
SIZE_T numBytes;
const int num_bytes = 16;
unsigned char hook[num_bytes];
HANDLE process = GetCurrentProcess();
ReadProcessMemory(process, (LPVOID)(0x0090de00), &hook, sizeof(hook), &numBytes);
LOGGER.LogMessage("Memory at 0x0090de00 is:\n\n");
for (int i = 0; i < num_bytes; i++) {
LOGGER.LogMessage("%2X ", hook[i]);
}
// Link lua linker functions with Supreme Commander lua functions
if(LuaLinker::Link())
{
LOGGER.LogMessage("Lua linker functions successefully linked with Supreme Commander Lua functions.\n");
LOGGER.LogMessage("luaL_openlib2()");
luaL_openlib2(L, "scse", scselib, 0);
// Spoiler: This is never reached
LOGGER.LogMessage("SCSE library successefully opened.\n");
}
else {
LOGGER.LogMessage("ERROR: Couldn't link lua linker functions with Supreme Commander Lua functions!\n");
}
return 1;
}
另外,我還讀取了0x0090de00
處的內存。 我可以事先給你結果:
Memory at 0x0090de00 is:
53 8B 5C 24 14 55 56 8B 74 24 10 57 8B 7C 24 18
正如我們在OllyDbg中看到的那樣,這是正確的-盡管我已經知道:
那么,你為什么在這里?
問題是,可能您在上面看到的任何luaL_openlib2
都沒有顯示luaL_openlib2
之后的日志消息。 在我的日志文件中,我看到的是:
Lua linker functions successefully linked with Supreme Commander Lua functions.
luaL_openlib2()
游戲加載開始屏幕,但停止運行。 不顯示按鈕等。它不會崩潰,但是基本上已經死了。 當我關閉它時,我所得到的只是最后的求助:
我正在尋找一種解釋-我不明白為什么這不起作用。 我只有一個猜測:
我正在加載的DLL 不是由我加載的。 它實際上是由游戲的腳本引擎加載的。 實際上,應該不可能從游戲中加載DLL。 但是,由於執行了上述代碼,因此將加載DLL。 因此,如果加載了DLL,則可能是內存混亂了? 不,至少不是我要定位的函數的前16個字節,因此我認為其余的也可以,除此之外,實際上應該更改的內容-什么也不能做。
我不確定是否有人可以在這里幫助我,但這對我來說似乎是一個難題。
有人嗎
順便說一句:抱歉,標題-請隨時提出建議,如果您還沒有嘗試使用Supreme Commander ,那就趕快行動吧!
如果游戲應用程序加載了DLL,則DLL在單獨的進程中運行。 您的應用程序正在不同的進程中運行。 在第一種情況下,DLL和您的應用程序在同一進程中運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.