public void Close() { adler32 = 0; header_size = 0; filetime = 0; foreach (System.Collections.Generic.KeyValuePair <string, Kom2SubFile> KeyValue in subfiles) { KeyValue.Value.Close(); } subfiles.Clear(); ecb = null; komtype = EKomType.notkom; }
static public EKomType IsKom(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); byte[] magicbyte = reader.ReadBytes(52); string magicstring = System.Text.ASCIIEncoding.ASCII.GetString(magicbyte).Trim('\0'); EKomType re = EKomType.notkom; uint size = reader.ReadUInt32(); bool compressed = true; if (reader.ReadUInt32() == 0) { compressed = false; } if (magicstring == "KOG GC TEAM MASSFILE V.0.3.") { reader.ReadUInt32(); reader.ReadUInt32(); UInt32 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') { re = EKomType.encrypt; } else { re = EKomType.newkom; } } else if (magicstring == "KOG GC TEAM MASSFILE V.0.2." || magicstring == "KOG GC TEAM MASSFILE V.0.1.") { re = EKomType.oldkom; } stream.Close(); return(re); }
public bool Encrypt() { if (ecb == null) { return(false); } foreach (System.Collections.Generic.KeyValuePair <string, Kom2SubFile> KeyValue in subfiles) { if ((Kom2SubFile.AlgorithmType)KeyValue.Value.Algorithm == Kom2SubFile.AlgorithmType.infilate) // 인크립트 되있으면 풀자 { KeyValue.Value.Convert(ecb, Kom2SubFile.AlgorithmType.infilateandblowfish); } } komtype = EKomType.encrypt; return(true); }
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); }