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
28 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(imagehlp
);
33 /***********************************************************************
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
);
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
);
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
));
80 pLoadedImage
->FileHeader
= HeapAlloc(IMAGEHLP_hHeap
, 0, sizeof(IMAGE_NT_HEADERS
));
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
);
101 pFind
=&pLoadedImage
->Links
;
102 pCurrent
=&IMAGEHLP_pFirstLoadedImage
->Links
;
103 while((pCurrent
!= pFind
) &&
105 pCurrent
= pCurrent
->Flink
;
109 SetLastError(ERROR_INVALID_PARAMETER
);
114 pCurrent
->Blink
->Flink
= pCurrent
->Flink
;
116 IMAGEHLP_pFirstLoadedImage
= pCurrent
->Flink
?CONTAINING_RECORD(
117 pCurrent
->Flink
, LOADED_IMAGE
, Links
):NULL
;
120 pCurrent
->Flink
->Blink
= pCurrent
->Blink
;
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
);
147 hFile
= CreateFileA(szFileName
,
148 GENERIC_READ
| (bReadOnly
? 0 : GENERIC_WRITE
),
150 NULL
, OPEN_EXISTING
, 0, NULL
);
151 if (hFile
== INVALID_HANDLE_VALUE
)
153 WARN("CreateFile: Error = %d\n", GetLastError());
157 hFileMapping
= CreateFileMappingA(hFile
, NULL
,
158 (bReadOnly
? PAGE_READONLY
: PAGE_READWRITE
) | SEC_COMMIT
,
162 WARN("CreateFileMapping: Error = %d\n", GetLastError());
166 mapping
= MapViewOfFile(hFileMapping
, bReadOnly
? FILE_MAP_READ
: FILE_MAP_WRITE
, 0, 0, 0);
167 CloseHandle(hFileMapping
);
170 WARN("MapViewOfFile: Error = %d\n", GetLastError());
174 if (!(pNtHeader
= RtlImageNtHeader(mapping
)))
176 WARN("Not an NT header\n");
177 UnmapViewOfFile(mapping
);
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
;
204 if (hFile
!= INVALID_HANDLE_VALUE
) CloseHandle(hFile
);
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
);
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
);