tags:

views:

100

answers:

1
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

So that is my code. I am not even sure if I have the types set correctly.

I am completely lost and need some guidance. I really wish there was more online help/documentation for alien, it confuses my poor brain.

What utterly baffles me is that it WriteProcessMemory will sometimes complete successfully (though it does nothing at all, to my knowledge) and will also sometimes fail to complete successfully. As I've stated, my brain hurts.

Any help appreciated.

A: 

It looks like your buffer contains only 2 bytes ("99"), but you specify 4 bytes in the call to WriteProcessMemory.

If your intention was to write the 32-bit value 99 into memory (as a number, not an ASCII string), you can use:

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

You can convert arbitrary integers to string representations using alien.struct.pack:

require "alien.struct"
s = alien.struct.pack('i', 99)
buf = alien.buffer(s)
interjay
This doesn't seem to change the behaviour of the program. Thanks for the reply though!Some more information; the OpenProcess function returns `userdata: 00000048`. Is this a correct example of what it should return?
I figure the OpenProcess isn't working, I'm trying to get it working as we speak.
@jefferysanders: OpenProcess returning a nonzero result means it succeeded. If WriteProcessMemory fails you can call GetLastError to see why. Maybe you need to call VirtualProtectEx to give yourself write permission first.
interjay