"import table" may contain not all DLLs. How about DLLs loaded by LoadLibrary?
Main Topics
Browse All TopicsHello,
I know the handle of an running process ( hProcess := OpenProcess(AccessRights, FALSE, PID); ) and I want to know which DLL files it have loaded. I do not want to know which DLL is in the process space of this running process (injected DLLs can be also in the process space, but injected DLLs are not loaded from a process, because injected DLLs are injected to the process.)
That means I can not use EnumProcessModules or Module32First, because these functions also enumerate the injected DLLs.
A solution could be to get the import table of this running process and look for the DLLs which the process is using. How can I do this? The .exe file of the running process is compressed, so I have to get the import table from the process in memory - not from the .exe file.
The solution should work on Windows NT (Win9x would be fine).
Thanky you for your answer for this difficult question
Ben
BTW: I think, here you can found something similar: Look for "function GetProcAddress32" at http://www.delphipages.com
or look for "FindCallerModuleHandle" on http://groups.google.com
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Something like that (it work with running exe, but you can do the same with a file):
function FindUsablePage(hProcess: THANDLE; PProcessBase: pointer): pointer;
var peHdrOffset: DWORD;
cBytesMoved: DWORD;
ntHdr: IMAGE_NT_HEADERS;
pSection: ^IMAGE_SECTION_HEADER;
i: ULONG;
tmpPtr: PBYTE;
section: IMAGE_SECTION_HEADER;
SecName: string;
begin
Result := nil;
// Read in the offset of the PE header within the debuggee
tmpPtr := PBYTE(PProcessBase);
inc(tmpPtr, $3C);
if ReadProcessMemory(ProcessI
tmpPtr,
@peHdrOffset,
sizeof(peHdrOffset),
cBytesMoved) = False then Exit;
// Read in the IMAGE_NT_HEADERS.OptionalH
tmpPtr := PBYTE(PProcessBase);
inc(tmpPtr, peHdrOffset);
if ReadProcessMemory(ProcessI
tmpPtr, @ntHdr, sizeof(ntHdr),
cBytesMoved) = False then Exit;
tmpPtr := PBYTE(PProcessBase);
inc(tmpPtr, peHdrOffset + 4 + sizeof(ntHdr.FileHeader) +
ntHdr.FileHeader.SizeOfOpt
pSection := pointer(tmpPtr);//(PIMAGE_
for i:=0 to Pred(ntHdr.FileHeader.Numb
//{IMAGE_SECTION_HEADER section;
if ReadProcessMemory(ProcessI
pSection, @section, sizeof(section),
cBytesMoved) = False then Exit;
// OutputDebugString( "trying section:
// OutputDebugString( section.Name )'
// OutputDebugString( "\r\n" )'
SecName := StrPas(@section.Name[0]);
// If it's writeable, and not the .idata section, we'll go with it
if(((section.Characteristi
(StrLComp(@section.Name[0]
OutputDebugString(PChar('u
Result := pointer(DWORD(PProcessBase
//Exit;
end;
Inc(pSection); // Not this section. Advance to next section.
end;
end;
You can read about PE format here:
http://msdn.microsoft.com/
Here is the code that read exports, but it's rather easy to make it read imports.
If any problems I'll can help tomorrow.
http://www.experts-exchang
Business Accounts
Answer for Membership
by: GloomyFriarPosted on 2003-11-11 at 05:08:18ID: 9721872
In a "running process" there is no differences between "loaded" and "injected" DLLs.