For one of my current projects, I'm using ReadProcessMemory() to search through a program's memory (0x00400000 -> 0x7FFFFFFF). This method is obviously obscure somehow as it takes hours to finish.
Some premade memory editors I've used have completed the same search in under 5 seconds, and I've searched for the more efficient method with no luck.
Would anybody happen to know, or have any ideas, on how to speed up my search?
For reference, this is the process I'm using:
My read function:
Code:public byte[] ReadProcessMemory(IntPtr MemoryAddress, uint bytesToRead, out int bytesReaded)
{
byte[] buffer = new byte[bytesToRead];
IntPtr ptrBytesReaded;
ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess, MemoryAddress, buffer, bytesToRead, out ptrBytesReaded);
bytesReaded = ptrBytesReaded.ToInt32();
return buffer;
}
And my calls:
So it's grabbing 5 bytes, 1 byte at a time. For each address. It grabs 5 because the array of bytes I'm looking for (an unchanging marker) is 5 bytes long.Code:for (int i = 0x00400000; i < 0x7FFFFFFF; i++)
{
tempRead = pReader.ReadProcessMemory((IntPtr)i, 5, out bytesRead);
//All my if statements, etc
}
My question, reiterated: Would anybody happen to know, or have any ideas, how the entire scope can be searched in < 10 seconds?