Microsoft
Software
Hardware
Network
Question : Writing directly to memory.
I just spent an hour trying to find this on Google. So you guys really are my last resort :)
Is it possible to read and write directly to a memory address using Python? And if it is possible, how?
Thanks.
Answer : Writing directly to memory.
You'll need to use ctypes (
http://starship.python.ne
t/crew/the
ller/ctype
s/
) to drive the Win32 API. Below is an example that uses ReadProcessMemory to read another process's memory. There's an equivalent WriteProcessMemory for going the other way.
from ctypes import *
from ctypes.wintypes import *
OpenProcess = windll.kernel32.OpenProces
s
ReadProcessMemory = windll.kernel32.ReadProces
sMemory
CloseHandle = windll.kernel32.CloseHandl
e
PROCESS_ALL_ACCESS = 0x1F0FFF
pid = 4044 # I assume you have this from somewhere.
address = 0x1000000 # Likewise; for illustration I'll get the .exe header.
buffer = c_char_p("The data goes here")
bufferSize = len(buffer.value)
bytesRead = c_ulong(0)
processHandle = OpenProcess(PROCESS_ALL_AC
CESS, False, pid)
if ReadProcessMemory(processH
andle, address, buffer, bufferSize, byref(bytesRead)):
print "Success:", buffer
else:
print "Failed."
CloseHandle(processHandle)
Random Solutions
nslookup problem
Can't use NTbackup on ISA Server - Error 11, 12292
NTBackup not responding
Hide original sender to distribution group
Server Side Application
Command Line parameters into CeRunAppAtTime
PPTP port need to open on firewall
Network neigborhood
Tranform Data in DTS
Microsoft, Windows, XP, DHCP Ping Issues