1998-10-11 19:04:17 +02:00
|
|
|
/*
|
|
|
|
* IMAGEHLP library
|
|
|
|
*
|
|
|
|
* Copyright 1998 Patrik Stridvall
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnt.h"
|
|
|
|
#include "winerror.h"
|
1999-03-14 17:35:05 +01:00
|
|
|
#include "windef.h"
|
1998-10-11 19:04:17 +02:00
|
|
|
#include "heap.h"
|
1999-05-14 10:17:14 +02:00
|
|
|
#include "debugtools.h"
|
1998-10-11 19:04:17 +02:00
|
|
|
#include "imagehlp.h"
|
|
|
|
|
2000-03-28 22:22:59 +02:00
|
|
|
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 */
|
|
|
|
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; */
|
|
|
|
};
|
|
|
|
|
|
|
|
/***********************************************************************
|
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)
|
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
FIXME("(0x%08x, %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
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
FIXME("(0x%08x): 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
|
|
|
* ImageDirectoryEntryToData (IMAGEHLP.@)
|
1998-10-11 19:04:17 +02:00
|
|
|
*/
|
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)
|
|
|
|
{
|
2000-05-11 23:48:28 +02:00
|
|
|
FIXME("(%p, %d, %hd, %p): stub\n",
|
1998-10-11 19:04:17 +02:00
|
|
|
Base, MappedAsImage, DirectoryEntry, Size
|
|
|
|
);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
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
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* ImageNtHeader (IMAGEHLP.@)
|
1998-10-11 19:04:17 +02:00
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* ImageRvaToSection (IMAGEHLP.@)
|
1998-10-11 19:04:17 +02:00
|
|
|
*/
|
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
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
FIXME("(%p, %p, %ld): stub\n", NtHeaders, Base, Rva);
|
1998-10-11 19:04:17 +02:00
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* ImageRvaToVa (IMAGEHLP.@)
|
1998-10-11 19:04:17 +02:00
|
|
|
*/
|
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
|
|
|
{
|
1999-05-14 10:17:14 +02:00
|
|
|
FIXME("(%p, %p, %ld, %p): stub\n",
|
1998-10-11 19:04:17 +02:00
|
|
|
NtHeaders, Base, Rva, LastRvaSection
|
|
|
|
);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
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;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
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];
|
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"); */
|
|
|
|
|
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 */
|
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();
|
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);
|
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();
|
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);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|