How to get a list of used DLLs?

我的梦境 提交于 2019-12-01 23:44:43

问题


I would like to get a list of used DLLs from application itself. My goal is to compare the list with hardcoded one to see if any DLL is injected. I can not find any examples in Google.


回答1:


You can use PSAPI for this. The function you need is EnumProcessModules. There's some sample code on MSDN.

The main alternative is the Tool Help library. It goes like this:

  • Call CreateToolhelp32Snapshot.
  • Start enumeration with Module32First.
  • Repeatedly call Module32Next.
  • When you are done call CloseHandle to destroy the snapshot.

Personally, I prefer Tool Help for this task. Here's a very simple example:

{$APPTYPE CONSOLE}

uses
  SysUtils, Windows, TlHelp32;

var
  Handle: THandle;
  ModuleEntry: TModuleEntry32;
begin
  Handle := CreateToolHelp32SnapShot(TH32CS_SNAPMODULE, 0);
  Win32Check(Handle <> INVALID_HANDLE_VALUE);
  try
    ModuleEntry.dwSize := Sizeof(ModuleEntry);
    Win32Check(Module32First(Handle, ModuleEntry));
    repeat
      Writeln(ModuleEntry.szModule);
    until not Module32Next(Handle, ModuleEntry);
  finally
    CloseHandle(Handle);
  end;
  Readln;
end.



回答2:


Install Jedi Code Library (http://jcl.sf.net)

It has an exceptions reporting dialog which includes stack trace, Windows/hardware brief, and - the list of loaded DLLs and their versions. You can copy or call that part, generating this list, out of it.




回答3:


If you want a non-programmatic solution, just run the app under the Dependency Walker.

It will not only show static dependencies but will also trap and track dynamic loading of modules at runtime and let you know which module called LoadLibrary.



来源:https://stackoverflow.com/questions/21180094/how-to-get-a-list-of-used-dlls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!