| Index: sandbox/win/src/service_resolver_unittest.cc
|
| diff --git a/sandbox/win/src/service_resolver_unittest.cc b/sandbox/win/src/service_resolver_unittest.cc
|
| index 59105cc49defa6b55a343c576354edbf2828979c..b01fedfbf09cfb73f292ee7d2e9bdeae6724d25a 100644
|
| --- a/sandbox/win/src/service_resolver_unittest.cc
|
| +++ b/sandbox/win/src/service_resolver_unittest.cc
|
| @@ -44,7 +44,7 @@ class ResolverThunkTest : public T {
|
| EXPECT_EQ(STATUS_SUCCESS, ret);
|
|
|
| target_ = fake_target_;
|
| - ntdll_base_ = ::GetModuleHandle(L"ntdll.dll");
|
| +
|
| return ret;
|
| };
|
|
|
| @@ -108,6 +108,8 @@ NTSTATUS PatchNtdllWithResolver(const char* function, bool relaxed,
|
| scoped_ptr<char[]> thunk(new char[thunk_size]);
|
| size_t used;
|
|
|
| + resolver->AllowLocalPatches();
|
| +
|
| NTSTATUS ret = resolver->Setup(ntdll_base, NULL, function, NULL,
|
| function_entry, thunk.get(), thunk_size,
|
| &used);
|
| @@ -224,4 +226,41 @@ TEST(ServiceResolverTest, MultiplePatchedServices) {
|
| #endif
|
| }
|
|
|
| +TEST(ServiceResolverTest, LocalPatchesAllowed) {
|
| + sandbox::ServiceResolverThunk* resolver = GetTestResolver(true);
|
| +
|
| + HMODULE ntdll_base = ::GetModuleHandle(L"ntdll.dll");
|
| + ASSERT_TRUE(NULL != ntdll_base);
|
| +
|
| + const char kFunctionName[] = "NtClose";
|
| +
|
| + void* target = ::GetProcAddress(ntdll_base, kFunctionName);
|
| + ASSERT_TRUE(NULL != target);
|
| +
|
| + BYTE service[50];
|
| + memcpy(service, target, sizeof(service));
|
| + static_cast<WinXpResolverTest*>(resolver)->set_target(service);
|
| +
|
| + // Any pointer will do as an interception_entry_point
|
| + void* function_entry = resolver;
|
| + size_t thunk_size = resolver->GetThunkSize();
|
| + scoped_ptr<char[]> thunk(new char[thunk_size]);
|
| + size_t used;
|
| +
|
| + NTSTATUS ret = STATUS_UNSUCCESSFUL;
|
| +
|
| + // First try patching without having allowed local patches.
|
| + ret = resolver->Setup(ntdll_base, NULL, kFunctionName, NULL,
|
| + function_entry, thunk.get(), thunk_size,
|
| + &used);
|
| + EXPECT_FALSE(NT_SUCCESS(ret));
|
| +
|
| + // Now allow local patches and check that things work.
|
| + resolver->AllowLocalPatches();
|
| + ret = resolver->Setup(ntdll_base, NULL, kFunctionName, NULL,
|
| + function_entry, thunk.get(), thunk_size,
|
| + &used);
|
| + EXPECT_EQ(STATUS_SUCCESS, ret);
|
| +}
|
| +
|
| } // namespace
|
|
|