コード例 #1
0
ファイル: RPMode.cs プロジェクト: naderr1ua/DarksProtector
        protected static TypeDef GetDelegateType(RPContext ctx, MethodSig sig)
        {
            TypeDef def;

            if (!ctx.Delegates.TryGetValue(sig, out def))
            {
                def = new TypeDefUser(ctx.Name.RandomName(), ctx.Name.RandomName(), ctx.Module.CorLibTypes.GetTypeRef("System", "MulticastDelegate"))
                {
                    Attributes = TypeAttributes.AnsiClass | TypeAttributes.Sealed
                };
                MethodDefUser item = new MethodDefUser(".ctor", MethodSig.CreateInstance(ctx.Module.CorLibTypes.Void, ctx.Module.CorLibTypes.Object, ctx.Module.CorLibTypes.IntPtr))
                {
                    Attributes     = MethodAttributes.Assembly | MethodAttributes.HideBySig | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName,
                    ImplAttributes = MethodImplAttributes.CodeTypeMask
                };
                def.Methods.Add(item);
                MethodDefUser user2 = new MethodDefUser("Invoke", sig.Clone())
                {
                    MethodSig      = { HasThis = true },
                    Attributes     = MethodAttributes.Assembly | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual,
                    ImplAttributes = MethodImplAttributes.CodeTypeMask
                };
                def.Methods.Add(user2);
                ctx.Module.Types.Add(def);
                foreach (IDnlibDef def2 in def.FindDefinitions())
                {
                    ctx.Marker.Mark(def2, ctx.Protection);
                    ctx.Name.SetCanRename(def2, false);
                }
                ctx.Delegates[sig] = def;
            }
            return(def);
        }
コード例 #2
0
ファイル: RPMode.cs プロジェクト: 2sic4you/ConfuserEx
        protected static TypeDef GetDelegateType(RPContext ctx, MethodSig sig)
        {
            TypeDef ret;
            if (ctx.Delegates.TryGetValue(sig, out ret))
                return ret;

            ret = new TypeDefUser(ctx.Name.ObfuscateName(ctx.Method.DeclaringType.Namespace, RenameMode.Unicode), ctx.Name.RandomName(), ctx.Module.CorLibTypes.GetTypeRef("System", "MulticastDelegate"));
            ret.Attributes = TypeAttributes.NotPublic | TypeAttributes.Sealed;

            var ctor = new MethodDefUser(".ctor", MethodSig.CreateInstance(ctx.Module.CorLibTypes.Void, ctx.Module.CorLibTypes.Object, ctx.Module.CorLibTypes.IntPtr));
            ctor.Attributes = MethodAttributes.Assembly | MethodAttributes.HideBySig | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName;
            ctor.ImplAttributes = MethodImplAttributes.Runtime;
            ret.Methods.Add(ctor);

            var invoke = new MethodDefUser("Invoke", sig.Clone());
            invoke.MethodSig.HasThis = true;
            invoke.Attributes = MethodAttributes.Assembly | MethodAttributes.HideBySig | MethodAttributes.Virtual | MethodAttributes.NewSlot;
            invoke.ImplAttributes = MethodImplAttributes.Runtime;
            ret.Methods.Add(invoke);

            ctx.Module.Types.Add(ret);

            foreach (IDnlibDef def in ret.FindDefinitions()) {
                ctx.Marker.Mark(def);
                ctx.Name.SetCanRename(def, false);
            }

            ctx.Delegates[sig] = ret;
            return ret;
        }
コード例 #3
0
ファイル: RPMode.cs プロジェクト: nereva/ConfuserEx
        protected static TypeDef GetDelegateType(RPContext ctx, MethodSig sig)
        {
            if (ctx.Delegates.TryGetValue(sig, out var ret))
            {
                return(ret);
            }

            ret = new TypeDefUser(ctx.Name.ObfuscateName(ctx.Method.DeclaringType.Namespace, RenameMode.Unicode), ctx.Name.RandomName(), ctx.Module.CorLibTypes.GetTypeRef("System", "MulticastDelegate"))
            {
                Attributes = TypeAttributes.NotPublic | TypeAttributes.Sealed
            };

            var ctor = new MethodDefUser(".ctor", MethodSig.CreateInstance(ctx.Module.CorLibTypes.Void, ctx.Module.CorLibTypes.Object, ctx.Module.CorLibTypes.IntPtr))
            {
                Attributes     = MethodAttributes.Assembly | MethodAttributes.HideBySig | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName,
                ImplAttributes = MethodImplAttributes.Runtime
            };

            ret.Methods.Add(ctor);

            var invoke = new MethodDefUser("Invoke", sig.Clone());

            invoke.MethodSig.HasThis = true;
            invoke.Attributes        = MethodAttributes.Assembly | MethodAttributes.HideBySig | MethodAttributes.Virtual | MethodAttributes.NewSlot;
            invoke.ImplAttributes    = MethodImplAttributes.Runtime;
            ret.Methods.Add(invoke);

            ctx.Module.Types.Add(ret);

            foreach (var def in ret.FindDefinitions())
            {
                ctx.Marker.Mark(def, ctx.Protection);
                ctx.Name.SetCanRename(def, false);
            }

            ctx.Delegates[sig] = ret;
            return(ret);
        }