在不使用ReadProcessMemory的情况下读取我自己进程的内存

时间:2016-05-22 19:59:51

标签: delphi readprocessmemory copymemory

使用这种方式我可以获得正确的值,但是我想要一个如何在不使用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;

如何正确使用CopyMemory函数?

1 个答案:

答案 0 :(得分:0)

从您自己的进程中读取内存时,您无需做任何特殊操作。这是你的程序已经一直在做什么。你当然不需要ReadProcessMemory。相反,您只需取消引用指针。

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

var
  GetWindowTextAAPI: PDWord;

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

GetWindowTextAAPI := GetProcAddress(Modulo, 'GetWindowTextA');
Value1 := GetWindowTextAAPI^;
相关问题