-1

I'm trying to read a value from another process using Python.

I came across this answer, though it doesn't seem to work.

My code:

from ctypes import *
from ctypes.wintypes import *
OpenProcess = windll.kernel32.OpenProcess
ReadProcessMemory = windll.kernel32.ReadProcessMemory
CloseHandle = windll.kernel32.CloseHandle
PROCESS_ALL_ACCESS = 0x1F0FFF
pid = 4580
address = 0x04782FF8
buffer = c_uint()
bufferSize = sizeof(buffer)
bytesRead = c_ulong(0)
processHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
if ReadProcessMemory(processHandle, address, buffer, bufferSize, byref(bytesRead)):
    print("Success:", buffer)
else:
    print("Failed.")

CloseHandle(processHandle)

GetLastError() seems to return 6, which means the handle is invalid.

Though, OpenProcess() returns a nonzero value, and GetLastError() doesn't show anything about it.

I've tried editing the first argument passed in OpenProcess() (which I made 0x0010), but still no results.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Invision
  • 90
  • 1
  • 10

1 Answers1

-1

The process ID was dec, and not hex, which broke a few things.

I also had to replace c_uint() with create_string_buffer(4) for the buffer.

Seems to work fine now!

Invision
  • 90
  • 1
  • 10