Skip to content

Instantly share code, notes, and snippets.

@jandk
Created March 27, 2016 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jandk/285d52aa4250deb5e9c2 to your computer and use it in GitHub Desktop.
Save jandk/285d52aa4250deb5e9c2 to your computer and use it in GitHub Desktop.
using System.IO;
public static class Misc
{
/// <summary>
/// Calculates the checksum on a v0.90 MD superblock.
/// Don't ask me why I needed it.
/// </summary>
/// <param name="filename">
/// The filename of the superblock.
/// </param>
/// <returns>
/// The checksum.
/// </returns>
public static uint CalculateMDSum(string filename)
{
ulong newcsum = 0;
using (var reader = new BinaryReader(File.OpenRead(filename)))
{
for (int i = 0; i < (4096 / 4); i++)
{
if (i != 38)
newcsum += reader.ReadUInt32();
else
reader.BaseStream.Seek(4, SeekOrigin.Current);
}
}
return (uint)((newcsum & 0xffffffff) + (newcsum >> 32));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment