Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

checksum.c File Reference

#include "ntrtlp.h"

Go to the source code of this file.

Functions

USHORT ChkSum (ULONG PartialSum, PUSHORT Source, ULONG Length)
BOOLEAN LdrVerifyMappedImageMatchesChecksum (IN PVOID BaseAddress, IN ULONG FileLength)


Function Documentation

USHORT ChkSum ULONG  PartialSum,
PUSHORT  Source,
ULONG  Length
 

Definition at line 48 of file checksum.c.

References RTL_PAGED_CODE, and USHORT.

Referenced by LdrVerifyMappedImageMatchesChecksum().

00056 : 00057 00058 Compute a partial checksum on a portion of an imagefile. 00059 00060 Arguments: 00061 00062 PartialSum - Supplies the initial checksum value. 00063 00064 Sources - Supplies a pointer to the array of words for which the 00065 checksum is computed. 00066 00067 Length - Supplies the length of the array in words. 00068 00069 Return Value: 00070 00071 The computed checksum value is returned as the function value. 00072 00073 --*/ 00074 00075 { 00076 00077 RTL_PAGED_CODE(); 00078 00079 // 00080 // Compute the word wise checksum allowing carries to occur into the 00081 // high order half of the checksum longword. 00082 // 00083 00084 while (Length--) { 00085 PartialSum += *Source++; 00086 PartialSum = (PartialSum >> 16) + (PartialSum & 0xffff); 00087 } 00088 00089 // 00090 // Fold final carry into a single word result and return the resultant 00091 // value. 00092 // 00093 00094 return (USHORT)(((PartialSum >> 16) + PartialSum) & 0xffff); 00095 } #endif // !defined(_IA64_)

BOOLEAN LdrVerifyMappedImageMatchesChecksum IN PVOID  BaseAddress,
IN ULONG  FileLength
 

Definition at line 99 of file checksum.c.

References ChkSum(), NULL, PUSHORT, RTL_PAGED_CODE, RtlImageNtHeader(), TRUE, and USHORT.

Referenced by LdrVerifyImageMatchesChecksum(), and MmCheckSystemImage().

00106 : 00107 00108 This functions computes the checksum of an image mapped as a data file. 00109 00110 Arguments: 00111 00112 BaseAddress - Supplies a pointer to the base of the mapped file. 00113 00114 FileLength - Supplies the length of the file in bytes. 00115 00116 Return Value: 00117 00118 TRUE - The checksum stored in the image matches the checksum of the data. 00119 00120 FALSE - The checksum in the image is not correct. 00121 00122 --*/ 00123 00124 { 00125 00126 PUSHORT AdjustSum; 00127 PIMAGE_NT_HEADERS NtHeaders; 00128 USHORT PartialSum; 00129 ULONG HeaderSum; 00130 ULONG CheckSum; 00131 00132 RTL_PAGED_CODE(); 00133 00134 // 00135 // Compute the checksum of the file and zero the header checksum value. 00136 // 00137 00138 HeaderSum = 0; 00139 PartialSum = ChkSum(0, (PUSHORT)BaseAddress, (FileLength + 1) >> 1); 00140 00141 // 00142 // If the file is an image file, then subtract the two checksum words 00143 // in the optional header from the computed checksum before adding 00144 // the file length, and set the value of the header checksum. 00145 // 00146 00147 NtHeaders = RtlImageNtHeader(BaseAddress); 00148 if (NtHeaders != NULL) { 00149 HeaderSum = NtHeaders->OptionalHeader.CheckSum; 00150 00151 #ifndef NTOS_KERNEL_RUNTIME 00152 // 00153 // On Nt 3.1 and 3.5, we allowed printer drivers with 0 checksums into 00154 // csrss unintentionally. This means that we must allow this forever. 00155 // I don't want to allow this for kernel mode drivers, so I will only 00156 // allow 0 checksums of the high order bit is clear ? 00157 // 00158 00159 00160 if ( HeaderSum == 0 ) { 00161 return TRUE; 00162 } 00163 #endif // NTOS_KERNEL_RUNTIME 00164 00165 AdjustSum = (PUSHORT)(&NtHeaders->OptionalHeader.CheckSum); 00166 PartialSum -= (PartialSum < AdjustSum[0]); 00167 PartialSum -= AdjustSum[0]; 00168 PartialSum -= (PartialSum < AdjustSum[1]); 00169 PartialSum -= AdjustSum[1]; 00170 } else { 00171 PartialSum = 0; 00172 HeaderSum = FileLength; 00173 } 00174 00175 // 00176 // Compute the final checksum value as the sum of the paritial checksum 00177 // and the file length. 00178 // 00179 00180 CheckSum = (ULONG)PartialSum + FileLength; 00181 return (CheckSum == HeaderSum); 00182 } }


Generated on Sat May 15 19:43:03 2004 for test by doxygen 1.3.7