コード例 #1
0
        private void ReadTypeTree5(List <TypeTreeNode> typeTree)
        {
            int numberOfNodes    = reader.ReadInt32();
            int stringBufferSize = reader.ReadInt32();

            reader.Position += numberOfNodes * 24;
            using (var stringBufferReader = new BinaryReader(new MemoryStream(reader.ReadBytes(stringBufferSize))))
            {
                reader.Position -= numberOfNodes * 24 + stringBufferSize;
                for (int i = 0; i < numberOfNodes; i++)
                {
                    var typeTreeNode = new TypeTreeNode();
                    typeTree.Add(typeTreeNode);
                    typeTreeNode.m_Version = reader.ReadUInt16();
                    typeTreeNode.m_Level   = reader.ReadByte();
                    typeTreeNode.m_IsArray = reader.ReadBoolean() ? 1 : 0;

                    var m_TypeStrOffset = reader.ReadUInt16();
                    var temp            = reader.ReadUInt16();
                    if (temp == 0)
                    {
                        stringBufferReader.BaseStream.Position = m_TypeStrOffset;
                        typeTreeNode.m_Type = stringBufferReader.ReadStringToNull();
                    }
                    else
                    {
                        typeTreeNode.m_Type = CommonString.StringBuffer.ContainsKey(m_TypeStrOffset) ? CommonString.StringBuffer[m_TypeStrOffset] : m_TypeStrOffset.ToString();
                    }

                    var m_NameStrOffset = reader.ReadUInt16();
                    temp = reader.ReadUInt16();
                    if (temp == 0)
                    {
                        stringBufferReader.BaseStream.Position = m_NameStrOffset;
                        typeTreeNode.m_Name = stringBufferReader.ReadStringToNull();
                    }
                    else
                    {
                        typeTreeNode.m_Name = CommonString.StringBuffer.ContainsKey(m_NameStrOffset) ? CommonString.StringBuffer[m_NameStrOffset] : m_NameStrOffset.ToString();
                    }

                    typeTreeNode.m_ByteSize = reader.ReadInt32();
                    typeTreeNode.m_Index    = reader.ReadInt32();
                    typeTreeNode.m_MetaFlag = reader.ReadInt32();
                }
                reader.Position += stringBufferSize;
            }
        }
コード例 #2
0
        private void ReadTypeTree5(List <TypeTreeNode> typeTree)
        {
            int numberOfNodes    = reader.ReadInt32();
            int stringBufferSize = reader.ReadInt32();

            var nodeSize = 24;

            if (header.m_Version > 17)
            {
                nodeSize = 32;
            }
            reader.Position += numberOfNodes * nodeSize;
            using (var stringBufferReader = new BinaryReader(new MemoryStream(reader.ReadBytes(stringBufferSize))))
            {
                reader.Position -= numberOfNodes * nodeSize + stringBufferSize;
                for (int i = 0; i < numberOfNodes; i++)
                {
                    var typeTreeNode = new TypeTreeNode();
                    typeTree.Add(typeTreeNode);
                    typeTreeNode.m_Version       = reader.ReadUInt16();
                    typeTreeNode.m_Level         = reader.ReadByte();
                    typeTreeNode.m_IsArray       = reader.ReadBoolean() ? 1 : 0;
                    typeTreeNode.m_TypeStrOffset = reader.ReadUInt32();
                    typeTreeNode.m_NameStrOffset = reader.ReadUInt32();
                    typeTreeNode.m_ByteSize      = reader.ReadInt32();
                    typeTreeNode.m_Index         = reader.ReadInt32();
                    typeTreeNode.m_MetaFlag      = reader.ReadInt32();

                    if (header.m_Version > 17)
                    {
                        reader.Position += 8;
                    }

                    typeTreeNode.m_Type = ReadString(stringBufferReader, typeTreeNode.m_TypeStrOffset);
                    typeTreeNode.m_Name = ReadString(stringBufferReader, typeTreeNode.m_NameStrOffset);
                }
                reader.Position += stringBufferSize;
            }
            if (header.m_Version >= 21)
            {
                reader.Position += 4;
            }
            string ReadString(BinaryReader stringBufferReader, uint value)
            {
                var isOffset = (value & 0x80000000) == 0;

                if (isOffset)
                {
                    stringBufferReader.BaseStream.Position = value;
                    return(stringBufferReader.ReadStringToNull());
                }
                var offset = value & 0x7FFFFFFF;

                if (CommonString.StringBuffer.TryGetValue(offset, out var str))
                {
                    return(str);
                }
                return(offset.ToString());
            }
        }
コード例 #3
0
        private void TypeTreeBlobRead(List <TypeTreeNode> typeTree)
        {
            int numberOfNodes    = reader.ReadInt32();
            int stringBufferSize = reader.ReadInt32();

            for (int i = 0; i < numberOfNodes; i++)
            {
                var typeTreeNode = new TypeTreeNode();
                typeTree.Add(typeTreeNode);
                typeTreeNode.m_Version       = reader.ReadUInt16();
                typeTreeNode.m_Level         = reader.ReadByte();
                typeTreeNode.m_IsArray       = reader.ReadBoolean() ? 1 : 0;
                typeTreeNode.m_TypeStrOffset = reader.ReadUInt32();
                typeTreeNode.m_NameStrOffset = reader.ReadUInt32();
                typeTreeNode.m_ByteSize      = reader.ReadInt32();
                typeTreeNode.m_Index         = reader.ReadInt32();
                typeTreeNode.m_MetaFlag      = reader.ReadInt32();
                if (header.m_Version >= 19)
                {
                    typeTreeNode.m_RefTypeHash = reader.ReadUInt64();
                }
            }
            var m_StringBuffer = reader.ReadBytes(stringBufferSize);

            using (var stringBufferReader = new BinaryReader(new MemoryStream(m_StringBuffer)))
            {
                for (int i = 0; i < numberOfNodes; i++)
                {
                    var typeTreeNode = typeTree[i];
                    typeTreeNode.m_Type = ReadString(stringBufferReader, typeTreeNode.m_TypeStrOffset);
                    typeTreeNode.m_Name = ReadString(stringBufferReader, typeTreeNode.m_NameStrOffset);
                }
            }

            string ReadString(BinaryReader stringBufferReader, uint value)
            {
                var isOffset = (value & 0x80000000) == 0;

                if (isOffset)
                {
                    stringBufferReader.BaseStream.Position = value;
                    return(stringBufferReader.ReadStringToNull());
                }
                var offset = value & 0x7FFFFFFF;

                if (CommonString.StringBuffer.TryGetValue(offset, out var str))
                {
                    return(str);
                }
                return(offset.ToString());
            }
        }
