计算文件系统识别校验和
FILE_SYSTEM_RECOGNITION_STRUCTURE结构由 Windows 在内部定义,由文件系统识别 (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;
}
相关主题