示例#1
0
            static LibSystem()
            {
                typeof(LibSystem).ResolveDynDllImports(new Dictionary <string, List <DynDllMapping> >
                {
                    ["libSystem"] = new List <DynDllMapping>
                    {
                        "/usr/lib/libSystem.dylib"                         // OSX POSIX
                    }
                });

                var libsystem = DynDll.OpenLibrary("/usr/lib/libSystem.dylib");

                TaskSelf = libsystem.GetFunction("mach_task_self_");                 // This isn't a function but rather an exported symbol
            }
示例#2
0
        private void TestNativeDetoursWindows(dt_rand d_not_rand, IntPtr ptr_not_rand)
        {
            DidNothing = true;
            msvcrt_rand();
            Assert.True(DidNothing);

            DidNothing = true;
            Assert.Equal(-1, d_not_rand());
            Assert.False(DidNothing);

            using (new NativeDetour(
                       typeof(NativeDetourTest).GetMethod("msvcrt_rand"),
                       typeof(NativeDetourTest).GetMethod("not_rand")
                       )) {
                DidNothing = true;
                Assert.Equal(-1, msvcrt_rand());
                Assert.False(DidNothing);
            }

            DidNothing = true;
            msvcrt_rand();
            Assert.True(DidNothing);

            NativeDetour d = new NativeDetour(
                DynDll.OpenLibrary($"msvcrt.{PlatformHelper.LibrarySuffix}").GetFunction("rand"),
                ptr_not_rand
                );

            DidNothing = true;
            Assert.Equal(-1, msvcrt_rand());
            Assert.False(DidNothing);

            d.Dispose();

            DidNothing = true;
            msvcrt_rand();
            Assert.True(DidNothing);
        }