コード例 #4
0
        private void TypeTreeBlobRead(TypeTree m_Type)
        {
            int numberOfNodes    = reader.ReadInt32();
            int stringBufferSize = reader.ReadInt32();

            for (int i = 0; i < numberOfNodes; i++)
            {
                var typeTreeNode = new TypeTreeNode();
                m_Type.m_Nodes.Add(typeTreeNode);
                typeTreeNode.m_Version       = reader.ReadUInt16();
                typeTreeNode.m_Level         = reader.ReadByte();
                typeTreeNode.m_TypeFlags     = reader.ReadByte();
                typeTreeNode.m_TypeStrOffset = reader.ReadUInt32();
                typeTreeNode.m_NameStrOffset = reader.ReadUInt32();
                typeTreeNode.m_ByteSize      = reader.ReadInt32();
                typeTreeNode.m_Index         = reader.ReadInt32();
                typeTreeNode.m_MetaFlag      = reader.ReadInt32();
                if (header.m_Version >= SerializedFileFormatVersion.kTypeTreeNodeWithTypeFlags)
                {
                    typeTreeNode.m_RefTypeHash = reader.ReadUInt64();
                }
            }
            m_Type.m_StringBuffer = reader.ReadBytes(stringBufferSize);

            using (var stringBufferReader = new BinaryReader(new MemoryStream(m_Type.m_StringBuffer)))
            {
                for (int i = 0; i < numberOfNodes; i++)
                {
                    var m_Node = m_Type.m_Nodes[i];
                    m_Node.m_Type = ReadString(stringBufferReader, m_Node.m_TypeStrOffset);
                    m_Node.m_Name = ReadString(stringBufferReader, m_Node.m_NameStrOffset);
                }
            }

            string ReadString(BinaryReader stringBufferReader, uint value)
            {
                var isOffset = (value & 0x80000000) == 0;

                if (isOffset)
                {
                    stringBufferReader.BaseStream.Position = value;
                    return(stringBufferReader.ReadStringToNull());
                }
                var offset = value & 0x7FFFFFFF;

                if (CommonString.StringBuffer.TryGetValue(offset, out var str))
                {
                    return(str);
                }
                return(offset.ToString());
            }
        }
コード例 #5
0
        private void readBase5()
        {
            int classID = reader.ReadInt32();

            if (fileGen > 15)//5.5.0 and up
            {
                reader.ReadByte();
                int type1;
                if ((type1 = reader.ReadInt16()) >= 0)
                {
                    type1 = -1 - type1;
                }
                else
                {
                    type1 = classID;
                }
                classIDs.Add(new[] { type1, classID });
                if (classID == 114)
                {
                    reader.Position += 16;
                }
                classID = type1;
            }
            else if (classID < 0)
            {
                reader.Position += 16;
            }
            reader.Position += 16;

            if (baseDefinitions)
            {
                int varCount   = reader.ReadInt32();
                int stringSize = reader.ReadInt32();

                reader.Position += varCount * 24;
                using (var stringReader = new BinaryReader(new MemoryStream(reader.ReadBytes(stringSize))))
                {
                    string className = "";
                    var    classVar  = new List <ClassMember>();
                    //build Class Structures
                    reader.Position -= varCount * 24 + stringSize;
                    for (int i = 0; i < varCount; i++)
                    {
                        ushort num0    = reader.ReadUInt16();
                        byte   level   = reader.ReadByte();
                        bool   isArray = reader.ReadBoolean();

                        ushort varTypeIndex = reader.ReadUInt16();
                        ushort test         = reader.ReadUInt16();
                        string varTypeStr;
                        if (test == 0) //varType is an offset in the string block
                        {
                            stringReader.BaseStream.Position = varTypeIndex;
                            varTypeStr = stringReader.ReadStringToNull();
                        }
                        else //varType is an index in an internal strig array
                        {
                            varTypeStr = baseStrings.ContainsKey(varTypeIndex) ? baseStrings[varTypeIndex] : varTypeIndex.ToString();
                        }

                        ushort varNameIndex = reader.ReadUInt16();
                        test = reader.ReadUInt16();
                        string varNameStr;
                        if (test == 0)
                        {
                            stringReader.BaseStream.Position = varNameIndex;
                            varNameStr = stringReader.ReadStringToNull();
                        }
                        else
                        {
                            varNameStr = baseStrings.ContainsKey(varNameIndex) ? baseStrings[varNameIndex] : varNameIndex.ToString();
                        }

                        int size  = reader.ReadInt32();
                        int index = reader.ReadInt32();
                        int flag  = reader.ReadInt32();

                        if (index == 0)
                        {
                            className = varTypeStr + " " + varNameStr;
                        }
                        else
                        {
                            classVar.Add(new ClassMember
                            {
                                Level = level - 1,
                                Type  = varTypeStr,
                                Name  = varNameStr,
                                Size  = size,
                                Flag  = flag
                            });
                        }
                    }
                    reader.Position += stringSize;
                    var aClass = new ClassStruct {
                        ID = classID, Text = className, members = classVar
                    };
                    aClass.SubItems.Add(classID.ToString());
                    ClassStructures[classID] = aClass;
                }
            }
        }
コード例 #6
0
        public SerializedFile(AssetsManager assetsManager, string fullName, EndianBinaryReader reader)
        {
            this.assetsManager = assetsManager;
            this.reader        = reader;
            this.fullName      = fullName;
            fileName           = Path.GetFileName(fullName);

            //ReadHeader
            header = new SerializedFileHeader();
            header.m_MetadataSize = reader.ReadUInt32();
            header.m_FileSize     = reader.ReadUInt32();
            header.m_Version      = reader.ReadUInt32();
            header.m_DataOffset   = reader.ReadUInt32();

            if (header.m_Version >= 9)
            {
                header.m_Endianess = reader.ReadByte();
                header.m_Reserved  = reader.ReadBytes(3);
                m_FileEndianess    = (EndianType)header.m_Endianess;
            }
            else
            {
                reader.Position = header.m_FileSize - header.m_MetadataSize;
                m_FileEndianess = (EndianType)reader.ReadByte();
            }

            if (header.m_Version >= 22)
            {
                header.m_MetadataSize = reader.ReadUInt32();
                header.m_FileSize     = reader.ReadInt64();
                header.m_DataOffset   = reader.ReadInt64();
                reader.ReadInt64(); // unknown
            }

            //ReadMetadata
            if (m_FileEndianess == EndianType.LittleEndian)
            {
                reader.endian = EndianType.LittleEndian;
            }
            if (header.m_Version >= 7)
            {
                unityVersion = reader.ReadStringToNull();
                SetVersion(unityVersion);
            }
            if (header.m_Version >= 8)
            {
                m_TargetPlatform = (BuildTarget)reader.ReadInt32();
                if (!Enum.IsDefined(typeof(BuildTarget), m_TargetPlatform))
                {
                    m_TargetPlatform = BuildTarget.UnknownPlatform;
                }
            }
            if (header.m_Version >= 13)
            {
                m_EnableTypeTree = reader.ReadBoolean();
            }

            //ReadTypes
            int typeCount = reader.ReadInt32();

            m_Types = new List <SerializedType>(typeCount);
            for (int i = 0; i < typeCount; i++)
            {
                m_Types.Add(ReadSerializedType());
            }

            var bigIDEnabled = 0;

            if (header.m_Version >= 7 && header.m_Version < 14)
            {
                bigIDEnabled = reader.ReadInt32();
            }

            //ReadObjects
            int objectCount = reader.ReadInt32();

            m_Objects  = new List <ObjectInfo>(objectCount);
            Objects    = new List <Object>(objectCount);
            ObjectsDic = new Dictionary <long, Object>(objectCount);
            for (int i = 0; i < objectCount; i++)
            {
                var objectInfo = new ObjectInfo();
                if (bigIDEnabled != 0)
                {
                    objectInfo.m_PathID = reader.ReadInt64();
                }
                else if (header.m_Version < 14)
                {
                    objectInfo.m_PathID = reader.ReadInt32();
                }
                else
                {
                    reader.AlignStream();
                    objectInfo.m_PathID = reader.ReadInt64();
                }

                if (header.m_Version >= 22)
                {
                    objectInfo.byteStart = reader.ReadInt64();
                }
                else
                {
                    objectInfo.byteStart = reader.ReadUInt32();
                }

                objectInfo.byteStart += header.m_DataOffset;
                objectInfo.byteSize   = reader.ReadUInt32();
                objectInfo.typeID     = reader.ReadInt32();
                if (header.m_Version < 16)
                {
                    objectInfo.classID        = reader.ReadUInt16();
                    objectInfo.serializedType = m_Types.Find(x => x.classID == objectInfo.typeID);
                }
                else
                {
                    var type = m_Types[objectInfo.typeID];
                    objectInfo.serializedType = type;
                    objectInfo.classID        = type.classID;
                }
                if (header.m_Version < 11)
                {
                    var isDestroyed = reader.ReadUInt16();
                }
                if (header.m_Version >= 11 && header.m_Version < 17)
                {
                    var m_ScriptTypeIndex = reader.ReadInt16();
                    if (objectInfo.serializedType != null)
                    {
                        objectInfo.serializedType.m_ScriptTypeIndex = m_ScriptTypeIndex;
                    }
                }
                if (header.m_Version == 15 || header.m_Version == 16)
                {
                    var stripped = reader.ReadByte();
                }
                m_Objects.Add(objectInfo);
            }

            if (header.m_Version >= 11)
            {
                int scriptCount = reader.ReadInt32();
                m_ScriptTypes = new List <LocalSerializedObjectIdentifier>(scriptCount);
                for (int i = 0; i < scriptCount; i++)
                {
                    var m_ScriptType = new LocalSerializedObjectIdentifier();
                    m_ScriptType.localSerializedFileIndex = reader.ReadInt32();
                    if (header.m_Version < 14)
                    {
                        m_ScriptType.localIdentifierInFile = reader.ReadInt32();
                    }
                    else
                    {
                        reader.AlignStream();
                        m_ScriptType.localIdentifierInFile = reader.ReadInt64();
                    }
                    m_ScriptTypes.Add(m_ScriptType);
                }
            }

            int externalsCount = reader.ReadInt32();

            m_Externals = new List <FileIdentifier>(externalsCount);
            for (int i = 0; i < externalsCount; i++)
            {
                var m_External = new FileIdentifier();
                if (header.m_Version >= 6)
                {
                    var tempEmpty = reader.ReadStringToNull();
                }
                if (header.m_Version >= 5)
                {
                    m_External.guid = new Guid(reader.ReadBytes(16));
                    m_External.type = reader.ReadInt32();
                }
                m_External.pathName = reader.ReadStringToNull();
                m_External.fileName = Path.GetFileName(m_External.pathName);
                m_Externals.Add(m_External);
            }

            if (header.m_Version >= 20)
            {
                int refTypesCount = reader.ReadInt32();
                m_RefTypes = new List <SerializedType>(refTypesCount);
                for (int i = 0; i < refTypesCount; i++)
                {
                    m_RefTypes.Add(ReadSerializedType());
                }
            }

            if (header.m_Version >= 5)
            {
                var userInformation = reader.ReadStringToNull();
            }

            //reader.AlignStream(16);
        }
