Note how the search order matches that described. First, the loader checks the .LOCAL subdirectory, then the directory where the executable resides, then C:\Windows\System32 directory (because this is a 32-bit executable, that redirects to C:\Windows\SysWOW64), then the 16-bit Windows directory, then C:\Windows, and finally, the current directory at the time the executable was launched. The Load Image event confirms that the loader successfully resolved the import.
Loaded Module Database
The loader maintains a list of all modules (DLLs as well as the primary executable) that have been loaded by a process. This information is stored in a per-process structure called the process environment block, or PEB (see Chapter 5 for a full description of the PEB)—namely, in a substructure identified by
Field
Meaning
Name of the module itself, without the full path
Used by
Holds the base address at which the module was loaded
Contains the initial routine of the module (such as
Contains the SxS/Fusion activation context when calling initializers
Loader state flags for this module (See Table 3-25 for a description of the flags.)
Linked list of modules that were loaded as a result of export table forwarders from the module
Fully qualified path name of the module
Linked list used during process startup and shutdown for quicker lookups
Links this entry into each of the three ordered lists part of the loader database
Reference count for the module (that is, how many times it has been loaded)
Stores the system time value when this module was being loaded
Stores the original base address (set by the linker) of this module, enabling faster processing of relocated import entries
Information that’s relevant during a hotpatch operation on this module
Linked list of services (see Chapter 4 for more information) referencing this module
Size of the module in memory
Linked list of modules loaded as a result of static references from this one
Time stamp written by the linker when the module was linked, which the loader obtains from the module’s image PE header
Thread local storage slot associated with this module
One way to look at a process’ loader database is to use WinDbg and its formatted output of the PEB. The next experiment shows you how to do this and how to look at the LDR_DATA_TABLE_ENTRY structures on your own.
EXPERIMENT: Dumping the Loaded Modules Database
Before starting the experiment, perform the same steps as in the previous two experiments to launch Notepad.exe with WinDbg as the debugger. When you get to the first prompt (where you’ve been instructed to type g
until now), follow these instructions:You can look at the PEB of the current process with the