2010-04-03 30 views
2
require "alien" 

--the address im trying to edit in the Mahjong game on Win7 
local SCOREREF = 0x0744D554 
--this should give me full access to the process 
local ACCESS = 0x001F0FFF 
--this is my process ID for my open window of Mahjong 
local PID = 1136 

--function to open proc 
local op = alien.Kernel32.OpenProcess 
op:types{ ret = "pointer", abi = "stdcall"; "int", "int", "int"} 

--function to write to proc mem 
local wm = alien.Kernel32.WriteProcessMemory 
wm:types{ ret = "long", abi = "stdcall"; "pointer", "pointer", "pointer", "long", "pointer" } 


local pRef = op(ACCESS, true, PID) 
local buf = alien.buffer("99") 

--   ptr,uint32,byte arr (no idea what to make this),int, ptr 
print(wm(pRef, SCOREREF, buf, 4, nil)) 
--prints 1 if success, 0 if failed 

这就是我的代码。我甚至不确定是否正确设置了类型。Lua Alien模块 - 使用WriteProcessMemory函数时遇到问题,不确定类型(unit32)

我完全失去了,需要一些指导。我真的希望有更多的外来在线帮助/文档,它会让我可怜的大脑混乱。

什么让我感到困惑的是,它WriteProcessMemory有时会成功完成(虽然它根本不知道),并且有时也无法成功完成。正如我所说,我的大脑受伤了。

任何帮助表示赞赏。

回答

0

它看起来像您的缓冲区只包含2个字节(“99”),但您在调用WriteProcessMemory时指定4个字节。

如果你的意图是要写入32位值99到内存中(如数字,不是一个ASCII字符串),你可以使用:

alien.buffer("\99\0\0\0") 

您可以任意整数转换为使用alien.struct.pack字符串表示:

require "alien.struct" 
s = alien.struct.pack('i', 99) 
buf = alien.buffer(s) 
+0

这似乎没有改变程序的行为。感谢您的回复! 更多信息; OpenProcess函数返回'userdata:00000048'。这是它应该返回的正确例子吗? – user308355 2010-04-04 05:04:12

+0

我认为OpenProcess不能正常工作,我试图让它在我们说话时正常工作。 – user308355 2010-04-04 08:31:48

+0

@jefferysanders:OpenProcess返回非零结果意味着它成功。如果WriteProcessMemory失败,您可以调用GetLastError来查看原因。也许你需要先打电话给VirtualProtectEx先给自己写许可。 – interjay 2010-04-04 11:42:01

相关问题