我正在尝试使用 luaC api 中的自定义函数来编辑内存,但是例如,当我喜欢 3 lua_tonumber(LS, -1) 时,它会混淆吗?请尝试查看我的代码并告诉我如何解决此问题..
lua_State *L;
using namespace std;
DWORD MyGetProcessId(LPCTSTR ProcessName)
{
PROCESSENTRY32 pt;
HANDLE hsnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
pt.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hsnap, &pt)) {
do {
if (!lstrcmpi(pt.szExeFile, ProcessName)) {
CloseHandle(hsnap);
return pt.th32ProcessID;
}
} while (Process32Next(hsnap, &pt));
}
CloseHandle(hsnap);
return 0;
}
int CustomGetProcessByName(lua_State* Ls) {
DWORD dieman = MyGetProcessId(lua_tostring(Ls, -1));
lua_pushvalue(Ls, dieman);
return 1;
}
int CustomWriteMemInt(lua_State* Ls) {
HANDLE ProcHand = OpenProcess(PROCESS_ALL_ACCESS, FALSE, lua_tonumber(Ls, -1));
int Value = lua_tonumber(Ls, -3);
WriteProcessMemory(ProcHand, (LPVOID)lua_topointer(Ls, -2), &Value, sizeof(Value), 0);
return 1;
}
void Load() {
L = luaL_newstate();
lua_register(L, "GetProcByName", CustomGetProcessByName);
lua_register(L, "WriteMemInt", CustomWriteMemInt);
}
int main() {
Load();
luaL_dostring(L, "a = GetProcByName('ac_client.exe')");
luaL_dostring(L, "WriteMemInt(a, 0x0293AA60, 9999)");
system("Pause");
}
我知道写作记忆功能有效,因为我没有这个就做到了..