[PATCH] [ImageHlp]: MapAndLoad

Eric Pouech eric.pouech at wanadoo.fr
Tue Dec 26 10:18:45 CST 2006


- Fixed computation of SizeOfImage (makes Zuma happy, and 
  completly fixes #6099)
- Now making use of the bReadOnly parameter

A+
---

 dlls/imagehlp/access.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/dlls/imagehlp/access.c b/dlls/imagehlp/access.c
index e303896..8af00d3 100644
--- a/dlls/imagehlp/access.c
+++ b/dlls/imagehlp/access.c
@@ -153,6 +153,7 @@ BOOL WINAPI MapAndLoad(LPSTR pszImageNam
     HANDLE hFileMapping = NULL;
     PVOID mapping = NULL;
     PIMAGE_NT_HEADERS pNtHeader = NULL;
+    unsigned i;
 
     TRACE("(%s, %s, %p, %d, %d)\n",
           pszImageName, pszDllPath, pLoadedImage, bDotDll, bReadOnly);
@@ -164,7 +165,9 @@ BOOL WINAPI MapAndLoad(LPSTR pszImageNam
         goto Error;
     }
 
-    hFile = CreateFileA(szFileName, GENERIC_READ, 1, /* FIXME: FILE_SHARE_READ not defined */
+    hFile = CreateFileA(szFileName,
+                        GENERIC_READ | (bReadOnly ? 0 : GENERIC_WRITE),
+                        1, /* FIXME: FILE_SHARE_READ not defined */
                         NULL, OPEN_EXISTING, 0, NULL);
     if (hFile == INVALID_HANDLE_VALUE)
     {
@@ -172,7 +175,9 @@ BOOL WINAPI MapAndLoad(LPSTR pszImageNam
         goto Error;
     }
 
-    hFileMapping = CreateFileMappingA(hFile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
+    hFileMapping = CreateFileMappingA(hFile, NULL, 
+                                      (bReadOnly ? PAGE_READONLY : PAGE_READWRITE) | SEC_COMMIT,
+                                      0, 0, NULL);
     if (!hFileMapping)
     {
         WARN("CreateFileMapping: Error = %d\n", GetLastError());
@@ -199,7 +204,10 @@ BOOL WINAPI MapAndLoad(LPSTR pszImageNam
         ((LPBYTE) &pNtHeader->OptionalHeader +
          pNtHeader->FileHeader.SizeOfOptionalHeader);
     pLoadedImage->NumberOfSections = pNtHeader->FileHeader.NumberOfSections;
-    pLoadedImage->SizeOfImage      = pNtHeader->OptionalHeader.SizeOfImage;
+    /* we need to return the size of image which has been mapped */
+    pLoadedImage->SizeOfImage      = pNtHeader->OptionalHeader.SizeOfHeaders;
+    for (i = 0; i < pLoadedImage->NumberOfSections; i++)
+        pLoadedImage->SizeOfImage  += pLoadedImage->Sections[i].SizeOfRawData;
     pLoadedImage->Characteristics  = pNtHeader->FileHeader.Characteristics;
     pLoadedImage->LastRvaSection   = pLoadedImage->Sections;
 



More information about the wine-patches mailing list