Exemple #1
0
 public bool Identify(System.IO.Stream stream)
 {
     using (var reader = new Switch_Toolbox.Library.IO.FileReader(stream, true))
     {
         return(reader.CheckSignature(4, "WEST"));
     }
 }
Exemple #2
0
 public bool Identify(System.IO.Stream stream)
 {
     using (var reader = new Switch_Toolbox.Library.IO.FileReader(stream, true))
     {
         return(reader.CheckSignature(4, "FLIM", reader.BaseStream.Length - 0x28));
     }
 }
Exemple #3
0
 public bool Identify(System.IO.Stream stream)
 {
     using (var reader = new Switch_Toolbox.Library.IO.FileReader(stream, true))
     {
         return(reader.ReadInt32() == MagicFileConstant);
     }
 }
 public bool Identify(System.IO.Stream stream)
 {
     using (var reader = new Switch_Toolbox.Library.IO.FileReader(stream, true))
     {
         return Utils.GetExtension(FileName) == ".lzarc";
     }
 }
 public bool Identify(System.IO.Stream stream)
 {
     using (var reader = new Switch_Toolbox.Library.IO.FileReader(stream, true))
     {
         reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
         return(reader.ReadUInt32() == 0x02020000);
     }
 }
Exemple #6
0
 public bool Identify(System.IO.Stream stream)
 {
     using (var reader = new Switch_Toolbox.Library.IO.FileReader(stream, true))
     {
         bool IsMatch = reader.ReadUInt32() == 0xD6D1820C;
         reader.Position = 0;
         return(IsMatch || Utils.HasExtension(FileName, ".sp2"));
     }
 }
Exemple #7
0
 public bool Identify(System.IO.Stream stream)
 {
     using (var reader = new Switch_Toolbox.Library.IO.FileReader(stream, true))
     {
         if (reader.CheckSignature(4, "EFCF") ||
             reader.CheckSignature(4, "EFCC"))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemple #8
0
        public bool Identify(System.IO.Stream stream)
        {
            using (var reader = new Switch_Toolbox.Library.IO.FileReader(stream, true))
            {
                //File too small to have any data
                if (stream.Length <= 16)
                {
                    return(false);
                }

                if (reader.CheckSignature(2, "BY") || reader.CheckSignature(2, "YB"))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Gets the <see cref="IFileFormat"/> from a file or byte array.
        /// </summary>
        /// <param name="FileName">The name of the file</param>
        /// <param name="data">The byte array of the data</param>
        /// <param name="InArchive">If the file is in an archive so it can be saved back</param>
        /// <param name="archiveNode">The node being replaced from an archive</param>
        /// <param name="Compressed">If the file is being compressed or not</param>
        /// <param name="CompType">The type of <see cref="CompressionType"/> being used</param>
        /// <returns></returns>
        public static IFileFormat OpenFileFormat(string FileName, byte[] data = null, bool LeaveStreamOpen = false, bool InArchive      = false,
                                                 TreeNode archiveNode         = null, bool Compressed = false, CompressionType CompType = 0)
        {
            FileReader fileReader;

            if (data != null)
            {
                fileReader = new FileReader(data);
            }
            else
            {
                fileReader = new FileReader(FileName);
            }

            if (fileReader.BaseStream.Length <= 4)
            {
                fileReader.Close();
                fileReader.Dispose();
                return(null);
            }

            Cursor.Current       = Cursors.WaitCursor;
            fileReader.ByteOrder = ByteOrder.BigEndian;
            uint MagicHex = fileReader.ReadUInt32();

            string Magic = fileReader.ReadMagic(0, 4);

            fileReader.Position = 0;

            if (Magic == "Yaz0")
            {
                if (data != null)
                {
                    data = EveryFileExplorer.YAZ0.Decompress(data);
                }
                else
                {
                    data = EveryFileExplorer.YAZ0.Decompress(FileName);
                }

                return(OpenFileFormat(FileName, data, LeaveStreamOpen, InArchive, archiveNode, true, CompressionType.Yaz0));
            }
            if (Magic == "ZLIB")
            {
                if (data == null)
                {
                    data = File.ReadAllBytes(FileName);
                }

                data = STLibraryCompression.GZIP.Decompress(fileReader.getSection(64, data.Length - 64));
                return(OpenFileFormat(FileName, data, LeaveStreamOpen, InArchive, archiveNode, true, CompressionType.Zlib));
            }
            if (MagicHex == 0x1f8b0808 && CompType == CompressionType.None)
            {
                if (data == null)
                {
                    data = File.ReadAllBytes(FileName);
                }

                data = STLibraryCompression.GZIP.Decompress(data);
                return(OpenFileFormat(FileName, data, LeaveStreamOpen, InArchive, archiveNode, true, CompressionType.Gzip));
            }
            if (Path.GetExtension(FileName) == ".lz" && CompType == CompressionType.None)
            {
                if (data == null)
                {
                    data = File.ReadAllBytes(FileName);
                }

                data = STLibraryCompression.LZ77.Decompress(fileReader.getSection(16, data.Length - 16));
                return(OpenFileFormat(FileName, data, LeaveStreamOpen, InArchive, archiveNode, true, CompressionType.Zlib));
            }
            if (Path.GetExtension(FileName) == ".cmp" && CompType == CompressionType.None)
            {
                if (data == null)
                {
                    data = File.ReadAllBytes(FileName);
                }

                fileReader.Position = 0;
                int OuSize = fileReader.ReadInt32();
                int InSize = data.Length - 4;
                data = STLibraryCompression.Type_LZ4F.Decompress(fileReader.getSection(4, InSize));

                return(OpenFileFormat(FileName, data, InArchive, LeaveStreamOpen, archiveNode, true, CompressionType.Lz4f));
            }

            fileReader.Dispose();
            fileReader.Close();

            Stream stream;

            if (data != null)
            {
                stream = new MemoryStream(data);
            }
            else
            {
                stream = File.OpenRead(FileName);
            }

            foreach (IFileFormat fileFormat in FileManager.GetFileFormats())
            {
                //Set the file name so we can check it's extension in the identifier.
                //Most is by magic but some can be extension or name.

                fileFormat.FileName  = Path.GetFileName(FileName);
                fileFormat.IFileInfo = new IFileInfo();

                if (fileFormat.Identify(stream))
                {
                    return(SetFileFormat(fileFormat, FileName, stream, LeaveStreamOpen, InArchive, archiveNode, Compressed, CompType));
                }
            }

            return(null);
        }