https://git.reactos.org/?p=reactos.git;a=commitdiff;h=fc87cf0bc339281d0d346…
commit fc87cf0bc339281d0d346ecdbb25bfe8be1e612f
Author: Amine Khaldi <amine.khaldi(a)reactos.org>
AuthorDate: Fri Jan 19 00:37:52 2018 +0100
Commit: Amine Khaldi <amine.khaldi(a)reactos.org>
CommitDate: Fri Jan 19 00:37:52 2018 +0100
[IMAGEHLP] Sync with Wine 3.0. CORE-14225
---
dll/win32/imagehlp/access.c | 85 ++++++++----------
dll/win32/imagehlp/modify.c | 214 ++++++++++----------------------------------
media/doc/README.WINE | 2 +-
3 files changed, 86 insertions(+), 215 deletions(-)
diff --git a/dll/win32/imagehlp/access.c b/dll/win32/imagehlp/access.c
index b386ce323d..367efac5d5 100644
--- a/dll/win32/imagehlp/access.c
+++ b/dll/win32/imagehlp/access.c
@@ -25,7 +25,8 @@
/***********************************************************************
* Data
*/
-LIST_ENTRY image_list = { &image_list, &image_list };
+
+static PLOADED_IMAGE IMAGEHLP_pFirstLoadedImage=NULL;
DECLSPEC_HIDDEN extern HANDLE IMAGEHLP_hHeap;
@@ -60,69 +61,57 @@ DWORD WINAPI GetImageUnusedHeaderBytes(
/***********************************************************************
* ImageLoad (IMAGEHLP.@)
*/
-PLOADED_IMAGE WINAPI ImageLoad(PCSTR dll_name, PCSTR dll_path)
+PLOADED_IMAGE WINAPI ImageLoad(PCSTR DllName, PCSTR DllPath)
{
- LOADED_IMAGE *image;
-
- TRACE("(%s, %s)\n", dll_name, dll_path);
-
- image = HeapAlloc(IMAGEHLP_hHeap, 0, sizeof(*image));
- if (!image) return NULL;
-
- if (!MapAndLoad(dll_name, dll_path, image, TRUE, TRUE))
- {
- HeapFree(IMAGEHLP_hHeap, 0, image);
- return NULL;
- }
-
- image->Links.Flink = image_list.Flink;
- image->Links.Blink = &image_list;
- image_list.Flink->Blink = &image->Links;
- image_list.Flink = &image->Links;
-
- return image;
+ 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));
+
+ return pLoadedImage;
}
/***********************************************************************
* ImageUnload (IMAGEHLP.@)
*/
-BOOL WINAPI ImageUnload(PLOADED_IMAGE loaded_image)
+BOOL WINAPI ImageUnload(PLOADED_IMAGE pLoadedImage)
{
- LIST_ENTRY *entry, *mark;
- PLOADED_IMAGE image;
-
- FIXME("(%p)\n", loaded_image);
+ LIST_ENTRY *pCurrent, *pFind;
- if (!loaded_image)
+ TRACE("(%p)\n", pLoadedImage);
+
+ if(!IMAGEHLP_pFirstLoadedImage || !pLoadedImage)
{
- /* No image loaded or null pointer */
- SetLastError(ERROR_INVALID_PARAMETER);
- return FALSE;
+ /* No image loaded or null pointer */
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
}
- /* FIXME: do we really need to check this? */
- mark = &image_list;
- for (entry = mark->Flink; entry != mark; entry = entry->Flink)
+ pFind=&pLoadedImage->Links;
+ pCurrent=&IMAGEHLP_pFirstLoadedImage->Links;
+ while((pCurrent != pFind) &&
+ (pCurrent != NULL))
+ pCurrent = pCurrent->Flink;
+ if(!pCurrent)
{
- image = CONTAINING_RECORD(entry, LOADED_IMAGE, Links);
- if (image == loaded_image)
- break;
+ /* Not found */
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
}
- if (entry == mark)
- {
- /* Not found */
- SetLastError(ERROR_INVALID_PARAMETER);
- return FALSE;
- }
+ if(pCurrent->Blink)
+ pCurrent->Blink->Flink = pCurrent->Flink;
+ else
+ IMAGEHLP_pFirstLoadedImage = pCurrent->Flink?CONTAINING_RECORD(
+ pCurrent->Flink, LOADED_IMAGE, Links):NULL;
- entry->Blink->Flink = entry->Flink;
- entry->Flink->Blink = entry->Blink;
+ if(pCurrent->Flink)
+ pCurrent->Flink->Blink = pCurrent->Blink;
- UnMapAndLoad(loaded_image);
- HeapFree(IMAGEHLP_hHeap, 0, loaded_image);
-
- return TRUE;
+ return FALSE;
}
/***********************************************************************
diff --git a/dll/win32/imagehlp/modify.c b/dll/win32/imagehlp/modify.c
index 4ec92ebc98..6adabb6771 100644
--- a/dll/win32/imagehlp/modify.c
+++ b/dll/win32/imagehlp/modify.c
@@ -25,11 +25,9 @@
static WORD CalcCheckSum(DWORD StartValue, LPVOID BaseAddress, DWORD WordCount);
+
/***********************************************************************
* BindImage (IMAGEHLP.@)
- *
- * NOTES
- * See BindImageEx
*/
BOOL WINAPI BindImage(
PCSTR ImageName, PCSTR DllPath, PCSTR SymbolPath)
@@ -39,138 +37,42 @@ BOOL WINAPI BindImage(
/***********************************************************************
* BindImageEx (IMAGEHLP.@)
- *
- * Compute the virtual address of each function imported by a PE image
- *
- * PARAMS
- *
- * Flags [in] Bind options
- * ImageName [in] File name of the image to be bound
- * DllPath [in] Root of the fallback search path in case the ImageName file
cannot be opened
- * SymbolPath [in] Symbol file root search path
- * StatusRoutine [in] Pointer to a status routine which will be called during the
binding process
- *
- * RETURNS
- * Success: TRUE
- * Failure: FALSE
- *
- * NOTES
- * Binding is not implemented yet, so far this function only enumerates
- * all imported dlls/functions and returns TRUE.
*/
BOOL WINAPI BindImageEx(
DWORD Flags, PCSTR ImageName, PCSTR DllPath, PCSTR SymbolPath,
PIMAGEHLP_STATUS_ROUTINE StatusRoutine)
{
- LOADED_IMAGE loaded_image;
- const IMAGE_IMPORT_DESCRIPTOR *import_desc;
- ULONG size;
-
- FIXME("(%d, %s, %s, %s, %p): semi-stub\n",
- Flags, debugstr_a(ImageName), debugstr_a(DllPath),
- debugstr_a(SymbolPath), StatusRoutine
- );
-
- if (!(MapAndLoad(ImageName, DllPath, &loaded_image, TRUE, TRUE))) return FALSE;
-
- if (!(import_desc = RtlImageDirectoryEntryToData((HMODULE)loaded_image.MappedAddress,
FALSE,
- IMAGE_DIRECTORY_ENTRY_IMPORT,
&size)))
- {
- UnMapAndLoad(&loaded_image);
- return TRUE; /* No imported modules means nothing to bind, so we're done. */
- }
-
- /* FIXME: Does native imagehlp support both 32-bit and 64-bit PE executables? */
-#ifdef _WIN64
- if (loaded_image.FileHeader->OptionalHeader.Magic !=
IMAGE_NT_OPTIONAL_HDR64_MAGIC)
-#else
- if (loaded_image.FileHeader->OptionalHeader.Magic !=
IMAGE_NT_OPTIONAL_HDR32_MAGIC)
-#endif
- {
- FIXME("Wrong architecture in PE header, unable to enumerate
imports\n");
- UnMapAndLoad(&loaded_image);
- return TRUE;
- }
-
- for (; import_desc->Name && import_desc->FirstThunk; ++import_desc)
- {
- IMAGE_THUNK_DATA *thunk;
- char dll_fullname[MAX_PATH];
- const char *dll_name;
-
- if (!(dll_name = ImageRvaToVa(loaded_image.FileHeader,
loaded_image.MappedAddress,
- import_desc->Name, 0)))
- {
- UnMapAndLoad(&loaded_image);
- SetLastError(ERROR_INVALID_ACCESS); /* FIXME */
- return FALSE;
- }
-
- if (StatusRoutine)
- StatusRoutine(BindImportModule, ImageName, dll_name, 0, 0);
-
- if (!SearchPathA(DllPath, dll_name, 0, sizeof(dll_fullname), dll_fullname, 0))
- {
- UnMapAndLoad(&loaded_image);
- SetLastError(ERROR_FILE_NOT_FOUND);
- return FALSE;
- }
-
- if (!(thunk = ImageRvaToVa(loaded_image.FileHeader, loaded_image.MappedAddress,
- import_desc->OriginalFirstThunk ?
import_desc->OriginalFirstThunk :
- import_desc->FirstThunk, 0)))
- {
- ERR("Can't grab thunk data of %s, going to next imported
DLL\n", dll_name);
- continue;
- }
-
- for (; thunk->u1.Ordinal; ++thunk)
- {
- /* Ignoring ordinal imports for now */
- if(!IMAGE_SNAP_BY_ORDINAL(thunk->u1.Ordinal))
- {
- IMAGE_IMPORT_BY_NAME *iibn;
-
- if (!(iibn = ImageRvaToVa(loaded_image.FileHeader,
loaded_image.MappedAddress,
- thunk->u1.AddressOfData, 0)))
- {
- ERR("Can't grab import by name info, skipping to next
ordinal\n");
- continue;
- }
-
- if (StatusRoutine)
- StatusRoutine(BindImportProcedure, ImageName, dll_fullname, 0,
(ULONG_PTR)iibn->Name);
- }
- }
- }
-
- UnMapAndLoad(&loaded_image);
- return TRUE;
+ FIXME("(%d, %s, %s, %s, %p): stub\n",
+ Flags, debugstr_a(ImageName), debugstr_a(DllPath),
+ debugstr_a(SymbolPath), StatusRoutine
+ );
+ return TRUE;
}
/***********************************************************************
* CheckSum (internal)
*/
-static WORD CalcCheckSum(DWORD StartValue, LPVOID BaseAddress, DWORD ByteCount)
+static WORD CalcCheckSum(
+ DWORD StartValue, LPVOID BaseAddress, DWORD WordCount)
{
- LPWORD Ptr;
- DWORD Sum, i;
-
- Sum = StartValue;
- Ptr = (LPWORD)BaseAddress;
- for (i = ByteCount; i > 1; i -= 2)
- {
- Sum += *Ptr;
- if (HIWORD(Sum) != 0)
- Sum = LOWORD(Sum) + HIWORD(Sum);
- Ptr++;
- }
-
- if (i == 1)
- Sum += *(BYTE *)Ptr;
-
- return (WORD)(LOWORD(Sum) + HIWORD(Sum));
+ LPWORD Ptr;
+ DWORD Sum;
+ DWORD i;
+
+ Sum = StartValue;
+ Ptr = (LPWORD)BaseAddress;
+ for (i = 0; i < WordCount; i++)
+ {
+ Sum += *Ptr;
+ if (HIWORD(Sum) != 0)
+ {
+ Sum = LOWORD(Sum) + HIWORD(Sum);
+ }
+ Ptr++;
+ }
+
+ return (WORD)(LOWORD(Sum) + HIWORD(Sum));
}
@@ -184,57 +86,37 @@ PIMAGE_NT_HEADERS WINAPI CheckSumMappedFile(
IMAGE_DOS_HEADER *dos = (IMAGE_DOS_HEADER *) BaseAddress;
PIMAGE_NT_HEADERS32 Header32;
PIMAGE_NT_HEADERS64 Header64;
- PIMAGE_NT_HEADERS ret = NULL;
DWORD *ChecksumFile;
DWORD CalcSum;
- DWORD HdrSum = 0;
+ DWORD HdrSum;
TRACE("(%p, %d, %p, %p)\n",
BaseAddress, FileLength, HeaderSum, CheckSum
);
- CalcSum = (DWORD)CalcCheckSum(0, BaseAddress, FileLength);
+ CalcSum = (DWORD)CalcCheckSum(0,
+ BaseAddress,
+ (FileLength + 1) / sizeof(WORD));
- __TRY
- {
- if (dos->e_magic != IMAGE_DOS_SIGNATURE)
-#ifdef __REACTOS__
- _SEH2_LEAVE;
-#else
- break;
-#endif
-
- Header32 = (IMAGE_NT_HEADERS32 *)((char *)dos + dos->e_lfanew);
- if (Header32->Signature != IMAGE_NT_SIGNATURE)
-#ifdef __REACTOS__
- _SEH2_LEAVE;
-#else
- break;
-#endif
-
- ret = (PIMAGE_NT_HEADERS)Header32;
-
- if (Header32->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
- ChecksumFile = &Header32->OptionalHeader.CheckSum;
- else if (Header32->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
- {
- Header64 = (IMAGE_NT_HEADERS64 *)Header32;
- ChecksumFile = &Header64->OptionalHeader.CheckSum;
- }
- else
-#ifdef __REACTOS__
- _SEH2_LEAVE;
-#else
- break;
-#endif
-
- HdrSum = *ChecksumFile;
- }
- __EXCEPT_PAGE_FAULT
+ if (dos->e_magic != IMAGE_DOS_SIGNATURE)
+ return NULL;
+
+ Header32 = (IMAGE_NT_HEADERS32 *)((char *)dos + dos->e_lfanew);
+
+ if (Header32->Signature != IMAGE_NT_SIGNATURE)
+ return NULL;
+
+ if (Header32->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
+ ChecksumFile = &Header32->OptionalHeader.CheckSum;
+ else if (Header32->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
{
- /* nothing */
+ Header64 = (IMAGE_NT_HEADERS64 *)Header32;
+ ChecksumFile = &Header64->OptionalHeader.CheckSum;
}
- __ENDTRY
+ else
+ return NULL;
+
+ HdrSum = *ChecksumFile;
/* Subtract image checksum from calculated checksum. */
/* fix low word of checksum */
@@ -261,9 +143,9 @@ PIMAGE_NT_HEADERS WINAPI CheckSumMappedFile(
CalcSum += FileLength;
*CheckSum = CalcSum;
- *HeaderSum = HdrSum;
+ *HeaderSum = *ChecksumFile;
- return ret;
+ return (PIMAGE_NT_HEADERS) Header32;
}
/***********************************************************************
diff --git a/media/doc/README.WINE b/media/doc/README.WINE
index 0d0cc1caa1..83a7f59101 100644
--- a/media/doc/README.WINE
+++ b/media/doc/README.WINE
@@ -76,7 +76,7 @@ reactos/dll/win32/httpapi # Synced to WineStaging-2.9
reactos/dll/win32/iccvid # Synced to Wine-3.0
reactos/dll/win32/ieframe # Synced to Wine-3.0
reactos/dll/win32/imaadp32.acm # Synced to WineStaging-2.16
-reactos/dll/win32/imagehlp # Synced to WineStaging-2.9
+reactos/dll/win32/imagehlp # Synced to Wine-3.0
reactos/dll/win32/imm32 # Synced to Wine-2.22
reactos/dll/win32/inetcomm # Synced to WineStaging-2.16
reactos/dll/win32/inetmib1 # Synced to WineStaging-2.9