Exemple #1
0
        public static void DumpTAHEntries(Stream source)
        {
            TAHFile tah = new TAHFile(source);

            try
            {
                tah.LoadEntries();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex);
                return;
            }
            foreach (TAHEntry ent in tah.EntrySet.Entries)
            {
                if (ent.FileName != null && Path.GetExtension(ent.FileName).ToLower() == ".tso")
                {
                    byte[]        data = TAHUtil.ReadEntryData(tah.Reader, ent);
                    byte[]        hash = md5.ComputeHash(data);
                    StringBuilder sb   = new StringBuilder();
                    foreach (byte b in hash)
                    {
                        sb.Append(b.ToString("x2"));
                    }
                    string md5sum = sb.ToString();
                    Console.WriteLine("{0} {1}", md5sum, ent.FileName);
                }
            }
        }
Exemple #2
0
        public static void ReadExternalFileList()
        {
            external_files = new ext_file_list();

            if (System.IO.File.Exists("names.txt"))
            {
                System.IO.StreamReader reader      = new System.IO.StreamReader(System.IO.File.OpenRead("names.txt"));
                List <string>          known_files = new List <string>();
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    known_files.Add(line);
                }
                //map a list of hash keys to the file...
                external_files.files = known_files.ToArray();
                if (external_files.files != null)
                {
                    external_files.hashkeys = new UInt32[external_files.files.Length];
                    for (int i = 0; i < external_files.files.Length; i++)
                    {
                        external_files.hashkeys[i] = TAHUtil.CalcHash(external_files.files[i]);
                        //Console.WriteLine(external_files.hashkeys[i].ToString("X8") + "\t" + external_files.files[i]);
                    }
                }
                //sorting for faster look up...
                Array.Sort(external_files.hashkeys, external_files.files);
            }
        }
Exemple #3
0
        public void DumpTAHEntries(Stream source)
        {
            TAHFile tah = new TAHFile(source);

            try
            {
                tah.LoadEntries();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex);
                return;
            }
            foreach (TAHEntry ent in tah.EntrySet.Entries)
            {
                if (Path.GetExtension(ent.FileName) == ".tso")
                {
                    Console.WriteLine(ent.FileName);
                    byte[] data = TAHUtil.ReadEntryData(tah.Reader, ent);
                    using (MemoryStream ms = new MemoryStream(data))
                        LoadTSOFile(ms);
                    current_TSOFileName = ent.FileName;
                    AssignCurrentTMOFile(current_TSOFileName);
                    {
                        FrameMove();
                        Render();
                        SaveToBitmap();
                        ClearFigureList();
                        Application.DoEvents();
                    }
                    current_TSOFileName = null;
                }
            }
        }
Exemple #4
0
        public static byte[] ReadEntryData(BinaryReader br, TAHEntry e)
        {
            br.BaseStream.Seek(e.DataOffset, SeekOrigin.Begin);
            byte[] output = new byte[br.ReadInt32()];
            byte[] input  = br.ReadBytes(e.Length - 4);

            TAHUtil.Decrypt(input, output);

            return(output);
        }
Exemple #5
0
        public static byte[] Decrypt(byte[] input, byte[] output)
        {
            //debug   = true;

            try {
#if DECRYPT_DEBUG
                byte[] output2 = new byte[output.Length];

                if (debug)
                {
                    TAHUtil.DecryptOld(input.Clone() as byte[], output2);
                }
#endif
                DoDecrypt(input, output);
#if DECRYPT_DEBUG
                if (debug)
                {
                    for (int i = 0; i < output.Length; ++i)
                    {
                        System.Diagnostics.Debug.Assert(output2[i] == output[i]);
                    }
                }
#endif
#if ENCRYPT_DEBUG
                byte[] encrypted  = DoEncrypt(output);
                byte[] encrypted2 = new byte[output.Length];
                uint   length     = (uint)encrypted2.Length;
                //TAHdecrypt.Decrypter.encrypt(ref output, (uint)output.Length, ref encrypted2, ref length);
                byte[] decrypted = new byte[output.Length];
                DoDecrypt(encrypted, decrypted);
                if (debug)
                {
                    for (int i = 0; i < output.Length; ++i)
                    {
                        System.Diagnostics.Debug.Assert(decrypted[i] == output[i]);
                    }
                }
#endif
                return(output);
            }
            catch (Exception e) {
                DbgPrint(e.ToString());
                throw;
            }
        }
Exemple #6
0
        public void Write(BinaryWriter bw)
        {
            MemoryStream ms  = new MemoryStream();
            BinaryWriter bw2 = new BinaryWriter(ms);

            foreach (string i in Files)
            {
                if (i.EndsWith("/"))
                {
                    TAHUtil.WriteString(bw2, i);
                }
                else
                {
                    TAHUtil.WriteString(bw2, Path.GetFileName(i));
                }
            }

            bw2.Flush();
            byte[] encrypted = TAHUtil.Encrypt(ms.ToArray());

            bw.Write((uint)ms.Length);
            bw.Write(encrypted);
        }
Exemple #7
0
 public TAHContent LoadContent(BinaryReader br, TAHEntry e)
 {
     return(new TAHContent(e, TAHUtil.ReadEntryData(br, e)));
 }
Exemple #8
0
        public void Read(BinaryReader br, TAHFile file)
        {
            // ディレクトリデータの読み込み
            Files = new List <string>(file.Header.NumEntries);
            int output_length = br.ReadInt32();
            int input_length  = (int)(file.EntrySet[0].DataOffset - br.BaseStream.Position);             //- 16 - 8 * file.Header.NumEntries;

            byte[] input  = br.ReadBytes(input_length);
            byte[] output = new byte[output_length];

            if (output.Length == 0)
            {
                return;
            }

            TAHUtil.Decrypt(input, output);
            //TAHdecrypt.Decrypter.decrypt(ref input, (uint)input.Length, ref output, (uint)output.Length);

            MemoryStream ms  = new MemoryStream(output);
            BinaryReader br2 = new BinaryReader(ms);

            try {
                string dir = "";

                while (ms.Position < ms.Length)
                {
                    string name = TAHUtil.ReadString(br2);

                    if (name.Length == 0)
                    {
                    }
                    else
                    if (name.EndsWith("/"))
                    {
                        dir = name;
                        //DbgPrint("Directory:            " + dir);
                    }
                    else
                    {
                        name = dir + name;
                        uint     hash = TAHUtil.CalcHash(name);
                        TAHEntry ent;

                        //DbgPrint(hash.ToString("X").PadLeft(8, '0'));

                        if (file.EntrySet.TryGetValue(hash, out ent))
                        {
                            ent.FileName = name;
                            //DbgPrint(": Found:     " + file);
                        }
                        else
                        {
                            //DbgPrint(": Not Found: " + file);
                            System.Diagnostics.Debug.Assert(false);
                        }

                        //EntryMap[hash].FileName = FileName;
                    }

                    Files.Add(name);
                }
            }
            catch (EndOfStreamException) {
            }
        }