コード例 #7
0
        private void ReadBlocksInfoAndDirectory(EndianBinaryReader reader)
        {
            byte[] blocksInfoBytes;
            if (m_Header.version >= 7)
            {
                reader.AlignStream(16);
            }
            if ((m_Header.flags & 0x80) != 0) //kArchiveBlocksInfoAtTheEnd
            {
                var position = reader.Position;
                reader.Position = reader.BaseStream.Length - m_Header.compressedBlocksInfoSize;
                blocksInfoBytes = reader.ReadBytes((int)m_Header.compressedBlocksInfoSize);
                reader.Position = position;
            }
            else //0x40 kArchiveBlocksAndDirectoryInfoCombined
            {
                blocksInfoBytes = reader.ReadBytes((int)m_Header.compressedBlocksInfoSize);
            }
            var          blocksInfoCompressedStream = new MemoryStream(blocksInfoBytes);
            MemoryStream blocksInfoUncompresseddStream;

            switch (m_Header.flags & 0x3F) //kArchiveCompressionTypeMask
            {
            default:                       //None
            {
                blocksInfoUncompresseddStream = blocksInfoCompressedStream;
                break;
            }

            case 2:     //LZ4
            case 3:     //LZ4HC
            {
                var uncompressedBytes = new byte[m_Header.uncompressedBlocksInfoSize];
                using (var decoder = new Lz4DecoderStream(blocksInfoCompressedStream))
                {
                    decoder.Read(uncompressedBytes, 0, uncompressedBytes.Length);
                }
                blocksInfoUncompresseddStream = new MemoryStream(uncompressedBytes);
                break;
            }
            }
            using (var blocksInfoReader = new EndianBinaryReader(blocksInfoUncompresseddStream))
            {
                var uncompressedDataHash = blocksInfoReader.ReadBytes(16);
                var blocksInfoCount      = blocksInfoReader.ReadInt32();
                m_BlocksInfo = new StorageBlock[blocksInfoCount];
                uint offset = 0;
                for (int i = 0; i < blocksInfoCount; i++)
                {
                    m_BlocksInfo[i] = new StorageBlock
                    {
                        offset           = offset,
                        uncompressedSize = blocksInfoReader.ReadUInt32(),
                        compressedSize   = blocksInfoReader.ReadUInt32(),
                        flags            = blocksInfoReader.ReadUInt16()
                    };
                    offset += m_BlocksInfo[i].compressedSize;
                }

                var nodesCount = blocksInfoReader.ReadInt32();
                m_DirectoryInfo = new Node[nodesCount];
                for (int i = 0; i < nodesCount; i++)
                {
                    m_DirectoryInfo[i] = new Node
                    {
                        offset = blocksInfoReader.ReadInt64(),
                        size   = blocksInfoReader.ReadInt64(),
                        flags  = blocksInfoReader.ReadUInt32(),
                        path   = blocksInfoReader.ReadStringToNull(),
                    };
                }
            }
        }
コード例 #8
0
        private void ReadTypeTree5()
        {
            int classID = reader.ReadInt32();

            if (header.m_Version > 15)//5.5.0 and up
            {
                reader.ReadByte();
                int typeID = reader.ReadInt16();
                if (typeID >= 0)
                {
                    typeID = -1 - typeID;
                }
                else
                {
                    typeID = classID;
                }
                classIDs.Add(new[] { typeID, classID });
                if (classID == 114)
                {
                    reader.Position += 16;
                }
                classID = typeID;
            }
            else if (classID < 0)
            {
                reader.Position += 16;
            }
            reader.Position += 16;

            if (serializedTypeTrees)
            {
                int varCount   = reader.ReadInt32();
                int stringSize = reader.ReadInt32();

                reader.Position += varCount * 24;
                using (var stringReader = new BinaryReader(new MemoryStream(reader.ReadBytes(stringSize))))
                {
                    var typeTreeList = new List <TypeTree>();
                    reader.Position -= varCount * 24 + stringSize;
                    for (int i = 0; i < varCount; i++)
                    {
                        var typeTree = new TypeTree();
                        typeTreeList.Add(typeTree);
                        typeTree.m_Version = reader.ReadUInt16();
                        typeTree.m_Depth   = reader.ReadByte();
                        typeTree.m_IsArray = reader.ReadBoolean() ? 1 : 0;

                        ushort varTypeIndex = reader.ReadUInt16();
                        ushort test         = reader.ReadUInt16();
                        if (test == 0) //varType is an offset in the string block
                        {
                            stringReader.BaseStream.Position = varTypeIndex;
                            typeTree.m_Type = stringReader.ReadStringToNull();
                        }
                        else //varType is an index in an internal strig array
                        {
                            typeTree.m_Type = baseStrings.ContainsKey(varTypeIndex) ? baseStrings[varTypeIndex] : varTypeIndex.ToString();
                        }

                        ushort varNameIndex = reader.ReadUInt16();
                        test = reader.ReadUInt16();
                        if (test == 0)
                        {
                            stringReader.BaseStream.Position = varNameIndex;
                            typeTree.m_Name = stringReader.ReadStringToNull();
                        }
                        else
                        {
                            typeTree.m_Name = baseStrings.ContainsKey(varNameIndex) ? baseStrings[varNameIndex] : varNameIndex.ToString();
                        }

                        typeTree.m_ByteSize = reader.ReadInt32();
                        typeTree.m_Index    = reader.ReadInt32();
                        typeTree.m_MetaFlag = reader.ReadInt32();
                    }
                    reader.Position += stringSize;
                    m_Type[classID]  = typeTreeList;
                }
            }
        }
