mirror of
https://github.com/k1tbyte/Wand-Enhancer.git
synced 2026-08-30 22:01:23 +00:00
20956c3228
InsertFile resolved the grandparent node instead of the parent. Reads no longer create phantom directories in the header. Bound symlink traversal and skip reparse points when crawling. Locked or unreadable files now abort packing instead of being dropped. Read headers and integrity blocks with a full-read loop. Assert the header keeps its size before overwriting the placeholder. Validate Pickle buffer sizes, payload overflow and negative lengths. Check CreateSymbolicLink and external tool exit codes. Drop unused Pickle accessors, TransformedFile and FilesystemFilesAndLinks.Links.
80 lines
2.2 KiB
C#
80 lines
2.2 KiB
C#
using System;
|
|
using System.Text;
|
|
|
|
namespace AsarSharp.PickleTools
|
|
{
|
|
public class PickleIterator
|
|
{
|
|
private readonly byte[] _payload;
|
|
private readonly int _payloadOffset;
|
|
private int _readIndex;
|
|
private readonly int _endIndex;
|
|
|
|
public PickleIterator(Pickle pickle)
|
|
{
|
|
_payload = pickle.GetHeader();
|
|
_payloadOffset = pickle.GetHeaderSize();
|
|
_readIndex = 0;
|
|
_endIndex = pickle.GetPayloadSize();
|
|
}
|
|
|
|
|
|
|
|
public int ReadInt()
|
|
{
|
|
return ReadBytes(Pickle.SIZE_INT32, BitConverter.ToInt32);
|
|
}
|
|
|
|
public uint ReadUInt32()
|
|
{
|
|
return ReadBytes(Pickle.SIZE_UINT32, BitConverter.ToUInt32);
|
|
}
|
|
|
|
|
|
|
|
public string ReadString()
|
|
{
|
|
int length = ReadInt();
|
|
return Encoding.UTF8.GetString(ReadBytes(length));
|
|
}
|
|
|
|
private T ReadBytes<T>(int length, Func<byte[], int, T> converter)
|
|
{
|
|
int readPayloadOffset = GetReadPayloadOffsetAndAdvance(length);
|
|
return converter(_payload, readPayloadOffset);
|
|
}
|
|
|
|
private byte[] ReadBytes(int length)
|
|
{
|
|
int readPayloadOffset = GetReadPayloadOffsetAndAdvance(length);
|
|
byte[] result = new byte[length];
|
|
Array.Copy(_payload, readPayloadOffset, result, 0, length);
|
|
return result;
|
|
}
|
|
|
|
private int GetReadPayloadOffsetAndAdvance(int length)
|
|
{
|
|
if (length < 0 || length > _endIndex - _readIndex)
|
|
{
|
|
_readIndex = _endIndex;
|
|
throw new InvalidOperationException($"Failed to read data with length of {length}");
|
|
}
|
|
int readPayloadOffset = _payloadOffset + _readIndex;
|
|
Advance(length);
|
|
return readPayloadOffset;
|
|
}
|
|
|
|
private void Advance(int size)
|
|
{
|
|
int alignedSize = Pickle.AlignInt(size, Pickle.SIZE_UINT32);
|
|
if (_endIndex - _readIndex < alignedSize)
|
|
{
|
|
_readIndex = _endIndex;
|
|
}
|
|
else
|
|
{
|
|
_readIndex += alignedSize;
|
|
}
|
|
}
|
|
}
|
|
} |