ReactOS 0.4.17-dev-966-gf06eace
access.c
Go to the documentation of this file.
1/*
2 * IMAGEHLP library
3 *
4 * Copyright 1998 Patrik Stridvall
5 *
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.
10 *
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.
15 *
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
19 */
20
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 "winver.h"
29#include "wine/debug.h"
30#include "imagehlp.h"
31
33
34/***********************************************************************
35 * Data
36 */
38
39
40/***********************************************************************
41 * GetImageConfigInformation (IMAGEHLP.@)
42 */
44 PLOADED_IMAGE LoadedImage,
45 PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
46{
47 FIXME("(%p, %p): stub\n",
48 LoadedImage, ImageConfigInformation
49 );
51 return FALSE;
52}
53
54/***********************************************************************
55 * GetImageUnusedHeaderBytes (IMAGEHLP.@)
56 */
58 PLOADED_IMAGE LoadedImage,
59 LPDWORD SizeUnusedHeaderBytes)
60{
61 FIXME("(%p, %p): stub\n",
62 LoadedImage, SizeUnusedHeaderBytes
63 );
65 return 0;
66}
67
68/***********************************************************************
69 * ImageLoad (IMAGEHLP.@)
70 */
72{
74
75 TRACE("(%s, %s)\n", dll_name, dll_path);
76
77 image = HeapAlloc(GetProcessHeap(), 0, sizeof(*image));
78 if (!image) return NULL;
79
80 if (!MapAndLoad(dll_name, dll_path, image, TRUE, TRUE))
81 {
83 return NULL;
84 }
85
86 image->Links.Flink = image_list.Flink;
87 image->Links.Blink = &image_list;
88 image_list.Flink->Blink = &image->Links;
89 image_list.Flink = &image->Links;
90
91 return image;
92}
93
94/***********************************************************************
95 * ImageUnload (IMAGEHLP.@)
96 */
98{
99 LIST_ENTRY *entry, *mark;
101
102 TRACE("(%p)\n", loaded_image);
103
104 /* FIXME: do we really need to check this? */
105 mark = &image_list;
106 for (entry = mark->Flink; entry != mark; entry = entry->Flink)
107 {
109 if (image == loaded_image)
110 break;
111 }
112
113 if (entry == mark)
114 {
115 /* Not found */
117 return FALSE;
118 }
119
120 entry->Blink->Flink = entry->Flink;
121 entry->Flink->Blink = entry->Blink;
122
123 UnMapAndLoad(loaded_image);
124 HeapFree(GetProcessHeap(), 0, loaded_image);
125
126 return TRUE;
127}
128
129/***********************************************************************
130 * MapAndLoad (IMAGEHLP.@)
131 */
133 BOOL bDotDll, BOOL bReadOnly)
134{
135 CHAR szFileName[MAX_PATH];
137 HANDLE hFileMapping = NULL;
139 PIMAGE_NT_HEADERS pNtHeader = NULL;
140
141 TRACE("(%s, %s, %p, %d, %d)\n",
142 pszImageName, pszDllPath, pLoadedImage, bDotDll, bReadOnly);
143
144 if (!SearchPathA(pszDllPath, pszImageName, bDotDll ? ".DLL" : ".EXE",
145 sizeof(szFileName), szFileName, NULL))
146 {
148 goto Error;
149 }
150
151 hFile = CreateFileA(szFileName,
152 GENERIC_READ | (bReadOnly ? 0 : GENERIC_WRITE),
154 NULL, OPEN_EXISTING, 0, NULL);
156 {
157 WARN("CreateFile: Error = %ld\n", GetLastError());
158 goto Error;
159 }
160
161 hFileMapping = CreateFileMappingA(hFile, NULL,
162 (bReadOnly ? PAGE_READONLY : PAGE_READWRITE) | SEC_COMMIT,
163 0, 0, NULL);
164 if (!hFileMapping)
165 {
166 WARN("CreateFileMapping: Error = %ld\n", GetLastError());
167 goto Error;
168 }
169
170 mapping = MapViewOfFile(hFileMapping, bReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE, 0, 0, 0);
171 CloseHandle(hFileMapping);
172 if (!mapping)
173 {
174 WARN("MapViewOfFile: Error = %ld\n", GetLastError());
175 goto Error;
176 }
177
178 if (!(pNtHeader = RtlImageNtHeader(mapping)))
179 {
180 WARN("Not an NT header\n");
182 goto Error;
183 }
184
185 pLoadedImage->ModuleName = HeapAlloc(GetProcessHeap(), 0,
186 strlen(szFileName) + 1);
187 if (pLoadedImage->ModuleName) strcpy(pLoadedImage->ModuleName, szFileName);
188 pLoadedImage->hFile = hFile;
189 pLoadedImage->MappedAddress = mapping;
190 pLoadedImage->FileHeader = pNtHeader;
191 pLoadedImage->Sections = IMAGE_FIRST_SECTION(pNtHeader);
192 pLoadedImage->NumberOfSections = pNtHeader->FileHeader.NumberOfSections;
193 pLoadedImage->SizeOfImage = GetFileSize(hFile, NULL);
194 pLoadedImage->Characteristics = pNtHeader->FileHeader.Characteristics;
195 pLoadedImage->LastRvaSection = pLoadedImage->Sections;
196
197 pLoadedImage->fSystemImage = FALSE; /* FIXME */
198 pLoadedImage->fDOSImage = FALSE; /* FIXME */
199
200 pLoadedImage->Links.Flink = &pLoadedImage->Links;
201 pLoadedImage->Links.Blink = &pLoadedImage->Links;
202
203 return TRUE;
204
205Error:
207 return FALSE;
208}
209
210/***********************************************************************
211 * SetImageConfigInformation (IMAGEHLP.@)
212 */
214 PLOADED_IMAGE LoadedImage,
215 PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
216{
217 FIXME("(%p, %p): stub\n",
218 LoadedImage, ImageConfigInformation
219 );
221 return FALSE;
222}
223
224/***********************************************************************
225 * UnMapAndLoad (IMAGEHLP.@)
226 */
228{
229 HeapFree(GetProcessHeap(), 0, pLoadedImage->ModuleName);
230 /* FIXME: MSDN states that a new checksum is computed and stored into the file */
231 if (pLoadedImage->MappedAddress) UnmapViewOfFile(pLoadedImage->MappedAddress);
232 if (pLoadedImage->hFile != INVALID_HANDLE_VALUE) CloseHandle(pLoadedImage->hFile);
233 return TRUE;
234}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
BOOL Error
Definition: chkdsk.c:66
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define PAGE_READONLY
Definition: compat.h:138
#define UnmapViewOfFile
Definition: compat.h:746
#define OPEN_EXISTING
Definition: compat.h:775
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define GENERIC_READ
Definition: compat.h:135
#define RtlImageNtHeader
Definition: compat.h:806
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define FILE_MAP_READ
Definition: compat.h:776
#define MapViewOfFile
Definition: compat.h:745
#define FILE_SHARE_READ
Definition: compat.h:136
PLOADED_IMAGE WINAPI ImageLoad(PCSTR dll_name, PCSTR dll_path)
Definition: access.c:71
BOOL WINAPI MapAndLoad(PCSTR pszImageName, PCSTR pszDllPath, PLOADED_IMAGE pLoadedImage, BOOL bDotDll, BOOL bReadOnly)
Definition: access.c:132
BOOL WINAPI SetImageConfigInformation(PLOADED_IMAGE LoadedImage, PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
Definition: access.c:213
static LIST_ENTRY image_list
Definition: access.c:37
BOOL WINAPI GetImageConfigInformation(PLOADED_IMAGE LoadedImage, PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
Definition: access.c:43
BOOL WINAPI ImageUnload(PLOADED_IMAGE loaded_image)
Definition: access.c:97
BOOL WINAPI UnMapAndLoad(PLOADED_IMAGE pLoadedImage)
Definition: access.c:227
DWORD WINAPI GetImageUnusedHeaderBytes(PLOADED_IMAGE LoadedImage, LPDWORD SizeUnusedHeaderBytes)
Definition: access.c:57
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
DWORD WINAPI SearchPathA(IN LPCSTR lpPath OPTIONAL, IN LPCSTR lpFileName, IN LPCSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPSTR lpBuffer, OUT LPSTR *lpFilePart OPTIONAL)
Definition: path.c:1222
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
HANDLE NTAPI CreateFileMappingA(IN HANDLE hFile, IN LPSECURITY_ATTRIBUTES lpFileMappingAttributes, IN DWORD flProtect, IN DWORD dwMaximumSizeHigh, IN DWORD dwMaximumSizeLow, IN LPCSTR lpName)
Definition: filemap.c:23
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLenum GLenum GLenum mapping
Definition: glext.h:9031
uint32_t entry
Definition: isohybrid.c:63
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
LPCWSTR pszImageName
Definition: env.c:57
_In_ HANDLE hFile
Definition: mswsock.h:90
#define SEC_COMMIT
Definition: mmtypes.h:100
#define PAGE_READWRITE
Definition: nt_native.h:1307
#define GENERIC_WRITE
Definition: nt_native.h:90
#define IMAGE_FIRST_SECTION(NtHeader)
Definition: ntimage.h:427
char CHAR
Definition: pedump.c:57
strcpy
Definition: string.h:131
#define TRACE(s)
Definition: solgame.cpp:4
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
Definition: typedefs.h:120
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
PIMAGE_SECTION_HEADER Sections
Definition: dbghelp.h:109
BOOLEAN fSystemImage
Definition: dbghelp.h:111
LIST_ENTRY Links
Definition: dbghelp.h:115
ULONG Characteristics
Definition: dbghelp.h:110
ULONG SizeOfImage
Definition: dbghelp.h:116
PUCHAR MappedAddress
Definition: dbghelp.h:101
HANDLE hFile
Definition: dbghelp.h:100
PIMAGE_SECTION_HEADER LastRvaSection
Definition: dbghelp.h:107
PIMAGE_NT_HEADERS32 FileHeader
Definition: dbghelp.h:105
ULONG NumberOfSections
Definition: dbghelp.h:108
PSTR ModuleName
Definition: dbghelp.h:99
BOOLEAN fDOSImage
Definition: dbghelp.h:112
Definition: image.c:84
uint32_t * LPDWORD
Definition: typedefs.h:59
const char * PCSTR
Definition: typedefs.h:52
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FILE_MAP_WRITE
Definition: winbase.h:157
#define WINAPI
Definition: msvc.h:6