コード例 #9
0
        public AssetsFile(string fullName, EndianBinaryReader reader)
        {
            this.reader   = reader;
            filePath      = fullName;
            fileName      = Path.GetFileName(fullName);
            upperFileName = fileName.ToUpper();
            try
            {
                //SerializedFile::ReadHeader
                header = new SerializedFileHeader();
                header.m_MetadataSize = reader.ReadUInt32();
                header.m_FileSize     = reader.ReadUInt32();
                header.m_Version      = reader.ReadUInt32();
                header.m_DataOffset   = reader.ReadUInt32();

                if (header.m_Version >= 9)
                {
                    header.m_Endianess = reader.ReadByte();
                    header.m_Reserved  = reader.ReadBytes(3);
                    m_FileEndianess    = (EndianType)header.m_Endianess;
                }
                else
                {
                    reader.Position = header.m_FileSize - header.m_MetadataSize;
                    m_FileEndianess = (EndianType)reader.ReadByte();
                }

                //SerializedFile::ReadMetadata
                if (m_FileEndianess == EndianType.LittleEndian)
                {
                    reader.endian = EndianType.LittleEndian;
                }
                if (header.m_Version >= 7)
                {
                    unityVersion = reader.ReadStringToNull();
                }
                if (header.m_Version >= 8)
                {
                    m_TargetPlatform = (BuildTarget)reader.ReadInt32();
                    if (!Enum.IsDefined(typeof(BuildTarget), m_TargetPlatform))
                    {
                        m_TargetPlatform = BuildTarget.UnknownPlatform;
                    }
                }
                platformStr = m_TargetPlatform.ToString();
                if (header.m_Version >= 14)
                {
                    serializedTypeTrees = reader.ReadBoolean();
                }

                // Read	types
                int typeCount = reader.ReadInt32();
                for (int i = 0; i < typeCount; i++)
                {
                    if (header.m_Version < 14)
                    {
                        int classID      = reader.ReadInt32();
                        var typeTreeList = new List <TypeTree>();
                        ReadTypeTree(typeTreeList, 0);
                        m_Type.Add(classID, typeTreeList);
                    }
                    else
                    {
                        ReadTypeTree5();
                    }
                }

                if (header.m_Version >= 7 && header.m_Version < 14)
                {
                    var bigIDEnabled = reader.ReadInt32();
                }

                // Read Objects
                int objectCount = reader.ReadInt32();

                string assetIDfmt = "D" + objectCount.ToString().Length; //format for unique ID

                for (int i = 0; i < objectCount; i++)
                {
                    //each table entry is aligned individually, not the whole table
                    if (header.m_Version >= 14)
                    {
                        reader.AlignStream(4);
                    }

                    AssetPreloadData asset = new AssetPreloadData();
                    asset.m_PathID = header.m_Version < 14 ? reader.ReadInt32() : reader.ReadInt64();
                    asset.Offset   = reader.ReadUInt32();
                    asset.Offset  += header.m_DataOffset;
                    asset.Size     = reader.ReadInt32();
                    if (header.m_Version > 15)
                    {
                        int index = reader.ReadInt32();
                        asset.Type1 = classIDs[index][0];
                        asset.Type2 = classIDs[index][1];
                    }
                    else
                    {
                        asset.Type1      = reader.ReadInt32();
                        asset.Type2      = reader.ReadUInt16();
                        reader.Position += 2;
                    }
                    if (header.m_Version == 15)
                    {
                        byte unknownByte = reader.ReadByte();
                        //this is a single byte, not an int32
                        //the next entry is aligned after this
                        //but not the last!
                    }

                    if (Enum.IsDefined(typeof(ClassIDReference), asset.Type2))
                    {
                        asset.Type       = (ClassIDReference)asset.Type2;
                        asset.TypeString = asset.Type.ToString();
                    }
                    else
                    {
                        asset.Type       = ClassIDReference.UnknownType;
                        asset.TypeString = "UnknownType " + asset.Type2;
                    }

                    asset.uniqueID = i.ToString(assetIDfmt);

                    asset.fullSize   = asset.Size;
                    asset.sourceFile = this;

                    preloadTable.Add(asset.m_PathID, asset);

                    #region read BuildSettings to get version for version 2.x files
                    if (asset.Type == ClassIDReference.BuildSettings && header.m_Version == 6)
                    {
                        long nextAsset = reader.Position;

                        BuildSettings BSettings = new BuildSettings(asset);
                        unityVersion = BSettings.m_Version;

                        reader.Position = nextAsset;
                    }
                    #endregion
                }

                if (header.m_Version >= 14)
                {
                    //this looks like a list of assets that need to be preloaded in memory before anytihng else
                    int someCount = reader.ReadInt32();
                    for (int i = 0; i < someCount; i++)
                    {
                        int num1 = reader.ReadInt32();
                        reader.AlignStream(4);
                        long m_PathID = reader.ReadInt64();
                    }
                }

                sharedAssetsList[0].fileName = fileName; //reference itself because sharedFileIDs start from 1
                int sharedFileCount = reader.ReadInt32();
                for (int i = 0; i < sharedFileCount; i++)
                {
                    var shared = new SharedAssets();
                    shared.aName     = reader.ReadStringToNull();
                    reader.Position += 20;
                    var sharedFilePath = reader.ReadStringToNull(); //relative path
                    shared.fileName = Path.GetFileName(sharedFilePath);
                    sharedAssetsList.Add(shared);
                }

                buildType = Regex.Replace(unityVersion, @"\d", "").Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                var firstVersion = int.Parse(unityVersion.Split('.')[0]);
                version = Regex.Matches(unityVersion, @"\d").Cast <Match>().Select(m => int.Parse(m.Value)).ToArray();
                if (firstVersion > 5)//2017 and up
                {
                    var nversion = new int[version.Length - 3];
                    nversion[0] = firstVersion;
                    Array.Copy(version, 4, nversion, 1, version.Length - 4);
                    version = nversion;
                }

                valid = true;
            }
            catch
            {
            }
        }
