Example #1
0
 private void LoadAssetsFromMemory(FileReader reader, string originalPath, string unityVersion = null)
 {
     if (!assetsFileListHash.Contains(reader.FileName))
     {
         try
         {
             var assetsFile = new SerializedFile(reader, this);
             assetsFile.originalPath = originalPath;
             if (!string.IsNullOrEmpty(unityVersion) && assetsFile.header.m_Version < SerializedFileFormatVersion.Unknown_7)
             {
                 assetsFile.SetVersion(unityVersion);
             }
             CheckStrippedVersion(assetsFile);
             assetsFileList.Add(assetsFile);
             assetsFileListHash.Add(assetsFile.fileName);
         }
         catch (Exception e)
         {
             Logger.Error($"Error while reading assets file {reader.FullPath} from {Path.GetFileName(originalPath)}", e);
             resourceFileReaders.Add(reader.FileName, reader);
         }
     }
     else
     {
         Logger.Info($"Skipping {originalPath} ({reader.FileName})");
     }
 }
Example #2
0
        private void LoadAssetsFromMemory(string fullName, EndianBinaryReader reader, string originalPath, string unityVersion = null, bool singleFile = false)
        {
            var fileName = Path.GetFileName(fullName);

            if (!assetsFileListHash.Contains(fileName))
            {
                try
                {
                    var assetsFile = new SerializedFile(this, fullName, reader);
                    if (singleFile)
                    {
                        assetsFile.singleFile = true;
                    }
                    assetsFile.originalPath = originalPath;
                    if (assetsFile.header.m_Version < 7)
                    {
                        assetsFile.SetVersion(unityVersion);
                    }
                    assetsFileList.Add(assetsFile);
                    assetsFileListHash.Add(assetsFile.fileName);
                }
                catch
                {
                    //Logger.Error($"Unable to load assets file {fileName} from {Path.GetFileName(originalPath)}");
                    resourceFileReaders.Add(fileName, reader);
                }
            }
        }
Example #3
0
 public ResourceReader(string path, SerializedFile assetsFile, long offset, int size)
 {
     needSearch      = true;
     this.path       = path;
     this.assetsFile = assetsFile;
     this.offset     = offset;
     this.size       = size;
 }
