private static MemberRef gettt(MethodDef met)
        {
            TypeDef decType = met.DeclaringType;

            if (decType.BaseType.FullName == "System.MulticastDelegate")
            {
                foreach (MethodDef method in decType.Methods)
                {
                    if (method.HasBody && method.Body.HasInstructions)
                    {
                        for (int i = 0; i < method.Body.Instructions.Count; i++)
                        {
                            if (method.Body.Instructions[i].IsLdcI4())
                            {
                                int      value     = method.Body.Instructions[i].GetLdcI4Value();
                                FieldDef fieldDele = getfieldofdelegate(decType);

                                string name = fieldDele.Name;
                                if (name.EndsWith("%"))
                                {
                                    flag = true;
                                    name = name.TrimEnd(new char[] { '%' });
                                }
                                uint        num             = BitConverter.ToUInt32(Convert.FromBase64String(name), 0);
                                ModuleDefMD MDMod           = (ModuleDefMD)Globals.ASM.ManifestModule;
                                MemberRef   solvedMemberRef = MDMod.ResolveMemberRef((uint)((long)num + 167772161L) - 167772160U);
                                return(solvedMemberRef);
                            }
                        }
                    }
                }
            }
            return(null);
        }
示例#2
0
        private static MemberRef ResolveDelegate(FieldDef field)//Most of this process was copied from the method from Agile
        {
            MemberRef result   = null;
            TypeDef   deleType = field.DeclaringType;                                                 //Get the type of the field

            if (deleType.BaseType.FullName == "System.MulticastDelegate")                             //Check to see if the type is a delegate
            {
                foreach (MethodDef meth in deleType.Methods)                                          //Go through all the methods in the type
                {
                    if (meth.HasBody && meth.Body.HasInstructions)                                    //Check to see if the method has a valid body with instructions
                    {
                        for (int o = 0; o < meth.Body.Instructions.Count; o++)                        //Go through all the instructions in the method
                        {
                            if (meth.Body.Instructions[o].OpCode == dnlib.DotNet.Emit.OpCodes.Ldc_I4) //find the int to use when solving the method
                            {
                                int    valuetest = meth.Body.Instructions[o].GetLdcI4Value();         //Get the value
                                string name      = field.Name;                                        //Get the field name
                                bool   flag      = false;
                                if (name.EndsWith("%"))                                               //This method is originally from Agile
                                {
                                    flag = true;
                                    name = name.TrimEnd(new char[]
                                    {
                                        '%'
                                    });
                                }
                                uint        num             = BitConverter.ToUInt32(Convert.FromBase64String(name), 0);
                                ModuleDefMD MDMod           = (ModuleDefMD)Globals.ASM.ManifestModule;
                                MemberRef   solvedMemberRef = MDMod.ResolveMemberRef((uint)((long)num + 167772161L) - 167772160U); //Resolve the method!
                                result = solvedMemberRef;                                                                          //set the local variable with the resolved memberef
                            }
                        }
                    }
                }
            }
            return(result);//return the result
        }