c# - 内存扫描仪未找到结果

标签 c# pointers memory readprocessmemory

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

我有以下代码:

[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/

相关文章:

c# - 错误无法将类型'string'隐式转换为'int'-ForEach循环中的迭代器

c# - 有没有办法在 Api Controller 中获取当前用户

c - typedef 结构体和指针

java - 是由 jvm 限制的 C 代码在 JNA(或 JNI)中分配的内存(参数 -Xmx 或架构 32/64)

java - Hotspot Java/JVM 是如何存储内存的?

c++ - 静态对象如何跨 DLL 和 Windows 二进制内存共享

c# - 当我想要同名控件时如何处理 "FindControl requires that controls have unique IDs"?

c++ - 指针中(星号)的确切用途是什么?

c - 如何声明函数一次传递一个参数 argv[i]?在C中

c# - 如何监控麦克风的噪音?