简体   繁体   English

访问其他进程内存

[英]Access Other Process Memory

This line doesn't work in my code now here is the code and error 这行现在在我的代码中不起作用,这是代码和错误

uint PROCESS_ALL_ACCESS = (DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER | SYNCHRONIZE | END);

A field Initialize cannot reverence the non static field 初始化字段不能引用非静态字段

Here is the article i made this from: http://blackandodd.blogspot.com/2012/12/c-read-and-write-process-memory-in.html 这是我从以下网站获得的文章: http : //blackandodd.blogspot.com/2012/12/c-read-and-write-process-memory-in.html

public class MAin
{

    [DllImport("kernel32.dll")]
    public static extern int OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);

    [DllImport("kernel32.dll")]
    public static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, byte[] buffer, int size, int lpNumberOfBytesRead);

    [DllImport("kernel32.dll")]
    public static extern bool WriteProcessMemory(int hProcess, int lpBaseAddress, byte[] buffer, int size, int lpNumberOfBytesWritten);

    uint DELETE = 0x00010000;
    uint READ_CONTROL = 0x00020000;
    uint WRITE_DAC = 0x00040000;
    uint WRITE_OWNER = 0x00080000;
    uint SYNCHRONIZE = 0x00100000;
    uint END = 0xFFF; //if you have Windows XP or Windows Server 2003 you must change this to 0xFFFF
    uint PROCESS_ALL_ACCESS = (DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER | SYNCHRONIZE | END);



    public void OnLoad(){

        Console.WriteLine ("");

        Process[] p = Process.GetProcessesByName("notepad");

        int processHandle = OpenProcess(PROCESS_ALL_ACCESS, false, p[0].Id); 

    }


    public byte[] ReadMemory(int adress, int processSize, int processHandle) {
        byte[] buffer = new byte[processSize];
        ReadProcessMemory(processHandle, adress, buffer, processSize, 0);
        return buffer;
    }

    public void WriteMemory(int adress, byte[] processBytes, int processHandle) {
        WriteProcessMemory(processHandle, adress, processBytes, processBytes.Length, 0);
    }

    public int GetObjectSize(object TestObject) {
        BinaryFormatter bf = new BinaryFormatter();
        MemoryStream ms = new MemoryStream();
        byte[] Array;
        bf.Serialize(ms, TestObject);
        Array = ms.ToArray();
        return Array.Length;
    }
}

Change the definitions ( uint DELETE and all the others) to const uint DELETE , this will allow you to reference the values as an expression. 将定义( uint DELETE和所有其他定义)更改为const uint DELETE ,这将允许您将值引用为表达式。

const uint DELETE = 0x00010000;
const uint READ_CONTROL = 0x00020000;
const uint WRITE_DAC = 0x00040000;
const uint WRITE_OWNER = 0x00080000;
const uint SYNCHRONIZE = 0x00100000;
const uint END = 0xFFF; //if you have Windows XP or Windows Server 2003 you must change this to 0xFFFF
const uint PROCESS_ALL_ACCESS = (DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER | SYNCHRONIZE | END);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检测对进程的内存访问 - Detecting memory access to a process .NET 理解其他进程的内存/从其他进程读取变量 - .NET understanding memory of other process / read variables from other process 读取其他进程内存将返回问号 - Reading other process memory returns question marks 如何访问其他程序内存中的结构? - How to access structure in other program's memory? IIS 工作进程在需要任何其他应用程序之前不释放 memory memory - IIS Worker Process not releasing memory until any other Application required memory c#如果文件被其他进程处理,如何访问该文件? - c# How to access file if that file is processed by other process? SetupIconFile 上的 Inno Setup 错误 - 该进程无法访问该文件,因为它正被其他进程使用 - Inno Setup error on SetupIconFile - The process cannot access the file because it is being used by other process 进程无法访问文件“ \\ Path”,因为其他进程正在使用该文件 - Process Cannot Access the file “\Path” because it is being used by some other process 尝试读取或写入受保护的内存。 这通常表明 c# 中的其他内存已损坏(访问冲突) - Attempted to read or write protected memory. This is often an indication that other memory is corrupt in c# (Access violation) 使用MaxWorkingSet限制进程内存 - Limiting process memory with MaxWorkingSet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM