計算檔案系統辨識總和檢查碼
由 Windows 內部定義的 FILE_SYSTEM_RECOGNITION_STRUCTURE 結構,並由 檔案系統辨識 (FRS) 使用,包含必須正確計算總和檢查碼值,FRS 才能與指定的無法辨識檔案系統正常運作。 下列範例會完成此計算。
typedef struct _FILE_SYSTEM_RECOGNITION_STRUCTURE {
UCHAR Jmp[3];
UCHAR FsName[8];
UCHAR MustBeZero[5];
ULONG Identifier;
USHORT Length;
USHORT Checksum;
} FILE_SYSTEM_RECOGNITION_STRUCTURE, *PFILE_SYSTEM_RECOGNITION_STRUCTURE;
USHORT ComputeFileSystemInformationChecksum (
__in PFILE_SYSTEM_RECOGNITION_STRUCTURE Fsrs
)
/*++
Routine Description:
This routine computes the file record checksum.
Arguments:
Fsrs - Pointer to the record.
Return Value:
The checksum result.
--*/
{
USHORT Checksum = 0;
USHORT i;
PUCHAR Buffer = (PUCHAR)Fsrs;
USHORT StartOffset;
//
// Skip the jump instruction
//
StartOffset = FIELD_OFFSET(FILE_SYSTEM_RECOGNITION_STRUCTURE, FsName);
for (i = StartOffset; i < Fsrs->Length; i++) {
//
// Skip the checksum field itself, which is a USHORT.
//
if ((i == FIELD_OFFSET(FILE_SYSTEM_RECOGNITION_STRUCTURE, Checksum)) ||
(i == FIELD_OFFSET(FILE_SYSTEM_RECOGNITION_STRUCTURE, Checksum)+1)) {
continue;
}
Checksum = ((Checksum & 1) ? 0x8000 : 0) + (Checksum >> 1) + Buffer[i];
}
return Checksum;
}
相關主題