예제 #1
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);
            }
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
0
 public TAHContent LoadContent(BinaryReader br, TAHEntry e)
 {
     return(new TAHContent(e, TAHUtil.ReadEntryData(br, e)));
 }
예제 #5
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;
            }

            // add konoa:tahdecryptorのバグ回避.
            if (input.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)
            {
            }
        }