Пример #1
0
        public void MethodCallReplacer_MathOperator_Test()
        {
            var module = GetContractModule(typeof(TestContract));
            {
                var res = ContainsMathOpCode(
                    GetModule(typeof(TestContract)).Types.Single(t => t.FullName == typeof(TestContract).FullName)
                    .Methods
                    .First(m => m.Name == nameof(TestContract.TestStateType)), OpCodes.Add);
                res.ShouldBeTrue();
            }

            var replacer = new MethodCallReplacer();

            replacer.Patch(module);

            {
                var res = ContainsMathOpCode(
                    module.Types.Single(t => t.FullName == typeof(TestContract).FullName)
                    .Methods
                    .First(m => m.Name == nameof(TestContract.TestStateType)), OpCodes.Add);
                res.ShouldBeFalse();
            }

            {
                var res = ContainsMathOpCode(
                    module.Types.Single(t => t.FullName == typeof(TestContract).FullName)
                    .Methods
                    .First(m => m.Name == nameof(TestContract.TestStateType)), OpCodes.Add_Ovf);
                res.ShouldBeTrue();
            }
        }
Пример #2
0
        public static IQueryable <T> FixDbFunctionCalls <T>(this IQueryable <T> source)
        {
            var            replacer      = new MethodCallReplacer();
            Expression     newExpresiion = replacer.Visit(source.Expression);
            IQueryable <T> newQueryable  = source.Provider.CreateQuery <T>(newExpresiion);

            return(newQueryable);
        }
Пример #3
0
        private static byte[] InjectCallReplacerCode(byte[] code)
        {
            var asm     = AssemblyDefinition.ReadAssembly(new MemoryStream(code));
            var patcher = new MethodCallReplacer();

            patcher.Patch(asm.MainModule);

            var newCode = new MemoryStream();

            asm.Write(newCode);
            return(newCode.ToArray());
        }
Пример #4
0
        public void MethodCallReplacer_StringConcat_Test()
        {
            var module = GetContractModule(typeof(TestContract));
            {
                var m   = module.Types.Single(t => t.Name == nameof(TestContractReflection)).GetStaticConstructor();
                var res = ContainsMethodCall(m,
                                             GetModule(typeof(AElfString)).Types.Single(t => t.FullName == typeof(AElfString).FullName).Methods
                                             .First(m => m.Name == nameof(string.Concat)));
                res.ShouldBeFalse();
            }

            var replacer = new MethodCallReplacer();

            replacer.Patch(module);

            {
                var m   = module.Types.Single(t => t.Name == nameof(TestContractReflection)).GetStaticConstructor();
                var res = ContainsMethodCall(m,
                                             GetModule(typeof(AElfString)).Types.Single(t => t.FullName == typeof(AElfString).FullName).Methods
                                             .First(m => m.Name == nameof(string.Concat)));
                res.ShouldBeTrue();
            }
        }