|
|
|
@ -78,26 +78,23 @@ namespace DepotDownloader
|
|
|
|
|
public static List<ProtoManifest.ChunkData> ValidateSteam3FileChecksums(FileStream fs, ProtoManifest.ChunkData[] chunkdata)
|
|
|
|
|
{
|
|
|
|
|
var neededChunks = new List<ProtoManifest.ChunkData>();
|
|
|
|
|
int read;
|
|
|
|
|
|
|
|
|
|
foreach (var data in chunkdata)
|
|
|
|
|
{
|
|
|
|
|
var chunk = new byte[data.UncompressedLength];
|
|
|
|
|
fs.Seek((long)data.Offset, SeekOrigin.Begin);
|
|
|
|
|
read = fs.Read(chunk, 0, (int)data.UncompressedLength);
|
|
|
|
|
|
|
|
|
|
byte[] tempchunk;
|
|
|
|
|
if (read < data.UncompressedLength)
|
|
|
|
|
{
|
|
|
|
|
tempchunk = new byte[read];
|
|
|
|
|
Array.Copy(chunk, 0, tempchunk, 0, read);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
uint a = 0, b = 0;
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < data.UncompressedLength; i++)
|
|
|
|
|
{
|
|
|
|
|
tempchunk = chunk;
|
|
|
|
|
var c = (uint)fs.ReadByte();
|
|
|
|
|
|
|
|
|
|
// adler hash
|
|
|
|
|
a = (a + c) % 65521;
|
|
|
|
|
b = (b + a) % 65521;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var adler = AdlerHash(tempchunk);
|
|
|
|
|
var adler = BitConverter.GetBytes(a | (b << 16));
|
|
|
|
|
if (!adler.SequenceEqual(data.Checksum))
|
|
|
|
|
{
|
|
|
|
|
neededChunks.Add(data);
|
|
|
|
@ -107,18 +104,6 @@ namespace DepotDownloader
|
|
|
|
|
return neededChunks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static byte[] AdlerHash(byte[] input)
|
|
|
|
|
{
|
|
|
|
|
uint a = 0, b = 0;
|
|
|
|
|
for (var i = 0; i < input.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
a = (a + input[i]) % 65521;
|
|
|
|
|
b = (b + a) % 65521;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BitConverter.GetBytes(a | (b << 16));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static byte[] DecodeHexString(string hex)
|
|
|
|
|
{
|
|
|
|
|
if (hex == null)
|
|
|
|
@ -133,13 +118,6 @@ namespace DepotDownloader
|
|
|
|
|
return bytes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string EncodeHexString(byte[] input)
|
|
|
|
|
{
|
|
|
|
|
return input.Aggregate(new StringBuilder(),
|
|
|
|
|
(sb, v) => sb.Append(v.ToString("x2"))
|
|
|
|
|
).ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Decrypts using AES/ECB/PKCS7
|
|
|
|
|
/// </summary>
|
|
|
|
|