コード例 #10
0
        private static object ReadValue(List <TypeTree> members, EndianBinaryReader reader, ref int i)
        {
            var    member     = members[i];
            var    level      = member.m_Depth;
            var    varTypeStr = member.m_Type;
            object value;
            var    align = (member.m_MetaFlag & 0x4000) != 0;

            switch (varTypeStr)
            {
            case "SInt8":
                value = reader.ReadSByte();
                break;

            case "UInt8":
                value = reader.ReadByte();
                break;

            case "short":
            case "SInt16":
                value = reader.ReadInt16();
                break;

            case "UInt16":
            case "unsigned short":
                value = reader.ReadUInt16();
                break;

            case "int":
            case "SInt32":
                value = reader.ReadInt32();
                break;

            case "UInt32":
            case "unsigned int":
            case "Type*":
                value = reader.ReadUInt32();
                break;

            case "long long":
            case "SInt64":
                value = reader.ReadInt64();
                break;

            case "UInt64":
            case "unsigned long long":
                value = reader.ReadUInt64();
                break;

            case "float":
                value = reader.ReadSingle();
                break;

            case "double":
                value = reader.ReadDouble();
                break;

            case "bool":
                value = reader.ReadBoolean();
                break;

            case "string":
                value = reader.ReadAlignedString();
                i    += 3;
                break;

            case "vector":
            {
                if ((members[i + 1].m_MetaFlag & 0x4000) != 0)
                {
                    align = true;
                }
                var size   = reader.ReadInt32();
                var list   = new List <object>(size);
                var vector = GetMembers(members, level, i);
                i += vector.Count - 1;
                vector.RemoveRange(0, 3);
                for (int j = 0; j < size; j++)
                {
                    int tmp = 0;
                    list.Add(ReadValue(vector, reader, ref tmp));
                }
                value = list;
                break;
            }

            case "map":
            {
                if ((members[i + 1].m_MetaFlag & 0x4000) != 0)
                {
                    align = true;
                }
                var size = reader.ReadInt32();
                var dic  = new List <KeyValuePair <object, object> >(size);
                var map  = GetMembers(members, level, i);
                i += map.Count - 1;
                map.RemoveRange(0, 4);
                var first = GetMembers(map, map[0].m_Depth, 0);
                map.RemoveRange(0, first.Count);
                var second = map;
                for (int j = 0; j < size; j++)
                {
                    int tmp1 = 0;
                    int tmp2 = 0;
                    dic.Add(new KeyValuePair <object, object>(ReadValue(first, reader, ref tmp1), ReadValue(second, reader, ref tmp2)));
                }
                value = dic;
                break;
            }

            case "TypelessData":
            {
                var size = reader.ReadInt32();
                value = reader.ReadBytes(size);
                i    += 2;
                break;
            }

            default:
            {
                if (i != members.Count && members[i + 1].m_Type == "Array")
                {
                    goto case "vector";
                }
                var @class = GetMembers(members, level, i);
                @class.RemoveAt(0);
                i += @class.Count;
                var obj    = new ExpandoObject();
                var objdic = (IDictionary <string, object>)obj;
                for (int j = 0; j < @class.Count; j++)
                {
                    var classmember = @class[j];
                    var name        = classmember.m_Name;
                    objdic[name] = ReadValue(@class, reader, ref j);
                }
                value = obj;
                break;
            }
            }
            if (align)
            {
                reader.AlignStream(4);
            }
            return(value);
        }
コード例 #11
0
        private static void ReadStringValue(StringBuilder sb, List <TypeTree> members, EndianBinaryReader reader, ref int i)
        {
            var    member     = members[i];
            var    level      = member.m_Depth;
            var    varTypeStr = member.m_Type;
            var    varNameStr = member.m_Name;
            object value      = null;
            var    append     = true;
            var    align      = (member.m_MetaFlag & 0x4000) != 0;

            switch (varTypeStr)
            {
            case "SInt8":
                value = reader.ReadSByte();
                break;

            case "UInt8":
                value = reader.ReadByte();
                break;

            case "short":
            case "SInt16":
                value = reader.ReadInt16();
                break;

            case "UInt16":
            case "unsigned short":
                value = reader.ReadUInt16();
                break;

            case "int":
            case "SInt32":
                value = reader.ReadInt32();
                break;

            case "UInt32":
            case "unsigned int":
            case "Type*":
                value = reader.ReadUInt32();
                break;

            case "long long":
            case "SInt64":
                value = reader.ReadInt64();
                break;

            case "UInt64":
            case "unsigned long long":
                value = reader.ReadUInt64();
                break;

            case "float":
                value = reader.ReadSingle();
                break;

            case "double":
                value = reader.ReadDouble();
                break;

            case "bool":
                value = reader.ReadBoolean();
                break;

            case "string":
                append = false;
                var str = reader.ReadAlignedString();
                sb.AppendFormat("{0}{1} {2} = \"{3}\"\r\n", (new string('\t', level)), varTypeStr, varNameStr, str);
                i += 3;
                break;

            case "vector":
            {
                if ((members[i + 1].m_MetaFlag & 0x4000) != 0)
                {
                    align = true;
                }
                append = false;
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level + 1)), "Array", "Array");
                var size = reader.ReadInt32();
                sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level + 1)), "int", "size", size);
                var vector = GetMembers(members, level, i);
                i += vector.Count - 1;
                vector.RemoveRange(0, 3);
                for (int j = 0; j < size; j++)
                {
                    sb.AppendFormat("{0}[{1}]\r\n", (new string('\t', level + 2)), j);
                    int tmp = 0;
                    ReadStringValue(sb, vector, reader, ref tmp);
                }
                break;
            }

            case "map":
            {
                if ((members[i + 1].m_MetaFlag & 0x4000) != 0)
                {
                    align = true;
                }
                append = false;
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level + 1)), "Array", "Array");
                var size = reader.ReadInt32();
                sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level + 1)), "int", "size", size);
                var map = GetMembers(members, level, i);
                i += map.Count - 1;
                map.RemoveRange(0, 4);
                var first = GetMembers(map, map[0].m_Depth, 0);
                map.RemoveRange(0, first.Count);
                var second = map;
                for (int j = 0; j < size; j++)
                {
                    sb.AppendFormat("{0}[{1}]\r\n", (new string('\t', level + 2)), j);
                    sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level + 2)), "pair", "data");
                    int tmp1 = 0;
                    int tmp2 = 0;
                    ReadStringValue(sb, first, reader, ref tmp1);
                    ReadStringValue(sb, second, reader, ref tmp2);
                }
                break;
            }

            case "TypelessData":
            {
                append = false;
                var size = reader.ReadInt32();
                reader.ReadBytes(size);
                i += 2;
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), "int", "size", size);
                break;
            }

            default:
            {
                if (i != members.Count && members[i + 1].m_Type == "Array")
                {
                    goto case "vector";
                }
                append = false;
                sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                var @class = GetMembers(members, level, i);
                @class.RemoveAt(0);
                i += @class.Count;
                for (int j = 0; j < @class.Count; j++)
                {
                    ReadStringValue(sb, @class, reader, ref j);
                }
                break;
            }
            }
            if (append)
            {
                sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), varTypeStr, varNameStr, value);
            }
            if (align)
            {
                reader.AlignStream(4);
            }
        }
コード例 #12
0
ファイル: AssetsFile.cs プロジェクト: veloting/AssetStudio
        public AssetsFile(string fullName, EndianBinaryReader reader)
        {
            this.reader   = reader;
            filePath      = fullName;
            fileName      = Path.GetFileName(fullName);
            upperFileName = fileName.ToUpper();
            try
            {
                //SerializedFile::ReadHeader
                header = new SerializedFileHeader();
                header.m_MetadataSize = reader.ReadUInt32();
                header.m_FileSize     = reader.ReadUInt32();
                header.m_Version      = reader.ReadUInt32();
                header.m_DataOffset   = reader.ReadUInt32();

                if (header.m_Version >= 9)
                {
                    header.m_Endianess = reader.ReadByte();
                    header.m_Reserved  = reader.ReadBytes(3);
                    m_FileEndianess    = (EndianType)header.m_Endianess;
                }
                else
                {
                    reader.Position = header.m_FileSize - header.m_MetadataSize;
                    m_FileEndianess = (EndianType)reader.ReadByte();
                }

                //SerializedFile::ReadMetadata
                if (m_FileEndianess == EndianType.LittleEndian)
                {
                    reader.endian = EndianType.LittleEndian;
                }
                if (header.m_Version >= 7)
                {
                    unityVersion = reader.ReadStringToNull();
                }
                if (header.m_Version >= 8)
                {
                    m_TargetPlatform = (BuildTarget)reader.ReadInt32();
                    if (!Enum.IsDefined(typeof(BuildTarget), m_TargetPlatform))
                    {
                        m_TargetPlatform = BuildTarget.UnknownPlatform;
                    }
                }
                platformStr = m_TargetPlatform.ToString();
                if (header.m_Version >= 13)
                {
                    m_EnableTypeTree = reader.ReadBoolean();
                }

                //Read types
                int typeCount = reader.ReadInt32();
                m_Types = new List <SerializedType>(typeCount);
                for (int i = 0; i < typeCount; i++)
                {
                    m_Types.Add(ReadSerializedType());
                }

                if (header.m_Version >= 7 && header.m_Version < 14)
                {
                    var bigIDEnabled = reader.ReadInt32();
                }

                //Read Objects
                int objectCount = reader.ReadInt32();

                var assetIDfmt = "D" + objectCount.ToString().Length; //format for unique ID

                m_Objects = new Dictionary <long, ObjectInfo>(objectCount);
                for (int i = 0; i < objectCount; i++)
                {
                    var objectInfo = new ObjectInfo();
                    if (header.m_Version < 14)
                    {
                        objectInfo.m_PathID = reader.ReadInt32();
                    }
                    else
                    {
                        reader.AlignStream(4);
                        objectInfo.m_PathID = reader.ReadInt64();
                    }
                    objectInfo.byteStart  = reader.ReadUInt32();
                    objectInfo.byteStart += header.m_DataOffset;
                    objectInfo.byteSize   = reader.ReadUInt32();
                    objectInfo.typeID     = reader.ReadInt32();
                    if (header.m_Version < 16)
                    {
                        objectInfo.classID        = reader.ReadUInt16();
                        objectInfo.serializedType = m_Types.Find(x => x.classID == objectInfo.typeID);
                        objectInfo.isDestroyed    = reader.ReadUInt16();
                    }
                    else
                    {
                        var type = m_Types[objectInfo.typeID];
                        objectInfo.serializedType = type;
                        objectInfo.classID        = type.classID;
                    }
                    if (header.m_Version == 15 || header.m_Version == 16)
                    {
                        var stripped = reader.ReadByte();
                    }
                    m_Objects.Add(objectInfo.m_PathID, objectInfo);

                    //Create AssetPreloadData
                    var asset = new AssetPreloadData(this, objectInfo, i.ToString(assetIDfmt));
                    preloadTable.Add(asset.m_PathID, asset);

                    #region read BuildSettings to get version for version 2.x files
                    if (asset.Type == ClassIDType.BuildSettings && header.m_Version == 6)
                    {
                        var nextAsset = reader.Position;

                        var BSettings = new BuildSettings(asset);
                        unityVersion = BSettings.m_Version;

                        reader.Position = nextAsset;
                    }
                    #endregion
                }

                if (header.m_Version >= 11)
                {
                    int scriptCount = reader.ReadInt32();
                    m_ScriptTypes = new List <LocalSerializedObjectIdentifier>(scriptCount);
                    for (int i = 0; i < scriptCount; i++)
                    {
                        var m_ScriptType = new LocalSerializedObjectIdentifier();
                        m_ScriptType.localSerializedFileIndex = reader.ReadInt32();
                        if (header.m_Version < 14)
                        {
                            m_ScriptType.localIdentifierInFile = reader.ReadInt32();
                        }
                        else
                        {
                            reader.AlignStream(4);
                            m_ScriptType.localIdentifierInFile = reader.ReadInt64();
                        }
                        m_ScriptTypes.Add(m_ScriptType);
                    }
                }

                int externalsCount = reader.ReadInt32();
                m_Externals = new List <FileIdentifier>(externalsCount);
                for (int i = 0; i < externalsCount; i++)
                {
                    var m_External = new FileIdentifier();
                    if (header.m_Version >= 6)
                    {
                        var tempEmpty = reader.ReadStringToNull();
                    }
                    if (header.m_Version >= 5)
                    {
                        m_External.guid = new Guid(reader.ReadBytes(16));
                        m_External.type = reader.ReadInt32();
                    }
                    m_External.pathName = reader.ReadStringToNull();
                    m_External.fileName = Path.GetFileName(m_External.pathName);
                    m_Externals.Add(m_External);
                }

                if (header.m_Version >= 5)
                {
                    //var userInformation = reader.ReadStringToNull();
                }

                buildType = Regex.Replace(unityVersion, @"\d", "").Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                var firstVersion = int.Parse(unityVersion.Split('.')[0]);
                version = Regex.Matches(unityVersion, @"\d").Cast <Match>().Select(m => int.Parse(m.Value)).ToArray();
                if (firstVersion > 5)//2017 and up
                {
                    var nversion = new int[version.Length - 3];
                    nversion[0] = firstVersion;
                    Array.Copy(version, 4, nversion, 1, version.Length - 4);
                    version = nversion;
                }

                valid = true;
            }
            catch
            {
            }
        }
