Link to home
Create AccountLog in
Avatar of Eriandus
EriandusFlag for Poland

asked on

List of imported DLLs

Hello,
I'm injecting DLL into application and before I do that, I need to check whether I haven't already done it before. I saw that multiple applications like WinHex, ImpRec etc are able to list imported DLLs of process and output DLL filenames. It would be a perfect solution for me, so how can I get the list of imported DLLs if I know process id?

I would be really thankful for some Delphi source code examples ;)

Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Eriandus

ASKER

Thanks a lot, that's it :) Here's an example in Delphi if somebody need it.

var
  hMod          : array [0..1023] of DWORD;
  cbNeeded      : DWORD;
  szProcessName : array [0..MAX_PATH] of Char;
{...}
  //hProcess is handle of process
  EnumProcessModules(hProcess, @hMod, SizeOf(hMod), cbNeeded);
  GetModuleFileNameEx(hProcess, hMod[0], szProcessName, SizeOf(szProcessName)); //reads filename of first module - so of exe file
 
  //Also to get number of returned modules:
  //cbNeeded div sizeof(DWORD)

Open in new window

Thanks :)
this assumes that you have no more than 1024 libraries:

procedure TForm1.Button8Click(Sender: TObject);
var mods: array[0..1023] of DWORD;
    need: Cardinal;
    cnt: Integer;
    file_name: array[0..MAX_PATH] of Char;
begin
  FillChar(mods, 1024, 0);
  need := 0;
  EnumProcessModules(GetCurrentProcess, @mods[0], 1024, need);
  for cnt := 0 to need - 1 do begin
    GetModuleFileName(mods[cnt], file_name, MAX_PATH);
    Memo1.Lines.Add(file_name);
  end;
end;

ziolko.
that was quick:)

ziolko.