Ejemplo n.º 1
0
        /// <summary>
        ///     Asserts that the specified number of bytes can be read from <c>data</c> starting at <c>index</c>
        ///     <para></para>
        ///     The number of bytes must be pushed onto the evaluation stack
        /// </summary>
        public void AssertLength()
        {
            LoadIndex();      // stack: [length, index]
            Il.Add();         // stack: [length + index]
            LoadDataLength(); // stack: [length + index, dataLength]
            var bigEnoughLabel = Il.DefineLabel("bigEnough");

            Il.Ble(bigEnoughLabel, true);
            Il.Ldstr("Unexpected end of data");
            var constructor = typeof(DataCorruptedException).GetConstructor(new[] { typeof(string) });

            if (constructor == null)
            {
                throw new MissingConstructorException(typeof(DataCorruptedException), typeof(string));
            }
            Il.Newobj(constructor);
            Il.Throw();
            Il.MarkLabel(bigEnoughLabel);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Asserts that the specified number of bytes can be written to <c>result</c> starting at <c>index</c>
        ///     <para></para>
        ///     The number of bytes must be pushed onto the evaluation stack
        /// </summary>
        public void AssertLength()
        {
            LoadIndex();        // stack: [length, index]
            Il.Add();           // stack: [length + index]
            LoadResultLength(); // stack: [length + index, resultLength]
            var bigEnoughLabel = Il.DefineLabel("bigEnough");

            Il.Ble(bigEnoughLabel, true);
            Il.Ldstr("Seems like the object being serialized has been changed during serialization");
            var constructor = typeof(InvalidOperationException).GetConstructor(new[] { typeof(string) });

            if (constructor == null)
            {
                throw new MissingConstructorException(typeof(InvalidOperationException), typeof(string));
            }
            Il.Newobj(constructor);
            Il.Throw();
            Il.MarkLabel(bigEnoughLabel);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Checks TypeCode and throws Exception if it is invalid
        /// </summary>
        public void CheckTypeCode()
        {
            LoadField(Context.Lengths);
            Il.Ldloc(TypeCode);     // stack: [lengths, typeCode]
            Il.Ldelem(typeof(int)); // stack: [lengths[typeCode]]
            var okLabel = Il.DefineLabel("ok");

            Il.Brtrue(okLabel); // if(lengths[typeCode] != 0) goto ok;
            Il.Ldstr("Unknown type code: ");
            Il.Ldloca(TypeCode);
            Il.Call(HackHelpers.GetMethodDefinition <int>(x => x.ToString()), typeof(int));
            Il.Call(HackHelpers.GetMethodDefinition <string>(s => s + "zzz"));
            var constructor = typeof(DataCorruptedException).GetConstructor(new[] { typeof(string) });

            if (constructor == null)
            {
                throw new MissingConstructorException(typeof(DataCorruptedException), typeof(string));
            }
            Il.Newobj(constructor);
            Il.Throw();
            Il.MarkLabel(okLabel);
        }