Menghitung Checksum Pengenalan Sistem File
Struktur FILE_SYSTEM_RECOGNITION_STRUCTURE , didefinisikan secara internal oleh Windows dan digunakan oleh pengenalan sistem file (FRS), berisi nilai checksum yang harus dihitung dengan benar agar FRS berfungsi dengan baik dengan sistem file yang tidak dikenal tertentu. Contoh berikut menyelesaikan komputasi ini.
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;
}
Topik terkait