コード例 #13
0
        public AssetsFile(string fullName, EndianBinaryReader reader)
        {
            assetsFileReader = reader;
            filePath         = fullName;
            fileName         = Path.GetFileName(fullName);
            upperFileName    = fileName.ToUpper();
            try
            {
                int tableSize = assetsFileReader.ReadInt32();
                int dataEnd   = assetsFileReader.ReadInt32();
                fileGen = assetsFileReader.ReadInt32();
                uint dataOffset = assetsFileReader.ReadUInt32();
                sharedAssetsList[0].fileName = fileName; //reference itself because sharedFileIDs start from 1

                switch (fileGen)
                {
                case 6:     //2.5.0 - 2.6.1
                {
                    assetsFileReader.Position  = (dataEnd - tableSize);
                    assetsFileReader.Position += 1;
                    break;
                }

                case 7:     //3.0.0 beta
                {
                    assetsFileReader.Position  = (dataEnd - tableSize);
                    assetsFileReader.Position += 1;
                    m_Version = assetsFileReader.ReadStringToNull();
                    break;
                }

                case 8:     //3.0.0 - 3.4.2
                {
                    assetsFileReader.Position  = (dataEnd - tableSize);
                    assetsFileReader.Position += 1;
                    m_Version = assetsFileReader.ReadStringToNull();
                    platform  = assetsFileReader.ReadInt32();
                    break;
                }

                case 9:                             //3.5.0 - 4.6.x
                {
                    assetsFileReader.Position += 4; //azero
                    m_Version = assetsFileReader.ReadStringToNull();
                    platform  = assetsFileReader.ReadInt32();
                    break;
                }

                case 14:                            //5.0.0 beta and final
                case 15:                            //5.0.1 - 5.4
                case 16:                            //??.. no sure
                case 17:                            //5.5.0 and up
                {
                    assetsFileReader.Position += 4; //azero
                    m_Version       = assetsFileReader.ReadStringToNull();
                    platform        = assetsFileReader.ReadInt32();
                    baseDefinitions = assetsFileReader.ReadBoolean();
                    break;
                }

                default:
                {
                    //MessageBox.Show("Unsupported version!" + fileGen, "AssetStudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                }

                if (platform > 255 || platform < 0)
                {
                    byte[] b32 = BitConverter.GetBytes(platform);
                    Array.Reverse(b32);
                    platform = BitConverter.ToInt32(b32, 0);
                    assetsFileReader.endian = EndianType.LittleEndian;
                }

                platformStr = Enum.IsDefined(typeof(BuildTarget), platform) ? ((BuildTarget)platform).ToString() : "Unknown Platform";

                int baseCount = assetsFileReader.ReadInt32();
                for (int i = 0; i < baseCount; i++)
                {
                    if (fileGen < 14)
                    {
                        int    classID  = assetsFileReader.ReadInt32();
                        string baseType = assetsFileReader.ReadStringToNull();
                        string baseName = assetsFileReader.ReadStringToNull();
                        assetsFileReader.Position += 20;
                        int memberCount = assetsFileReader.ReadInt32();

                        var cb = new List <ClassMember>();
                        for (int m = 0; m < memberCount; m++)
                        {
                            readBase(cb, 1);
                        }

                        var aClass = new ClassStruct {
                            ID = classID, Text = (baseType + " " + baseName), members = cb
                        };
                        aClass.SubItems.Add(classID.ToString());
                        ClassStructures.Add(classID, aClass);
                    }
                    else
                    {
                        readBase5();
                    }
                }

                if (fileGen >= 7 && fileGen < 14)
                {
                    assetsFileReader.Position += 4; //azero
                }

                int assetCount = assetsFileReader.ReadInt32();

                #region asset preload table
                string assetIDfmt = "D" + assetCount.ToString().Length; //format for unique ID

                for (int i = 0; i < assetCount; i++)
                {
                    //each table entry is aligned individually, not the whole table
                    if (fileGen >= 14)
                    {
                        assetsFileReader.AlignStream(4);
                    }

                    AssetPreloadData asset = new AssetPreloadData();
                    asset.m_PathID = fileGen < 14 ? assetsFileReader.ReadInt32() : assetsFileReader.ReadInt64();
                    asset.Offset   = assetsFileReader.ReadUInt32();
                    asset.Offset  += dataOffset;
                    asset.Size     = assetsFileReader.ReadInt32();
                    if (fileGen > 15)
                    {
                        int index = assetsFileReader.ReadInt32();
                        asset.Type1 = classIDs[index][0];
                        asset.Type2 = classIDs[index][1];
                    }
                    else
                    {
                        asset.Type1 = assetsFileReader.ReadInt32();
                        asset.Type2 = assetsFileReader.ReadUInt16();
                        assetsFileReader.Position += 2;
                    }
                    if (fileGen == 15)
                    {
                        byte unknownByte = assetsFileReader.ReadByte();
                        //this is a single byte, not an int32
                        //the next entry is aligned after this
                        //but not the last!
                    }

                    if (Enum.IsDefined(typeof(ClassIDReference), asset.Type2))
                    {
                        asset.Type       = (ClassIDReference)asset.Type2;
                        asset.TypeString = asset.Type.ToString();
                    }
                    else
                    {
                        asset.Type       = ClassIDReference.UnknownType;
                        asset.TypeString = "UnknownType " + asset.Type2;
                    }

                    asset.uniqueID = i.ToString(assetIDfmt);

                    asset.fullSize   = asset.Size;
                    asset.sourceFile = this;

                    preloadTable.Add(asset.m_PathID, asset);

                    #region read BuildSettings to get version for version 2.x files
                    if (asset.Type == ClassIDReference.BuildSettings && fileGen == 6)
                    {
                        long nextAsset = assetsFileReader.Position;

                        BuildSettings BSettings = new BuildSettings(asset);
                        m_Version = BSettings.m_Version;

                        assetsFileReader.Position = nextAsset;
                    }
                    #endregion
                }
                #endregion

                buildType = Regex.Replace(m_Version, @"\d", "").Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                version   = Regex.Matches(m_Version, @"\d").Cast <Match>().Select(m => int.Parse(m.Value)).ToArray();
                if (version[0] == 2 && version[1] == 0 && version[2] == 1 && version[3] == 7)//2017.x
                {
                    var nversion = new int[version.Length - 3];
                    nversion[0] = 2017;
                    Array.Copy(version, 4, nversion, 1, version.Length - 4);
                    version = nversion;
                }
                if (fileGen >= 14)
                {
                    //this looks like a list of assets that need to be preloaded in memory before anytihng else
                    int someCount = assetsFileReader.ReadInt32();
                    for (int i = 0; i < someCount; i++)
                    {
                        int num1 = assetsFileReader.ReadInt32();
                        assetsFileReader.AlignStream(4);
                        long m_PathID = assetsFileReader.ReadInt64();
                    }
                }

                int sharedFileCount = assetsFileReader.ReadInt32();
                for (int i = 0; i < sharedFileCount; i++)
                {
                    var shared = new SharedAssets();
                    shared.aName = assetsFileReader.ReadStringToNull();
                    assetsFileReader.Position += 20;
                    var sharedFilePath = assetsFileReader.ReadStringToNull(); //relative path
                    shared.fileName = Path.GetFileName(sharedFilePath);
                    sharedAssetsList.Add(shared);
                }
                valid = true;
            }
            catch
            {
            }
        }
コード例 #14
0
        private void ReadBlocksInfoAndDirectory(EndianBinaryReader reader)
        {
            byte[] blocksInfoBytes;
            if (m_Header.version >= 7)
            {
                reader.AlignStream(16);
            }
            if ((m_Header.flags & ArchiveFlags.BlocksInfoAtTheEnd) != 0)
            {
                var position = reader.Position;
                reader.Position = reader.BaseStream.Length - m_Header.compressedBlocksInfoSize;
                blocksInfoBytes = reader.ReadBytes((int)m_Header.compressedBlocksInfoSize);
                reader.Position = position;
            }
            else //0x40 BlocksAndDirectoryInfoCombined
            {
                blocksInfoBytes = reader.ReadBytes((int)m_Header.compressedBlocksInfoSize);
            }
            MemoryStream blocksInfoUncompresseddStream;
            var          uncompressedSize = m_Header.uncompressedBlocksInfoSize;
            var          compressionType  = (CompressionType)(m_Header.flags & ArchiveFlags.CompressionTypeMask);

            switch (compressionType)
            {
            case CompressionType.None:
            {
                blocksInfoUncompresseddStream = new MemoryStream(blocksInfoBytes);
                break;
            }

            case CompressionType.Lzma:
            {
                blocksInfoUncompresseddStream = new MemoryStream((int)(uncompressedSize));
                using (var blocksInfoCompressedStream = new MemoryStream(blocksInfoBytes))
                {
                    SevenZipHelper.StreamDecompress(blocksInfoCompressedStream, blocksInfoUncompresseddStream, m_Header.compressedBlocksInfoSize, m_Header.uncompressedBlocksInfoSize);
                }
                blocksInfoUncompresseddStream.Position = 0;
                break;
            }

            case CompressionType.Lz4:
            case CompressionType.Lz4HC:
            {
                var uncompressedBytes = new byte[uncompressedSize];
                var numWrite          = LZ4Codec.Decode(blocksInfoBytes, uncompressedBytes);
                if (numWrite != uncompressedSize)
                {
                    throw new IOException($"Lz4 decompression error, write {numWrite} bytes but expected {uncompressedSize} bytes");
                }
                blocksInfoUncompresseddStream = new MemoryStream(uncompressedBytes);
                break;
            }

            default:
                throw new IOException($"Unsupported compression type {compressionType}");
            }
            using (var blocksInfoReader = new EndianBinaryReader(blocksInfoUncompresseddStream))
            {
                var uncompressedDataHash = blocksInfoReader.ReadBytes(16);
                var blocksInfoCount      = blocksInfoReader.ReadInt32();
                m_BlocksInfo = new StorageBlock[blocksInfoCount];
                for (int i = 0; i < blocksInfoCount; i++)
                {
                    m_BlocksInfo[i] = new StorageBlock
                    {
                        uncompressedSize = blocksInfoReader.ReadUInt32(),
                        compressedSize   = blocksInfoReader.ReadUInt32(),
                        flags            = (StorageBlockFlags)blocksInfoReader.ReadUInt16()
                    };
                }

                var nodesCount = blocksInfoReader.ReadInt32();
                m_DirectoryInfo = new Node[nodesCount];
                for (int i = 0; i < nodesCount; i++)
                {
                    m_DirectoryInfo[i] = new Node
                    {
                        offset = blocksInfoReader.ReadInt64(),
                        size   = blocksInfoReader.ReadInt64(),
                        flags  = blocksInfoReader.ReadUInt32(),
                        path   = blocksInfoReader.ReadStringToNull(),
                    };
                }
            }
            if ((m_Header.flags & ArchiveFlags.BlockInfoNeedPaddingAtStart) != 0)
            {
                reader.AlignStream(16);
            }
        }
コード例 #15
0
        public static void ReadClassStruct(StringBuilder sb, List <ClassMember> members, EndianBinaryReader reader)
        {
            for (int i = 0; i < members.Count; i++)
            {
                var    member     = members[i];
                var    level      = member.Level;
                var    varTypeStr = member.Type;
                var    varNameStr = member.Name;
                object value      = null;
                var    align      = (member.Flag & 0x4000) != 0;
                var    append     = true;
                if (member.alignBefore)
                {
                    reader.AlignStream(4);
                }
                switch (varTypeStr)
                {
                case "SInt8":
                    value = reader.ReadSByte();
                    break;

                case "UInt8":
                    value = reader.ReadByte();
                    break;

                case "short":
                case "SInt16":
                    value = reader.ReadInt16();
                    break;

                case "UInt16":
                case "unsigned short":
                    value = reader.ReadUInt16();
                    break;

                case "int":
                case "SInt32":
                    value = reader.ReadInt32();
                    break;

                case "UInt32":
                case "unsigned int":
                case "Type*":
                    value = reader.ReadUInt32();
                    break;

                case "long long":
                case "SInt64":
                    value = reader.ReadInt64();
                    break;

                case "UInt64":
                case "unsigned long long":
                    value = reader.ReadUInt64();
                    break;

                case "float":
                    value = reader.ReadSingle();
                    break;

                case "double":
                    value = reader.ReadDouble();
                    break;

                case "bool":
                    value = reader.ReadBoolean();
                    break;

                case "string":
                    append = false;
                    var str = reader.ReadAlignedString();
                    sb.AppendFormat("{0}{1} {2} = \"{3}\"\r\n", (new string('\t', level)), varTypeStr, varNameStr, str);
                    i += 3;    //skip
                    break;

                case "Array":
                {
                    append = false;
                    if ((members[i - 1].Flag & 0x4000) != 0)
                    {
                        align = true;
                    }
                    sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                    var size = reader.ReadInt32();
                    sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), "int", "size", size);
                    var array = ReadArray(members, level, i);
                    for (int j = 0; j < size; j++)
                    {
                        sb.AppendFormat("{0}[{1}]\r\n", (new string('\t', level + 1)), j);
                        ReadClassStruct(sb, array, reader);
                    }
                    i += array.Count + 1;        //skip
                    break;
                }

                case "TypelessData":
                {
                    append = false;
                    var size = reader.ReadInt32();
                    reader.ReadBytes(size);
                    i += 2;
                    sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                    sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), "int", "size", size);
                    break;
                }

                default:
                    append = false;
                    if (align)
                    {
                        align = false;
                        SetAlignBefore(members, level, i + 1);
                    }
                    sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr);
                    break;
                }
                if (append)
                {
                    sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), varTypeStr, varNameStr, value);
                }
                if (align)
                {
                    reader.AlignStream(4);
                }
            }
        }
