gpt4 book ai didi

c# - 内存扫描器找不到结果

转载 作者:太空宇宙 更新时间:2023-11-03 10:58:03 25 4
gpt4 key购买 nike

我正在编写一个小型内存扫描器应用程序来查找内存中的指针。
但我似乎没有得到预期的结果。

我有以下代码:

[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 的整数,但我没有得到任何结果。如果我扫描其他值,我有时会得到结果。

baseAddressprocess.MainModule.BaseAddress

lastAddressbaseAddress + 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com