尝试读取进程内存时出现错误299

本文关键字:错误 内存 读取 取进程 | 更新日期: 2023-09-27 18:27:18

我在读取进程的内存时遇到了一些问题,我得到的只是错误299,有时是错误5/6,我对内存读取/写入很陌生,可以使用任何帮助。

这就是我目前所拥有的:

    private void ScanMemory()
    {
        uint PID;
        GetWindowThreadProcessId(GetWindowHandle(), out PID);
        label3.Text = "" + (int)PID;
        int valueToSearch = 4;
        List<int> matchAddresses = new List<int>();
        long MaxAddress = 0x7fffffff;
        long address = 0;
        do
        {
            MEMORY_BASIC_INFORMATION32 m;
            IntPtr Handle = OpenProcess((int)ProcessAccessFlags.All, false, (int)PID);
            uint result = VirtualQueryEx((int)Handle, (int)address, out m, (int)Marshal.SizeOf(typeof(MEMORY_BASIC_INFORMATION32)));
            if (address == (long)m.BaseAddress + (long)m.RegionSize)
                break;
            address = (long)m.BaseAddress + (long)m.RegionSize;
            SearchIntSizeValue(Handle, (int)m.BaseAddress, (int)m.RegionSize, valueToSearch, matchAddresses);
        } while (address <= MaxAddress);
        foreach (int res in matchAddresses)
        {
            listBox1.Items.Add(res);
        }
    }
    public void SearchIntSizeValue(IntPtr hProcess, int startAddress, int endAddress, int valueToSearch, List<int> addresses)
    {
        byte[] buffer = new byte[4];
        IntPtr bytesread;
        while (startAddress < endAddress)
        {
            ReadProcessMemory(hProcess, (IntPtr)startAddress, buffer, 4, out bytesread);
            int res = BitConverter.ToInt32(buffer, 0);
            if (res == valueToSearch)
            {
                addresses.Add(startAddress);
            }
            else
            {
                int le;
                if ((le = Marshal.GetLastWin32Error()) != 0)
                {
                }
            }
            startAddress += 4;
        }
    }
[StructLayout(LayoutKind.Sequential)]
 struct MEMORY_BASIC_INFORMATION32
{
    public uint BaseAddress;
    public uint AllocationBase;
    public int AllocationProtect;
    public uint RegionSize;
    public int State;
    public int Protect;
    public int lType;
}

我现在正在阅读int的大小,但并没有真正起作用:|,从谷歌上的阅读中,我看到了这个有特权的东西,不过,我在windows 7上使用管理员权限运行vs2010,我希望这是足够的信息,让你发现我的问题,提前感谢!

尝试读取进程内存时出现错误299

我在www.codeproject.com上帮助解决方案:解决监测标准输出的问题。

解决方案保护应用程序免受Microsoft文档中未提及的其他死锁的影响。