我正在开发一个用于操作SFS图像的控制台程序。有许多文件系统名称为SFS,具体而言,this是我正在实施的规范。但是我不明白如何计算校验和。
我已经看了一段时间这段代码,这很明显 这是计算校验和的地方,但我不懂Basic。
' compute checksum
For wl = start + &H1AC To start + &H1BC
Get ff, wl, wb
wi = wi + wb
Next wl
wb = (256 - (wi And &HFF)) And &HFF
可以找到完整的来源here。该片段来自“sfs.bas”文件,该方法称为“format_sfs”。
答案 0 :(得分:0)
我明白了。这是校验和方法的C#实现。
/// <summary>
/// Calculates the checksum of the given <paramref name="superBlock"/>.
/// </summary>
/// <param name="superBlock">The super block to calculate the checksum from.</param>
/// <returns>The calculated checksum.</returns>
private static byte Checksum(SuperBlock superBlock)
{
byte[] bytes = Structures.ToBytes(superBlock);
int result = 0;
for (int i = 0x1AC; i < 0x1BD; i++)
result += bytes[i];
return (byte)((256 - (result & 0xFF)) & 0xFF);
}