Exemple #1
0
    def ReadDirectoryIndex(self, key: Optional[str] = None):
        self._aeskey = key
        starttime = time.time()
        if self.HasDirectoryIndex:
            if not self.IsEncrypted:
                IndexReader = BinaryStream(io.BytesIO(self._directoryIndexBuffer), len(self._directoryIndexBuffer))
            else:
                if not CrytoAval:
                    raise ImportError(
                        "Failed to Import \"pycryptodome\", Index is Encrypted it is required for decryption.")
                if self._aeskey is None:
                    raise InvalidEncryptionKey("Index is Encrypted and Key was not provided.")

                bytekey = bytearray.fromhex(self._aeskey)
                decryptor = AES.new(bytekey, AES.MODE_ECB)
                IndexReader = BinaryStream(io.BytesIO(decryptor.decrypt(self._directoryIndexBuffer)),
                                           len(self._directoryIndexBuffer))

                stringLen = IndexReader.readInt32()
                if stringLen > 512 or stringLen < -512:
                    raise ValueError(f"Provided key didn't work with {self.FileName}")
                if stringLen < 0:
                    IndexReader.base_stream.seek((stringLen - 1) * 2, 1)
                    if IndexReader.readUInt16() != 0:
                        raise ValueError(f"Provided key didn't work with {self.FileName}")
                else:
                    IndexReader.base_stream.seek(stringLen - 1, 1)
                    if int.from_bytes(IndexReader.readByte(), "little") != 0:
                        raise ValueError(f"Provided key didn't work with {self.FileName}")
                IndexReader.seek(0, 0)
            del self.TocResource.DirectoryIndexBuffer
            del self._directoryIndexBuffer

            self._directory_index = FIoDirectoryIndexResource(IndexReader, self.caseinSensitive)
            self.ContainerFile.MountPoint = self._directory_index.MountPoint
            firstEntry = self.GetChildDirectory(FIoDirectoryIndexHandle(FIoDirectoryIndexHandle.Root))

            tempFiles: Dict[str, FIoStoreEntry]
            Chunks: Dict[str, str]
            tempFiles, Chunks = self.ReadIndex("", firstEntry)  # TODO use Chunks IDs

            files = UpdateIndex(self.FileName, self.ContainerFile, tempFiles)

            time_taken = round(time.time() - starttime, 2)
            logger.info("{} contains {} files, mount point: {}, version: {}, in: {}s".format
                        (self.FileName, len(tempFiles), self._directory_index.MountPoint, self.TocResource.Header.Version, time_taken))

            del self._directory_index
            return files, Chunks
Exemple #2
0
    def ReadIndex(self, directoryName: str, dir: FIoDirectoryIndexHandle):
        outfile = {}
        outchunk = {}
        while dir.isValid():
            sub_dir_name = f"{directoryName}{self.GetDirectoryName(dir)}/"
            file = self.GetFile(dir)
            while file.isValid():
                name = self.GetFileName(file)
                path = self._directory_index.MountPoint + sub_dir_name + name
                data = self.GetFileData(file)  # UseData
                entry = FIoStoreEntry(self, data, path)
                outchunk[entry.ChunkId] = path
                outfile[path] = entry
                file = self.GetNextFile(file)

            childoutfile, childoutchunk = self.ReadIndex(sub_dir_name, self.GetChildDirectory(dir), )
            outfile.update(childoutfile)
            outchunk.update(childoutchunk)
            dir = self.GetNextDirectory(dir)

        return outfile, outchunk
Exemple #3
0
 def GetDirectoryEntry(self, directory: FIoDirectoryIndexHandle):
     return self._directory_index.DirectoryEntries[directory.ToIndex()]
Exemple #4
0
 def GetFileEntry(self, file: FIoDirectoryIndexHandle):
     return self._directory_index.FileEntries[file.ToIndex()]
Exemple #5
0
 def GetFileName(self, file: FIoDirectoryIndexHandle):
     if file.isValid() and self.IsValidIndex:
         index = self.GetFileEntry(file).Name
         return self._directory_index.StringTable[index]
Exemple #6
0
 def GetFileData(self, file: FIoDirectoryIndexHandle):
     if file.isValid() and self.IsValidIndex:
         return self._directory_index.FileEntries[file.ToIndex()].UserData
     else:
         return 0
Exemple #7
0
 def GetDirectoryName(self, directory: FIoDirectoryIndexHandle):
     if directory.isValid() and self.IsValidIndex:
         index = self.GetDirectoryEntry(directory).Name
         return self._directory_index.StringTable[index]
Exemple #8
0
 def GetNextFile(self, file: FIoDirectoryIndexHandle):
     if file.isValid() and self.IsValidIndex:
         return FIoDirectoryIndexHandle(self.GetFileEntry(file).NextFileEntry)
Exemple #9
0
 def GetFile(self, directory: FIoDirectoryIndexHandle):
     if directory.isValid() and self.IsValidIndex:
         return FIoDirectoryIndexHandle(self.GetDirectoryEntry(directory).FirstFileEntry)
Exemple #10
0
 def GetNextDirectory(self, directory: FIoDirectoryIndexHandle):
     if directory.isValid() and self.IsValidIndex:
         return FIoDirectoryIndexHandle(self.GetDirectoryEntry(directory).NextSiblingEntry)
     else:
         return FIoDirectoryIndexHandle()
Exemple #11
0
 def GetChildDirectory(self, directory: FIoDirectoryIndexHandle):
     return FIoDirectoryIndexHandle(
         self.GetDirectoryEntry(directory).FirstChildEntry) if directory.isValid() else FIoDirectoryIndexHandle()