| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 InterceptionManager. | 5 // This file contains unit tests for InterceptionManager. |
| 6 // The tests require private information so the whole interception.cc file is | 6 // The tests require private information so the whole interception.cc file is |
| 7 // included from this file. | 7 // included from this file. |
| 8 | 8 |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <memory> |
| 13 #include <set> | 14 #include <set> |
| 14 | 15 |
| 15 #include "base/bits.h" | 16 #include "base/bits.h" |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "sandbox/win/src/interception.h" | 17 #include "sandbox/win/src/interception.h" |
| 18 #include "sandbox/win/src/interception_internal.h" | 18 #include "sandbox/win/src/interception_internal.h" |
| 19 #include "sandbox/win/src/interceptors.h" | 19 #include "sandbox/win/src/interceptors.h" |
| 20 #include "sandbox/win/src/target_process.h" | 20 #include "sandbox/win/src/target_process.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 namespace sandbox { | 23 namespace sandbox { |
| 24 | 24 |
| 25 namespace internal { | 25 namespace internal { |
| 26 size_t GetGranularAlignedRandomOffset(size_t size); | 26 size_t GetGranularAlignedRandomOffset(size_t size); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 INTERCEPTION_EAT, function, OPEN_KEY_ID); | 176 INTERCEPTION_EAT, function, OPEN_KEY_ID); |
| 177 interceptions.AddToPatchedFunctions(L"a.dll", "BIsLame", | 177 interceptions.AddToPatchedFunctions(L"a.dll", "BIsLame", |
| 178 INTERCEPTION_EAT, function, OPEN_KEY_ID); | 178 INTERCEPTION_EAT, function, OPEN_KEY_ID); |
| 179 interceptions.AddToPatchedFunctions(L"a.dll", "ARules", | 179 interceptions.AddToPatchedFunctions(L"a.dll", "ARules", |
| 180 INTERCEPTION_EAT, function, OPEN_KEY_ID); | 180 INTERCEPTION_EAT, function, OPEN_KEY_ID); |
| 181 | 181 |
| 182 // Verify that all interceptions were added | 182 // Verify that all interceptions were added |
| 183 ASSERT_EQ(18u, interceptions.interceptions_.size()); | 183 ASSERT_EQ(18u, interceptions.interceptions_.size()); |
| 184 | 184 |
| 185 size_t buffer_size = interceptions.GetBufferSize(); | 185 size_t buffer_size = interceptions.GetBufferSize(); |
| 186 scoped_ptr<BYTE[]> local_buffer(new BYTE[buffer_size]); | 186 std::unique_ptr<BYTE[]> local_buffer(new BYTE[buffer_size]); |
| 187 | 187 |
| 188 ASSERT_TRUE(interceptions.SetupConfigBuffer(local_buffer.get(), | 188 ASSERT_TRUE(interceptions.SetupConfigBuffer(local_buffer.get(), |
| 189 buffer_size)); | 189 buffer_size)); |
| 190 | 190 |
| 191 // At this point, the interceptions should have been separated into two | 191 // At this point, the interceptions should have been separated into two |
| 192 // groups: one group with the local ("cold") interceptions, consisting of | 192 // groups: one group with the local ("cold") interceptions, consisting of |
| 193 // everything from ntdll and stuff set as INTRECEPTION_SERVICE_CALL, and | 193 // everything from ntdll and stuff set as INTRECEPTION_SERVICE_CALL, and |
| 194 // another group with the interceptions belonging to dlls that will be "hot" | 194 // another group with the interceptions belonging to dlls that will be "hot" |
| 195 // patched on the client. The second group lives on local_buffer, and the | 195 // patched on the client. The second group lives on local_buffer, and the |
| 196 // first group remains on the list of interceptions (inside the object | 196 // first group remains on the list of interceptions (inside the object |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 interceptions.AddToPatchedFunctions(L"kernel32.dll", "CreateFileEx", | 229 interceptions.AddToPatchedFunctions(L"kernel32.dll", "CreateFileEx", |
| 230 INTERCEPTION_EAT, function, OPEN_FILE_ID); | 230 INTERCEPTION_EAT, function, OPEN_FILE_ID); |
| 231 interceptions.AddToUnloadModules(L"some02.dll"); | 231 interceptions.AddToUnloadModules(L"some02.dll"); |
| 232 interceptions.AddToPatchedFunctions(L"kernel32.dll", "SomeFileEx", | 232 interceptions.AddToPatchedFunctions(L"kernel32.dll", "SomeFileEx", |
| 233 INTERCEPTION_SMART_SIDESTEP, function, | 233 INTERCEPTION_SMART_SIDESTEP, function, |
| 234 OPEN_FILE_ID); | 234 OPEN_FILE_ID); |
| 235 // Verify that all interceptions were added | 235 // Verify that all interceptions were added |
| 236 ASSERT_EQ(5u, interceptions.interceptions_.size()); | 236 ASSERT_EQ(5u, interceptions.interceptions_.size()); |
| 237 | 237 |
| 238 size_t buffer_size = interceptions.GetBufferSize(); | 238 size_t buffer_size = interceptions.GetBufferSize(); |
| 239 scoped_ptr<BYTE[]> local_buffer(new BYTE[buffer_size]); | 239 std::unique_ptr<BYTE[]> local_buffer(new BYTE[buffer_size]); |
| 240 | 240 |
| 241 ASSERT_TRUE(interceptions.SetupConfigBuffer(local_buffer.get(), | 241 ASSERT_TRUE(interceptions.SetupConfigBuffer(local_buffer.get(), |
| 242 buffer_size)); | 242 buffer_size)); |
| 243 | 243 |
| 244 // At this point, the interceptions should have been separated into two | 244 // At this point, the interceptions should have been separated into two |
| 245 // groups: one group with the local ("cold") interceptions, and another | 245 // groups: one group with the local ("cold") interceptions, and another |
| 246 // group with the interceptions belonging to dlls that will be "hot" | 246 // group with the interceptions belonging to dlls that will be "hot" |
| 247 // patched on the client. The second group lives on local_buffer, and the | 247 // patched on the client. The second group lives on local_buffer, and the |
| 248 // first group remains on the list of interceptions, in this case just one. | 248 // first group remains on the list of interceptions, in this case just one. |
| 249 EXPECT_EQ(1u, interceptions.interceptions_.size()); | 249 EXPECT_EQ(1u, interceptions.interceptions_.size()); |
| 250 | 250 |
| 251 int num_dlls, num_functions, num_names; | 251 int num_dlls, num_functions, num_names; |
| 252 WalkBuffer(local_buffer.get(), buffer_size, &num_dlls, &num_functions, | 252 WalkBuffer(local_buffer.get(), buffer_size, &num_dlls, &num_functions, |
| 253 &num_names); | 253 &num_names); |
| 254 | 254 |
| 255 EXPECT_EQ(3, num_dlls); | 255 EXPECT_EQ(3, num_dlls); |
| 256 EXPECT_EQ(4, num_functions); | 256 EXPECT_EQ(4, num_functions); |
| 257 EXPECT_EQ(0, num_names); | 257 EXPECT_EQ(0, num_names); |
| 258 } | 258 } |
| 259 | 259 |
| 260 } // namespace sandbox | 260 } // namespace sandbox |
| OLD | NEW |