private void ConvertCallToCallvirt(List <MethodDefDeclaration> alteredMethods)
        {
            // TODO: Handle Ldftn -> Ldvirtftn

            using Sdk.CodeWeaver.Weaver weaver = new Sdk.CodeWeaver.Weaver(this.Project);
            weaver.AddMethodLevelAdvice(new CallToCallvirtWeaverAdvice(), null, JoinPointKinds.InsteadOfCall, alteredMethods);
            weaver.Weave();
        }
        bool FindInitializeCalls(Project project, AssemblyLoaderInfo assemblyLoaderInfo)
        {
            INamedType           packerUtilityType       = (INamedType)project.Module.FindType(typeof(PackerUtility));
            MethodDefDeclaration packerUtilityInitialize =
                project.Module.FindMethod(packerUtilityType, "Initialize").GetMethodDefinition();

            Sdk.CodeWeaver.Weaver weaver = new Sdk.CodeWeaver.Weaver(project);
            ReplacePackerUtilityInitializeAdvice replacingAdvice = new ReplacePackerUtilityInitializeAdvice(assemblyLoaderInfo.AttachMethod);

            weaver.AddMethodLevelAdvice(replacingAdvice, null,
                                        JoinPointKinds.InsteadOfCall, new[] { packerUtilityInitialize });
            weaver.Weave();
            return(replacingAdvice.ReplacedAtLeastOneCall);
        }
        public override bool Execute()
        {
            this.wrapperType = this.GetWrapperType(this.Project.Module.Assembly, new HashSet <string>());
            if (this.wrapperType == null)
            {
                Message.Write(this.Project.Module.Assembly.GetSystemAssembly(), SeverityType.Error, "CUMA001", "You must create a CheckMemoryAccess class with the appropriate source code in your project.");
                return(false);
            }

            this.methods.Add(OpCodeNumber.Stind_I, this.wrapperType.Methods.GetOneByName("StoreIntPtr").Translate(this.Project.Module));
            this.methods.Add(OpCodeNumber.Stind_I1, this.wrapperType.Methods.GetOneByName("StoreByte").Translate(this.Project.Module));
            this.methods.Add(OpCodeNumber.Stind_I2, this.wrapperType.Methods.GetOneByName("StoreInt16").Translate(this.Project.Module));
            this.methods.Add(OpCodeNumber.Stind_I4, this.wrapperType.Methods.GetOneByName("StoreInt32").Translate(this.Project.Module));
            this.methods.Add(OpCodeNumber.Stind_I8, this.wrapperType.Methods.GetOneByName("StoreInt64").Translate(this.Project.Module));
            this.methods.Add(OpCodeNumber.Stind_R4, this.wrapperType.Methods.GetOneByName("StoreSingle").Translate(this.Project.Module));
            this.methods.Add(OpCodeNumber.Stind_R8, this.wrapperType.Methods.GetOneByName("StoreDouble").Translate(this.Project.Module));

            Sdk.CodeWeaver.Weaver weaver = new Sdk.CodeWeaver.Weaver(this.Project);
            weaver.AddMethodLevelAdvice(this, null, JoinPointKinds.InsteadOfStoreIndirect, null);
            weaver.Weave();
            return(base.Execute());
        }