Example #1
0
            public DumbBlockMethodVisitor(IMetadataHost host, MethodBody method, string methodName)
                : base(host, method)
            {
                Console.WriteLine(MemberHelper.GetMemberSignature(method.MethodDefinition, NameFormattingOptions.None));

                this.anchors    = new Dictionary <uint, uint>();
                this.methodName = //methodName;// method.MethodDefinition.ToString();
                                  MemberHelper.GetMethodSignature(method.MethodDefinition, NameFormattingOptions.SmartTypeName);

                var zombieAssemblyIdentity  = new AssemblyIdentity(host.NameTable.GetNameFor("Zombie"), "", new Version(1, 0, 0), new byte[0], "Zombie.dll");
                var zombieAssemblyReference = new AssemblyReference()
                {
                    Host             = host,
                    AssemblyIdentity = zombieAssemblyIdentity
                };
                var counterClassNamespaceReference = ILMethodBodyRewriter.CreateTypeReference(host, zombieAssemblyReference, "BlockCounter");

                this.blockCounterDotVisitMaybeAnchorInstruction = new Microsoft.Cci.MethodReference(
                    this.host, counterClassNamespaceReference,
                    CallingConvention.Default,
                    host.PlatformType.SystemVoid,
                    host.NameTable.GetNameFor("VisitMaybeAnchorInstruction"),
                    0,
                    host.PlatformType.SystemString);

                this.blockCounterDotVisitInstruction = new Microsoft.Cci.MethodReference(
                    this.host, counterClassNamespaceReference,
                    CallingConvention.Default,
                    host.PlatformType.SystemVoid,
                    host.NameTable.GetNameFor("VisitInstruction"),
                    0,
                    host.PlatformType.SystemString);
            }
        protected ILMethodBodyRewriter(IMetadataHost host, MethodBody methodBody, ILGenerator generator)
        {
            Contract.Requires(host != null);
            Contract.Requires(methodBody != null);
            Contract.Requires(generator != null);
            Contract.Requires(methodBody != Dummy.MethodBody);

            this.host       = host;
            this.methodBody = methodBody;
            this.generator  = generator;

            // Make a label for each branch target
            this.offset2Label = ILMethodBodyRewriter.RecordBranchTargets(this.methodBody.Operations);
            //Record all offsets that appear as part of an exception handler
            this.offsetsUsedInExceptionInformation = ILMethodBodyRewriter.RecordExceptionHandlerOffsets(this.methodBody.OperationExceptionInformation);
        }