| OLD | NEW |
| 1 // Copyright (c) 2011 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 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 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 (*num_dlls)++; | 72 (*num_dlls)++; |
| 73 dll = reinterpret_cast<DllPatchInfo*>(reinterpret_cast<char*>(dll) + | 73 dll = reinterpret_cast<DllPatchInfo*>(reinterpret_cast<char*>(dll) + |
| 74 dll->record_bytes); | 74 dll->record_bytes); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 TEST(InterceptionManagerTest, BufferLayout1) { | 78 TEST(InterceptionManagerTest, BufferLayout1) { |
| 79 wchar_t exe_name[MAX_PATH]; | 79 wchar_t exe_name[MAX_PATH]; |
| 80 ASSERT_NE(0u, GetModuleFileName(NULL, exe_name, MAX_PATH - 1)); | 80 ASSERT_NE(0u, GetModuleFileName(NULL, exe_name, MAX_PATH - 1)); |
| 81 | 81 |
| 82 TargetProcess *target = MakeTestTargetProcess(::GetCurrentProcess(), | 82 base::win::ScopedHandle current_process; |
| 83 ASSERT_TRUE( |
| 84 ::DuplicateHandle(::GetCurrentProcess(), ::GetCurrentProcess(), |
| 85 ::GetCurrentProcess(), current_process.Receive(), |
| 86 0, FALSE, DUPLICATE_SAME_ACCESS)); |
| 87 |
| 88 TargetProcess *target = MakeTestTargetProcess(current_process.Take(), |
| 83 ::GetModuleHandle(exe_name)); | 89 ::GetModuleHandle(exe_name)); |
| 84 | 90 |
| 85 InterceptionManager interceptions(target, true); | 91 InterceptionManager interceptions(target, true); |
| 86 | 92 |
| 87 // Any pointer will do for a function pointer. | 93 // Any pointer will do for a function pointer. |
| 88 void* function = &interceptions; | 94 void* function = &interceptions; |
| 89 | 95 |
| 90 // We don't care about the interceptor id. | 96 // We don't care about the interceptor id. |
| 91 interceptions.AddToPatchedFunctions(L"ntdll.dll", "NtCreateFile", | 97 interceptions.AddToPatchedFunctions(L"ntdll.dll", "NtCreateFile", |
| 92 INTERCEPTION_SERVICE_CALL, function, | 98 INTERCEPTION_SERVICE_CALL, function, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // interceptor function. | 165 // interceptor function. |
| 160 EXPECT_EQ(6, num_dlls); | 166 EXPECT_EQ(6, num_dlls); |
| 161 EXPECT_EQ(15, num_functions); | 167 EXPECT_EQ(15, num_functions); |
| 162 EXPECT_EQ(4, num_names); | 168 EXPECT_EQ(4, num_names); |
| 163 } | 169 } |
| 164 | 170 |
| 165 TEST(InterceptionManagerTest, BufferLayout2) { | 171 TEST(InterceptionManagerTest, BufferLayout2) { |
| 166 wchar_t exe_name[MAX_PATH]; | 172 wchar_t exe_name[MAX_PATH]; |
| 167 ASSERT_NE(0u, GetModuleFileName(NULL, exe_name, MAX_PATH - 1)); | 173 ASSERT_NE(0u, GetModuleFileName(NULL, exe_name, MAX_PATH - 1)); |
| 168 | 174 |
| 169 TargetProcess *target = MakeTestTargetProcess(::GetCurrentProcess(), | 175 base::win::ScopedHandle current_process; |
| 176 ASSERT_TRUE( |
| 177 ::DuplicateHandle(::GetCurrentProcess(), ::GetCurrentProcess(), |
| 178 ::GetCurrentProcess(), current_process.Receive(), |
| 179 0, FALSE, DUPLICATE_SAME_ACCESS)); |
| 180 |
| 181 TargetProcess *target = MakeTestTargetProcess(current_process.Take(), |
| 170 ::GetModuleHandle(exe_name)); | 182 ::GetModuleHandle(exe_name)); |
| 171 | 183 |
| 172 InterceptionManager interceptions(target, true); | 184 InterceptionManager interceptions(target, true); |
| 173 | 185 |
| 174 // Any pointer will do for a function pointer. | 186 // Any pointer will do for a function pointer. |
| 175 void* function = &interceptions; | 187 void* function = &interceptions; |
| 176 interceptions.AddToUnloadModules(L"some01.dll"); | 188 interceptions.AddToUnloadModules(L"some01.dll"); |
| 177 // We don't care about the interceptor id. | 189 // We don't care about the interceptor id. |
| 178 interceptions.AddToPatchedFunctions(L"ntdll.dll", "NtCreateFile", | 190 interceptions.AddToPatchedFunctions(L"ntdll.dll", "NtCreateFile", |
| 179 INTERCEPTION_SERVICE_CALL, function, | 191 INTERCEPTION_SERVICE_CALL, function, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 203 int num_dlls, num_functions, num_names; | 215 int num_dlls, num_functions, num_names; |
| 204 WalkBuffer(local_buffer.get(), buffer_size, &num_dlls, &num_functions, | 216 WalkBuffer(local_buffer.get(), buffer_size, &num_dlls, &num_functions, |
| 205 &num_names); | 217 &num_names); |
| 206 | 218 |
| 207 EXPECT_EQ(3, num_dlls); | 219 EXPECT_EQ(3, num_dlls); |
| 208 EXPECT_EQ(4, num_functions); | 220 EXPECT_EQ(4, num_functions); |
| 209 EXPECT_EQ(0, num_names); | 221 EXPECT_EQ(0, num_names); |
| 210 } | 222 } |
| 211 | 223 |
| 212 } // namespace sandbox | 224 } // namespace sandbox |
| OLD | NEW |