private void extractOnlyRawText(Asset.AssetObjectInfo objinfo, TypeTree typeTree, string outputPath)
 {
     if (typeTree != null) {
         SerializeObject sobj = new SerializeObject(typeTree, objinfo.data);
         ExtractRawText(sobj,outputPath);
     }
 }
        private void extractRawTextOrRawBits(Asset.AssetObjectInfo objinfo, TypeTree typeTree, string outputPath)
        {
            if (typeTree != null) {
                extractOnlyRawText(objinfo, typeTree, outputPath);
            } else {
                extractOnlyRawBits(objinfo,typeTree,outputPath);
            }

        }
 private void ExtractAuto(Asset.AssetObjectInfo objinfo,TypeTree typeTree, string outputPath)
 {
     if (typeTree != null) {
         SerializeObject sobj = new SerializeObject(typeTree, objinfo.data);
         ISerializeObjectExtrator extrator;
         if (mObjectExtratorDic.TryGetValue(typeTree.type, out extrator)) {
             extrator.Extract(sobj, outputPath);
         } else {
             extractOnlyRawText(objinfo, typeTree, outputPath);
         }
     } else {
         extractOnlyRawBits(objinfo, typeTree, outputPath);
     }
 }
 public void ExtractObjct(Asset.AssetObjectInfo obj, TypeTree typeTree, string outputPath, ExtractMode mode = ExtractMode.Auto)
 {
     outputPath = outputPath + "\\" + AssetToolUtility.ClassIDToClassName(obj.classID) + "\\";
     switch (mode) {
         case ExtractMode.Auto:
         ExtractAuto(obj, typeTree, outputPath);
         break;
         case ExtractMode.OnlyRawBits:
         extractOnlyRawBits(obj, typeTree, outputPath);
         break;
         case ExtractMode.OnlyRawText:
         extractOnlyRawText(obj, typeTree, outputPath);
         break;
         case ExtractMode.RawTextOrRawBits:
         extractRawTextOrRawBits(obj, typeTree, outputPath);
         break;
     }
 }
 private void extractOnlyRawBits(Asset.AssetObjectInfo objinfo, TypeTree typeTree, string outputPath)
 {
     string name = "";
     if (typeTree != null && Path.GetFileName(outputPath) == "") {           
         try {
             SerializeObject sobj  = new SerializeObject(typeTree, objinfo.data);
            var nameProperty = sobj.FindProperty("m_Name");              
             if (nameProperty != null) {
                 name = nameProperty.Value as string;
                 outputPath += "/" + name;
             }
         } catch {
             Debug.LogError("Can't Create SerializeObject.TypeVerion:{0},TypeClassID:{1},TypeName:{2}",
                 typeTree.version, objinfo.classID, typeTree.type);
         }
     }
     ExtractRawBits(objinfo, outputPath);
 }
        private void ExtractRawBits(Asset.AssetObjectInfo obj, string outputPath)
        {

            if (Path.GetFileName(outputPath) == "") {
                string name = (gID++) + "_" + obj.PathID.ToString();
                outputPath = outputPath + "/" + name;
            }
            if (Path.GetExtension(outputPath) == "") {
                outputPath += ".raw";
            }
          


            outputPath = AssetToolUtility.FixOuputPath(outputPath);
            if (!Directory.Exists(Path.GetDirectoryName(outputPath))) {
                Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
            }       
            var bytes = obj.data;
            var fs = new FileStream(outputPath, FileMode.OpenOrCreate, FileAccess.Write);
            fs.Write(bytes, 0, bytes.Length);
            fs.Flush();
            fs.Dispose();
        }
 public void Extract(Asset asset, TypeTreeDataBase typeTreeDB, string outputPath, ExtractMode mode = ExtractMode.Auto)
 {
     foreach (var objinfo in asset.ObjectInfos) {
         string className = AssetToolUtility.ClassIDToClassName(objinfo.classID);
         var path = outputPath + "/Class " +objinfo.classID+" "+ className+"/";
         var typeTree = typeTreeDB.GetType(asset.AssetVersion, objinfo.classID);
         ExtractObjct(objinfo, typeTree, outputPath, mode);
     }     
 }
Esempio n. 8
0
        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;    
        }