[ros-diffs] [fireball] 51061: [RTL] - Hack away LdrVerifyMappedImageMatchesChecksum() invocations with zero ImageSize until MM is fixed. - Implement a helper ChkSum() routine to be used later by LdrVerifyMappe...

fireball at svn.reactos.org fireball at svn.reactos.org
Wed Mar 16 11:58:14 UTC 2011


Author: fireball
Date: Wed Mar 16 11:58:12 2011
New Revision: 51061

URL: http://svn.reactos.org/svn/reactos?rev=51061&view=rev
Log:
[RTL]
- Hack away LdrVerifyMappedImageMatchesChecksum() invocations with zero ImageSize until MM is fixed.
- Implement a helper ChkSum() routine to be used later by LdrVerifyMappedImageMatchesChecksum().

Modified:
    trunk/reactos/lib/rtl/image.c

Modified: trunk/reactos/lib/rtl/image.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/image.c?rev=51061&r1=51060&r2=51061&view=diff
==============================================================================
--- trunk/reactos/lib/rtl/image.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/image.c [iso-8859-1] Wed Mar 16 11:58:12 2011
@@ -20,6 +20,25 @@
 
 /* FUNCTIONS *****************************************************************/
 
+USHORT
+FORCEINLINE
+ChkSum(ULONG Sum, PUSHORT Src, ULONG Len)
+{
+    ULONG i;
+
+    for (i=0; i<Len; i++)
+    {
+        /* Sum up the current word */
+        Sum += Src[i];
+
+        /* Sum up everything above the low word as a carry */
+        Sum = (Sum & 0xFFFF) + (Sum >> 16);
+    }
+
+    /* Apply carry one more time and clamp to the USHORT */
+    return (Sum + (Sum >> 16)) & 0xFFFF;
+}
+
 BOOLEAN
 NTAPI
 LdrVerifyMappedImageMatchesChecksum(
@@ -34,8 +53,11 @@
     ULONG HeaderSum;
     ULONG i;
 
+    // HACK: Ignore calls with ImageSize=0. Should be fixed by new MM.
+    if (ImageSize == 0) return TRUE;
+
     /* Get NT header to check if it's an image at all */
-    Header = RtlImageNtHeader (BaseAddress);
+    Header = RtlImageNtHeader(BaseAddress);
     if (!Header) return FALSE;
 
     /* Get checksum to match */
@@ -93,7 +115,7 @@
     CalcSum += ImageSize;
 
     if (CalcSum != HeaderSum)
-        DPRINT1("Image %p checksum mismatches! 0x%x != 0x%x\n", BaseAddress, CalcSum, HeaderSum);
+        DPRINT1("Image %p checksum mismatches! 0x%x != 0x%x, ImageSize %x, FileLen %x\n", BaseAddress, CalcSum, HeaderSum, ImageSize, FileLength);
 
     return (BOOLEAN)(CalcSum == HeaderSum);
 }




More information about the Ros-diffs mailing list