Commit 8ca3ca5a authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

imagehlp: MapAndLoad should do some useful stuff now.

parent 3b87fe97
......@@ -145,95 +145,75 @@ BOOL WINAPI ImageUnload(PLOADED_IMAGE pLoadedImage)
/***********************************************************************
* MapAndLoad (IMAGEHLP.@)
*/
BOOL WINAPI MapAndLoad(
LPSTR pszImageName, LPSTR pszDllPath, PLOADED_IMAGE pLoadedImage,
BOOL WINAPI MapAndLoad(LPSTR pszImageName, LPSTR pszDllPath, PLOADED_IMAGE pLoadedImage,
BOOL bDotDll, BOOL bReadOnly)
{
CHAR szFileName[MAX_PATH];
HANDLE hFile = NULL;
HANDLE hFile = INVALID_HANDLE_VALUE;
HANDLE hFileMapping = NULL;
HMODULE hModule = NULL;
PVOID mapping = NULL;
PIMAGE_NT_HEADERS pNtHeader = NULL;
TRACE("(%s, %s, %p, %d, %d)\n", pszImageName, pszDllPath, pLoadedImage,
bDotDll, bReadOnly);
TRACE("(%s, %s, %p, %d, %d)\n",
pszImageName, pszDllPath, pLoadedImage, bDotDll, bReadOnly);
/* PathCombine(&szFileName, pszDllPath, pszImageName); */
/* PathRenameExtension(&szFileName, bDotDll?:"dll":"exe"); */
/* FIXME: Check if the file already loaded (use IMAGEHLP_pFirstLoadedImage) */
if(!(hFile = CreateFileA(
szFileName, GENERIC_READ, 1, /* FIXME: FILE_SHARE_READ not defined */
NULL, OPEN_EXISTING, 0, NULL)))
if (!SearchPathA(pszDllPath, pszImageName, bDotDll ? ".DLL" : ".EXE",
sizeof(szFileName), szFileName, NULL))
{
SetLastError(ERROR_FILE_NOT_FOUND);
goto Error;
}
if(!(hFileMapping = CreateFileMappingA(
hFile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL)))
hFile = CreateFileA(szFileName, GENERIC_READ, 1, /* FIXME: FILE_SHARE_READ not defined */
NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
DWORD dwLastError = GetLastError();
WARN("CreateFileMapping: Error = %d\n", dwLastError);
SetLastError(dwLastError);
WARN("CreateFile: Error = %d\n", GetLastError());
goto Error;
}
CloseHandle(hFile);
hFile = NULL;
if(!(hModule = (HMODULE) MapViewOfFile(
hFileMapping, FILE_MAP_READ, 0, 0, 0)))
hFileMapping = CreateFileMappingA(hFile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
if (!hFileMapping)
{
DWORD dwLastError = GetLastError();
WARN("MapViewOfFile: Error = %d\n", dwLastError);
SetLastError(dwLastError);
WARN("CreateFileMapping: Error = %d\n", GetLastError());
goto Error;
}
mapping = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
CloseHandle(hFileMapping);
hFileMapping=NULL;
pLoadedImage = HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(LOADED_IMAGE));
if (!mapping)
{
WARN("MapViewOfFile: Error = %d\n", GetLastError());
goto Error;
}
pNtHeader = RtlImageNtHeader(hModule);
pNtHeader = RtlImageNtHeader(mapping);
pLoadedImage->ModuleName = HeapAlloc(IMAGEHLP_hHeap, 0, strlen(pszDllPath)+1); /* FIXME: Correct? */
strcpy( pLoadedImage->ModuleName, pszDllPath );
pLoadedImage->ModuleName = HeapAlloc(GetProcessHeap(), 0,
strlen(szFileName) + 1);
if (pLoadedImage->ModuleName) strcpy(pLoadedImage->ModuleName, szFileName);
pLoadedImage->hFile = hFile;
pLoadedImage->MappedAddress = (PUCHAR) hModule;
pLoadedImage->MappedAddress = mapping;
pLoadedImage->FileHeader = pNtHeader;
pLoadedImage->Sections = (PIMAGE_SECTION_HEADER)
((LPBYTE) &pNtHeader->OptionalHeader +
pNtHeader->FileHeader.SizeOfOptionalHeader);
pLoadedImage->NumberOfSections =
pNtHeader->FileHeader.NumberOfSections;
pLoadedImage->SizeOfImage =
pNtHeader->OptionalHeader.SizeOfImage;
pLoadedImage->Characteristics =
pNtHeader->FileHeader.Characteristics;
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;
pLoadedImage->Links.Blink = &IMAGEHLP_pLastLoadedImage->Links;
if(IMAGEHLP_pLastLoadedImage)
IMAGEHLP_pLastLoadedImage->Links.Flink = &pLoadedImage->Links;
IMAGEHLP_pLastLoadedImage = pLoadedImage;
if(!IMAGEHLP_pFirstLoadedImage)
IMAGEHLP_pFirstLoadedImage = pLoadedImage;
pLoadedImage->Links.Flink = &pLoadedImage->Links;
pLoadedImage->Links.Blink = &pLoadedImage->Links;
return TRUE;
Error:
if(hModule)
UnmapViewOfFile((PVOID) hModule);
if(hFileMapping)
CloseHandle(hFileMapping);
if(hFile)
CloseHandle(hFile);
if (mapping) UnmapViewOfFile(mapping);
if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile);
return FALSE;
}
......@@ -254,9 +234,11 @@ BOOL WINAPI SetImageConfigInformation(
/***********************************************************************
* UnMapAndLoad (IMAGEHLP.@)
*/
BOOL WINAPI UnMapAndLoad(PLOADED_IMAGE LoadedImage)
BOOL WINAPI UnMapAndLoad(PLOADED_IMAGE pLoadedImage)
{
FIXME("(%p): stub\n", LoadedImage);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
HeapFree(GetProcessHeap(), 0, pLoadedImage->ModuleName);
/* FIXME: MSDN states that a new checksum is computed and stored into the file */
if (pLoadedImage->MappedAddress) UnmapViewOfFile(pLoadedImage->MappedAddress);
if (pLoadedImage->hFile != INVALID_HANDLE_VALUE) CloseHandle(pLoadedImage->hFile);
return TRUE;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment