Пример #1
0
 public void ReadIndex(byte[] key, PakFilter filter = null)
 {
     ReadIndexInternal(key, filter, out var exc);
     if (exc != null)
     {
         throw exc;
     }
 }
Пример #2
0
 public PakIndex(bool cacheFiles, bool caseSensitive = true, PakFilter filter = null)
 {
     CacheFiles    = cacheFiles;
     CaseSensitive = caseSensitive;
     Filter        = filter;
     if (CacheFiles)
     {
         CachedFiles = new Dictionary <string, ArraySegment <byte> >();
     }
 }
Пример #3
0
 public PakIndex(IEnumerable <Stream> streams, bool cacheFiles, bool caseSensitive = true, PakFilter filter = null)
 {
     CacheFiles    = cacheFiles;
     CaseSensitive = caseSensitive;
     Filter        = filter;
     if (CacheFiles)
     {
         CachedFiles = new Dictionary <string, ArraySegment <byte> >();
     }
     foreach (var stream in streams)
     {
         PakFiles.Add(new PakFileReader(string.Empty, stream, caseSensitive));
     }
 }
Пример #4
0
        void ReadIndexInternal(byte[] key, PakFilter filter, out Exception exc)
        {
            if (Initialized)
            {
                exc = new InvalidOperationException("Index is already initialized");
                return;
            }

            if (Info.bEncryptedIndex && key == null)
            {
                exc = new ArgumentException("Index is encrypted but no key was provided", nameof(key));
                return;
            }

            Stream.Position = Info.IndexOffset;

            BinaryReader IndexReader;

            if (Info.bEncryptedIndex)
            {
                IndexReader = new BinaryReader(new MemoryStream(AESDecryptor.DecryptAES(Reader.ReadBytes((int)Info.IndexSize), key)));
                int stringLen = IndexReader.ReadInt32();
                if (stringLen > 512 || stringLen < -512)
                {
                    exc = new ArgumentException("The provided key is invalid", nameof(key));
                    return;
                }
                if (stringLen < 0)
                {
                    IndexReader.BaseStream.Position += (stringLen - 1) * 2;
                    if (IndexReader.ReadUInt16() != 0)
                    {
                        exc = new ArgumentException("The provided key is invalid", nameof(key));
                        return;
                    }
                }
                else
                {
                    IndexReader.BaseStream.Position += stringLen - 1;
                    if (IndexReader.ReadByte() != 0)
                    {
                        exc = new ArgumentException("The provided key is invalid", nameof(key));
                        return;
                    }
                }
                IndexReader.BaseStream.Position = 0;
            }
            else
            {
                IndexReader = Reader;
            }

            Dictionary <string, FPakEntry> tempFiles;

            if (Info.Version >= EPakVersion.PATH_HASH_INDEX)
            {
                ReadIndexUpdated(IndexReader, key, out tempFiles, filter);
            }
            else
            {
                // https://github.com/EpicGames/UnrealEngine/blob/bf95c2cbc703123e08ab54e3ceccdd47e48d224a/Engine/Source/Runtime/PakFile/Private/IPlatformFilePak.cpp#L4509
                MountPoint = IndexReader.ReadFString() ?? "";
                if (MountPoint.StartsWith("../../.."))
                {
                    MountPoint = MountPoint[8..];
Пример #5
0
 public bool TryReadIndex(byte[] key, PakFilter filter = null)
 {
     ReadIndexInternal(key, filter, out var exc);
     return(exc == null);
 }
Пример #6
0
 public PakIndex(string path, bool cacheFiles, bool caseSensitive = true, PakFilter filter = null) : this(Directory.EnumerateFiles(path, "*.pak"), cacheFiles, caseSensitive, filter)
 {
 }