4 * Copyright 1998 Patrik Stridvall
11 #include "debugtools.h"
14 DEFAULT_DEBUG_CHANNEL(imagehlp);
16 /***********************************************************************
20 static PLOADED_IMAGE IMAGEHLP_pFirstLoadedImage=NULL;
21 static PLOADED_IMAGE IMAGEHLP_pLastLoadedImage=NULL;
23 static LOADED_IMAGE IMAGEHLP_EmptyLoadedImage = {
24 NULL, /* ModuleName */
25 0xffffffff, /* hFile */
26 NULL, /* MappedAddress */
27 NULL, /* FileHeader */
28 NULL, /* LastRvaSection */
29 0, /* NumberOfSections */
31 1, /* Characteristics */
32 FALSE, /* fSystemImage */
33 FALSE, /* fDOSImage */
34 { &IMAGEHLP_EmptyLoadedImage.Links, &IMAGEHLP_EmptyLoadedImage.Links }, /* Links */
35 148, /* SizeOfImage; */
38 /***********************************************************************
39 * EnumerateLoadedModules (IMAGEHLP.@)
41 BOOL WINAPI EnumerateLoadedModules(
43 PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback,
46 FIXME("(0x%08x, %p, %p): stub\n",
47 hProcess, EnumLoadedModulesCallback, UserContext
49 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
53 /***********************************************************************
54 * GetTimestampForLoadedLibrary (IMAGEHLP.@)
56 DWORD WINAPI GetTimestampForLoadedLibrary(HMODULE Module)
58 FIXME("(0x%08x): stub\n", Module);
59 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
63 /***********************************************************************
64 * GetImageConfigInformation (IMAGEHLP.@)
66 BOOL WINAPI GetImageConfigInformation(
67 PLOADED_IMAGE LoadedImage,
68 PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
70 FIXME("(%p, %p): stub\n",
71 LoadedImage, ImageConfigInformation
73 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
77 /***********************************************************************
78 * GetImageUnusedHeaderBytes (IMAGEHLP.@)
80 DWORD WINAPI GetImageUnusedHeaderBytes(
81 PLOADED_IMAGE LoadedImage,
82 LPDWORD SizeUnusedHeaderBytes)
84 FIXME("(%p, %p): stub\n",
85 LoadedImage, SizeUnusedHeaderBytes
87 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
91 /***********************************************************************
92 * ImageDirectoryEntryToData (IMAGEHLP.@)
94 PVOID WINAPI ImageDirectoryEntryToData(
95 PVOID Base, BOOLEAN MappedAsImage, USHORT DirectoryEntry, PULONG Size)
97 FIXME("(%p, %d, %hd, %p): stub\n",
98 Base, MappedAsImage, DirectoryEntry, Size
100 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
104 /***********************************************************************
105 * ImageLoad (IMAGEHLP.@)
107 PLOADED_IMAGE WINAPI ImageLoad(LPSTR DllName, LPSTR DllPath)
109 PLOADED_IMAGE pLoadedImage =
110 HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(LOADED_IMAGE));
114 /***********************************************************************
115 * ImageNtHeader (IMAGEHLP.@)
117 PIMAGE_NT_HEADERS WINAPI ImageNtHeader(PVOID Base)
119 return (PIMAGE_NT_HEADERS)
120 ((LPBYTE) Base + ((PIMAGE_DOS_HEADER) Base)->e_lfanew);
123 /***********************************************************************
124 * ImageRvaToSection (IMAGEHLP.@)
126 PIMAGE_SECTION_HEADER WINAPI ImageRvaToSection(
127 PIMAGE_NT_HEADERS NtHeaders, PVOID Base, ULONG Rva)
129 FIXME("(%p, %p, %ld): stub\n", NtHeaders, Base, Rva);
130 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
134 /***********************************************************************
135 * ImageRvaToVa (IMAGEHLP.@)
137 PVOID WINAPI ImageRvaToVa(
138 PIMAGE_NT_HEADERS NtHeaders, PVOID Base, ULONG Rva,
139 PIMAGE_SECTION_HEADER *LastRvaSection)
141 FIXME("(%p, %p, %ld, %p): stub\n",
142 NtHeaders, Base, Rva, LastRvaSection
144 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
148 /***********************************************************************
149 * ImageUnload (IMAGEHLP.@)
151 BOOL WINAPI ImageUnload(PLOADED_IMAGE pLoadedImage)
153 LIST_ENTRY *pCurrent, *pFind;
154 if(!IMAGEHLP_pFirstLoadedImage || !pLoadedImage)
156 /* No image loaded or null pointer */
157 SetLastError(ERROR_INVALID_PARAMETER);
161 pFind=&pLoadedImage->Links;
162 pCurrent=&IMAGEHLP_pFirstLoadedImage->Links;
163 while((pCurrent != pFind) &&
165 pCurrent = pCurrent->Flink;
169 SetLastError(ERROR_INVALID_PARAMETER);
174 pCurrent->Blink->Flink = pCurrent->Flink;
176 IMAGEHLP_pFirstLoadedImage = pCurrent->Flink?CONTAINING_RECORD(
177 pCurrent->Flink, LOADED_IMAGE, Links):NULL;
180 pCurrent->Flink->Blink = pCurrent->Blink;
182 IMAGEHLP_pLastLoadedImage = pCurrent->Blink?CONTAINING_RECORD(
183 pCurrent->Blink, LOADED_IMAGE, Links):NULL;
188 /***********************************************************************
189 * MapAndLoad (IMAGEHLP.@)
191 BOOL WINAPI MapAndLoad(
192 LPSTR pszImageName, LPSTR pszDllPath, PLOADED_IMAGE pLoadedImage,
193 BOOL bDotDll, BOOL bReadOnly)
195 CHAR szFileName[MAX_PATH];
196 HANDLE hFile = (HANDLE) NULL;
197 HANDLE hFileMapping = (HANDLE) NULL;
198 HMODULE hModule = (HMODULE) NULL;
199 PIMAGE_NT_HEADERS pNtHeader = NULL;
201 /* PathCombine(&szFileName, pszDllPath, pszImageName); */
202 /* PathRenameExtension(&szFileName, bDotDll?:"dll":"exe"); */
204 /* FIXME: Check if the file already loaded (use IMAGEHLP_pFirstLoadedImage) */
205 if(!(hFile = CreateFileA(
206 szFileName, GENERIC_READ, 1, /* FIXME: FILE_SHARE_READ not defined */
207 NULL, OPEN_EXISTING, 0, (HANDLE) NULL)))
209 SetLastError(ERROR_FILE_NOT_FOUND);
213 if(!(hFileMapping = CreateFileMappingA(
214 hFile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL)))
216 DWORD dwLastError = GetLastError();
217 WARN("CreateFileMapping: Error = %ld\n", dwLastError);
218 SetLastError(dwLastError);
222 hFile = (HANDLE) NULL;
224 if(!(hModule = (HMODULE) MapViewOfFile(
225 hFileMapping, FILE_MAP_READ, 0, 0, 0)))
227 DWORD dwLastError = GetLastError();
228 WARN("MapViewOfFile: Error = %ld\n", dwLastError);
229 SetLastError(dwLastError);
233 CloseHandle(hFileMapping);
234 hFileMapping=(HANDLE) NULL;
236 pLoadedImage = (PLOADED_IMAGE) HeapAlloc(
237 IMAGEHLP_hHeap, 0, sizeof(LOADED_IMAGE)
240 pNtHeader = ImageNtHeader((PVOID) hModule);
242 pLoadedImage->ModuleName = HeapAlloc(IMAGEHLP_hHeap, 0, strlen(pszDllPath)+1); /* FIXME: Correct? */
243 strcpy( pLoadedImage->ModuleName, pszDllPath );
244 pLoadedImage->hFile = hFile;
245 pLoadedImage->MappedAddress = (PUCHAR) hModule;
246 pLoadedImage->FileHeader = pNtHeader;
247 pLoadedImage->Sections = (PIMAGE_SECTION_HEADER)
248 ((LPBYTE) &pNtHeader->OptionalHeader +
249 pNtHeader->FileHeader.SizeOfOptionalHeader);
250 pLoadedImage->NumberOfSections =
251 pNtHeader->FileHeader.NumberOfSections;
252 pLoadedImage->SizeOfImage =
253 pNtHeader->OptionalHeader.SizeOfImage;
254 pLoadedImage->Characteristics =
255 pNtHeader->FileHeader.Characteristics;
256 pLoadedImage->LastRvaSection = pLoadedImage->Sections;
258 pLoadedImage->fSystemImage = FALSE; /* FIXME */
259 pLoadedImage->fDOSImage = FALSE; /* FIXME */
261 /* FIXME: Make thread safe */
262 pLoadedImage->Links.Flink = NULL;
263 pLoadedImage->Links.Blink = &IMAGEHLP_pLastLoadedImage->Links;
264 if(IMAGEHLP_pLastLoadedImage)
265 IMAGEHLP_pLastLoadedImage->Links.Flink = &pLoadedImage->Links;
266 IMAGEHLP_pLastLoadedImage = pLoadedImage;
267 if(!IMAGEHLP_pFirstLoadedImage)
268 IMAGEHLP_pFirstLoadedImage = pLoadedImage;
274 UnmapViewOfFile((PVOID) hModule);
276 CloseHandle(hFileMapping);
282 /***********************************************************************
283 * SetImageConfigInformation (IMAGEHLP.@)
285 BOOL WINAPI SetImageConfigInformation(
286 PLOADED_IMAGE LoadedImage,
287 PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
289 FIXME("(%p, %p): stub\n",
290 LoadedImage, ImageConfigInformation
292 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
296 /***********************************************************************
297 * UnMapAndLoad (IMAGEHLP.@)
299 BOOL WINAPI UnMapAndLoad(PLOADED_IMAGE LoadedImage)
301 FIXME("(%p): stub\n", LoadedImage);
302 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);