OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file contains unit tests for ServiceResolverThunk. | 5 // This file contains unit tests for ServiceResolverThunk. |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <memory> |
| 10 |
9 #include "base/bit_cast.h" | 11 #include "base/bit_cast.h" |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
13 #include "sandbox/win/src/resolver.h" | 14 #include "sandbox/win/src/resolver.h" |
14 #include "sandbox/win/src/sandbox_utils.h" | 15 #include "sandbox/win/src/sandbox_utils.h" |
15 #include "sandbox/win/src/service_resolver.h" | 16 #include "sandbox/win/src/service_resolver.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // This is the concrete resolver used to perform service-call type functions | 21 // This is the concrete resolver used to perform service-call type functions |
21 // inside ntdll.dll. | 22 // inside ntdll.dll. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 return STATUS_UNSUCCESSFUL; | 102 return STATUS_UNSUCCESSFUL; |
102 | 103 |
103 BYTE service[50]; | 104 BYTE service[50]; |
104 memcpy(service, target, sizeof(service)); | 105 memcpy(service, target, sizeof(service)); |
105 | 106 |
106 static_cast<WinXpResolverTest*>(resolver)->set_target(service); | 107 static_cast<WinXpResolverTest*>(resolver)->set_target(service); |
107 | 108 |
108 // Any pointer will do as an interception_entry_point | 109 // Any pointer will do as an interception_entry_point |
109 void* function_entry = resolver; | 110 void* function_entry = resolver; |
110 size_t thunk_size = resolver->GetThunkSize(); | 111 size_t thunk_size = resolver->GetThunkSize(); |
111 scoped_ptr<char[]> thunk(new char[thunk_size]); | 112 std::unique_ptr<char[]> thunk(new char[thunk_size]); |
112 size_t used; | 113 size_t used; |
113 | 114 |
114 resolver->AllowLocalPatches(); | 115 resolver->AllowLocalPatches(); |
115 | 116 |
116 NTSTATUS ret = resolver->Setup(ntdll_base, NULL, function, NULL, | 117 NTSTATUS ret = resolver->Setup(ntdll_base, NULL, function, NULL, |
117 function_entry, thunk.get(), thunk_size, | 118 function_entry, thunk.get(), thunk_size, |
118 &used); | 119 &used); |
119 if (NT_SUCCESS(ret)) { | 120 if (NT_SUCCESS(ret)) { |
120 EXPECT_EQ(thunk_size, used); | 121 EXPECT_EQ(thunk_size, used); |
121 EXPECT_NE(0, memcmp(service, target, sizeof(service))); | 122 EXPECT_NE(0, memcmp(service, target, sizeof(service))); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 void* target = ::GetProcAddress(ntdll_base, kFunctionName); | 240 void* target = ::GetProcAddress(ntdll_base, kFunctionName); |
240 ASSERT_TRUE(NULL != target); | 241 ASSERT_TRUE(NULL != target); |
241 | 242 |
242 BYTE service[50]; | 243 BYTE service[50]; |
243 memcpy(service, target, sizeof(service)); | 244 memcpy(service, target, sizeof(service)); |
244 static_cast<WinXpResolverTest*>(resolver)->set_target(service); | 245 static_cast<WinXpResolverTest*>(resolver)->set_target(service); |
245 | 246 |
246 // Any pointer will do as an interception_entry_point | 247 // Any pointer will do as an interception_entry_point |
247 void* function_entry = resolver; | 248 void* function_entry = resolver; |
248 size_t thunk_size = resolver->GetThunkSize(); | 249 size_t thunk_size = resolver->GetThunkSize(); |
249 scoped_ptr<char[]> thunk(new char[thunk_size]); | 250 std::unique_ptr<char[]> thunk(new char[thunk_size]); |
250 size_t used; | 251 size_t used; |
251 | 252 |
252 NTSTATUS ret = STATUS_UNSUCCESSFUL; | 253 NTSTATUS ret = STATUS_UNSUCCESSFUL; |
253 | 254 |
254 // First try patching without having allowed local patches. | 255 // First try patching without having allowed local patches. |
255 ret = resolver->Setup(ntdll_base, NULL, kFunctionName, NULL, | 256 ret = resolver->Setup(ntdll_base, NULL, kFunctionName, NULL, |
256 function_entry, thunk.get(), thunk_size, | 257 function_entry, thunk.get(), thunk_size, |
257 &used); | 258 &used); |
258 EXPECT_FALSE(NT_SUCCESS(ret)); | 259 EXPECT_FALSE(NT_SUCCESS(ret)); |
259 | 260 |
260 // Now allow local patches and check that things work. | 261 // Now allow local patches and check that things work. |
261 resolver->AllowLocalPatches(); | 262 resolver->AllowLocalPatches(); |
262 ret = resolver->Setup(ntdll_base, NULL, kFunctionName, NULL, | 263 ret = resolver->Setup(ntdll_base, NULL, kFunctionName, NULL, |
263 function_entry, thunk.get(), thunk_size, | 264 function_entry, thunk.get(), thunk_size, |
264 &used); | 265 &used); |
265 EXPECT_EQ(STATUS_SUCCESS, ret); | 266 EXPECT_EQ(STATUS_SUCCESS, ret); |
266 } | 267 } |
267 | 268 |
268 } // namespace | 269 } // namespace |
OLD | NEW |