1998-10-11 19:04:17 +02:00
|
|
|
/*
|
|
|
|
* IMAGEHLP library
|
|
|
|
*
|
|
|
|
* Copyright 1998 Patrik Stridvall
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1998-10-11 19:04:17 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-01-26 21:43:40 +01:00
|
|
|
#include <string.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
1998-10-11 19:04:17 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnt.h"
|
2003-11-21 22:31:35 +01:00
|
|
|
#include "winreg.h"
|
|
|
|
#include "winternl.h"
|
1998-10-11 19:04:17 +02:00
|
|
|
#include "winerror.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1998-10-11 19:04:17 +02:00
|
|
|
#include "imagehlp.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(imagehlp);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
1998-10-11 19:04:17 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* Data
|
|
|
|
*/
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
static PLOADED_IMAGE IMAGEHLP_pFirstLoadedImage=NULL;
|
|
|
|
static PLOADED_IMAGE IMAGEHLP_pLastLoadedImage=NULL;
|
1998-10-11 19:04:17 +02:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
static LOADED_IMAGE IMAGEHLP_EmptyLoadedImage = {
|
1998-10-11 19:04:17 +02:00
|
|
|
NULL, /* ModuleName */
|
2002-10-04 02:27:10 +02:00
|
|
|
0, /* hFile */
|
1998-10-11 19:04:17 +02:00
|
|
|
NULL, /* MappedAddress */
|
|
|
|
NULL, /* FileHeader */
|
|
|
|
NULL, /* LastRvaSection */
|
|
|
|
0, /* NumberOfSections */
|
|
|
|
NULL, /* Sections */
|
|
|
|
1, /* Characteristics */
|
|
|
|
FALSE, /* fSystemImage */
|
|
|
|
FALSE, /* fDOSImage */
|
1999-02-26 12:11:13 +01:00
|
|
|
{ &IMAGEHLP_EmptyLoadedImage.Links, &IMAGEHLP_EmptyLoadedImage.Links }, /* Links */
|
1998-10-11 19:04:17 +02:00
|
|
|
148, /* SizeOfImage; */
|
|
|
|
};
|
|
|
|
|
2003-06-28 00:24:23 +02:00
|
|
|
extern HANDLE IMAGEHLP_hHeap;
|
|
|
|
|
1998-10-11 19:04:17 +02:00
|
|
|
/***********************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* EnumerateLoadedModules (IMAGEHLP.@)
|
1998-10-11 19:04:17 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL WINAPI EnumerateLoadedModules(
|
|
|
|
HANDLE hProcess,
|
|
|
|
PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback,
|
1998-10-11 19:04:17 +02:00
|
|
|
PVOID UserContext)
|
|
|
|
{
|
2002-10-22 02:45:27 +02:00
|
|
|
FIXME("(%p, %p, %p): stub\n",
|
1998-10-11 19:04:17 +02:00
|
|
|
hProcess, EnumLoadedModulesCallback, UserContext
|
|
|
|
);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* GetTimestampForLoadedLibrary (IMAGEHLP.@)
|
1998-10-11 19:04:17 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
DWORD WINAPI GetTimestampForLoadedLibrary(HMODULE Module)
|
1998-10-11 19:04:17 +02:00
|
|
|
{
|
2002-10-22 02:45:27 +02:00
|
|
|
FIXME("(%p): stub\n", Module);
|
1998-10-11 19:04:17 +02:00
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* GetImageConfigInformation (IMAGEHLP.@)
|
1998-10-11 19:04:17 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL WINAPI GetImageConfigInformation(
|
|
|
|
PLOADED_IMAGE LoadedImage,
|
|
|
|
PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
|
1998-10-11 19:04:17 +02:00
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
FIXME("(%p, %p): stub\n",
|
1998-10-11 19:04:17 +02:00
|
|
|
LoadedImage, ImageConfigInformation
|
|
|
|
);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* GetImageUnusedHeaderBytes (IMAGEHLP.@)
|
1998-10-11 19:04:17 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
DWORD WINAPI GetImageUnusedHeaderBytes(
|
|
|
|
PLOADED_IMAGE LoadedImage,
|
1998-10-11 19:04:17 +02:00
|
|
|
LPDWORD SizeUnusedHeaderBytes)
|
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
FIXME("(%p, %p): stub\n",
|
1998-10-11 19:04:17 +02:00
|
|
|
LoadedImage, SizeUnusedHeaderBytes
|
|
|
|
);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* ImageLoad (IMAGEHLP.@)
|
1998-10-11 19:04:17 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
PLOADED_IMAGE WINAPI ImageLoad(LPSTR DllName, LPSTR DllPath)
|
1998-10-11 19:04:17 +02:00
|
|
|
{
|
2003-08-19 02:57:29 +02:00
|
|
|
PLOADED_IMAGE pLoadedImage;
|
|
|
|
|
|
|
|
FIXME("(%s, %s): stub\n", DllName, DllPath);
|
|
|
|
|
|
|
|
pLoadedImage = HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(LOADED_IMAGE));
|
|
|
|
if (pLoadedImage)
|
|
|
|
pLoadedImage->FileHeader = HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(IMAGE_NT_HEADERS));
|
|
|
|
|
1998-10-11 19:04:17 +02:00
|
|
|
return pLoadedImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* ImageUnload (IMAGEHLP.@)
|
1998-10-11 19:04:17 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL WINAPI ImageUnload(PLOADED_IMAGE pLoadedImage)
|
1998-10-11 19:04:17 +02:00
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
LIST_ENTRY *pCurrent, *pFind;
|
2003-08-19 02:57:29 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", pLoadedImage);
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
if(!IMAGEHLP_pFirstLoadedImage || !pLoadedImage)
|
1998-10-11 19:04:17 +02:00
|
|
|
{
|
|
|
|
/* No image loaded or null pointer */
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
pFind=&pLoadedImage->Links;
|
1999-02-26 12:11:13 +01:00
|
|
|
pCurrent=&IMAGEHLP_pFirstLoadedImage->Links;
|
2002-06-01 01:06:46 +02:00
|
|
|
while((pCurrent != pFind) &&
|
|
|
|
(pCurrent != NULL))
|
1998-10-11 19:04:17 +02:00
|
|
|
pCurrent = pCurrent->Flink;
|
|
|
|
if(!pCurrent)
|
|
|
|
{
|
|
|
|
/* Not found */
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pCurrent->Blink)
|
|
|
|
pCurrent->Blink->Flink = pCurrent->Flink;
|
|
|
|
else
|
1999-02-26 12:11:13 +01:00
|
|
|
IMAGEHLP_pFirstLoadedImage = pCurrent->Flink?CONTAINING_RECORD(
|
|
|
|
pCurrent->Flink, LOADED_IMAGE, Links):NULL;
|
1998-10-11 19:04:17 +02:00
|
|
|
|
|
|
|
if(pCurrent->Flink)
|
|
|
|
pCurrent->Flink->Blink = pCurrent->Blink;
|
|
|
|
else
|
1999-02-26 12:11:13 +01:00
|
|
|
IMAGEHLP_pLastLoadedImage = pCurrent->Blink?CONTAINING_RECORD(
|
|
|
|
pCurrent->Blink, LOADED_IMAGE, Links):NULL;
|
1998-10-11 19:04:17 +02:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* MapAndLoad (IMAGEHLP.@)
|
1998-10-11 19:04:17 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL WINAPI MapAndLoad(
|
|
|
|
LPSTR pszImageName, LPSTR pszDllPath, PLOADED_IMAGE pLoadedImage,
|
|
|
|
BOOL bDotDll, BOOL bReadOnly)
|
1998-10-11 19:04:17 +02:00
|
|
|
{
|
|
|
|
CHAR szFileName[MAX_PATH];
|
2003-01-15 00:43:41 +01:00
|
|
|
HANDLE hFile = NULL;
|
|
|
|
HANDLE hFileMapping = NULL;
|
|
|
|
HMODULE hModule = NULL;
|
1999-02-26 12:11:13 +01:00
|
|
|
PIMAGE_NT_HEADERS pNtHeader = NULL;
|
1998-10-11 19:04:17 +02:00
|
|
|
|
2003-08-19 02:57:29 +02:00
|
|
|
TRACE("(%s, %s, %p, %d, %d)\n", pszImageName, pszDllPath, pLoadedImage,
|
|
|
|
bDotDll, bReadOnly);
|
|
|
|
|
1998-10-11 19:04:17 +02:00
|
|
|
/* PathCombine(&szFileName, pszDllPath, pszImageName); */
|
|
|
|
/* PathRenameExtension(&szFileName, bDotDll?:"dll":"exe"); */
|
|
|
|
|
2000-03-28 22:22:59 +02:00
|
|
|
/* FIXME: Check if the file already loaded (use IMAGEHLP_pFirstLoadedImage) */
|
1999-02-26 12:11:13 +01:00
|
|
|
if(!(hFile = CreateFileA(
|
1998-10-11 19:04:17 +02:00
|
|
|
szFileName, GENERIC_READ, 1, /* FIXME: FILE_SHARE_READ not defined */
|
2003-01-15 00:43:41 +01:00
|
|
|
NULL, OPEN_EXISTING, 0, NULL)))
|
1998-10-11 19:04:17 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_FILE_NOT_FOUND);
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
if(!(hFileMapping = CreateFileMappingA(
|
1998-10-11 19:04:17 +02:00
|
|
|
hFile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL)))
|
|
|
|
{
|
|
|
|
DWORD dwLastError = GetLastError();
|
1999-05-14 10:17:14 +02:00
|
|
|
WARN("CreateFileMapping: Error = %ld\n", dwLastError);
|
1998-10-11 19:04:17 +02:00
|
|
|
SetLastError(dwLastError);
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
CloseHandle(hFile);
|
2003-01-15 00:43:41 +01:00
|
|
|
hFile = NULL;
|
1998-10-11 19:04:17 +02:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
if(!(hModule = (HMODULE) MapViewOfFile(
|
1998-10-11 19:04:17 +02:00
|
|
|
hFileMapping, FILE_MAP_READ, 0, 0, 0)))
|
|
|
|
{
|
|
|
|
DWORD dwLastError = GetLastError();
|
1999-05-14 10:17:14 +02:00
|
|
|
WARN("MapViewOfFile: Error = %ld\n", dwLastError);
|
1998-10-11 19:04:17 +02:00
|
|
|
SetLastError(dwLastError);
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(hFileMapping);
|
2003-01-15 00:43:41 +01:00
|
|
|
hFileMapping=NULL;
|
1998-10-11 19:04:17 +02:00
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
pLoadedImage = (PLOADED_IMAGE) HeapAlloc(
|
|
|
|
IMAGEHLP_hHeap, 0, sizeof(LOADED_IMAGE)
|
1998-10-11 19:04:17 +02:00
|
|
|
);
|
|
|
|
|
2003-11-21 22:31:35 +01:00
|
|
|
pNtHeader = RtlImageNtHeader(hModule);
|
1998-10-11 19:04:17 +02:00
|
|
|
|
2000-11-13 05:16:05 +01:00
|
|
|
pLoadedImage->ModuleName = HeapAlloc(IMAGEHLP_hHeap, 0, strlen(pszDllPath)+1); /* FIXME: Correct? */
|
|
|
|
strcpy( pLoadedImage->ModuleName, pszDllPath );
|
1998-10-11 19:04:17 +02:00
|
|
|
pLoadedImage->hFile = hFile;
|
|
|
|
pLoadedImage->MappedAddress = (PUCHAR) hModule;
|
|
|
|
pLoadedImage->FileHeader = pNtHeader;
|
1999-02-26 12:11:13 +01:00
|
|
|
pLoadedImage->Sections = (PIMAGE_SECTION_HEADER)
|
1998-10-11 19:04:17 +02:00
|
|
|
((LPBYTE) &pNtHeader->OptionalHeader +
|
|
|
|
pNtHeader->FileHeader.SizeOfOptionalHeader);
|
|
|
|
pLoadedImage->NumberOfSections =
|
|
|
|
pNtHeader->FileHeader.NumberOfSections;
|
|
|
|
pLoadedImage->SizeOfImage =
|
|
|
|
pNtHeader->OptionalHeader.SizeOfImage;
|
|
|
|
pLoadedImage->Characteristics =
|
|
|
|
pNtHeader->FileHeader.Characteristics;
|
|
|
|
pLoadedImage->LastRvaSection = pLoadedImage->Sections;
|
|
|
|
|
|
|
|
pLoadedImage->fSystemImage = FALSE; /* FIXME */
|
|
|
|
pLoadedImage->fDOSImage = FALSE; /* FIXME */
|
|
|
|
|
|
|
|
/* FIXME: Make thread safe */
|
|
|
|
pLoadedImage->Links.Flink = NULL;
|
1999-02-26 12:11:13 +01:00
|
|
|
pLoadedImage->Links.Blink = &IMAGEHLP_pLastLoadedImage->Links;
|
|
|
|
if(IMAGEHLP_pLastLoadedImage)
|
|
|
|
IMAGEHLP_pLastLoadedImage->Links.Flink = &pLoadedImage->Links;
|
|
|
|
IMAGEHLP_pLastLoadedImage = pLoadedImage;
|
|
|
|
if(!IMAGEHLP_pFirstLoadedImage)
|
|
|
|
IMAGEHLP_pFirstLoadedImage = pLoadedImage;
|
1998-10-11 19:04:17 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
Error:
|
|
|
|
if(hModule)
|
|
|
|
UnmapViewOfFile((PVOID) hModule);
|
|
|
|
if(hFileMapping)
|
|
|
|
CloseHandle(hFileMapping);
|
|
|
|
if(hFile)
|
|
|
|
CloseHandle(hFile);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* SetImageConfigInformation (IMAGEHLP.@)
|
1998-10-11 19:04:17 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL WINAPI SetImageConfigInformation(
|
|
|
|
PLOADED_IMAGE LoadedImage,
|
|
|
|
PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
|
1998-10-11 19:04:17 +02:00
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
FIXME("(%p, %p): stub\n",
|
1998-10-11 19:04:17 +02:00
|
|
|
LoadedImage, ImageConfigInformation
|
|
|
|
);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* UnMapAndLoad (IMAGEHLP.@)
|
1998-10-11 19:04:17 +02:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL WINAPI UnMapAndLoad(PLOADED_IMAGE LoadedImage)
|
1998-10-11 19:04:17 +02:00
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
FIXME("(%p): stub\n", LoadedImage);
|
1998-10-11 19:04:17 +02:00
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|