mshtml: Rename fire_event_obj and dispatch_event.
[wine.git] / dlls / imagehlp / access.c
blob6a33c0c677246923494b8e692c4ed8bce97fa5ba
1 /*
2 * IMAGEHLP library
4 * Copyright 1998 Patrik Stridvall
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <string.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winnt.h"
26 #include "winternl.h"
27 #include "winerror.h"
28 #include "wine/debug.h"
29 #include "imagehlp.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(imagehlp);
33 /***********************************************************************
34 * Data
37 static PLOADED_IMAGE IMAGEHLP_pFirstLoadedImage=NULL;
39 DECLSPEC_HIDDEN extern HANDLE IMAGEHLP_hHeap;
41 /***********************************************************************
42 * GetImageConfigInformation (IMAGEHLP.@)
44 BOOL WINAPI GetImageConfigInformation(
45 PLOADED_IMAGE LoadedImage,
46 PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
48 FIXME("(%p, %p): stub\n",
49 LoadedImage, ImageConfigInformation
51 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
52 return FALSE;
55 /***********************************************************************
56 * GetImageUnusedHeaderBytes (IMAGEHLP.@)
58 DWORD WINAPI GetImageUnusedHeaderBytes(
59 PLOADED_IMAGE LoadedImage,
60 LPDWORD SizeUnusedHeaderBytes)
62 FIXME("(%p, %p): stub\n",
63 LoadedImage, SizeUnusedHeaderBytes
65 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
66 return 0;
69 /***********************************************************************
70 * ImageLoad (IMAGEHLP.@)
72 PLOADED_IMAGE WINAPI ImageLoad(PCSTR DllName, PCSTR DllPath)
74 PLOADED_IMAGE pLoadedImage;
76 FIXME("(%s, %s): stub\n", DllName, DllPath);
78 pLoadedImage = HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(LOADED_IMAGE));
79 if (pLoadedImage)
80 pLoadedImage->FileHeader = HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(IMAGE_NT_HEADERS));
82 return pLoadedImage;
85 /***********************************************************************
86 * ImageUnload (IMAGEHLP.@)
88 BOOL WINAPI ImageUnload(PLOADED_IMAGE pLoadedImage)
90 LIST_ENTRY *pCurrent, *pFind;
92 TRACE("(%p)\n", pLoadedImage);
94 if(!IMAGEHLP_pFirstLoadedImage || !pLoadedImage)
96 /* No image loaded or null pointer */
97 SetLastError(ERROR_INVALID_PARAMETER);
98 return FALSE;
101 pFind=&pLoadedImage->Links;
102 pCurrent=&IMAGEHLP_pFirstLoadedImage->Links;
103 while((pCurrent != pFind) &&
104 (pCurrent != NULL))
105 pCurrent = pCurrent->Flink;
106 if(!pCurrent)
108 /* Not found */
109 SetLastError(ERROR_INVALID_PARAMETER);
110 return FALSE;
113 if(pCurrent->Blink)
114 pCurrent->Blink->Flink = pCurrent->Flink;
115 else
116 IMAGEHLP_pFirstLoadedImage = pCurrent->Flink?CONTAINING_RECORD(
117 pCurrent->Flink, LOADED_IMAGE, Links):NULL;
119 if(pCurrent->Flink)
120 pCurrent->Flink->Blink = pCurrent->Blink;
122 return FALSE;
125 /***********************************************************************
126 * MapAndLoad (IMAGEHLP.@)
128 BOOL WINAPI MapAndLoad(PCSTR pszImageName, PCSTR pszDllPath, PLOADED_IMAGE pLoadedImage,
129 BOOL bDotDll, BOOL bReadOnly)
131 CHAR szFileName[MAX_PATH];
132 HANDLE hFile = INVALID_HANDLE_VALUE;
133 HANDLE hFileMapping = NULL;
134 PVOID mapping = NULL;
135 PIMAGE_NT_HEADERS pNtHeader = NULL;
137 TRACE("(%s, %s, %p, %d, %d)\n",
138 pszImageName, pszDllPath, pLoadedImage, bDotDll, bReadOnly);
140 if (!SearchPathA(pszDllPath, pszImageName, bDotDll ? ".DLL" : ".EXE",
141 sizeof(szFileName), szFileName, NULL))
143 SetLastError(ERROR_FILE_NOT_FOUND);
144 goto Error;
147 hFile = CreateFileA(szFileName,
148 GENERIC_READ | (bReadOnly ? 0 : GENERIC_WRITE),
149 FILE_SHARE_READ,
150 NULL, OPEN_EXISTING, 0, NULL);
151 if (hFile == INVALID_HANDLE_VALUE)
153 WARN("CreateFile: Error = %d\n", GetLastError());
154 goto Error;
157 hFileMapping = CreateFileMappingA(hFile, NULL,
158 (bReadOnly ? PAGE_READONLY : PAGE_READWRITE) | SEC_COMMIT,
159 0, 0, NULL);
160 if (!hFileMapping)
162 WARN("CreateFileMapping: Error = %d\n", GetLastError());
163 goto Error;
166 mapping = MapViewOfFile(hFileMapping, bReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE, 0, 0, 0);
167 CloseHandle(hFileMapping);
168 if (!mapping)
170 WARN("MapViewOfFile: Error = %d\n", GetLastError());
171 goto Error;
174 if (!(pNtHeader = RtlImageNtHeader(mapping)))
176 WARN("Not an NT header\n");
177 UnmapViewOfFile(mapping);
178 goto Error;
181 pLoadedImage->ModuleName = HeapAlloc(GetProcessHeap(), 0,
182 strlen(szFileName) + 1);
183 if (pLoadedImage->ModuleName) strcpy(pLoadedImage->ModuleName, szFileName);
184 pLoadedImage->hFile = hFile;
185 pLoadedImage->MappedAddress = mapping;
186 pLoadedImage->FileHeader = pNtHeader;
187 pLoadedImage->Sections = (PIMAGE_SECTION_HEADER)
188 ((LPBYTE) &pNtHeader->OptionalHeader +
189 pNtHeader->FileHeader.SizeOfOptionalHeader);
190 pLoadedImage->NumberOfSections = pNtHeader->FileHeader.NumberOfSections;
191 pLoadedImage->SizeOfImage = GetFileSize(hFile, NULL);
192 pLoadedImage->Characteristics = pNtHeader->FileHeader.Characteristics;
193 pLoadedImage->LastRvaSection = pLoadedImage->Sections;
195 pLoadedImage->fSystemImage = FALSE; /* FIXME */
196 pLoadedImage->fDOSImage = FALSE; /* FIXME */
198 pLoadedImage->Links.Flink = &pLoadedImage->Links;
199 pLoadedImage->Links.Blink = &pLoadedImage->Links;
201 return TRUE;
203 Error:
204 if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile);
205 return FALSE;
208 /***********************************************************************
209 * SetImageConfigInformation (IMAGEHLP.@)
211 BOOL WINAPI SetImageConfigInformation(
212 PLOADED_IMAGE LoadedImage,
213 PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
215 FIXME("(%p, %p): stub\n",
216 LoadedImage, ImageConfigInformation
218 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
219 return FALSE;
222 /***********************************************************************
223 * UnMapAndLoad (IMAGEHLP.@)
225 BOOL WINAPI UnMapAndLoad(PLOADED_IMAGE pLoadedImage)
227 HeapFree(GetProcessHeap(), 0, pLoadedImage->ModuleName);
228 /* FIXME: MSDN states that a new checksum is computed and stored into the file */
229 if (pLoadedImage->MappedAddress) UnmapViewOfFile(pLoadedImage->MappedAddress);
230 if (pLoadedImage->hFile != INVALID_HANDLE_VALUE) CloseHandle(pLoadedImage->hFile);
231 return TRUE;