1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64:
| unit GetLoadedDLLs_Unit;
interface
uses Windows, SysUtils;
type TLoadedModule = record ModuleName: String; FullName: String; BaseAddress: THandle; end; TLoadedModules = array of TLoadedModule; PLoadedModules = ^TLoadedModules;
procedure GetLoadedDLLs(Modules: PLoadedModules);
implementation
procedure GetLoadedDLLs(Modules: PLoadedModules); var Address: PByte; MBI: TMemoryBasicInformation; Size: LongWord; S: String; begin
Address := nil; Size := SizeOf(TMemoryBasicInformation); FillChar(MBI, Size, 0); SetLength(Modules^, 0);
while (VirtualQuery(Address, MBI, Size) = Size) do begin
if MBI.State = MEM_FREE then MBI.AllocationBase := MBI.BaseAddress;
if (LongWord(MBI.AllocationBase) <> HInstance) and (MBI.AllocationBase = MBI.BaseAddress) and (MBI.AllocationBase <> nil) then begin SetLength(S, MAX_PATH); SetLength(S, GetModuleFileName(THandle(MBI.AllocationBase), PChar(S), MAX_PATH)); if Length(S) > 0 then begin SetLength(Modules^, Length(Modules^) + 1); with Modules^[High(Modules^)] do begin FullName := S; ModuleName := ExtractFileName(S); BaseAddress := THandle(MBI.AllocationBase); end; end; end;
inc(Address, MBI.RegionSize);
end;
end;
end. |