public override void DeSerialize(DataReader data) { header.DeSerialize(data); uint n1 = BitConverter.ToUInt32(new byte[] { 1, 0, 0, 0 }, 0); data.byteOrder = DataReader.ByteOrder.Little; //compress with lzma if (!header.signature.Contains("UnityRaw")) { SevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder(); data.position = header.headerSize; byte[] properties = data.ReadBytes(5); long uncompressFileSize = data.ReadInt64(); decoder.SetDecoderProperties(properties); MemoryStream outMs = new MemoryStream((int)uncompressFileSize); decoder.Code(data.BaseStream,outMs,data.BaseStream.Length-header.headerSize,uncompressFileSize,null); data.Close(); data = new DataReader(outMs); data.position = 0; } data.byteOrder = DataReader.ByteOrder.Big; numOfEntryCount = data.ReadInt32(); entrys = new SerializeBundleEntry[numOfEntryCount]; for (int i = 0; i < numOfEntryCount; i++) { entrys[i] = new SerializeBundleEntry(); entrys[i].DeSerialize(data); } }
public override void DeSerialize(DataReader data) { header.DeSerialize(data); data.byteOrder = DataReader.ByteOrder.Little; UnityVersion = data.ReadStringNull(); attributes = data.ReadInt32(); numOfTypeTrees = data.ReadInt32(); typeTrees = new SerializeTypeTree[numOfTypeTrees]; for (int i = 0; i < numOfTypeTrees; i++) { typeTrees[i] = new SerializeTypeTree(); typeTrees[i].DeSerialize(data); } //padding data.ReadInt32(); numOfObjects = data.ReadInt32(); objectInfos = new SerializeAssetObject[numOfObjects]; for (int i = 0; i < numOfObjects; i++) { objectInfos[i] = new SerializeAssetObject((int)header.DataOffset); objectInfos[i].DeSerialize(data); } numOfFileIdentifiers = data.ReadInt32(); fileIdentifiers = new SerializeFileIdentifier[numOfFileIdentifiers]; for (int i = 0; i < numOfFileIdentifiers; i++) { fileIdentifiers[i] = new SerializeFileIdentifier(); fileIdentifiers[i].DeSerialize(data); } }
public override void DeSerialize(DataReader data) { name = data.ReadStringNull(); offset = data.ReadUint32(); size = data.ReadUint32(); assetData = data.GetRangeBytes(offset, size); }
public SerializeObject(TypeTree type, byte[] rawData) { RootProperty = new SerializeProperty(type); MemoryStream ms = new MemoryStream(rawData); DataReader br = new DataReader(ms); RootProperty.DeSerialize(br); br.Close(); ms.Close(); }
public override void DeSerialize(DataReader data) { data.byteOrder = DataReader.ByteOrder.Big; MetaDataSize = data.ReadInt32(); FileSize = data.ReadUint32(); Version = data.ReadInt32(); DataOffset = data.ReadUint32(); endianness = data.ReadByte(); reserved = data.ReadBytes(3); }
static public bool IsBundle(string path) { try { FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); DataReader data = new DataReader(fs); data.byteOrder = DataReader.ByteOrder.Big; string signature = data.ReadStringNull(); data.Close(); fs.Dispose(); if (signature.Contains("Unity")) { return true; } return false; } catch { return false; } }
public override void DeSerialize(DataReader br) { br.byteOrder = DataReader.ByteOrder.Big; signature = br.ReadStringNull(); streamVersion = br.ReadInt32(); unityVersion = br.ReadStringNull(); unityRevision = br.ReadStringNull(); minimumStreamedBytes = br.ReadUInt32(); headerSize = br.ReadInt32(); numberOfLevelsToDownload = br.ReadInt32(); numberOfLevels = br.ReadInt32(); levelByteEnd.Clear(); for (int i = 0; i < numberOfLevels; i++) { levelByteEnd.Add(new KeyValuePair<uint, uint>(br.ReadUInt32(), br.ReadUInt32())); } completeFileSize = br.ReadUInt32(); dataHeaderSize = br.ReadUInt32(); resvers = br.ReadBytes(1); }
public override void DeSerialize(DataReader br) { header.DeSerialize(br); br.byteOrder = DataReader.ByteOrder.Little; UnityVersion = br.ReadStringNull(); attributes = br.ReadInt32(); embedded = br.ReadBool(); numOfBaseClasses = br.ReadInt32(); classes = new SerializeTypeTreeData[numOfBaseClasses]; for (int i = 0; i < numOfBaseClasses; i++) { classes[i] = new SerializeTypeTreeData(embedded); classes[i].DeSerialize(br); } numOfObjects = br.ReadInt32(); objectInfos = new SerializeAssetObject[numOfObjects]; for (int i = 0; i < numOfObjects; i++) { objectInfos[i] = new SerializeAssetObject((int)header.DataOffset); objectInfos[i].DeSerialize(br); } numOfObjectIdentifiers = br.ReadInt32(); objectIdentifiers = new SerializeObjectIdentifier[numOfObjectIdentifiers]; for (int i = 0; i < numOfObjectIdentifiers; i++) { objectIdentifiers[i] = new SerializeObjectIdentifier(); objectIdentifiers[i].DeSerialize(br); } numOfFileIdentifiers = br.ReadInt32(); fileIdentifiers = new SerializeFileIdentifier[numOfFileIdentifiers]; for (int i = 0; i < numOfFileIdentifiers; i++) { fileIdentifiers[i] = new SerializeFileIdentifier(); fileIdentifiers[i].DeSerialize(br); } }
public bool DeSerialize(string packgePath) { ZipFile zipFile = null; try { zipFile = new ZipFile(packgePath); } catch { Debug.LogError("Cant't uncomress file "+packgePath); return false; } //load mainData var mainDataEntry = zipFile.GetEntry("assets/bin/Data/mainData"); if (mainDataEntry == null) { Debug.LogError("Cant't uncomress file " + packgePath); } var zipStream = zipFile.GetInputStream(mainDataEntry); var mainDataStream = AssetToolUtility.ZipInputStream2MemoryStream(zipStream,mainDataEntry.Size); zipStream.Close(); Version = AssetToolUtility.GetAssetsFileVersion(mainDataStream); Debug.Log("MainDataVersion:" + Version); var serializeAsset = SerializeAssetFactory.CreateWithVersion(Version); if (serializeAsset == null) { Debug.LogError("Cant't uncomress file {0},Version:",packgePath, Version); zipFile.Close(); return false; } DataReader dr = new DataReader(mainDataStream); serializeAsset.DeSerialize(dr); string rootPath = "assets/bin/Data/"; var mainDataAsset = new Asset(serializeAsset); foreach (var externFileIdentier in mainDataAsset.ExternalFiles) { string filePath = externFileIdentier.filePath; //fix unity default resources path if (filePath.StartsWith("library/") && zipFile.GetEntry(rootPath+filePath) == null) { filePath = filePath.Remove(0, 8); } string path = rootPath + filePath; try { MemoryStream externStream = new MemoryStream(); var externZipEntry = zipFile.GetEntry(path); if (externZipEntry != null) { var externZipStream = zipFile.GetInputStream(externZipEntry); externStream = AssetToolUtility.ZipInputStream2MemoryStream(externZipStream, externZipEntry.Size); externZipStream.Dispose(); } else { if (zipFile.GetEntry(path + ".split0") != null) { //handel split file int splitIndex = 0; ZipEntry splitEntry = null; while ((splitEntry = zipFile.GetEntry(path + ".split" + splitIndex++)) != null) { var splitZipStream = zipFile.GetInputStream(splitEntry); byte[] buffer = new byte[splitEntry.Size]; splitZipStream.Read(buffer, 0,buffer.Length); splitZipStream.Dispose(); externStream.Write(buffer, 0, buffer.Length); } } else { Debug.LogError("Can't find file {0} in apk", path); continue; } } externStream.Position = 0; DataReader externDataReader = new DataReader(externStream); var externSerializeFile = SerializeAssetFactory.CreateWithVersion(Version); externSerializeFile.DeSerialize(externDataReader); externStream.Dispose(); Asset externAsset = new Asset(externSerializeFile); AssetList.Add(externAsset); Debug.Log("Added:" +path); } catch { Debug.LogError("Cant't deserialize asset {0},Version:", path); zipFile.Close(); return false; } } //load typeTreeDataBase var typetreedb = AssetToolUtility.LoadTypeTreeDataBase(Properties.Resources.TypeTreeDataBasePath); //serach resource manager SerializeObject resourMgrObj = null; foreach (var obj in mainDataAsset.ObjectInfos) { if (obj.classID == 147) { var resmgrType = typetreedb.GetType(Version, 147); if (resmgrType != null) { resourMgrObj = new SerializeObject(resmgrType, obj.data); ResMgr.Deserialize(resourMgrObj.RootProperty); } else { Debug.LogError("Can't find resource manager typetree."); zipFile.Close(); return false; } break; } } if (resourMgrObj == null) { Debug.LogError("Can't find resource manager in mainData."); zipFile.Close(); return false; } zipFile.Close(); return true; }
public override void DeSerialize(DataReader data) { assetPath = data.ReadStringNull(); var oldOrder = data.byteOrder; data.byteOrder = DataReader.ByteOrder.Big; guidMost = data.ReadInt64(); guidLeast = data.ReadInt64(); data.byteOrder = oldOrder; type = data.ReadInt32(); filePath = data.ReadStringNull(); }
public override void DeSerialize(DataReader br) { PathID = br.ReadUint32(); offset = br.ReadUint32(); length = br.ReadUint32(); typeID = br.ReadInt32(); classID = br.ReadInt16(); isDestroyed = br.ReadInt16(); data = br.GetRangeBytes((uint)(mDataOffset + offset), length); }
public override void DeSerialize(DataReader data) { type = data.ReadStringNull(); name = data.ReadStringNull(); size = data.ReadInt32(); index = data.ReadInt32(); isArray = data.ReadInt32(); version = data.ReadInt32(); metaFlag = data.ReadInt32(); numOfChildren = data.ReadInt32(); children = new SerializeTypeTreeData[numOfChildren]; for (int i = 0; i < numOfChildren; i++) { children[i] = new SerializeTypeTreeData(); children[i].DeSerialize(data); } }
public override void DeSerialize(DataReader br) { version = br.ReadInt16(); treeLevel = br.ReadByte(); isArray = br.ReadBool(); typeOffset = br.ReadInt32(); nameOffset = br.ReadInt32(); size = br.ReadInt32(); index = br.ReadInt32(); metaFlag = br.ReadInt32(); }
static public TypeTreeDataBase GenerateTypeTreeDataBase(SerializeAssetV15 asset) { TypeTreeDataBase DB = new TypeTreeDataBase(); Dictionary<int, string> typeNameTable = new Dictionary<int, string>(); //一个共享的类型字符串表 string defaultTypeStr = Properties.Resources.ResourceManager.GetString("TypeStringTableV15"); var typeStrArray = defaultTypeStr.Split('\n'); int startOffset = 1 << 31; for (int i = 0; i < typeStrArray.Length; i++) { typeNameTable[startOffset] = typeStrArray[i].Substring(0, typeStrArray[i].Length-1); startOffset += typeStrArray[i].Length; } foreach (var baseClass in asset.classes) { if (baseClass.stringTable == null) continue; Dictionary<int, string> onwerStrTable = new Dictionary<int, string>(); MemoryStream ms = new MemoryStream(baseClass.stringTable); DataReader data = new DataReader(ms); TypeTree rootType = new TypeTree(); TypeTree nodePrev = null; Dictionary<TypeTree, int> typeLevelDic = new Dictionary<TypeTree, int>(); foreach (var field in baseClass.types) { string name = ""; string type = ""; if (field.nameOffset < 0) { if (typeNameTable.ContainsKey(field.nameOffset)) { name = typeNameTable[field.nameOffset]; } } else { data.position = field.nameOffset; name = data.ReadStringNull(); } if (field.typeOffset < 0) { if (typeNameTable.ContainsKey(field.typeOffset)) { type = typeNameTable[field.typeOffset]; } } else { data.position = field.typeOffset; type = data.ReadStringNull(); } if (nodePrev == null) { rootType.name = name; rootType.type = type; rootType.metaFlag = field.metaFlag; nodePrev = rootType; typeLevelDic[nodePrev] = field.treeLevel; continue; } TypeTree nodeCurr = new TypeTree(); nodeCurr.name = name; nodeCurr.type = type; nodeCurr.metaFlag = field.metaFlag; typeLevelDic[nodeCurr] = field.treeLevel; int levels = typeLevelDic[nodePrev] - field.treeLevel; if (levels >= 0) { for (int i = 0; i < levels; i++) { nodePrev = nodePrev.parent; } nodePrev.parent.AddChild(nodeCurr); } else { nodePrev.AddChild(nodeCurr); } nodePrev = nodeCurr; } DB.Put(15, baseClass.ClassID, rootType); Console.Write(rootType); data.Close(); ms.Close(); } return DB; }
public override void DeSerialize(DataReader br) { ClassID = br.ReadInt32(); if (ClassID < 0) { hash = br.ReadBytes(16); } oldhash = br.ReadBytes(16); if (isEmbedded) { fildsCount = br.ReadInt32(); strTableSize = br.ReadInt32(); types = new SerializeTypeData[fildsCount]; for (int i = 0; i < fildsCount; i++) { types[i] = new SerializeTypeData(); types[i].DeSerialize(br); } stringTable = br.ReadBytes(strTableSize); } }
public override void DeSerialize(DataReader br) { br.Align(4); PathID = br.ReadInt64(); offset = br.ReadUint32(); length = br.ReadUint32(); typeID = br.ReadInt32(); classID = br.ReadInt16(); scriptTypeIndex = br.ReadInt16(); stripped = br.ReadBool(); data = br.GetRangeBytes((uint)(mDataOffset + offset), length); }
private void readTypeDatas(DataReader data) { SerializeTypeTreeData node = new SerializeTypeTreeData(); node.DeSerialize(data); int numOfChildren = data.ReadInt32(); for (int i = 0; i < numOfChildren; i++) { readTypeDatas(data); } }
public override void DeSerialize(DataReader data) { serializeFileIndex = data.ReadInt32(); identifierInFile = data.ReadInt64(); data.Align(4); }
public SerializeObject(TypeTree type, DataReader data) { RootProperty = new SerializeProperty(type); RootProperty.DeSerialize(data); }
public override void DeSerialize(DataReader data) { ClassID = data.ReadInt32(); rootType = new SerializeTypeTreeData(); rootType.DeSerialize(data); }
private object readValue(SerializePropertyType ptype,TypeTree typeTree, DataReader data) { object ret = null; switch (ptype) { case SerializePropertyType.Bool: ret = data.ReadBool(); break; case SerializePropertyType.SByte: ret = data.ReadSbyte(); break; case SerializePropertyType.Byte: ret = data.ReadByte(); break; case SerializePropertyType.Short: ret = data.ReadInt16(); break; case SerializePropertyType.UShort: ret = data.ReadUInt16(); break; case SerializePropertyType.Int: ret = data.ReadInt32(); break; case SerializePropertyType.UInt: ret = data.ReadUint32(); break; case SerializePropertyType.Long: ret = data.ReadInt64(); break; case SerializePropertyType.ULong: ret = data.ReadUInt64(); break; case SerializePropertyType.Float: ret = data.ReadFloat(); break; case SerializePropertyType.Double: ret = data.ReadDouble(); break; case SerializePropertyType.String: int strSize = data.ReadInt32(); ret = UnicodeEncoding.UTF8.GetString(data.ReadBytes(strSize)); //ret = UTF8Encoding.Default.GetString(); break; default: break; } if (((typeTree.metaFlag & TypeTree.FLAG_FORCE_ALIGN) != 0) || propertyType == SerializePropertyType.String) { data.Align(4); } return ret; }
public virtual void DeSerialize(DataReader data) { }
public object readArrayValue(TypeTree typeTree, DataReader data) { var elementType = typeTree.GetChildren()[1]; arrayLength = data.ReadInt32(); arrayElementType = typeStr2PropertyType(elementType.type); object ret = null; switch (arrayElementType) { case SerializePropertyType.Bool: ret = data.ReadBool(arrayLength); break; case SerializePropertyType.Byte: ret = data.ReadBytes(arrayLength); break; case SerializePropertyType.Double: ret = data.ReadDouble(arrayLength); break; case SerializePropertyType.Float: ret = data.ReadFloat(arrayLength); break; case SerializePropertyType.Int: ret = data.ReadInt32(arrayLength); break; case SerializePropertyType.Long: ret = data.ReadInt64(arrayLength); break; case SerializePropertyType.SByte: ret = data.ReadSbytes(arrayLength); break; case SerializePropertyType.Short: ret = data.ReadInt16(arrayLength); break; case SerializePropertyType.String: string[] stringArray = new string[arrayLength]; for (int i = 0; i < arrayLength; i++) { int strSize = data.ReadInt32(); stringArray[i] = UnicodeEncoding.UTF8.GetString(data.ReadBytes(strSize)); data.Align(4); } ret = stringArray; break; case SerializePropertyType.UInt: ret = data.ReadUint32(arrayLength); break; case SerializePropertyType.ULong: ret = data.ReadUInt64(arrayLength); break; case SerializePropertyType.UShort: ret = data.ReadUInt16(arrayLength); break; default: SerializeProperty[] properArray = new SerializeProperty[arrayLength]; for (int i = 0; i < arrayLength; i++) { SerializeProperty value = null; if (arrayElementType == SerializePropertyType.Property || arrayElementType == SerializePropertyType.Array) { var sp = new SerializeProperty(elementType); sp.DeSerialize(data); value = sp; } properArray[i] = value; } ret = properArray; break; } data.Align(4); return ret; }
public override void DeSerialize(DataReader data) { propertyType = typeStr2PropertyType(mType.type); if (propertyType == SerializePropertyType.Property) { var children = mType.GetChildren(); foreach (var child in children) { SerializeProperty childProperty = new SerializeProperty(child); childProperty.DeSerialize(data); this.AddChild(childProperty); } } else if (propertyType == SerializePropertyType.Array) { value = readArrayValue(mType,data); } else { value = readValue(propertyType,mType, data); } }