コード例 #1
0
        private static Command ReadCommand(BinaryReader s)
        {
            // the first byte indicates which kind and format it is
            var commandFormat = GetCommandFormat(s.ReadByte());

            // then we might have to read the parameters in
            Command result = new Command();

            result.Kind = commandFormat.Kind;
            if (commandFormat.Length1 > 0)
            {
                result.Parameter1 = StreamHelpers.ConvertFromBigEndian(s.ReadBytes(commandFormat.Length1));
            }
            else
            {
                // some of the commands encode the parameter directly into the command byte
                result.Parameter1 = commandFormat.ImmediateValue;
            }

            if (commandFormat.Length2 > 0)
            {
                result.Parameter2 = StreamHelpers.ConvertFromBigEndian(s.ReadBytes(commandFormat.Length2));
            }

            return(result);
        }
コード例 #2
0
        public static SignatureFile ParseSignatureFile(Stream s)
        {
            var  result      = new SignatureFile();
            var  r           = new BinaryReader(s);
            uint magicNumber = StreamHelpers.ReadBigEndianUint32(r);

            if (magicNumber == (uint)MagicNumber.Blake2Signature)
            {
                result.StrongSumMethod = CalculateBlake2StrongSum;
            }
            else
            {
                throw new InvalidDataException(string.Format("Unknown magic number {0}", magicNumber));
            }

            result.BlockLength     = (int)StreamHelpers.ReadBigEndianUint32(r);
            result.StrongSumLength = (int)StreamHelpers.ReadBigEndianUint32(r);

            var   signatures = new List <BlockSignature>();
            ulong i          = 0;

            while (true)
            {
                byte[] weakSumBytes = r.ReadBytes(4);
                if (weakSumBytes.Length == 0)
                {
                    // we're at the end of the file
                    break;
                }

                int    weakSum   = (int)StreamHelpers.ConvertFromBigEndian(weakSumBytes);
                byte[] strongSum = r.ReadBytes(result.StrongSumLength);
                signatures.Add(new BlockSignature
                {
                    StartPos  = (ulong)result.BlockLength * i,
                    WeakSum   = weakSum,
                    StrongSum = strongSum
                });

                i++;
            }

            result.BlockLookup = signatures.ToLookup(sig => sig.WeakSum);
            return(result);
        }
コード例 #3
0
        public static SignatureFile ParseSignatureFile(Stream s)
        {
            SignatureFile signatureFile = default(SignatureFile);
            BinaryReader  binaryReader  = new BinaryReader(s);
            uint          num           = StreamHelpers.ReadBigEndianUint32(binaryReader);

            if (num != 1920139575)
            {
                throw new InvalidDataException($"Unknown magic number {num}");
            }
            signatureFile.StrongSumMethod = CalculateBlake2StrongSum;
            signatureFile.BlockLength     = (int)StreamHelpers.ReadBigEndianUint32(binaryReader);
            signatureFile.StrongSumLength = (int)StreamHelpers.ReadBigEndianUint32(binaryReader);
            Dictionary <int, List <BlockSignature> > dictionary = new Dictionary <int, List <BlockSignature> >();
            ulong num2 = 0uL;

            while (true)
            {
                byte[] array = binaryReader.ReadBytes(4);
                if (array.Length == 0)
                {
                    break;
                }
                int    num3                 = (int)StreamHelpers.ConvertFromBigEndian(array);
                byte[] strongSum            = binaryReader.ReadBytes(signatureFile.StrongSumLength);
                List <BlockSignature> value = null;
                if (!dictionary.TryGetValue(num3, out value))
                {
                    value = new List <BlockSignature>();
                    dictionary.Add(num3, value);
                }
                value.Add(new BlockSignature
                {
                    StartPos  = (ulong)((long)signatureFile.BlockLength * (long)num2),
                    WeakSum   = num3,
                    StrongSum = strongSum
                });
                num2++;
            }
            signatureFile.BlockLookup = dictionary;
            return(signatureFile);
        }
コード例 #4
0
ファイル: PatchedStream.cs プロジェクト: Bectinced-aeN/vrcsdk
        private static Command ReadCommand(BinaryReader s)
        {
            CommandFormat commandFormat = GetCommandFormat(s.ReadByte());
            Command       result        = default(Command);

            result.Kind = commandFormat.Kind;
            if (commandFormat.Length1 > 0)
            {
                result.Parameter1 = StreamHelpers.ConvertFromBigEndian(s.ReadBytes(commandFormat.Length1));
            }
            else
            {
                result.Parameter1 = commandFormat.ImmediateValue;
            }
            if (commandFormat.Length2 > 0)
            {
                result.Parameter2 = StreamHelpers.ConvertFromBigEndian(s.ReadBytes(commandFormat.Length2));
            }
            return(result);
        }