尝试读取进程内存时出现错误 299 [英] Error 299 when trying to read process memory
问题描述
我在读取进程的内存时遇到了一些问题,我得到的只是错误 299,有时是错误 5/6,我是内存读取/写入的新手,可以使用任何帮助.
i'm having some problem with reading process's memory, all i get is error 299, sometimes error 5/6, i'm new to memory reading / writing and can use any help.
这是我目前所拥有的:
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,我希望它足够了信息让您发现我的问题,提前致谢!
i'm reading size of int at the moment, not really working :|, from reading in google, i saw there is this thing with privilege , though, i run vs2010 with Admin rights on windows 7, i hope it's enough information for you to spot my problme, thanks in advance!
推荐答案
Me help solution on www.codeproject.com:解决监测问题的标准输出.
Me helped solution on www.codeproject.com: Solving-Problems-of-Monitoring-Standard-Output.
解决方案保护应用程序免受 Microsoft 在其文档中未提及的其他死锁.
Solution protect application from additional deadlocks that Microsoft does not mention in their documentation.
这篇关于尝试读取进程内存时出现错误 299的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!