public AssetsFile(string fullName, EndianBinaryReader reader) { this.reader = reader; filePath = fullName; fileName = Path.GetFileName(fullName); upperFileName = fileName.ToUpper(); try { int tableSize = this.reader.ReadInt32(); int dataEnd = this.reader.ReadInt32(); fileGen = this.reader.ReadInt32(); uint dataOffset = this.reader.ReadUInt32(); sharedAssetsList[0].fileName = fileName; //reference itself because sharedFileIDs start from 1 switch (fileGen) { case 6: //2.5.0 - 2.6.1 { this.reader.Position = (dataEnd - tableSize); this.reader.Position += 1; break; } case 7: //3.0.0 beta { this.reader.Position = (dataEnd - tableSize); this.reader.Position += 1; m_Version = this.reader.ReadStringToNull(); break; } case 8: //3.0.0 - 3.4.2 { this.reader.Position = (dataEnd - tableSize); this.reader.Position += 1; m_Version = this.reader.ReadStringToNull(); platform = this.reader.ReadInt32(); break; } case 9: //3.5.0 - 4.6.x { this.reader.Position += 4; //azero m_Version = this.reader.ReadStringToNull(); platform = this.reader.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 { this.reader.Position += 4; //azero m_Version = this.reader.ReadStringToNull(); platform = this.reader.ReadInt32(); baseDefinitions = this.reader.ReadBoolean(); break; } default: { //MessageBox.Show("Unsupported version!" + fileGen, "AssetStudio Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (fileGen > 6 && m_Version == "") { return; } if (platform > 255 || platform < 0) { byte[] b32 = BitConverter.GetBytes(platform); Array.Reverse(b32); platform = BitConverter.ToInt32(b32, 0); this.reader.endian = EndianType.LittleEndian; } platformStr = Enum.IsDefined(typeof(BuildTarget), platform) ? ((BuildTarget)platform).ToString() : "Unknown Platform"; int baseCount = this.reader.ReadInt32(); for (int i = 0; i < baseCount; i++) { if (fileGen < 14) { int classID = this.reader.ReadInt32(); string baseType = this.reader.ReadStringToNull(); string baseName = this.reader.ReadStringToNull(); this.reader.Position += 20; int memberCount = this.reader.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) { this.reader.Position += 4; //azero } int assetCount = this.reader.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) { this.reader.AlignStream(4); } AssetPreloadData asset = new AssetPreloadData(); asset.m_PathID = fileGen < 14 ? this.reader.ReadInt32() : this.reader.ReadInt64(); asset.Offset = this.reader.ReadUInt32(); asset.Offset += dataOffset; asset.Size = this.reader.ReadInt32(); if (fileGen > 15) { int index = this.reader.ReadInt32(); asset.Type1 = classIDs[index][0]; asset.Type2 = classIDs[index][1]; } else { asset.Type1 = this.reader.ReadInt32(); asset.Type2 = this.reader.ReadUInt16(); this.reader.Position += 2; } if (fileGen == 15) { byte unknownByte = this.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 && fileGen == 6) { long nextAsset = this.reader.Position; BuildSettings BSettings = new BuildSettings(asset); m_Version = BSettings.m_Version; this.reader.Position = nextAsset; } #endregion } #endregion buildType = Regex.Replace(m_Version, @"\d", "").Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries); var firstVersion = int.Parse(m_Version.Split('.')[0]); version = Regex.Matches(m_Version, @"\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; } if (fileGen >= 14) { //this looks like a list of assets that need to be preloaded in memory before anytihng else int someCount = this.reader.ReadInt32(); for (int i = 0; i < someCount; i++) { int num1 = this.reader.ReadInt32(); this.reader.AlignStream(4); long m_PathID = this.reader.ReadInt64(); } } int sharedFileCount = this.reader.ReadInt32(); for (int i = 0; i < sharedFileCount; i++) { var shared = new SharedAssets(); shared.aName = this.reader.ReadStringToNull(); this.reader.Position += 20; var sharedFilePath = this.reader.ReadStringToNull(); //relative path shared.fileName = Path.GetFileName(sharedFilePath); sharedAssetsList.Add(shared); } valid = true; } catch { } }
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 { } }
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 { } }
public AssetsFile(string fileName, EndianStream fileStream) { //if (memFile != null) { Stream = new EndianStream(memFile, endianType); } //else { Stream = new EndianStream(File.OpenRead(fileName), endianType); } a_Stream = fileStream; filePath = fileName; int tableSize = a_Stream.ReadInt32(); int dataEnd = a_Stream.ReadInt32(); fileGen = a_Stream.ReadInt32(); int dataOffset = a_Stream.ReadInt32(); sharedAssetsList[0].fileName = Path.GetFileName(fileName); //reference itself because sharedFileIDs start from 1 switch (fileGen) { case 6: //2.5.0 - 2.6.1 { a_Stream.Position = (dataEnd - tableSize); a_Stream.Position += 1; break; } case 7: //3.0.0 beta { a_Stream.Position = (dataEnd - tableSize); a_Stream.Position += 1; m_Version = a_Stream.ReadStringToNull(); break; } case 8: //3.0.0 - 3.4.2 { a_Stream.Position = (dataEnd - tableSize); a_Stream.Position += 1; m_Version = a_Stream.ReadStringToNull(); platform = a_Stream.ReadInt32(); break; } case 9: //3.5.0 - 4.6.x { a_Stream.Position += 4; //azero m_Version = a_Stream.ReadStringToNull(); platform = a_Stream.ReadInt32(); break; } case 14: //5.0.0 beta and final case 15: //5.0.1 and up { a_Stream.Position += 4; //azero m_Version = a_Stream.ReadStringToNull(); platform = a_Stream.ReadInt32(); baseDefinitions = a_Stream.ReadBoolean(); break; } default: { //MessageBox.Show("Unsupported version!", "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); //endianType = EndianType.LittleEndian; a_Stream.endian = EndianType.LittleEndian; } switch (platform) { case -2: platformStr = "Unt Package"; break; case 4: platformStr = "OSX"; break; case 5: platformStr = "PC"; break; case 6: platformStr = "Web"; break; case 7: platformStr = "Web streamed"; break; case 9: platformStr = "iOS"; break; case 10: platformStr = "PS3"; break; case 11: platformStr = "Xbox 360"; break; case 13: platformStr = "Android"; break; case 16: platformStr = "Google NaCl"; break; case 21: platformStr = "WP8"; break; case 25: platformStr = "Linux"; break; } int baseCount = a_Stream.ReadInt32(); for (int i = 0; i < baseCount; i++) { if (fileGen < 14) { int classID = a_Stream.ReadInt32(); string baseType = a_Stream.ReadStringToNull(); string baseName = a_Stream.ReadStringToNull(); a_Stream.Position += 20; int memberCount = a_Stream.ReadInt32(); StringBuilder cb = new StringBuilder(); for (int m = 0; m < memberCount; m++) { readBase(cb, 1); } var aClass = new ClassStrStruct() { ID = classID, Text = (baseType + " " + baseName), members = cb.ToString() }; aClass.SubItems.Add(classID.ToString()); ClassStructures.Add(classID, aClass); } else { readBase5(); } } if (fileGen >= 7 && fileGen < 14) { a_Stream.Position += 4; } //azero int assetCount = a_Stream.ReadInt32(); #region asset preload table string assetIDfmt = "D" + assetCount.ToString().Length.ToString(); //format for unique ID for (int i = 0; i < assetCount; i++) { //each table entry is aligned individually, not the whole table if (fileGen >= 14) { a_Stream.AlignStream(4); } AssetPreloadData asset = new AssetPreloadData(); if (fileGen < 14) { asset.m_PathID = a_Stream.ReadInt32(); } else { asset.m_PathID = a_Stream.ReadInt64(); } asset.Offset = a_Stream.ReadInt32(); asset.Offset += dataOffset; asset.Size = a_Stream.ReadInt32(); asset.Type1 = a_Stream.ReadInt32(); asset.Type2 = a_Stream.ReadUInt16(); a_Stream.Position += 2; if (fileGen >= 15) { byte unknownByte = a_Stream.ReadByte(); //this is a single byte, not an int32 //the next entry is aligned after this //but not the last! if (unknownByte != 0) { bool investigate = true; } } if (UnityClassID.Names[asset.Type2] != null) { asset.TypeString = UnityClassID.Names[asset.Type2]; } asset.uniqueID = i.ToString(assetIDfmt); asset.exportSize = asset.Size; asset.sourceFile = this; preloadTable.Add(asset.m_PathID, asset); #region read BuildSettings to get version for 2.x files if (asset.Type2 == 141 && fileGen == 6) { long nextAsset = a_Stream.Position; BuildSettings BSettings = new BuildSettings(asset); m_Version = BSettings.m_Version; a_Stream.Position = nextAsset; } #endregion } #endregion buildType = m_Version.Split(new string[] { ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }, StringSplitOptions.RemoveEmptyEntries); string[] strver = (m_Version.Split(new string[] { ".", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "\n" }, StringSplitOptions.RemoveEmptyEntries)); version = Array.ConvertAll(strver, int.Parse); if (fileGen >= 14) { //this looks like a list of assets that need to be preloaded in memory before anytihng else int someCount = a_Stream.ReadInt32(); for (int i = 0; i < someCount; i++) { int num1 = a_Stream.ReadInt32(); a_Stream.AlignStream(4); long m_PathID = a_Stream.ReadInt64(); } } int sharedFileCount = a_Stream.ReadInt32(); for (int i = 0; i < sharedFileCount; i++) { UnityShared shared = new UnityShared(); shared.aName = a_Stream.ReadStringToNull(); a_Stream.Position += 20; string sharedFileName = a_Stream.ReadStringToNull(); //relative path shared.fileName = sharedFileName.Replace("/", "\\"); sharedAssetsList.Add(shared); } }