Exemple #1
0
        public override void Convert(BlowfishNET.BlowfishECB ECB, AlgorithmType newalgorithm)
        {
            ecb          = ECB;
            oldalgorithm = algorithm;
            algorithm    = newalgorithm;

            if (compressedmem == null)
            {
                LoadAndCompress();
            }

            if (oldalgorithm == algorithm || compressedsize < BlowfishNET.BlowfishECB.BLOCK_SIZE)
            {
                return;
            }

            int encryptlen = (int)compressedsize;

            if (encryptlen % BlowfishNET.BlowfishECB.BLOCK_SIZE != 0)
            {
                encryptlen -= encryptlen % BlowfishNET.BlowfishECB.BLOCK_SIZE;
            }

            byte [] tmp = (byte [])compressedmem.GetBuffer().Clone();

            if (algorithm == AlgorithmType.infilateandblowfish)
            {
                ecb.Encrypt(tmp, 0, compressedmem.GetBuffer(), 0, encryptlen);
            }
            else
            {
                ecb.Decrypt(tmp, 0, compressedmem.GetBuffer(), 0, encryptlen);
            }
            adler32 = AdlerCheckSum.GetAdler32(compressedmem, 0, (int)compressedmem.Length);
        }
Exemple #2
0
        public override void Convert(BlowfishNET.BlowfishECB ECB, AlgorithmType newalgorithm)
        {
            ecb       = ECB;
            algorithm = newalgorithm;

            if (oldalgorithm == algorithm || compressedsize < BlowfishNET.BlowfishECB.BLOCK_SIZE)
            {
                compressedmem = null;
                return;
            }

            int encryptlen = (int)compressedsize;

            compressedmem = new System.IO.MemoryStream();
            System.IO.FileStream filestream = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            filestream.Position = offset;
            byte[] data = new byte[encryptlen];
            filestream.Read(data, 0, encryptlen);
            byte[] tmp = (byte[])data.Clone();

            if (encryptlen % BlowfishNET.BlowfishECB.BLOCK_SIZE != 0)
            {
                encryptlen -= encryptlen % BlowfishNET.BlowfishECB.BLOCK_SIZE;
            }

            if (algorithm == AlgorithmType.infilateandblowfish)
            {
                ecb.Encrypt(tmp, 0, data, 0, encryptlen);
            }
            else
            {
                ecb.Decrypt(tmp, 0, data, 0, encryptlen);
            }
            compressedmem.Write(data, 0, (int)compressedsize);
            adler32 = AdlerCheckSum.GetAdler32(compressedmem, 0, (int)compressedmem.Length);
            filestream.Close();
        }
Exemple #3
0
        public bool Open(string filename)
        {
            System.IO.FileStream   stream = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);
            bool re = true;

            try
            {
                byte[] magicbyte = reader.ReadBytes(52);

                string magicstring = System.Text.ASCIIEncoding.ASCII.GetString(magicbyte).Trim('\0');

                uint size       = reader.ReadUInt32();
                bool compressed = true;
                if (reader.ReadUInt32() == 0)
                {
                    compressed = false;
                }

                switch (magicstring)
                {
                case "KOG GC TEAM MASSFILE V.0.3.":

                    komtype = EKomType.newkom;

                    filetime    = reader.ReadUInt32();
                    adler32     = reader.ReadUInt32();
                    header_size = reader.ReadUInt32();

                    System.Xml.XmlDocument headerxml = new System.Xml.XmlDocument();

                    byte[] header_raw = reader.ReadBytes((int)header_size);

                    if (header_raw[0] != '<' ||
                        header_raw[1] != '?' ||
                        header_raw[2] != 'x' ||
                        header_raw[3] != 'm' ||
                        header_raw[4] != 'l')
                    {
                        if (ecb == null)
                        {
                            throw new EncryptedKomException();
                        }

                        byte[] data = (byte[])header_raw.Clone();
                        ecb.Decrypt(data, 0, header_raw, 0, (int)header_size);
                        komtype = EKomType.encrypt;
                    }
                    string xmlstring = System.Text.ASCIIEncoding.ASCII.GetString(header_raw);
                    headerxml.LoadXml(xmlstring);
                    System.Xml.XmlNodeList files = headerxml.SelectNodes("Files/File");

                    UInt32 offset = OffsetStart + header_size;

                    foreach (System.Xml.XmlElement file in files)
                    {
                        string      key     = file.GetAttribute("Name");
                        Kom2SubFile subfile = Kom2SubFile.ReadSubFileFromKom(ecb, filename, file, offset);
                        offset += subfile.CompressedSize;
                        subfiles.Add(key, subfile);
                    }
                    break;

                case "KOG GC TEAM MASSFILE V.0.1.":
                case "KOG GC TEAM MASSFILE V.0.2.":

                    komtype = EKomType.oldkom;
                    for (int i = 0; i < size; i++)
                    {
                        string      key     = System.Text.ASCIIEncoding.ASCII.GetString(reader.ReadBytes(60)).Trim('\0');
                        Kom2SubFile subfile = Kom2SubFile.ReadSubFileFromOldKom(filename, reader, 60 + size * 72);
                        if (key != "crc.xml")
                        {
                            subfiles.Add(key, subfile);
                        }
                    }
                    break;

                default:
                    re = false;
                    break;
                }
            }
            catch (System.Exception ex)
            {
                komtype = EKomType.notkom;
                re      = false;
            }

            stream.Close();
            return(re);
        }