Exemplo n.º 1
0
        private IList <IArchiveFileInfo> LoadSwitch(Stream input)
        {
            using var br = new BinaryReaderX(input, true);

            // Read header
            _header = br.ReadType <MtHeader>();

            // Read entries
            var entries = br.ReadMultiple <MtEntrySwitch>(_header.entryCount);

            // Add files
            var result = new List <IArchiveFileInfo>();

            foreach (var entry in entries)
            {
                var fileStream = new SubStream(input, entry.Offset, entry.CompSize);
                var fileName   = entry.FileName.TrimEnd('\0') + MtArcSupport.DetermineExtension(entry.ExtensionHash);

                // It seems every file is compressed with ZLib on Switch
                // Reasoning: Example file game.arc contains of at least one file "om120a" where compressed and uncompressed size are equal but the file is still compressed
                //            the decompressed file is really the same size; comparing with other entries no clear differences were found, that would indicate a
                //            compression flag
                result.Add(new MtArchiveFileInfo(fileStream, fileName, entry, Kompression.Implementations.Compressions.ZLib, entry.GetDecompressedSize(_platform)));
            }

            return(result);
        }
Exemplo n.º 2
0
        private IList <IArchiveFileInfo> LoadLittleEndian(Stream input)
        {
            using var br = new BinaryReaderX(input, true);

            // Read header
            _header = br.ReadType <MtHeader>();

            // Skip additional int under certain conditions
            if (_header.version != 7 && _header.version != 8)
            {
                br.ReadInt32();
            }

            // Read entries
            var entries = br.ReadMultiple <MtEntry>(_header.entryCount);

            // Add files
            var result = new List <IArchiveFileInfo>();

            foreach (var entry in entries)
            {
                var fileStream = new SubStream(input, entry.Offset, entry.CompSize);
                var fileName   = entry.FileName.TrimEnd('\0') + MtArcSupport.DetermineExtension(entry.ExtensionHash);

                result.Add(CreateAfi(fileStream, fileName, entry, _platform));
            }

            return(result);
        }
Exemplo n.º 3
0
        public IList <IArchiveFileInfo> Load(Stream input)
        {
            using var br = new BinaryReaderX(input, true);

            // Read header
            _header = br.ReadType <MtHeader>();

            // Read entries
            var key         = GetCipherKey("imaguy_uyrag_igurustim_", "enokok_ikorodo_odohuran");
            var entryStream = new MtBlowfishStream(new SubStream(input, HeaderSize, _header.entryCount * EntrySize), key);

            using var entryBr = new BinaryReaderX(entryStream);
            var entries = entryBr.ReadMultiple <MtEntry>(_header.entryCount);

            // Add files
            var result = new List <IArchiveFileInfo>();

            foreach (var entry in entries)
            {
                var fileStream = new MtBlowfishStream(new SubStream(input, entry.Offset, entry.CompSize), key);
                var name       = entry.FileName + MtArcSupport.DetermineExtension(entry.ExtensionHash);

                result.Add(MtArc.CreateAfi(fileStream, name, entry, MtArcPlatform.LittleEndian));
            }

            return(result);
        }
Exemplo n.º 4
0
        public IList <IArchiveFileInfo> Load(Stream input)
        {
            _isEncrypted = IsEncrypted(input);
            var key = GetCipherKey("imaguy_uyrag_igurustim_", "enokok_ikorodo_odohuran");

            using var br = new BinaryReaderX(input, true);

            // Determine byte order
            var magic = br.ReadString(4);

            br.ByteOrder    = _byteOrder = magic == "\0CRA" ? ByteOrder.BigEndian : ByteOrder.LittleEndian;
            input.Position -= 4;

            // Header
            _header = br.ReadType <MtHeader>();

            // Determine possible platform the arc was found on
            _platform = MtArcSupport.DeterminePlatform(_byteOrder, _header);

            // Skip additional int under certain conditions
            if (_byteOrder == ByteOrder.LittleEndian && _header.version != 7 && _header.version != 8 && _header.version != 9)
            {
                br.ReadInt32();
            }

            // Read entries
            Stream entryStream = new SubStream(input, br.BaseStream.Position, input.Length - br.BaseStream.Position);

            if (_isEncrypted)
            {
                entryStream = new MtBlowfishStream(entryStream, key);
            }

            using var entryBr = new BinaryReaderX(entryStream);
            var entries = entryBr.ReadMultiple(_header.entryCount, _header.version == 9 ? typeof(MtEntrySwitch) : typeof(MtEntry)).Cast <IMtEntry>();

            // Add files
            var result = new List <IArchiveFileInfo>();

            foreach (var entry in entries)
            {
                Stream subStream = new SubStream(input, entry.Offset, entry.CompSize);
                var    fileName  = entry.FileName.TrimEnd('\0') + MtArcSupport.DetermineExtension(entry.ExtensionHash);

                if (_isEncrypted)
                {
                    subStream = new MtBlowfishStream(subStream, key);
                }

                result.Add(CreateAfi(subStream, fileName, entry, _platform));
            }

            return(result);
        }
Exemplo n.º 5
0
        private IList <IArchiveFileInfo> LoadBigEndian(Stream input)
        {
            using var br = new BinaryReaderX(input, true, ByteOrder.BigEndian);

            // Read header
            _header = br.ReadType <MtHeader>();

            // Read entries
            var entries = br.ReadMultiple <MtEntry>(_header.entryCount);

            // Add files
            var result = new List <IArchiveFileInfo>();

            foreach (var entry in entries)
            {
                var fileStream = new SubStream(input, entry.Offset, entry.CompSize);
                var fileName   = entry.FileName.TrimEnd('\0') + MtArcSupport.DetermineExtension(entry.ExtensionHash);

                result.Add(CreateAfi(fileStream, fileName, entry, _platform));
            }

            return(result);
        }