This function should execute at a speed on par with simply looping ReadProcessMemory between OpenProcess and CloseHandle.; Automatically closes handle when a new (or null) program is indicated ; Otherwise, keeps the process handle open between calls that specify the ; same program. When finished reading memory, call this function with no ; parameters to close the process handle i.e: "Closed := ReadMemory()" ReadMemory(MADDRESS=0,PROGRAM="") { Static OLDPROC, ProcessHandle VarSetCapacity(MVALUE,4,0) If PROGRAM != %OLDPROC% { WinGet, pid, pid, % OLDPROC := PROGRAM ProcessHandle := ( ProcessHandle ? 0*(closed:=DllCall("CloseHandle" ,"UInt",ProcessHandle)) : 0 )+(pid ? DllCall("OpenProcess" ,"Int",16,"Int",0,"UInt",pid) : 0) } If (ProcessHandle) && DllCall("ReadProcessMemory","UInt" ,ProcessHandle,"UInt",MADDRESS,"Str",MVALUE,"UInt",4,"UInt *",0) return *(&MVALUE+3)<<24 | *(&MVALUE+2)<<16 | *(&MVALUE+1)<<8 | *(&MVALUE) return !ProcessHandle ? "Handle Closed: " closed : "Fail" }
Helllo VxE, can you pleease tell me why this code block below returns FAIL instead of 10 as it should? I first have open Calculator before running, but is still not working.
ReadMemory(MADDRESS=0,PROGRAM="") { Static OLDPROC, ProcessHandle VarSetCapacity(MVALUE,4,0) If PROGRAM != %OLDPROC% { WinGet, pid, pid, % OLDPROC := PROGRAM ProcessHandle := ( ProcessHandle ? 0*(closed:=DllCall("CloseHandle" ,"UInt",ProcessHandle)) : 0 )+(pid ? DllCall("OpenProcess" ,"Int",16,"Int",0,"UInt",pid) : 0) } If (ProcessHandle) && DllCall("ReadProcessMemory","UInt" ,ProcessHandle,"UInt",MADDRESS,"Str",MVALUE,"UInt",4,"UInt *",0) return *(&MVALUE+3)<<24 | *(&MVALUE+2)<<16 | *(&MVALUE+1)<<8 | *(&MVALUE) return !ProcessHandle ? "Handle Closed: " closed : "Fail" } WriteMemory(WVALUE,MADDRESS,PROGRAM) { winget, pid, PID, %PROGRAM% ProcessHandle := DllCall("OpenProcess", "int", 2035711, "char", 0, "UInt", PID, "UInt") DllCall("WriteProcessMemory", "UInt", ProcessHandle, "UInt", MADDRESS, "Uint*", WVALUE, "Uint", 4, "Uint *", 0) DllCall("CloseHandle", "int", ProcessHandle) return } WriteMemory(10, 0x41000C,"Calc") sleep, 1000 value:=ReadMemory(0x41000C,"Calc") msgbox, Memory address 0x41000C = %value%
What am I possibly doing wrong here?