A
A
algotrader20132015-01-05 22:40:27
C++ / C#
algotrader2013, 2015-01-05 22:40:27

Why can't ReadProcessMemory be called in an infinite loop?

In C#, I wrote a program that first defines a pointer to the process
pname = ProcName.Replace(".exe", "");
Process[] proclist = Process.GetProcesses();
foreach (Process pr in proclist)
{
if (pr.ToString() == "System.Diagnostics.Process(" + pname + ")")
{
hand = pr.Handle;
}
}
after which an infinite reading takes place at a known memory address (the address is taken from CheatEngine)
ReadProcessMemory(hand, (IntPtr)Address, ret, (UInt32)ret.Length, ref o);
Thread.Sleep(1);
Everything starts up and works, but not for long, after about a minute it starts returning zeros. If you repeat the definition of the pointer to the process and restart the thread with an infinite loop, then it works again for a couple of minutes.
Please suggest which direction to go

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
algotrader2013, 2015-01-12
@algotrader2013

The issue was resolved. It was necessary to update each time hand = pr.Handle;

J
jcmvbkbc, 2015-01-06
@jcmvbkbc

Please advise which direction to go

Look at the result returned by ReadProcessMemory, if there is false, then at GetLastError.

A
AxisPod, 2015-01-12
@AxisPod

Well, it's worth understanding how memory is handled. For example, the .NET garbage collector performs defragmentation for small objects during collection, and after a while the data at a known address will be lost. Other garbage collectors may do the same. Maybe protection, etc. So the problem here is most likely in the application from which you are reading the data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question