从其他进程读取和写入 [英] read and write from other process

查看:26
本文介绍了从其他进程读取和写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够从另一个进程的内存中读取和写入.我调用了 Kernel32.dll 中的 Readprocessmemory()WriteProcessmemory() 函数,并使用了 GetProcessByName()函数来查找进程.这成功了.

I want to be able to read and write from another process's memory. I called the functions Readprocessmemory() and WriteProcessmemory() from Kernel32.dll and I used the GetProcessByName() function to look for the process. This succeeds.

我看到了使用 readprocessmemory() 函数并在从 kernel32.dll 调用它后声明它的示例,但我不明白它是如何工作的 - 如何使用该函数从另一个进程读取?我会很感激的一个例子.

I saw the example for taking the readprocessmemory() function and declare it after I call it from kernel32.dll, but I do not understand how it works - how do I use the function to read from another process? I would appreciate an example.

推荐答案

为了向另一个进程读取和写入内存,您需要使用 kernel32 提供的 ReadProcessMemory 和 WriteProcessMemory 函数.如果您使用的是 C#,则需要使用 PInvoke 将这些函数导入到您当前的进程中.

In order to read and write memory to another process you need to use the ReadProcessMemory and WriteProcessMemory functions provided by kernel32. If you are using C# you will need to use PInvoke to import these functions into your current process.

更一般地说,您需要做的是:

More generally, what you need to do is this:

  • 确定您想要读取/注入的进程
  • 调用 OpenProcess() 来获取进程的句柄.您需要发送 GENERIC_READ |GENERIC_WRITE 作为对此的标志,您将得到一个 HPROCESS,您需要检查它是否为 NULL.
  • 决定要从外部进程中读取的位置(这是一个外部进程指针).您还需要决定要读取的字节数.
  • 在当前进程中分配那么多字节来保存读取结果.
  • 调用 ReadProcessMemory 传入您已打开的 HPROCESS、要在其他进程中读取的外部进程指针、指向本地缓冲区的指针以及要从外部进程读取到本地的字节数缓冲区.

完成此操作后,您可以查看本地缓冲区,您会看到以前在外部进程中的数据,一切都会好起来的.

Once this is done you can look at your local buffer and you'll see data that used to be in the foreign process, and life will be good.

这篇关于从其他进程读取和写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