Publish verified live restoration source snapshot and known limits
This commit is contained in:
@@ -1,26 +1,56 @@
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
|
||||
public class UmaAssetBundleStream : FileStream
|
||||
public sealed class UmaAssetBundleStream : FileStream
|
||||
{
|
||||
private const int headerSize = 256;
|
||||
private readonly byte[] baseKeys = Config.Instance.ABKey;
|
||||
private readonly byte[] keys;
|
||||
private const int HeaderSize = 256;
|
||||
private const int FileBufferSize = 128 * 1024;
|
||||
|
||||
public UmaAssetBundleStream(string filename, byte[] keys) : base(filename, FileMode.Open, FileAccess.Read)
|
||||
private readonly byte[] keys;
|
||||
private readonly object readLock = new object();
|
||||
|
||||
public UmaAssetBundleStream(string filename, byte[] keys)
|
||||
: base(filename,FileMode.Open,FileAccess.Read,FileShare.Read,FileBufferSize,FileOptions.SequentialScan)
|
||||
{
|
||||
this.keys = keys;
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
long StartPosition = Position;
|
||||
int res = base.Read(buffer, offset, count);
|
||||
|
||||
for (long i = (StartPosition < headerSize ? headerSize - StartPosition : 0); i < count; i++)
|
||||
lock (readLock)
|
||||
{
|
||||
buffer[i] ^= keys[(StartPosition + i) % (baseKeys.Length * 8)];
|
||||
}
|
||||
long startPosition = Position;
|
||||
int read = base.Read(buffer, offset, count);
|
||||
|
||||
return res;
|
||||
if (read <= 0 || keys == null || keys.Length == 0)
|
||||
return read;
|
||||
|
||||
int begin = 0;
|
||||
|
||||
if (startPosition < HeaderSize)
|
||||
{
|
||||
long remainingHeader = HeaderSize - startPosition;
|
||||
if (remainingHeader >= read)
|
||||
return read;
|
||||
|
||||
begin = (int)remainingHeader;
|
||||
}
|
||||
|
||||
int keyLength = keys.Length;
|
||||
int keyIndex = (int)((startPosition + begin) % keyLength);
|
||||
int end = offset + read;
|
||||
|
||||
for (int bufferIndex = offset + begin;
|
||||
bufferIndex < end;
|
||||
bufferIndex++)
|
||||
{
|
||||
buffer[bufferIndex] ^= keys[keyIndex];
|
||||
keyIndex++;
|
||||
|
||||
if (keyIndex == keyLength)
|
||||
keyIndex = 0;
|
||||
}
|
||||
|
||||
return read;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user