【发布时间】:2016-07-02 12:48:40
【问题描述】:
我试过用Process.EnterDebugMode() 运行它,但它也不起作用。
我想读出Notepad-memory,但不知道如何访问,或者64位系统是否出现问题。
这就是我所做的:
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
public class MemoryRead
{
[DllImport("kernel32.dll")]
static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll")]
static extern bool ReadProcessMemory(int hProcess, Int64 lpBaseAddress, byte[] buffer, int size, ref int lpNumberOfBytesRead);
[DllImport("kernel32.dll")]
static extern bool CloseHandle(IntPtr hObject);
static void Main(string[] args)
{
var pid = 10956; //notepad.exe
var processHandle = OpenProcess(0x10, false, pid);
byte[] buffer = new byte[24];
int bytesRead = 0;
ReadProcessMemory((int)processHandle, 0x21106B35770, buffer, buffer.Length, ref bytesRead); //0x21106B35770 is the address where "hello world" is written in notepad
Console.WriteLine(Encoding.Unicode.GetString(buffer) +
" (" + bytesRead.ToString() + "bytes)");
Console.ReadLine();
CloseHandle(processHandle);
Console.ReadLine();
}
}
【问题讨论】:
-
以管理员身份运行您的应用程序
-
我认为你应该将它作为 x86 运行。我以前做过,不需要管理员权限
-
您可以在 www.pinvoke.net 中获取方法的 Pinvoke 声明
标签: c# access-denied readprocessmemory