1998-10-11 17:04:17 +00:00
|
|
|
/*
|
|
|
|
* IMAGEHLP library
|
|
|
|
*
|
|
|
|
* Copyright 1998 Patrik Stridvall
|
2002-03-09 23:29:33 +00: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 17:04:17 +00:00
|
|
|
*/
|
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
2001-01-26 20:43:40 +00:00
|
|
|
#include <string.h>
|
2003-09-05 23:08:26 +00:00
|
|
|
#include "windef.h"
|
1998-10-11 17:04:17 +00:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnt.h"
|
2003-11-21 21:31:35 +00:00
|
|
|
#include "winreg.h"
|
|
|
|
#include "winternl.h"
|
1998-10-11 17:04:17 +00:00
|
|
|
#include "winerror.h"
|
2002-03-09 23:29:33 +00:00
|
|
|
#include "wine/debug.h"
|
1998-10-11 17:04:17 +00:00
|
|
|
#include "imagehlp.h"
|
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(imagehlp);
|
1999-04-19 14:56:29 +00:00
|
|
|
|
1998-10-11 17:04:17 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* Data
|
|
|
|
*/
|
|
|
|
|
1999-02-26 11:11:13 +00:00
|
|
|
static PLOADED_IMAGE IMAGEHLP_pFirstLoadedImage=NULL;
|
|
|
|
static PLOADED_IMAGE IMAGEHLP_pLastLoadedImage=NULL;
|
1998-10-11 17:04:17 +00:00
|
|
|
|
1999-02-26 11:11:13 +00:00
|
|
|
static LOADED_IMAGE IMAGEHLP_EmptyLoadedImage = {
|
1998-10-11 17:04:17 +00:00
|
|
|
NULL, /* ModuleName */
|
2002-10-04 00:27:10 +00:00
|
|
|
0, /* hFile */
|
1998-10-11 17:04:17 +00:00
|
|
|
NULL, /* MappedAddress */
|
|
|
|
NULL, /* FileHeader */
|
|
|
|
NULL, /* LastRvaSection */
|
|
|
|
0, /* NumberOfSections */
|
|
|
|
NULL, /* Sections */
|
|
|
|
1, /* Characteristics */
|
|
|
|
FALSE, /* fSystemImage */
|
|
|
|
FALSE, /* fDOSImage */
|
1999-02-26 11:11:13 +00:00
|
|
|
{ &IMAGEHLP_EmptyLoadedImage.Links, &IMAGEHLP_EmptyLoadedImage.Links }, /* Links */
|
1998-10-11 17:04:17 +00:00
|
|
|
148, /* SizeOfImage; */
|
|
|
|
};
|
|
|
|
|
2003-06-27 22:24:23 +00:00
|
|
|
extern HANDLE IMAGEHLP_hHeap;
|
|
|
|
|
1998-10-11 17:04:17 +00:00
|
|
|
/***********************************************************************
|
2000-03-28 20:22:59 +00:00
|
|
|
* GetImageConfigInformation (IMAGEHLP.@)
|
1998-10-11 17:04:17 +00:00
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
BOOL WINAPI GetImageConfigInformation(
|
|
|
|
PLOADED_IMAGE LoadedImage,
|
|
|
|
PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
|
1998-10-11 17:04:17 +00:00
|
|
|
{
|
1999-05-14 08:17:14 +00:00
|
|
|
FIXME("(%p, %p): stub\n",
|
1998-10-11 17:04:17 +00:00
|
|
|
LoadedImage, ImageConfigInformation
|
|
|
|
);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 20:22:59 +00:00
|
|
|
* GetImageUnusedHeaderBytes (IMAGEHLP.@)
|
1998-10-11 17:04:17 +00:00
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
DWORD WINAPI GetImageUnusedHeaderBytes(
|
|
|
|
PLOADED_IMAGE LoadedImage,
|
1998-10-11 17:04:17 +00:00
|
|
|
LPDWORD SizeUnusedHeaderBytes)
|
|
|
|
{
|
1999-05-14 08:17:14 +00:00
|
|
|
FIXME("(%p, %p): stub\n",
|
1998-10-11 17:04:17 +00:00
|
|
|
LoadedImage, SizeUnusedHeaderBytes
|
|
|
|
);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 20:22:59 +00:00
|
|
|
* ImageLoad (IMAGEHLP.@)
|
1998-10-11 17:04:17 +00:00
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
PLOADED_IMAGE WINAPI ImageLoad(LPSTR DllName, LPSTR DllPath)
|
1998-10-11 17:04:17 +00:00
|
|
|
{
|
2003-08-19 00:57:29 +00: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 17:04:17 +00:00
|
|
|
return pLoadedImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 20:22:59 +00:00
|
|
|
* ImageUnload (IMAGEHLP.@)
|
1998-10-11 17:04:17 +00:00
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
BOOL WINAPI ImageUnload(PLOADED_IMAGE pLoadedImage)
|
1998-10-11 17:04:17 +00:00
|
|
|
{
|
1999-02-26 11:11:13 +00:00
|
|
|
LIST_ENTRY *pCurrent, *pFind;
|
2003-08-19 00:57:29 +00:00
|
|
|
|
|
|
|
TRACE("(%p)\n", pLoadedImage);
|
|
|
|
|
1999-02-26 11:11:13 +00:00
|
|
|
if(!IMAGEHLP_pFirstLoadedImage || !pLoadedImage)
|
1998-10-11 17:04:17 +00:00
|
|
|
{
|
|
|
|
/* No image loaded or null pointer */
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
pFind=&pLoadedImage->Links;
|
1999-02-26 11:11:13 +00:00
|
|
|
pCurrent=&IMAGEHLP_pFirstLoadedImage->Links;
|
2002-05-31 23:06:46 +00:00
|
|
|
while((pCurrent != pFind) &&
|
|
|
|
(pCurrent != NULL))
|
1998-10-11 17:04:17 +00: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 11:11:13 +00:00
|
|
|
IMAGEHLP_pFirstLoadedImage = pCurrent->Flink?CONTAINING_RECORD(
|
|
|
|
pCurrent->Flink, LOADED_IMAGE, Links):NULL;
|
1998-10-11 17:04:17 +00:00
|
|
|
|
|
|
|
if(pCurrent->Flink)
|
|
|
|
pCurrent->Flink->Blink = pCurrent->Blink;
|
|
|
|
else
|
1999-02-26 11:11:13 +00:00
|
|
|
IMAGEHLP_pLastLoadedImage = pCurrent->Blink?CONTAINING_RECORD(
|
|
|
|
pCurrent->Blink, LOADED_IMAGE, Links):NULL;
|
1998-10-11 17:04:17 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 20:22:59 +00:00
|
|
|
* MapAndLoad (IMAGEHLP.@)
|
1998-10-11 17:04:17 +00:00
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
BOOL WINAPI MapAndLoad(
|
|
|
|
LPSTR pszImageName, LPSTR pszDllPath, PLOADED_IMAGE pLoadedImage,
|
|
|
|
BOOL bDotDll, BOOL bReadOnly)
|
1998-10-11 17:04:17 +00:00
|
|
|
{
|
|
|
|
CHAR szFileName[MAX_PATH];
|
2003-01-14 23:43:41 +00:00
|
|
|
HANDLE hFile = NULL;
|
|
|
|
HANDLE hFileMapping = NULL;
|
|
|
|
HMODULE hModule = NULL;
|
1999-02-26 11:11:13 +00:00
|
|
|
PIMAGE_NT_HEADERS pNtHeader = NULL;
|
1998-10-11 17:04:17 +00:00
|
|
|
|
2003-08-19 00:57:29 +00:00
|
|
|
TRACE("(%s, %s, %p, %d, %d)\n", pszImageName, pszDllPath, pLoadedImage,
|
|
|
|
bDotDll, bReadOnly);
|
|
|
|
|
1998-10-11 17:04:17 +00:00
|
|
|
/* PathCombine(&szFileName, pszDllPath, pszImageName); */
|
|
|
|
/* PathRenameExtension(&szFileName, bDotDll?:"dll":"exe"); */
|
|
|
|
|
2000-03-28 20:22:59 +00:00
|
|
|
/* FIXME: Check if the file already loaded (use IMAGEHLP_pFirstLoadedImage) */
|
1999-02-26 11:11:13 +00:00
|
|
|
if(!(hFile = CreateFileA(
|
1998-10-11 17:04:17 +00:00
|
|
|
szFileName, GENERIC_READ, 1, /* FIXME: FILE_SHARE_READ not defined */
|
2003-01-14 23:43:41 +00:00
|
|
|
NULL, OPEN_EXISTING, 0, NULL)))
|
1998-10-11 17:04:17 +00:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_FILE_NOT_FOUND);
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
1999-02-26 11:11:13 +00:00
|
|
|
if(!(hFileMapping = CreateFileMappingA(
|
1998-10-11 17:04:17 +00:00
|
|
|
hFile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL)))
|
|
|
|
{
|
|
|
|
DWORD dwLastError = GetLastError();
|
1999-05-14 08:17:14 +00:00
|
|
|
WARN("CreateFileMapping: Error = %ld\n", dwLastError);
|
1998-10-11 17:04:17 +00:00
|
|
|
SetLastError(dwLastError);
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
CloseHandle(hFile);
|
2003-01-14 23:43:41 +00:00
|
|
|
hFile = NULL;
|
1998-10-11 17:04:17 +00:00
|
|
|
|
1999-02-26 11:11:13 +00:00
|
|
|
if(!(hModule = (HMODULE) MapViewOfFile(
|
1998-10-11 17:04:17 +00:00
|
|
|
hFileMapping, FILE_MAP_READ, 0, 0, 0)))
|
|
|
|
{
|
|
|
|
DWORD dwLastError = GetLastError();
|
1999-05-14 08:17:14 +00:00
|
|
|
WARN("MapViewOfFile: Error = %ld\n", dwLastError);
|
1998-10-11 17:04:17 +00:00
|
|
|
SetLastError(dwLastError);
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(hFileMapping);
|
2003-01-14 23:43:41 +00:00
|
|
|
hFileMapping=NULL;
|
1998-10-11 17:04:17 +00:00
|
|
|
|
2005-03-24 21:01:35 +00:00
|
|
|
pLoadedImage = HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(LOADED_IMAGE));
|
1998-10-11 17:04:17 +00:00
|
|
|
|
2003-11-21 21:31:35 +00:00
|
|
|
pNtHeader = RtlImageNtHeader(hModule);
|
1998-10-11 17:04:17 +00:00
|
|
|
|
2000-11-13 04:16:05 +00:00
|
|
|
pLoadedImage->ModuleName = HeapAlloc(IMAGEHLP_hHeap, 0, strlen(pszDllPath)+1); /* FIXME: Correct? */
|
|
|
|
strcpy( pLoadedImage->ModuleName, pszDllPath );
|
1998-10-11 17:04:17 +00:00
|
|
|
pLoadedImage->hFile = hFile;
|
|
|
|
pLoadedImage->MappedAddress = (PUCHAR) hModule;
|
|
|
|
pLoadedImage->FileHeader = pNtHeader;
|
1999-02-26 11:11:13 +00:00
|
|
|
pLoadedImage->Sections = (PIMAGE_SECTION_HEADER)
|
1998-10-11 17:04:17 +00: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 11:11:13 +00: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 17:04:17 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
Error:
|
|
|
|
if(hModule)
|
|
|
|
UnmapViewOfFile((PVOID) hModule);
|
|
|
|
if(hFileMapping)
|
|
|
|
CloseHandle(hFileMapping);
|
|
|
|
if(hFile)
|
|
|
|
CloseHandle(hFile);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 20:22:59 +00:00
|
|
|
* SetImageConfigInformation (IMAGEHLP.@)
|
1998-10-11 17:04:17 +00:00
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
BOOL WINAPI SetImageConfigInformation(
|
|
|
|
PLOADED_IMAGE LoadedImage,
|
|
|
|
PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigInformation)
|
1998-10-11 17:04:17 +00:00
|
|
|
{
|
1999-05-14 08:17:14 +00:00
|
|
|
FIXME("(%p, %p): stub\n",
|
1998-10-11 17:04:17 +00:00
|
|
|
LoadedImage, ImageConfigInformation
|
|
|
|
);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 20:22:59 +00:00
|
|
|
* UnMapAndLoad (IMAGEHLP.@)
|
1998-10-11 17:04:17 +00:00
|
|
|
*/
|
1999-02-26 11:11:13 +00:00
|
|
|
BOOL WINAPI UnMapAndLoad(PLOADED_IMAGE LoadedImage)
|
1998-10-11 17:04:17 +00:00
|
|
|
{
|
1999-05-14 08:17:14 +00:00
|
|
|
FIXME("(%p): stub\n", LoadedImage);
|
1998-10-11 17:04:17 +00:00
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|