Example #4
0
        private void LoadAssetsFile(FileReader reader)
        {
            if (!assetsFileListHash.Contains(reader.FileName))
            {
                Logger.Info($"Loading {reader.FullPath}");
                try
                {
                    var assetsFile = new SerializedFile(reader, this);
                    CheckStrippedVersion(assetsFile);
                    assetsFileList.Add(assetsFile);
                    assetsFileListHash.Add(assetsFile.fileName);

                    foreach (var sharedFile in assetsFile.m_Externals)
                    {
                        var sharedFileName = sharedFile.fileName;

                        if (!importFilesHash.Contains(sharedFileName))
                        {
                            var sharedFilePath = Path.Combine(Path.GetDirectoryName(reader.FullPath), sharedFileName);
                            if (!noexistFiles.Contains(sharedFilePath))
                            {
                                if (!File.Exists(sharedFilePath))
                                {
                                    var findFiles = Directory.GetFiles(Path.GetDirectoryName(reader.FullPath), sharedFileName, SearchOption.AllDirectories);
                                    if (findFiles.Length > 0)
                                    {
                                        sharedFilePath = findFiles[0];
                                    }
                                }
                                if (File.Exists(sharedFilePath))
                                {
                                    importFiles.Add(sharedFilePath);
                                    importFilesHash.Add(sharedFileName);
                                }
                                else
                                {
                                    noexistFiles.Add(sharedFilePath);
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.Error($"Error while reading assets file {reader.FullPath}", e);
                    reader.Dispose();
                }
            }
            else
            {
                Logger.Info($"Skipping {reader.FullPath}");
                reader.Dispose();
            }
        }
Example #5
0
 public void CheckStrippedVersion(SerializedFile assetsFile)
 {
     if (assetsFile.IsVersionStripped && string.IsNullOrEmpty(SpecifyUnityVersion))
     {
         throw new Exception("The Unity version has been stripped, please set the version in the options");
     }
     if (!string.IsNullOrEmpty(SpecifyUnityVersion))
     {
         assetsFile.SetVersion(SpecifyUnityVersion);
     }
 }
Example #6
0
        protected Object(ObjectReader reader)
        {
            this.reader = reader;
            reader.Reset();
            sourceFile = reader.assetsFile;
            version    = reader.version;
            buildType  = reader.buildType;
            platform   = reader.platform;

            if (platform == BuildTarget.NoTarget)
            {
                var m_ObjectHideFlags = reader.ReadUInt32();
            }
        }
Example #7
0
        private void LoadAssetsFile(string fullName, EndianBinaryReader reader)
        {
            var fileName = Path.GetFileName(fullName);

            if (!assetsFileListHash.Contains(fileName))
            {
                Logger.Info($"Loading {fileName}");
                try
                {
                    var assetsFile = new SerializedFile(this, fullName, reader);
                    assetsFileList.Add(assetsFile);
                    assetsFileListHash.Add(assetsFile.fileName);

                    foreach (var sharedFile in assetsFile.m_Externals)
                    {
                        var sharedFilePath = Path.Combine(Path.GetDirectoryName(fullName), sharedFile.fileName);
                        var sharedFileName = sharedFile.fileName;

                        if (!importFilesHash.Contains(sharedFileName))
                        {
                            if (!File.Exists(sharedFilePath))
                            {
                                var findFiles = Directory.GetFiles(Path.GetDirectoryName(fullName), sharedFileName, SearchOption.AllDirectories);
                                if (findFiles.Length > 0)
                                {
                                    sharedFilePath = findFiles[0];
                                }
                            }

                            if (File.Exists(sharedFilePath))
                            {
                                importFiles.Add(sharedFilePath);
                                importFilesHash.Add(sharedFileName);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.Error($"Error while reading assets file {fileName}", e);
                    reader.Dispose();
                }
            }
            else
            {
                reader.Dispose();
            }
        }
Example #8
0
        private void LoadAssetsFile(string fullName, EndianBinaryReader reader)
        {
            var fileName = Path.GetFileName(fullName);

            if (!assetsFileListHash.Contains(fileName))
            {
                Logger.Info($"Loading {fileName}");
                try
                {
                    var assetsFile = new SerializedFile(this, fullName, reader);
                    assetsFileList.Add(assetsFile);
                    assetsFileListHash.Add(assetsFile.fileName);

                    //foreach (var sharedFile in assetsFile.m_Externals)
                    //{
                    //    var sharedFilePath = Path.GetDirectoryName(fullName) + "\\" + sharedFile.fileName;
                    //    var sharedFileName = sharedFile.fileName;

                    //    if (!importFilesHash.Contains(sharedFileName))
                    //    {
                    //        if (!File.Exists(sharedFilePath))
                    //        {
                    //            var findFiles = Directory.GetFiles(Path.GetDirectoryName(fullName), sharedFileName, SearchOption.AllDirectories);
                    //            if (findFiles.Length > 0)
                    //            {
                    //                sharedFilePath = findFiles[0];
                    //            }
                    //        }

                    //        if (File.Exists(sharedFilePath))
                    //        {
                    //            importFiles.Add(sharedFilePath);
                    //            importFilesHash.Add(sharedFileName);
                    //        }
                    //    }
                    //}
                }
                catch
                {
                    reader.Dispose();
                    //Logger.Warning($"Unable to load assets file {fileName}");
                }
            }
            else
            {
                reader.Dispose();
            }
        }
Example #9
0
        private void LoadAssetsFile(string fullName, EndianBinaryReader reader)
        {
            var fileName = Path.GetFileName(fullName);

            if (!assetsfileListHash.Contains(fileName.ToUpper()))
            {
                Logger.Info($"Loading {fileName}");
                var assetsFile = new SerializedFile(this, fullName, reader);
                if (assetsFile.valid)
                {
                    assetsFileList.Add(assetsFile);
                    assetsfileListHash.Add(assetsFile.upperFileName);

                    foreach (var sharedFile in assetsFile.m_Externals)
                    {
                        var sharedFilePath = Path.GetDirectoryName(fullName) + "\\" + sharedFile.fileName;
                        var sharedFileName = sharedFile.fileName;

                        if (!importFilesHash.Contains(sharedFileName.ToUpper()))
                        {
                            if (!File.Exists(sharedFilePath))
                            {
                                var findFiles = Directory.GetFiles(Path.GetDirectoryName(fullName), sharedFileName, SearchOption.AllDirectories);
                                if (findFiles.Length > 0)
                                {
                                    sharedFilePath = findFiles[0];
                                }
                            }

                            if (File.Exists(sharedFilePath))
                            {
                                importFiles.Add(sharedFilePath);
                                importFilesHash.Add(sharedFileName.ToUpper());
                            }
                        }
                    }
                }
                else
                {
                    reader.Dispose();
                }
            }
            else
            {
                reader.Dispose();
            }
        }
Example #10
0
        private bool TryGetAssetsFile(out SerializedFile result)
        {
            result = null;
            if (m_FileID == 0)
            {
                result = assetsFile;
                return(true);
            }

            if (m_FileID > 0 && m_FileID - 1 < assetsFile.m_Externals.Count)
            {
                var assetsManager        = assetsFile.assetsManager;
                var assetsFileList       = assetsManager.assetsFileList;
                var assetsFileIndexCache = assetsManager.assetsFileIndexCache;

                if (index == -2)
                {
                    var m_External = assetsFile.m_Externals[m_FileID - 1];
                    var name       = m_External.fileName;
                    if (!assetsFileIndexCache.TryGetValue(name, out index))
                    {
                        if (m_External.cabId == null)
                        {
                            index = assetsFileList.FindIndex(x => x.fileName.Equals(name, StringComparison.OrdinalIgnoreCase));
                        }
                        else
                        {
                            Console.WriteLine("checking for {0}", String.Format("{0}_{1}", name, m_External.cabId.ToString()));
                            index = assetsFileList.FindIndex(
                                x => x.fileName.Equals(String.Format("{0}_{1}", name, m_External.cabId.ToString()),
                                                       StringComparison.OrdinalIgnoreCase));
                        }
                        assetsFileIndexCache.Add(name, index);
                    }
                }

                if (index >= 0)
                {
                    result = assetsFileList[index];
                    return(true);
                }
            }

            Logger.Warning(String.Format("couldn't resolve asset reference for file id {0} and path id {1}", m_FileID, m_PathID));
            return(false);
        }
Example #11
0
        private static FileType CheckFileType(EndianBinaryReader reader)
        {
            var signature = reader.ReadStringToNull(20);

            reader.Position = 0;
            switch (signature)
            {
            case "UnityWeb":
            case "UnityRaw":
            case "UnityArchive":
            case "UnityFS":
                return(FileType.BundleFile);

            case "UnityWebData1.0":
                return(FileType.WebFile);

            case "MXENGINEMXR":
            case "DIGILOCAPLY":
                return(FileType.MxrFile);

            default:
            {
                var magic = reader.ReadBytes(2);
                reader.Position = 0;
                if (WebFile.gzipMagic.SequenceEqual(magic))
                {
                    return(FileType.WebFile);
                }
                reader.Position = 0x20;
                magic           = reader.ReadBytes(6);
                reader.Position = 0;
                if (WebFile.brotliMagic.SequenceEqual(magic))
                {
                    return(FileType.WebFile);
                }
                if (SerializedFile.IsSerializedFile(reader))
                {
                    return(FileType.AssetsFile);
                }
                else
                {
                    return(FileType.ResourceFile);
                }
            }
            }
        }
Example #12
0
 public ObjectReader(EndianBinaryReader reader, SerializedFile assetsFile, ObjectInfo objectInfo) : base(reader.BaseStream, reader.endian)
 {
     this.assetsFile = assetsFile;
     m_PathID        = objectInfo.m_PathID;
     byteStart       = objectInfo.byteStart;
     byteSize        = objectInfo.byteSize;
     if (Enum.IsDefined(typeof(ClassIDType), objectInfo.classID))
     {
         type = (ClassIDType)objectInfo.classID;
     }
     else
     {
         type = ClassIDType.UnknownType;
     }
     serializedType = objectInfo.serializedType;
     platform       = assetsFile.m_TargetPlatform;
     m_Version      = assetsFile.header.m_Version;
 }
Example #13
0
        public Object(ObjectReader reader)
        {
            this.reader = reader;
            reader.Reset();
            assetsFile     = reader.assetsFile;
            type           = reader.type;
            m_PathID       = reader.m_PathID;
            version        = reader.version;
            buildType      = reader.buildType;
            platform       = reader.platform;
            serializedType = reader.serializedType;
            byteSize       = reader.byteSize;

            if (platform == BuildTarget.NoTarget)
            {
                var m_ObjectHideFlags = reader.ReadUInt32();
            }
        }
Example #14
0
 public ObjectReader(EndianBinaryReader reader, SerializedFile assetsFile, ObjectInfo objectInfo) : base(reader.BaseStream, reader.endian)
 {
     this.assetsFile = assetsFile;
     m_PathID        = objectInfo.m_PathID;
     byteStart       = objectInfo.byteStart;
     byteSize        = objectInfo.byteSize;
     if (Enum.IsDefined(typeof(ClassIDType), objectInfo.classID))
     {
         type = (ClassIDType)objectInfo.classID;
         //Logger.Info(String.Format("object type {0} ({1})", type, objectInfo.classID));
     }
     else
     {
         Logger.Error(String.Format("unknown type {0}", objectInfo.classID));
         type = ClassIDType.UnknownType;
     }
     serializedType = objectInfo.serializedType;
     platform       = assetsFile.m_TargetPlatform;
     m_Version      = assetsFile.header.m_Version;
 }
Example #15
0
        private void LoadBundleFile(string fullName, EndianBinaryReader reader, string parentPath = null)
        {
            var fileName = Path.GetFileName(fullName);

            Logger.Info("Loading " + fileName);
            try
            {
                var bundleFile = new BundleFile(reader, fullName);
                foreach (var file in bundleFile.fileList)
                {
                    var subReader = new EndianBinaryReader(file.stream);
                    if (SerializedFile.IsSerializedFile(subReader))
                    {
                        var dummyPath = Path.GetDirectoryName(fullName) + Path.DirectorySeparatorChar + file.fileName;
                        if (bundleFile.fileList.Length == 1)
                        {
                            dummyPath = fullName;
                        }
                        LoadAssetsFromMemory(dummyPath, subReader, parentPath ?? fullName, bundleFile.m_Header.unityRevision, (bundleFile.fileList.Length == 1));
                    }
                    else
                    {
                        resourceFileReaders.Add(file.fileName, subReader);
                    }
                }
            }
            catch
            {
                /*var str = $"Unable to load bundle file {fileName}";
                 * if (parentPath != null)
                 * {
                 *  str += $" from {Path.GetFileName(parentPath)}";
                 * }
                 * Logger.Error(str);*/
            }
            finally
            {
                reader.Dispose();
            }
        }
Example #16
0
        private void LoadAssetsFromMemory(string fullName, EndianBinaryReader reader, string originalPath, string unityVersion = null)
        {
            var fileName = Path.GetFileName(fullName);

            if (!assetsfileListHash.Contains(fileName.ToUpper()))
            {
                var assetsFile = new SerializedFile(this, fullName, reader);
                if (assetsFile.valid)
                {
                    assetsFile.originalPath = originalPath;
                    if (assetsFile.header.m_Version < 7)
                    {
                        assetsFile.SetVersion(unityVersion);
                    }

                    assetsFileList.Add(assetsFile);
                    assetsfileListHash.Add(assetsFile.upperFileName);
                }

                resourceFileReaders.Add(assetsFile.upperFileName, assetsFile.reader);
            }
        }
        public bool TryGetAssetsFile(out SerializedFile result)
        {
            result = null;
            if (m_FileID == 0)
            {
                result = assetsFile;
                return(true);
            }

            if (m_FileID <= 0 || m_FileID - 1 >= assetsFile.m_Externals.Count)
            {
                return(false);
            }

            var assetsManager        = assetsFile.assetsManager;
            var assetsFileList       = assetsManager.assetsFileList;
            var assetsFileIndexCache = assetsManager.assetsFileIndexCache;

            if (index == -2)
            {
                var m_External = assetsFile.m_Externals[m_FileID - 1];
                var name       = m_External.fileName;
                if (!assetsFileIndexCache.TryGetValue(name, out index))
                {
                    index = assetsFileList.FindIndex(x => x.fileName.Equals(name, StringComparison.OrdinalIgnoreCase));
                    assetsFileIndexCache.Add(name, index);
                }
            }

            if (index < 0)
            {
                return(false);
            }

            result = assetsFileList[index];
            return(true);
        }
Example #18
0
        private void LoadAssetsFromMemory(string fullName, EndianBinaryReader reader, string originalPath, string unityVersion = null)
        {
            var fileName = Path.GetFileName(fullName);

            if (!assetsFileListHash.Contains(fileName))
            {
                try
                {
                    var assetsFile = new SerializedFile(this, fullName, reader);
                    assetsFile.originalPath = originalPath;
                    if (assetsFile.header.m_Version < SerializedFileFormatVersion.kUnknown_7)
                    {
                        assetsFile.SetVersion(unityVersion);
                    }
                    assetsFileList.Add(assetsFile);
                    assetsFileListHash.Add(assetsFile.fileName);
                }
                catch (Exception e)
                {
                    Logger.Error($"Error while reading assets file {fileName} from {Path.GetFileName(originalPath)}", e);
                    resourceFileReaders.Add(fileName, reader);
                }
            }
        }
Example #19
0
        private void LoadBundleFile(string fullName, EndianBinaryReader reader, string parentPath = null)
        {
            var fileName = Path.GetFileName(fullName);

            Logger.Info("Loading " + fileName);
            try
            {
                var bundleFile = new BundleFile(reader, fullName);
                foreach (var file in bundleFile.fileList)
                {
                    var subReader = new EndianBinaryReader(file.stream);
                    if (SerializedFile.IsSerializedFile(subReader))
                    {
                        var dummyPath = Path.GetDirectoryName(fullName) + Path.DirectorySeparatorChar + file.fileName;
                        LoadAssetsFromMemory(dummyPath, subReader, parentPath ?? fullName, bundleFile.m_Header.unityRevision);
                    }
                    else
                    {
                        resourceFileReaders[file.fileName] = subReader; //TODO
                    }
                }
            }
            catch (Exception e)
            {
                var str = $"Error while reading bundle file {fileName}";
                if (parentPath != null)
                {
                    str += $" from {Path.GetFileName(parentPath)}";
                }
                Logger.Error(str, e);
            }
            finally
            {
                reader.Dispose();
            }
        }
Example #20
0
        private int index = -2; //-2 - Prepare, -1 - Missing

        public PPtr(ObjectReader reader)
        {
            m_FileID   = reader.ReadInt32();
            m_PathID   = reader.m_Version < 14 ? reader.ReadInt32() : reader.ReadInt64();
            assetsFile = reader.assetsFile;
        }
Example #21
0
        private int index = -2; //-2 - Prepare, -1 - Missing

        public PPtr(ObjectReader reader)
        {
            m_FileID   = reader.ReadInt32();
            m_PathID   = reader.m_Version < SerializedFileFormatVersion.Unknown_14 ? reader.ReadInt32() : reader.ReadInt64();
            assetsFile = reader.assetsFile;
        }