예제 #1
0
        public static unsafe bool Initialize()
        {
            NewCompileMethod = HookedCompileMethod;
            IntPtr pCompileMethod = Marshal.ReadIntPtr(VTableAddr);
            uint   old;

            if (
                !JITNative.VirtualProtect(pCompileMethod, (uint)IntPtr.Size,
                                          JITNative.Protection.PAGE_EXECUTE_READWRITE, out old))
            {
                return(false);
            }

            OriginalCompileMethod =
                (JITNative.CompileMethodDelegate)
                Marshal.GetDelegateForFunctionPointer(Marshal.ReadIntPtr(pCompileMethod), typeof(JITNative.CompileMethodDelegate));

            RuntimeHelpers.PrepareDelegate(NewCompileMethod);
            RuntimeHelpers.PrepareDelegate(OriginalCompileMethod);
            RuntimeHelpers.PrepareMethod(typeof(JITInterceptor).GetMethod("Initialize", BindingFlags.Static | BindingFlags.Public).MethodHandle);
            RuntimeHelpers.PrepareMethod(typeof(JITInterceptor).GetMethod("FindModule", BindingFlags.Static | BindingFlags.NonPublic).MethodHandle);

            Marshal.WriteIntPtr(pCompileMethod, Marshal.GetFunctionPointerForDelegate(NewCompileMethod));

            return(JITNative.VirtualProtect(pCompileMethod, (uint)IntPtr.Size,
                                            (JITNative.Protection)old, out old));
        }
예제 #2
0
        public static bool UnInitialize()
        {
            IntPtr pCompileMethod = Marshal.ReadIntPtr(VTableAddr);
            uint   old;

            if (
                !JITNative.VirtualProtect(pCompileMethod, (uint)IntPtr.Size,
                                          JITNative.Protection.PAGE_EXECUTE_READWRITE, out old))
            {
                return(false);
            }

            Marshal.WriteIntPtr(pCompileMethod, Marshal.GetFunctionPointerForDelegate(OriginalCompileMethod));

            return(JITNative.VirtualProtect(pCompileMethod, (uint)IntPtr.Size,
                                            (JITNative.Protection)old, out old));
        }