ctypes.readprocess memory

Michael C <[email protected]> Wed, 27 Sep 2017 17:12:06 -0700
Newsgroups gmane.comp.python.ctypes
Message-ID <CANyKM1i6tQgnqLL_KXPV67ZKLh12u7MunwXap=F-fTop+-04qw@mail.gmail.com>
--===============0529479370579386838==
Content-Type: multipart/alternative; boundary="001a11c1862641357d055a34c200"

--001a11c1862641357d055a34c200
Content-Type: text/plain; charset="UTF-8"

I am trying to figure out how to extract some information from this game I
have!

But I have run into a few problems:

All this code prints is this line:
        print('something is wrong')

because readprocessmemory isn't working properly, and I have no idea why!
Please take a look, thanks!




>code starts here

import ctypes

# setup ctypes.
User32 = ctypes.WinDLL('User32', use_last_error=True)
Kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)

PID = 5924 # or anything other number.

PROCESS_QUERY_INFORMATION = 0x0400
PROCESS_VM_READ = 0x0010

Process = Kernel32.OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,
False, PID)
ReadProcessMemory = Kernel32.ReadProcessMemory


# Did I set these up properly?
buffer = ctypes.create_string_buffer(4)
bufferSize = (ctypes.sizeof(buffer))


# I need a way to find out how big the process is!
for n in range(1000000000):
    if ReadProcessMemory(Process, n, buffer, bufferSize, None):
        print('buffer is: ',buffer)
    else:
        print('something is wrong')



print('Done.')

--001a11c1862641357d055a34c200
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I am trying to figure out how to extract some informa=
tion from this game I have!</div><div><br></div><div>But I have run into a =
few problems:</div><div><br></div><div>All this code prints is this line:</=
div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 print(&#39;something is wrong&#39;)<br=
></div><div><br></div><div>because readprocessmemory isn&#39;t working prop=
erly, and I have no idea why!</div><div>Please take a look, thanks!</div><d=
iv><br></div><div><br></div><div><br></div><div><br></div><div>&gt;code sta=
rts here</div><div><br></div><div>import ctypes</div><div><br></div><div># =
setup ctypes.</div><div>User32 =3D ctypes.WinDLL(&#39;User32&#39;, use_last=
_error=3DTrue)</div><div>Kernel32 =3D ctypes.WinDLL(&#39;kernel32&#39;, use=
_last_error=3DTrue)</div><div><br></div><div>PID =3D 5924 # or anything oth=
er number.</div><div><br></div><div>PROCESS_QUERY_INFORMATION =3D 0x0400</d=
iv><div>PROCESS_VM_READ =3D 0x0010</div><div><br></div><div>Process =3D Ker=
nel32.OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, False, PID)=C2=
=A0 =C2=A0</div><div>ReadProcessMemory =3D Kernel32.ReadProcessMemory</div>=
<div><br></div><div><br></div><div># Did I set these up properly?</div><div=
>buffer =3D ctypes.create_string_buffer(4)</div><div>bufferSize =3D (ctypes=
.sizeof(buffer))</div><div><br></div><div><br></div><div># I need a way to =
find out how big the process is!</div><div>for n in range(1000000000):</div=
><div>=C2=A0 =C2=A0 if ReadProcessMemory(Process, n, buffer, bufferSize, No=
ne):</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 print(&#39;buffer is: &#39;,buff=
er)</div><div>=C2=A0 =C2=A0 else:</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 pri=
nt(&#39;something is wrong&#39;)</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0=C2=A0</div><div><br></div><div><br></div><div>print(&#39;Done.&#=
39;)</div><div>=C2=A0</div></div>

--001a11c1862641357d055a34c200--


--===============0529479370579386838==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
--===============0529479370579386838==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users

--===============0529479370579386838==--