我在阅读进程的内存时遇到了一些问题,我得到的只是错误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管理员权限,我希望它足够了您可以提前感谢您发现我的问题的信息!
答案 0 :(得分:0)
我帮助解决了www.codeproject.com:Solving-Problems-of-Monitoring-Standard-Output。
解决方案保护应用程序免受Microsoft在其文档中未提及的其他死锁。