this slowpoke moves

Process Query Information

uses tlhelp32, psAPI

//

procedure TForm1.Button1Click(Sender: TObject);

var
  Process: THandle;
  Mbi: TMemoryBasicInformation;
  Filename: array [0..MAX_PATH] of Char;
  Txt: string;
begin
  Memo1.Clear();
  Process := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_OPERATION or
  PROCESS_VM_READ, False, GetCurrentProcessId()); // ...use your target
  if Process <> 0 then
  try
    Mbi.BaseAddress := nil;
    while (VirtualQueryEx(Process, Mbi.BaseAddress, Mbi,
    SizeOf(TMemoryBasicInformation)) > 0) and (Mbi.RegionSize > 0) do
    begin
      if (Mbi.State <> MEM_FREE) then
      begin
        // range
        Txt := IntToHex(Cardinal(Mbi.BaseAddress), 8) + '-' +
        IntToHex(Cardinal(Mbi.BaseAddress) + Mbi.RegionSize, 8);
        // state
        if Mbi.State = MEM_COMMIT then
          Txt := Txt + ' [commited]'
        else if Mbi.State = MEM_RESERVE then
          Txt := Txt + ' [reserved]';
        // type
        if Mbi.Type_9 = MEM_IMAGE then
          Txt := Txt + ' (image)'
        else if Mbi.Type_9 = MEM_MAPPED then
          Txt := Txt + ' (mapped)'
        else if Mbi.Type_9 = MEM_PRIVATE then
          Txt := Txt + ' (private)';
          // ...AllocationProtect
          // ...Protect

          // try to get image name (uses PSApi - WinNT only)
          // (requires PROCESS_VM_READ)
        if GetModuleFileNameEx(Process, HINST(Mbi.AllocationBase),
          Filename, MAX_PATH) > 0 then
          Txt := Txt + ' - ' + Filename;

        Memo1.Lines.Add(Txt);
      end;
      Inc(Cardinal(Mbi.BaseAddress), Mbi.RegionSize);
    end;
  finally
    CloseHandle(Process);
  end;
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate