Exemplo n.º 1
0
        private static string CallingConventionString(dnlib.DotNet.CallingConvention callingConvention)
        {
            switch (callingConvention)
            {
            case dnlib.DotNet.CallingConvention.C:
                return("CallConvCdecl");

            case dnlib.DotNet.CallingConvention.StdCall:
                return("CallConvStdcall");

            case dnlib.DotNet.CallingConvention.ThisCall:
                return("CallConvThiscall");

            default:
                throw new ArgumentOutOfRangeException(nameof(callingConvention), callingConvention, null);
            }
        }
Exemplo n.º 2
0
        public static void ApplyExportBugFix(MethodDef method, dnlib.DotNet.CallingConvention callingConvention)
        {
            var type = method.MethodSig.RetType;

            type = new CModOptSig(method.Module.CorLibTypes.GetTypeRef("System.Runtime.CompilerServices", CallingConventionString(callingConvention)), type);
            method.MethodSig.RetType = type;
            var ca = method.Module.Assembly.CustomAttributes.Find("System.Diagnostics.DebuggableAttribute");

            if (!(ca is null) && ca.ConstructorArguments.Count == 1)
            {
                var arg = ca.ConstructorArguments[0];
                if (arg.Type.FullName == "System.Diagnostics.DebuggableAttribute/DebuggingModes" && arg.Value is int value && value == 0x107)
                {
                    arg.Value = value & ~(int)DebuggableAttribute.DebuggingModes.EnableEditAndContinue;
                    ca.ConstructorArguments[0] = arg;
                }
            }
        }