We help IT Professionals succeed at work.

List of imported DLLs

Eriandus
Eriandus asked
on
225 Views
Last Modified: 2010-05-18
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
Comment
Watch Question

software developer
CERTIFIED EXPERT
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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

Author

Commented:
Thanks :)
Lukasz Zielinskisoftware developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
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.
Lukasz Zielinskisoftware developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
that was quick:)

ziolko.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.