我正在编写一个小型内存扫描器应用程序来查找内存中的指针。
但我似乎没有得到预期的结果。
我有以下代码:
[DllImport("kernel32.dll")]
private static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] buffer, UInt32 size, IntPtr lpNumberOfBytesRead);
public int ReadInt(long Address)
{
byte[] buffer = new byte[4];
ReadProcessMemory(ProcessHandle, (IntPtr)Address, buffer, 4, IntPtr.Zero); // this always returns true
return BitConverter.ToInt32(buffer, 0);
}
public List<long> SearchInt(long start, long end, int value)
{
List<long> results = new List<long>();
for (long i = start; i < end; i++)
{
try
{
if (ReadInt(i) == value)
results.Add(i);
}
catch (Exception)
{
break; // no exceptions occur
}
}
return results;
}
如果我这样调用方法:
SearchInt(baseAddress.ToInt64(), lastAddress.ToInt64(), 1234)
我知道我正在读取的进程有一个值为 1234 的整数,但我没有得到任何结果。如果我扫描其他值,有时会得到结果。
baseAddress
是 process.MainModule.BaseAddress
和
lastAddress
是 baseAddress + process.MainModule.ModuleMemorySize
我在这里错过了什么吗?
最佳答案
如果您要搜索的值是在运行时初始化的并且不是静态编译代码的一部分,则此方法将不起作用。然后它将位于 BaseAddress
+ ModuleMemorySize
来自ProcessModule.ModuleMemorySize
:
ModuleMemorySize does not include any additional memory allocations that the module makes once it is running; it includes only the size of the static code and data in the module file.
关于c# - 内存扫描仪未找到结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18714878/