コード例 #16
0
        private void ReadBlocksInfoAndDirectory(EndianBinaryReader reader)
        {
            byte[] blocksInfoBytes;
            if (m_Header.version >= 7)
            {
                reader.AlignStream(16);
            }
            if ((m_Header.flags & 0x80) != 0) //kArchiveBlocksInfoAtTheEnd
            {
                var position = reader.Position;
                reader.Position = reader.BaseStream.Length - m_Header.compressedBlocksInfoSize;
                blocksInfoBytes = reader.ReadBytes((int)m_Header.compressedBlocksInfoSize);
                reader.Position = position;
            }
            else //0x40 kArchiveBlocksAndDirectoryInfoCombined
            {
                blocksInfoBytes = reader.ReadBytes((int)m_Header.compressedBlocksInfoSize);
            }
            MemoryStream blocksInfoUncompresseddStream;
            var          uncompressedSize = m_Header.uncompressedBlocksInfoSize;

            switch (m_Header.flags & 0x3F) //kArchiveCompressionTypeMask
            {
            default:                       //None
            {
                blocksInfoUncompresseddStream = new MemoryStream(blocksInfoBytes);
                break;
            }

            case 1:     //LZMA
            {
                blocksInfoUncompresseddStream = new MemoryStream((int)(uncompressedSize));
                using (var blocksInfoCompressedStream = new MemoryStream(blocksInfoBytes))
                {
                    SevenZipHelper.StreamDecompress(blocksInfoCompressedStream, blocksInfoUncompresseddStream, m_Header.compressedBlocksInfoSize, m_Header.uncompressedBlocksInfoSize);
                }
                blocksInfoUncompresseddStream.Position = 0;
                break;
            }

            case 2:     //LZ4
            case 3:     //LZ4HC
            {
                var uncompressedBytes = new byte[uncompressedSize];
                var numWrite          = LZ4Codec.Decode(blocksInfoBytes, uncompressedBytes);
                if (numWrite != uncompressedSize)
                {
                    throw new IOException($"Lz4 decompression error, write {numWrite} bytes but expected {uncompressedSize} bytes");
                }
                blocksInfoUncompresseddStream = new MemoryStream(uncompressedBytes);
                break;
            }
            }
            using (var blocksInfoReader = new EndianBinaryReader(blocksInfoUncompresseddStream))
            {
                var uncompressedDataHash = blocksInfoReader.ReadBytes(16);
                var blocksInfoCount      = blocksInfoReader.ReadInt32();
                m_BlocksInfo = new StorageBlock[blocksInfoCount];
                for (int i = 0; i < blocksInfoCount; i++)
                {
                    m_BlocksInfo[i] = new StorageBlock
                    {
                        uncompressedSize = blocksInfoReader.ReadUInt32(),
                        compressedSize   = blocksInfoReader.ReadUInt32(),
                        flags            = blocksInfoReader.ReadUInt16()
                    };
                }

                var nodesCount = blocksInfoReader.ReadInt32();
                m_DirectoryInfo = new Node[nodesCount];
                for (int i = 0; i < nodesCount; i++)
                {
                    m_DirectoryInfo[i] = new Node
                    {
                        offset = blocksInfoReader.ReadInt64(),
                        size   = blocksInfoReader.ReadInt64(),
                        flags  = blocksInfoReader.ReadUInt32(),
                        path   = blocksInfoReader.ReadStringToNull(),
                    };
                }
            }
        }