Answer the question
In order to leave comments, you need to log in
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
The issue was resolved. It was necessary to update each time hand = pr.Handle;
Please advise which direction to go
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 questionAsk a Question
731 491 924 answers to any question