Delphi | Чтение карты памяти

unit unitMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TfrmMain = class(TForm)
    btnInfo: TButton;
    Memo1: TMemo;
    Button1: TButton;
    procedure btnInfoClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;

implementation

{$R *.dfm}

procedure TfrmMain.btnInfoClick(Sender: TObject);
var
  mySystemInfo:TSystemInfo;
  myMinP,myMaxP,mTemp:Pointer;
  myMemBasInfo:TMemoryBasicInformation;
  i:DWORD;
  iFree,iCommit,iReserve,iPageReadWrite,iReadOnly, iNoAccess,iWriteCopy,iExecute,iExecuteRead,iExecuteReadWrite:Integer;
  iExecuteWriteCopy,iGuard,iNoCache:integer;
begin
  Memo1.Lines.Clear;
  GetSystemInfo(mySystemInfo);
  myMinP:=mySystemInfo.lpMinimumApplicationAddress;
  myMaxP:=mySystemInfo.lpMaximumApplicationAddress;
  Memo1.Lines.Add('Начальный адрес: '+IntToStr(DWORD(myMinP)));
  Memo1.Lines.Add('Конечный адрес: '+IntToStr(DWORD(myMaxP)));
  i:=DWORD(myMinP);
  while i<=(DWORD(myMaxP)) do
  begin
    VirtualQuery(Pointer(i),myMemBasInfo,SizeOf(myMemBasInfo));
    case myMemBasInfo.State of
    MEM_FREE:
      inc(iFree,myMemBasInfo.RegionSize);
    MEM_RESERVE:
      inc(iReserve,myMemBasInfo.RegionSize);
    MEM_COMMIT:
      case myMemBasInfo.Type_9 of
      MEM_IMAGE:
        inc(iCommit,myMemBasInfo.RegionSize);
      MEM_MAPPED:
        inc(iCommit,myMemBasInfo.RegionSize);
      MEM_PRIVATE:
        inc(iCommit,myMemBasInfo.RegionSize);
      end;
    end;
    case myMemBasInfo.AllocationProtect of
      PAGE_NOACCESS: inc(iNoAccess,myMemBasInfo.RegionSize);
      PAGE_READONLY: inc(iReadOnly,myMemBasInfo.RegionSize);
      PAGE_READWRITE: inc(iPageReadWrite,myMemBasInfo.RegionSize);
      PAGE_WRITECOPY: inc(iWriteCopy,myMemBasInfo.RegionSize);
      PAGE_EXECUTE: inc(iExecute,myMemBasInfo.RegionSize);
      PAGE_EXECUTE_READ: inc(iExecuteRead,myMemBasInfo.RegionSize);
      PAGE_EXECUTE_READWRITE: inc(iExecuteReadWrite,myMemBasInfo.RegionSize);
      PAGE_EXECUTE_WRITECOPY: inc(iExecuteWriteCopy,myMemBasInfo.RegionSize);
      PAGE_GUARD: inc(iGuard,myMemBasInfo.RegionSize);
      PAGE_NOCACHE: inc(iNoCache,myMemBasInfo.RegionSize);
    end;
    inc(i,myMemBasInfo.RegionSize);
  end;

  Memo1.Lines.Add('');
  Memo1.Lines.Add('Закреплено: '+IntToStr(iCommit));
  Memo1.Lines.Add('Свободно: '+IntToStr(iFree));
  Memo1.Lines.Add('Зарезервированно: '+IntToStr(iReserve));
  Memo1.Lines.Add('');
  Memo1.Lines.Add('PAGE_READONLY: '+IntToStr(iReadOnly));
  Memo1.Lines.Add('PAGE_READWRITE: '+IntToStr(iPageReadWrite));
  Memo1.Lines.Add('PAGE_NOACCESS: '+IntToStr(iNoAccess));
  Memo1.Lines.Add('PAGE_WRITECOPY: '+IntToStr(iWriteCopy));
  Memo1.Lines.Add('PAGE_EXECUTE: '+IntToStr(iExecute));
  Memo1.Lines.Add('PAGE_EXECUTE_READ: '+IntToStr(iExecuteRead));
  Memo1.Lines.Add('PAGE_EXECUTE_READWRITE: '+IntToStr(iExecuteReadWrite));
  Memo1.Lines.Add('PAGE_EXECUTE_WRITECOPY: '+IntToStr(iExecuteWriteCopy));
  Memo1.Lines.Add('PAGE_GUARD: '+IntToStr(iGuard));
  Memo1.Lines.Add('PAGE_NOCACHE: '+IntToStr(iNoCache));
end;

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  GetCurrentProcessId;
end;

end.
 
Скачать исходник можно отсюда
dle

Помоги проекту! Расскажи друзьям об этом сайте: