MapAndLoad()
The IMAGEHLP.DLL can also take care of memory mapping a PE file for you. The MapAndLoad() function maps the requested PE file in memory and fills in the LOADED_IMAGE structure with some useful information about the mapped file.
BOOL MapAndLoad( LPSTR ImageName, LPSTR DllPath, PLOADED_IMAGE LoadedImage, BOOL DotDll, BOOL ReadOnly );
PARAMETERS
| ImageName | Name of the PE file that is loaded. |
| DllPath | Path used to locate the file if the name provided cannot be found. If NULL is passed, then normal rules for searching using the PATH environment variable are applied. |
| LoadedImage | The structure LOADED_IMAGE is defined in the IMAGEHLP.H file. The structure has the following members: |
| ModuleName | Name of the loaded file. |
| hFile | Handle obtained through the call to CreateFile. |
| MappedAddress | Memory address where the file is mapped. |
| FileHeader | Pointer to the PE header within the mapped file. |
| LastRvaSection | The function sets it to the first section (see ImageRvaToVa). |
| NumberOfSections | Number of sections in the loaded PE file. |
| Sections | Pointer to the first section header within the mapped file. |
| Characteristics | Characteristics of the PE file (this is explained in more detail later in this chapter). |
| fSystemImage | Flag indicating whether it is a kernel-mode driver/DLL. |
| fDOSImage | Flag indicating whether it is a DOS executable. |
| Links | List of loaded images. |
| SizeOfImage | Size of the image. |
The function sets the members in the structure appropriately after loading the PE file.
| DotDll | If the file needs to be searched and does not have an extension, then either the .exe or the .dll extension is used. If the DotDll flag is set to TRUE, the .dll extension is used; otherwise, the .exe extension is used. |
| ReadOnly | If the flag is set to TRUE, the file is mapped as read-only. |