/// <summary> /// Initialize a new 32 bit hook for JIT on the supplied assembly with the callback CompileMethod. /// Will determine the runtime version (and JIT hook to use). /// </summary> /// <param name="asm">The assembly to wrap</param> /// <param name="hookedCompileMethod32">The CompileMethod to call instead of the original.</param> public HookHelper32(Assembly asm, Data.CompileMethodDel hookedCompileMethod32) { LoadedAssembly = asm; ModuleScope = LoadedAssembly.ManifestModule.GetScope(); // .NET 4.0+ Hook = new JITHook <ClrjitAddrProvider>(hookedCompileMethod32); Original = Hook.OriginalCompileMethod32; }
private static unsafe void Main22() { _jitHook = new JITHook<ClrjitAddrProvider>(); if (_jitHook.Hook(HookedCompileMethod)) Console.WriteLine("Successfully installed hook!\r\n"); Console.WriteLine(Foo()); Console.WriteLine("\r\n"); if (_jitHook.UnHook()) Console.WriteLine("Successfully uninstalled hook!\r\n"); Console.WriteLine(Bar()); Console.ReadLine(); }
/// <summary> /// Initialize a new 32 bit hook for JIT on the supplied assembly with the callback CompileMethod. /// Will determine the runtime version (and JIT hook to use). /// </summary> /// <param name="asm">The assembly to wrap</param> /// <param name="hookedCompileMethod32">The CompileMethod to call instead of the original.</param> public HookHelper32(Assembly asm, Data.CompileMethodDel hookedCompileMethod32) { LoadedAssembly = asm; ModuleScope = LoadedAssembly.ManifestModule.GetScope(); if (LoadedAssembly.ImageRuntimeVersion == "v2.0.50727") { // .NET 2.0-3.5 Hook = new JITHook <MscorjitAddrProvider>(hookedCompileMethod32); } else { // .NET 4.0+ Hook = new JITHook <ClrjitAddrProvider>(hookedCompileMethod32); } Original = Hook.OriginalCompileMethod32; }
private static unsafe void Main22() { _jitHook = new JITHook <ClrjitAddrProvider>(); if (_jitHook.Hook(HookedCompileMethod)) { Console.WriteLine("Successfully installed hook!\r\n"); } Console.WriteLine(Foo()); Console.WriteLine("\r\n"); if (_jitHook.UnHook()) { Console.WriteLine("Successfully uninstalled hook!\r\n"); } Console.WriteLine(Bar()); Console.ReadLine(); }
static void Main(string[] args) { PerfManager perfManager = PerfManager.Instance; Console.Out.WriteLine("NetAsmDemo. Framework .NET Version {0}", RuntimeEnvironment.GetSystemVersion()); // ----------------------------------------------------------------------------------- // Install the JITHook. // Test a Global Code Injector with pattern regex on classes names. Perform a Global // Code Injection only on NetAsmDemo..* namespace JITHook.Install("NetAsmDemo\\..*", new GlobalCodeInjector()); perfManager.Run(TestGlobalInjection.RunPublicMethod, true); // Remove it JITHook.Remove(); // The JITHook with the Global Injector is removed here // ----------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------- // Reinstall a standard JITHook with no Global Code Injector JITHook.Install(); // Run All tests perfManager.Run(TestHelloWorld.Run, true); perfManager.Run(TestStaticCodeInjection.Run, true); perfManager.Run(TestDllCodeInjection.Run, true); perfManager.Run(TestDynamicCodeInjection.Run, true); perfManager.Run(TestCallingConventions.Run, true); perfManager.Run(TestStructure.Run, true); perfManager.Run(TestCast.Run, true); perfManager.Run(TestCpuid.Run, true); perfManager.Run(TestSimpleAddBenchmark.Run, true); perfManager.Run(TestMatrixMulBenchmark.Run, true); JITHook.Remove(); // ----------------------------------------------------------------------------------- Console.Out.WriteLine("Press Enter to close the program"); Console.In.ReadLine(); }