读取我自己的进程的内存,而不使用ReadProcessMemory



使用这种方式,我可以得到正确的值,但我想要一个如何在不使用 ReadProcessMemory 的情况下读取我自己进程的内存的示例。

var
  Modulo : HMODULE;
  Value1, Value2, Read : Cardinal;
  GetWindowTextAAPI: function (hWnd: HWND; lpString: PChar; nMaxCount: integer):integer; stdcall;
begin
  Modulo := GetModuleHandle('user32.dll');
  if (Modulo <> 0) then
  begin
    @GetWindowTextAAPI := GetProcAddress(Modulo, 'GetWindowTextA');
    if (@GetWindowTextAAPI <> nil) then
    begin
      ReadProcessMemory(GetCurrentProcess, Pointer(@GetWindowTextAAPI), Addr(Value1), 4, Read);
      ReadProcessMemory(GetCurrentProcess, Pointer(DWORD(@GetWindowTextAAPI)+4), Addr(Value2), 4, Read);
      ShowMessage(
      IntToStr(Value1)
      + ' ' +
      IntToStr(Value2)
      );
    end;
  end;
end;

如何正确使用复制内存功能?

从自己的进程中读取内存不需要执行任何特殊操作。这是您的程序一直在做的事情。你当然不需要ReadProcessMemory.相反,您只需取消引用指针。

由于您看起来对调用 API 函数不感兴趣,因此您可以从简化函数指针声明开始:

var
  GetWindowTextAAPI: PDWord;

然后,分配指针并读取值:

GetWindowTextAAPI := GetProcAddress(Modulo, 'GetWindowTextA');
Value1 := GetWindowTextAAPI^;

相关内容

  • 没有找到相关文章

最新更新