This commit is contained in:
Razmoth
2023-05-06 09:46:35 +04:00
parent 85ab8eec3c
commit 8e0f97ce2d
34 changed files with 903 additions and 864 deletions

View File

@@ -2,11 +2,13 @@
namespace AssetStudio
{
public class XORStream : SubStream
public class XORStream : OffsetStream
{
private readonly byte[] _xorpad;
private readonly long _offset;
private long Index => AbsolutePosition - _offset;
public XORStream(Stream stream, long offset, byte[] xorpad) : base(stream, offset)
{
_xorpad = xorpad;
@@ -15,11 +17,14 @@ namespace AssetStudio
public override int Read(byte[] buffer, int offset, int count)
{
var pos = AbsolutePosition - _offset;
var pos = Index;
var read = base.Read(buffer, offset, count);
for (int i = 0; i < count; i++)
if (pos >= 0)
{
buffer[i] ^= _xorpad[pos++ % _xorpad.Length];
for (int i = offset; i < count; i++)
{
buffer[i] ^= _xorpad[pos++ % _xorpad.Length];
}
}
return read;
}