1998-10-11 19:04:17 +02:00
|
|
|
/*
|
|
|
|
* IMAGEHLP library
|
|
|
|
*
|
|
|
|
* Copyright 1998 Patrik Stridvall
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnt.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "wintypes.h"
|
|
|
|
#include "heap.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "imagehlp.h"
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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 */
|
|
|
|
0xffffffff, /* hFile */
|
|
|
|
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; */
|
|
|
|
};
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* EnumerateLoadedModules32 (IMAGEHLP.4)
|
|
|
|
*/
|
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)
|
|
|
|
{
|
|
|
|
FIXME(imagehlp, "(0x%08x, %p, %p): stub\n",
|
|
|
|
hProcess, EnumLoadedModulesCallback, UserContext
|
|
|
|
);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetTimestampForLoadedLibrary32 (IMAGEHLP.9)
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
DWORD WINAPI GetTimestampForLoadedLibrary(HMODULE Module)
|
1998-10-11 19:04:17 +02:00
|
|
|
{
|
|
|
|
FIXME(imagehlp, "(0x%08x): stub\n", Module);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetImageConfigInformation32 (IMAGEHLP.7)
|
|
|
|
*/
|
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
|
|
|
{
|
|
|
|
FIXME(imagehlp, "(%p, %p): stub\n",
|
|
|
|
LoadedImage, ImageConfigInformation
|
|
|
|
);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetImageUnusedHeaderBytes32 (IMAGEHLP.8)
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
DWORD WINAPI GetImageUnusedHeaderBytes(
|
|
|
|
PLOADED_IMAGE LoadedImage,
|
1998-10-11 19:04:17 +02:00
|
|
|
LPDWORD SizeUnusedHeaderBytes)
|
|
|
|
{
|
|
|
|
FIXME(imagehlp, "(%p, %p): stub\n",
|
|
|
|
LoadedImage, SizeUnusedHeaderBytes
|
|
|
|
);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ImageDirectoryEntryToData32 (IMAGEHLP.11)
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
PVOID WINAPI ImageDirectoryEntryToData(
|
1998-10-11 19:04:17 +02:00
|
|
|
PVOID Base, BOOLEAN MappedAsImage, USHORT DirectoryEntry, PULONG Size)
|
|
|
|
{
|
|
|
|
FIXME(imagehlp, "(%p, %d, %d, %p): stub\n",
|
|
|
|
Base, MappedAsImage, DirectoryEntry, Size
|
|
|
|
);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ImageLoad32 (IMAGEHLP.16)
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
PLOADED_IMAGE WINAPI ImageLoad(LPSTR DllName, LPSTR DllPath)
|
1998-10-11 19:04:17 +02:00
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
PLOADED_IMAGE pLoadedImage =
|
|
|
|
HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(LOADED_IMAGE));
|
1998-10-11 19:04:17 +02:00
|
|
|
return pLoadedImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ImageNtHeader32 (IMAGEHLP.17)
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
PIMAGE_NT_HEADERS WINAPI ImageNtHeader(PVOID Base)
|
1998-10-11 19:04:17 +02:00
|
|
|
{
|
1999-02-26 12:11:13 +01:00
|
|
|
return (PIMAGE_NT_HEADERS)
|
|
|
|
((LPBYTE) Base + ((PIMAGE_DOS_HEADER) Base)->e_lfanew);
|
1998-10-11 19:04:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ImageRvaToSection32 (IMAGEHLP.19)
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
PIMAGE_SECTION_HEADER WINAPI ImageRvaToSection(
|
|
|
|
PIMAGE_NT_HEADERS NtHeaders, PVOID Base, ULONG Rva)
|
1998-10-11 19:04:17 +02:00
|
|
|
{
|
|
|
|
FIXME(imagehlp, "(%p, %p, %ld): stub\n", NtHeaders, Base, Rva);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ImageRvaToVa32 (IMAGEHLP.20)
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
PVOID WINAPI ImageRvaToVa(
|
|
|
|
PIMAGE_NT_HEADERS NtHeaders, PVOID Base, ULONG Rva,
|
|
|
|
PIMAGE_SECTION_HEADER *LastRvaSection)
|
1998-10-11 19:04:17 +02:00
|
|
|
{
|
|
|
|
FIXME(imagehlp, "(%p, %p, %ld, %p): stub\n",
|
|
|
|
NtHeaders, Base, Rva, LastRvaSection
|
|
|
|
);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ImageUnload32 (IMAGEHLP.21)
|
|
|
|
*/
|
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;
|
|
|
|
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;
|
1998-10-11 19:04:17 +02:00
|
|
|
while((pCurrent != pFind) &&
|
|
|
|
(pCurrent != NULL))
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* MapAndLoad32 (IMAGEHLP.25)
|
|
|
|
*/
|
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];
|
1999-02-26 12:11:13 +01:00
|
|
|
HANDLE hFile = (HANDLE) NULL;
|
|
|
|
HANDLE hFileMapping = (HANDLE) NULL;
|
|
|
|
HMODULE hModule = (HMODULE) NULL;
|
|
|
|
PIMAGE_NT_HEADERS pNtHeader = NULL;
|
1998-10-11 19:04:17 +02:00
|
|
|
|
|
|
|
/* PathCombine(&szFileName, pszDllPath, pszImageName); */
|
|
|
|
/* PathRenameExtension(&szFileName, bDotDll?:"dll":"exe"); */
|
|
|
|
|
|
|
|
/* FIXME: Check if the file already loaded (use IMAGEHLP_pFirstLoadedImage32) */
|
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 */
|
1999-02-26 12:11:13 +01:00
|
|
|
NULL, OPEN_EXISTING, 0, (HANDLE) 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();
|
|
|
|
WARN(imagehlp, "CreateFileMapping: Error = %ld\n", dwLastError);
|
|
|
|
SetLastError(dwLastError);
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
CloseHandle(hFile);
|
1999-02-26 12:11:13 +01:00
|
|
|
hFile = (HANDLE) 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();
|
|
|
|
WARN(imagehlp, "MapViewOfFile: Error = %ld\n", dwLastError);
|
|
|
|
SetLastError(dwLastError);
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(hFileMapping);
|
1999-02-26 12:11:13 +01:00
|
|
|
hFileMapping=(HANDLE) 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
|
|
|
);
|
|
|
|
|
1999-02-26 12:11:13 +01:00
|
|
|
pNtHeader = ImageNtHeader((PVOID) hModule);
|
1998-10-11 19:04:17 +02:00
|
|
|
|
|
|
|
pLoadedImage->ModuleName =
|
1999-02-26 12:11:13 +01:00
|
|
|
HEAP_strdupA(IMAGEHLP_hHeap, 0, pszDllPath); /* FIXME: Correct? */
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetImageConfigInformation32 (IMAGEHLP.34)
|
|
|
|
*/
|
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
|
|
|
{
|
|
|
|
FIXME(imagehlp, "(%p, %p): stub\n",
|
|
|
|
LoadedImage, ImageConfigInformation
|
|
|
|
);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* UnMapAndLoad32 (IMAGEHLP.58)
|
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL WINAPI UnMapAndLoad(PLOADED_IMAGE LoadedImage)
|
1998-10-11 19:04:17 +02:00
|
|
|
{
|
|
|
|
FIXME(imagehlp, "(%p): stub\n", LoadedImage);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|