Exemple #1
0
        public byte[] ExtractResource(TAHEntry entry)
        {
            //data読み込み長さ
            //-4はdata書き出し長さ格納領域 (UInt32) を減じている
            UInt32 input_length = entry.length - 4;

            //data読み込みバッファ
            byte[] data_input = new byte[input_length];
            UInt32 output_length;

            reader.BaseStream.Position = entry.offset;

            //data書き出し長さ
            output_length = reader.ReadUInt32();
            data_input    = reader.ReadBytes((int)input_length);
            //-- data読み込み(復号前)完了! --

            //data書き出しバッファ
            byte[] data_output = new byte[output_length];

            TAHCryption.crypt(ref data_input, input_length, output_length);
            Decompression.infrate(ref data_input, input_length, ref data_output, output_length);
            //-- data復号完了! --

            return(data_output);
        }
Exemple #2
0
        // modified:
        // (c)2002 Jonathan Bennett ([email protected])

        /*LZSS compressor*/
        public static void encrypt(ref byte[] data_input, UInt32 input_length, ref byte[] data_output, ref UInt32 output_length)
        {
            // Set up initial values
            UInt32 m_nDataStreamPos       = 0;                  // We are at the start of the input data
            UInt32 m_nCompressedStreamPos = 0;                  // We are at the start of the compressed data

            HS_LZSS_OUTPUT_BUFFER     = 0;
            HS_LZSS_OUTPUT_BUFFER_POS = 0;
            data_output = new byte[1024 * 1024]; //1MB buffer

            // If the input file is too small then there is a chance of
            // buffer overrun, so just abort
            if (input_length < 32)
            {
                data_output = data_input;
                return;
            }

            // Initialize our hash table
            HashTableInit();

            //
            // Jump to our main compression function
            //

            deflate_loop(ref data_input, input_length, ref data_output, ref output_length, ref m_nDataStreamPos, ref m_nCompressedStreamPos);

            TAHCryption.crypt(ref data_output, output_length, input_length);
        }
Exemple #3
0
        /* TAH Procedures*/

        public void extract_TAH_directory()
        {
            Entries = null;

            UInt32 arc_size = (UInt32)reader.BaseStream.Length;

            byte[] magic = reader.ReadBytes(4);

            if (magic[0] != (byte)'T' || magic[1] != (byte)'A' || magic[2] != (byte)'H' || magic[3] != (byte)'2')
            {
                throw new Exception("File is not TAH");
            }

            Header tah_header;

            tah_header.index_entry_count = reader.ReadUInt32();
            tah_header.version           = reader.ReadUInt32();
            tah_header.reserved          = reader.ReadUInt32();

            UInt32 index_buffer_size = tah_header.index_entry_count * 8; //sizeof(index_entry) == 8

            Entries = new TAHEntry[tah_header.index_entry_count];

            for (int i = 0; i < tah_header.index_entry_count; i++)
            {
                Entries[i] = new TAHEntry();

                Entries[i].hash_code = reader.ReadUInt32();
                Entries[i].offset    = reader.ReadUInt32();
            }

            UInt32 output_length = reader.ReadUInt32();

            //entry情報の読み出し長さ
            UInt32 input_length = Entries[0].offset - /*sizeof(Header)*/ 16 - index_buffer_size;

            //entry情報の読み出しバッファ
            byte[] data_input = new byte[input_length];

            data_input = reader.ReadBytes((int)input_length);
            //-- entry情報の読み込み完了! --

            byte[] output_data = new byte[output_length];

            TAHCryption.crypt(ref data_input, input_length, output_length);
            Decompression.infrate(ref data_input, input_length, ref output_data, output_length);
            //-- entry情報の復号完了! --

            build_TAHEntries(output_data, arc_size);
        }
Exemple #4
0
        public static void decrypt(ref byte[] data_input, UInt32 input_length, ref byte[] data_output, UInt32 output_length)
        {
            TAHCryption.crypt(ref data_input, input_length, output_length);

            infrate(ref data_input, input_length, ref data_output, output_length);
        }