DbgHelp: Fix for Loading .DBG Files

Robert Shearman rob at codeweavers.com
Sun Oct 3 16:50:54 CDT 2004


Hi,

The PE .dbg files do not contain the IMAGE_NT_SIGNATURE, so 
RtlImageNtHeader will return NULL and the current code will crash. This 
patch fixes the code to not rely on RtlImageNtHeader and to do some 
simple validation and use IMAGE_SEPARATE_DEBUG_HEADER (the actual header 
of a .dbg file) instead of IMAGE_NT_HEADERS.

Rob

Changelog:
Fix the loading .dbg files by no longer using RtlImageNtHeader which 
would return NULL and using looking at the IMAGE_SEPARATE_DEBUG_HEADER 
directly instead.
-------------- next part --------------
Index: wine/dlls/dbghelp/msc.c
===================================================================
RCS file: /home/wine/wine/dlls/dbghelp/msc.c,v
retrieving revision 1.6
diff -u -p -r1.6 msc.c
--- wine/dlls/dbghelp/msc.c	30 Aug 2004 19:31:14 -0000	1.6
+++ wine/dlls/dbghelp/msc.c	3 Oct 2004 21:37:09 -0000
@@ -2997,11 +2997,12 @@ BOOL pe_load_debug_directory(const struc
     BOOL                        ret;
     int                         i;
     struct msc_debug_info       msc_dbg;
-    const IMAGE_NT_HEADERS*     nth = RtlImageNtHeader((void*)mapping);
+    const IMAGE_SEPARATE_DEBUG_HEADER* dbg_hdr = (const IMAGE_SEPARATE_DEBUG_HEADER*)mapping;
 
     msc_dbg.module = module;
-    msc_dbg.nsect  = nth->FileHeader.NumberOfSections;
-    msc_dbg.sectp  = (const IMAGE_SECTION_HEADER*)((const char*)&nth->OptionalHeader + nth->FileHeader.SizeOfOptionalHeader);
+    msc_dbg.nsect  = dbg_hdr->NumberOfSections;
+    /* section headers come immediately after debug header */
+    msc_dbg.sectp  = (const IMAGE_SECTION_HEADER*)(dbg_hdr + 1);
     msc_dbg.nomap  = 0;
     msc_dbg.omapp  = NULL;
 
Index: wine/dlls/dbghelp/pe_module.c
===================================================================
RCS file: /home/wine/wine/dlls/dbghelp/pe_module.c,v
retrieving revision 1.5
diff -u -p -r1.5 pe_module.c
--- wine/dlls/dbghelp/pe_module.c	30 Aug 2004 19:31:13 -0000	1.5
+++ wine/dlls/dbghelp/pe_module.c	3 Oct 2004 21:37:09 -0000
@@ -115,13 +115,18 @@ static BOOL pe_load_dbg_file(const struc
              * which have incorrect timestamps.
              */
         }
-        dbg = (const IMAGE_DEBUG_DIRECTORY*) 
-            (dbg_mapping + sizeof(*hdr) + 
-             hdr->NumberOfSections * sizeof(IMAGE_SECTION_HEADER) +
-             hdr->ExportedNamesSize);
-
-        ret = pe_load_debug_directory(pcs, module, dbg_mapping, dbg, 
-                                      hdr->DebugDirectorySize / sizeof(*dbg));
+        if (hdr->Signature == IMAGE_SEPARATE_DEBUG_SIGNATURE)
+        {
+            dbg = (const IMAGE_DEBUG_DIRECTORY*) 
+                (dbg_mapping + sizeof(*hdr) + 
+                 hdr->NumberOfSections * sizeof(IMAGE_SECTION_HEADER) +
+                 hdr->ExportedNamesSize);
+    
+            ret = pe_load_debug_directory(pcs, module, dbg_mapping, dbg, 
+                                          hdr->DebugDirectorySize / sizeof(*dbg));
+        }
+        else
+            ERR("Wrong signature in .DBG file %s\n", debugstr_a(tmp));
     }
     else
         WINE_ERR("-Unable to peruse .DBG file %s (%s)\n", dbg_name, debugstr_a(tmp));


More information about the wine-patches mailing list