Created
March 27, 2016 09:56
-
-
Save jandk/285d52aa4250deb5e9c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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