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.
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:
CreateToolhelp32Snapshot
.Module32First
.Module32Next
.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.