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
00136
00137
00138 HeaderSum = 0;
00139 PartialSum =
ChkSum(0, (PUSHORT)BaseAddress, (FileLength + 1) >> 1);
00140
00141
00142
00143
00144
00145
00146
00147 NtHeaders =
RtlImageNtHeader(BaseAddress);
00148
if (NtHeaders !=
NULL) {
00149 HeaderSum = NtHeaders->OptionalHeader.CheckSum;
00150
00151
#ifndef NTOS_KERNEL_RUNTIME
00152
00153
00154
00155
00156
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
00177
00178
00179
00180 CheckSum = (ULONG)PartialSum + FileLength;
00181
return (CheckSum == HeaderSum);
00182 }
}