Beispiel #1
0
        public void Dispose()
        {
            var directory = new GGHash(new Dictionary <string, GGValue> {
                { "files", _gFiles }
            });

            byte[] directoryData;
            var    dirOffset = (int)_bw.BaseStream.Position;

            using (var ms = new MemoryStream())
            {
                using (var gbw = new GGBinaryWriter(new BinaryWriter(ms)))
                {
                    directory.WriteTo(gbw);
                }
                directoryData = ms.ToArray();
                GGBinaryReader.EncodeUnbreakableXor(directoryData);
            }
            _bw.Write(directoryData);
            var size = directoryData.Length;

            _bw.BaseStream.Position = 0;
            _bw.Write(dirOffset);
            _bw.Write(size);
        }
Beispiel #2
0
        public GGPackWriter WriteFile(string path)
        {
            var filename = Path.GetFileName(path);

            using (var fs = File.OpenRead(path))
            {
                if (string.Equals(Path.GetExtension(filename), ".nut", StringComparison.OrdinalIgnoreCase))
                {
                    filename = Path.ChangeExtension(filename, ".bnut");
                }
                var hash = new GGHash
                {
                    { "filename", new GGLiteral(filename) },
                    { "offset", new GGLiteral(_offset) },
                    { "size", new GGLiteral((int)fs.Length) },
                };
                _gFiles.Add(hash);
                _offset += (int)fs.Length;
            }

            var data = File.ReadAllBytes(path);

            if (string.Equals(Path.GetExtension(filename), ".nut", StringComparison.OrdinalIgnoreCase))
            {
                GGPack.DecryptBnut(data);
            }
            else if (string.Equals(Path.GetExtension(filename), ".wimpy", StringComparison.OrdinalIgnoreCase))
            {
                GGHash hash;
                using (var ms = new MemoryStream(data))
                {
                    var parser = new GGParser(ms);
                    hash = parser.ParseHash();
                }
                using (var ms = new MemoryStream())
                {
                    using (var writer = new GGBinaryWriter(new BinaryWriter(ms)))
                    {
                        hash.WriteTo(writer);
                    }
                    data = ms.ToArray();
                }
            }
            GGBinaryReader.EncodeUnbreakableXor(data);
            _bw.Write(data);

            return(this);
        }
Beispiel #3
0
        public Stream GetEntryStream(string name)
        {
            var entry = Entries.First(o => Equals(o.Name, name));

            _stream.Position = entry.Offset;
            var buf = new byte[entry.Size];

            _stream.Read(buf, 0, entry.Size);
            GGBinaryReader.DecodeUnbreakableXor(buf);
            var extension = Path.GetExtension(name);

            if (string.Equals(extension, ".bnut", System.StringComparison.OrdinalIgnoreCase))
            {
                DecryptBnut(buf);
            }
            return(new MemoryStream(buf));
        }