public override void ElaborateCheck(Stream stream)
        {
            if (stream.Length > 10 * 1024 * 1024)
            {
                IsCandidate = false;
            }
            if (!IsCandidate)
            {
                return;
            }

            var sr   = new StreamReader(stream, Encoding.UTF8, true, 2048);
            var line = ReadLines(sr, 1024).FirstOrDefault() ?? "";

            IsCandidate = line.Contains("VobSub index file, v");

            if (IsCandidate)
            {
                stream.Position = 0;
                sr.DiscardBufferedData();
                try {
                    idx = new IDX(sr.ReadToEnd());
                } catch { }
            }
        }
Exemple #2
0
        /// <summary>
        /// Trys to find the fitting file type for the given file with the file signature.
        /// </summary>
        public static Type GetFileTypeFromSignature(Stream stream)
        {
            byte[] buffer = new byte[8];
            stream.Read(buffer, 0, buffer.Length);

            //Archives
            if (AFS.IsValid(buffer))
            {
                return(typeof(AFS));
            }
            if (GZ.IsValid(buffer))
            {
                return(typeof(GZ));
            }
            if (IDX.IsValid(buffer))
            {
                return(typeof(IDX));
            }
            if (IPAC.IsValid(buffer))
            {
                return(typeof(IPAC));
            }
            if (PKF.IsValid(buffer))
            {
                return(typeof(PKF));
            }
            if (PKS.IsValid(buffer))
            {
                return(typeof(PKS));
            }
            //if (SPR.IsValid(buffer)) return typeof(SPR); //same as TEXN skip and base identification on extension
            if (TAD.IsValid(buffer))
            {
                return(typeof(TAD));
            }

            //Textures/Images
            if (TEXN.IsValid(buffer))
            {
                return(typeof(TEXN));
            }
            if (PVRT.IsValid(buffer))
            {
                return(typeof(PVRT));
            }
            if (DDS.IsValid(buffer))
            {
                return(typeof(DDS));
            }

            //Models
            if (MT5.IsValid(buffer))
            {
                return(typeof(MT5));
            }
            if (MT7.IsValid(buffer))
            {
                return(typeof(MT7));
            }

            //Subtitles
            if (SUB.IsValid(buffer))
            {
                return(typeof(SUB));
            }

            return(null);
        }
Exemple #3
0
        public static string GetExtensionFromBuffer(byte[] buffer)
        {
            //Archives
            if (AFS.IsValid(buffer))
            {
                return("AFS");
            }
            if (GZ.IsValid(buffer))
            {
                return("GZ");
            }
            if (IDX.IsValid(buffer))
            {
                return("IDX");
            }
            if (IPAC.IsValid(buffer))
            {
                return("IPAC");
            }
            if (PKF.IsValid(buffer))
            {
                return("PKF");
            }
            if (PKS.IsValid(buffer))
            {
                return("PKS");
            }
            //if (SPR.IsValid(buffer)) return typeof(SPR); //same as TEXN skip and base identification on extension
            if (TAD.IsValid(buffer))
            {
                return("TAD");
            }

            //Textures/Images
            if (TEXN.IsValid(buffer))
            {
                return("TEXN");
            }
            if (PVRT.IsValid(buffer))
            {
                return("PVRT");
            }
            if (DDS.IsValid(buffer))
            {
                return("DDS");
            }

            //Models
            if (MT5.IsValid(buffer))
            {
                return("MT5");
            }
            if (MT7.IsValid(buffer))
            {
                return("MT7");
            }

            //Subtitles
            if (SUB.IsValid(buffer))
            {
                return("SUB");
            }

            return("UNKNOWN");
        }
Exemple #4
0
        private static void Main(string[] args)
        {
            Console.WriteLine("OpenKH Core / Debug Console");
            Console.WriteLine("Early Version by GovanifY");
            Console.Write("Please enter the name of the game you want to load(KH2 or KH1):");
            string game = Console.ReadLine();

            Console.Write("Please enter the name of the iso you want to load:");
            string isoname = Console.ReadLine();

            Console.Write("Please enter the name of the file you want to load:");
            string inputname = @Console.ReadLine();

            if (game == "KH2")
            {
                Console.Write("Trying to load the iso...");
                FileStream isoStream = File.Open(isoname, FileMode.Open, FileAccess.Read, FileShare.Read);
                var        iso       = new ISOFileReader(isoStream);
                Console.WriteLine("Done!");
                Console.Write("Searching the IDX and IMG files...");
                Stream dumb         = new FileStream(@"libKh.dll", FileMode.Open, FileAccess.Read);
                var    IDXStream    = new Substream(dumb); //Anti CS0165
                var    IMGStream    = new Substream(dumb); //Anti CS0165
                var    OVLIMGStream = new Substream(dumb); //Anti CS0165
                var    OVLIDXStream = new Substream(dumb); //Anti CS0165
                foreach (FileDescriptor file in iso)
                {
                    string file2 = file.FullName;
                    if (file2.EndsWith("OVL.IDX"))
                    {
                        OVLIDXStream = iso.GetFileStream(file);
                    }
                    if (file2.EndsWith("OVL.IMG"))
                    {
                        OVLIMGStream = iso.GetFileStream(file);
                    }
                    if (file2.EndsWith("KH2.IDX"))
                    {
                        IDXStream = iso.GetFileStream(file);
                    }
                    if (file2.EndsWith("KH2.IMG"))
                    {
                        IMGStream = iso.GetFileStream(file);
                    }
                }
                if (IDXStream == IMGStream)
                {
                    throw new Exception("IDX or IMG Stream isn't loaded correctly!");
                }
                Console.WriteLine("Done!");
                var LIBKHIDX = new IDX(IDXStream, IMGStream); // TODO add a f*****g support for the OVL!
                Console.Write("Opening the internal file...");
                Stream internalfile = LIBKHIDX.OpenFile(inputname);
                Console.WriteLine("Done!");
                Console.Write("Extracting the file...");
                string inputname2 = Path.GetFullPath("output/" + inputname);
                Directory.CreateDirectory(Path.GetDirectoryName(inputname2));
                var output = new FileStream(inputname2, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
                internalfile.CopyTo(output);
                Console.WriteLine("Done!");
                var br = new BinaryReader(output);
                if (br.ReadUInt32() != 0x01524142)
                {
                    Console.WriteLine("Not a BAR file, continue anyway");
                }
                else
                {
                    Console.WriteLine("BAR file detected! Unbarring him...");
                    var msgSys = new BAR(internalfile);
                }
                Console.Read();
            }
            else
            {
                throw new Exception("NOT IMPLEMENTED");
            }
        }