Delphi 获取进程内存范围  
官方Delphi 学习QQ群: 682628230(三千人)
频道

Delphi 获取进程内存范围


program ReadProcessMemoryinfo2;


{$APPTYPE CONSOLE}


uses

  Windows,

  TLHelp32,

  SysUtils;


var

  Snap, err: dword;

  sysinfo: TSystemInfo;

  Process: TPROCESSENTRY32;

  Handle: THandle;

  Mbi: TMemoryBasicInformation;

  Addr: dword;


begin

  GetSystemInfo(sysinfo); // no error checking here either!

  Snap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

  if Snap <> INVALID_HANDLE_VALUE then

  begin

    Process.dwSize := SizeOf(TPROCESSENTRY32);

    if Process32First(Snap, Process) then

    begin

      repeat

        Handle := OpenProcess(PROCESS_QUERY_INFORMATION, false,

          Process.th32ProcessID);

        if Handle <> 0 then

        begin

          writeln(Process.szExeFile);

          Addr := dword(sysinfo.lpMinimumApplicationAddress);

          while (Addr < $80000000) do

          begin

            if VirtualQueryEx(Handle, Ptr(Addr), Mbi, SizeOf(Mbi)) = 0 then

            begin

              err := GetLastError;

              inc(Addr, sysinfo.dwPageSize);

              continue;

            end;

            write(inttohex(Integer(Mbi.BaseAddress), 8));

            write(Output, ' - ');

            writeln(inttohex(Integer(Mbi.RegionSize), 8));

            if Addr + Mbi.RegionSize < Addr then

              break;

            Addr := Addr + Mbi.RegionSize;

          end;

          CloseHandle(Handle)

        end

      until not Process32Next(Snap, Process);

      CloseHandle(Snap);

    end;

  end;

  Readln;

end.



推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.033999919891357 seconds