Ejemplo n.º 1
0
    private NadeoPak(byte[] key)
    {
        Key     = key;
        Folders = new List <NadeoPakFolder>();
        Files   = new List <NadeoPakFile>();
        Stream  = null !;

        blowfish = null !;
        files    = null !;
    }
Ejemplo n.º 2
0
    public byte[]? GetData()
    {
        if (data is not null)
        {
            return(data);
        }

        owner.Stream.Position = owner.DataStart + Offset;

        var roundedDataSize = 8 + CompressedSize;

        if ((roundedDataSize & 7) != 0)
        {
            roundedDataSize = (roundedDataSize & ~7) + 8;
        }

        var buffer = new byte[roundedDataSize];

        owner.Stream.Read(buffer, 0, buffer.Length);

        using var ms = new MemoryStream(buffer);
        using var r  = new GameBoxReader(ms);

        var iv = r.ReadUInt64();

        using var blowfish = new BlowfishCBCStream(ms, owner.Key, iv);

        if (IsCompressed)
        {
            using var deflate = new CompressedStream(blowfish, CompressionMode.Decompress);
            using var rr      = new GameBoxReader(deflate);

            try
            {
                data = rr.ReadBytes(UncompressedSize); // CopyTo nefunguje xd
            }
            catch (InvalidDataException)
            {
            }
        }
        else
        {
            using var rr = new GameBoxReader(blowfish);
            data         = rr.ReadBytes(UncompressedSize); // CopyTo nefunguje xd
        }

        return(data);
    }
Ejemplo n.º 3
0
    private void Read(GameBoxReader r)
    {
        if (!r.HasMagic("NadeoPak"))
        {
            throw new Exception("Not a pak file.");
        }

        Version = r.ReadInt32();
        var headerIV = r.ReadUInt64();

        using (blowfish = new BlowfishCBCStream(r.BaseStream, Key, headerIV))
            using (var rr = new GameBoxReader(blowfish))
            {
                ReadEncrypted(rr);
            }
    }
Ejemplo n.º 4
0
    private void ReadMetadata()
    {
        Stream.Position = MetadataStart;

        using var reader = new GameBoxReader(Stream);
        var iv = reader.ReadUInt64();

        using (blowfish = new BlowfishCBCStream(Stream, Key, iv))
            using (var deflate = new CompressedStream(blowfish, CompressionMode.Decompress))
                using (var r = new GameBoxReader(deflate))
                {
                    int fileIndex;

                    do
                    {
                        fileIndex = r.ReadInt32();
                        var header = new GameBoxHeaderInfo(r);
                    }while (fileIndex != -1);
                }
    }