public void DetourInternalFunction2() { _GetCurrentNlsCacheCalled = false; using (var hook = LocalHook.Create( LocalHook.GetProcAddress("kernelbase.dll", "GetCurrentNlsCache"), new GetCurrentNlsCacheDelegate(GetCurrentNlsCacheHook), this)) { hook.ThreadACL.SetInclusiveACL(new int[] { 0 }); GetCurrentNlsCacheFunction = (GetCurrentNlsCacheDelegate) Marshal.GetDelegateForFunctionPointer( hook.HookBypassAddress, typeof(GetCurrentNlsCacheDelegate)); string stringA = "HelloWorld"; string stringB = "Hello"; int comparisonResult = CompareStringW( LOCALE_USER_DEFAULT, NORM_LINGUISTIC_CASING, stringA, stringA.Length, stringB, stringB.Length); Assert.Equal(CSTR_GREATER_THAN, comparisonResult); Assert.True(_GetCurrentNlsCacheCalled); } }
public void ShouldDetourInternalFunctionCalledByCompareString() { _GetCurrentNlsCacheCalled = false; using (var hook = LocalHook.Create( LocalHook.GetProcAddress(Interop.Libraries.KernelBase, "GetCurrentNlsCache"), new GetCurrentNlsCacheDelegate(Detour_GetCurrentNlsCache), this)) { hook.ThreadACL.SetInclusiveACL(new int[] { 0 }); GetCurrentNlsCacheFunction = hook.OriginalAddress.ToFunction <GetCurrentNlsCacheDelegate>(); string stringA = "HelloWorld"; string stringB = "Hello"; int comparisonResult = Interop.KernelBase.CompareStringW( LOCALE_USER_DEFAULT, NORM_LINGUISTIC_CASING, stringA, stringA.Length, stringB, stringB.Length); Assert.Equal(CSTR_GREATER_THAN, comparisonResult); Assert.True(_GetCurrentNlsCacheCalled); } }