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 #include "sandbox/win/src/win_utils.h" | 5 #include "sandbox/win/src/win_utils.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
| 10 #include <memory> |
10 | 11 |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/win/pe_image.h" | 14 #include "base/win/pe_image.h" |
15 #include "sandbox/win/src/internal_types.h" | 15 #include "sandbox/win/src/internal_types.h" |
16 #include "sandbox/win/src/nt_internals.h" | 16 #include "sandbox/win/src/nt_internals.h" |
17 #include "sandbox/win/src/sandbox_nt_util.h" | 17 #include "sandbox/win/src/sandbox_nt_util.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // Holds the information about a known registry key. | 21 // Holds the information about a known registry key. |
22 struct KnownReservedKey { | 22 struct KnownReservedKey { |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 return false; | 287 return false; |
288 | 288 |
289 bool is_nt_path = IsNTPath(temp_path, &temp_path); | 289 bool is_nt_path = IsNTPath(temp_path, &temp_path); |
290 bool added_implied_device = false; | 290 bool added_implied_device = false; |
291 if (!StartsWithDriveLetter(temp_path) && is_nt_path) { | 291 if (!StartsWithDriveLetter(temp_path) && is_nt_path) { |
292 temp_path = base::string16(kNTDotPrefix) + temp_path; | 292 temp_path = base::string16(kNTDotPrefix) + temp_path; |
293 added_implied_device = true; | 293 added_implied_device = true; |
294 } | 294 } |
295 | 295 |
296 DWORD size = MAX_PATH; | 296 DWORD size = MAX_PATH; |
297 scoped_ptr<wchar_t[]> long_path_buf(new wchar_t[size]); | 297 std::unique_ptr<wchar_t[]> long_path_buf(new wchar_t[size]); |
298 | 298 |
299 DWORD return_value = ::GetLongPathName(temp_path.c_str(), long_path_buf.get(), | 299 DWORD return_value = ::GetLongPathName(temp_path.c_str(), long_path_buf.get(), |
300 size); | 300 size); |
301 while (return_value >= size) { | 301 while (return_value >= size) { |
302 size *= 2; | 302 size *= 2; |
303 long_path_buf.reset(new wchar_t[size]); | 303 long_path_buf.reset(new wchar_t[size]); |
304 return_value = ::GetLongPathName(temp_path.c_str(), long_path_buf.get(), | 304 return_value = ::GetLongPathName(temp_path.c_str(), long_path_buf.get(), |
305 size); | 305 size); |
306 } | 306 } |
307 | 307 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 ResolveNTFunctionPtr("NtQueryObject", &NtQueryObject); | 348 ResolveNTFunctionPtr("NtQueryObject", &NtQueryObject); |
349 | 349 |
350 OBJECT_NAME_INFORMATION initial_buffer; | 350 OBJECT_NAME_INFORMATION initial_buffer; |
351 OBJECT_NAME_INFORMATION* name = &initial_buffer; | 351 OBJECT_NAME_INFORMATION* name = &initial_buffer; |
352 ULONG size = sizeof(initial_buffer); | 352 ULONG size = sizeof(initial_buffer); |
353 // Query the name information a first time to get the size of the name. | 353 // Query the name information a first time to get the size of the name. |
354 // Windows XP requires that the size of the buffer passed in here be != 0. | 354 // Windows XP requires that the size of the buffer passed in here be != 0. |
355 NTSTATUS status = NtQueryObject(handle, ObjectNameInformation, name, size, | 355 NTSTATUS status = NtQueryObject(handle, ObjectNameInformation, name, size, |
356 &size); | 356 &size); |
357 | 357 |
358 scoped_ptr<BYTE[]> name_ptr; | 358 std::unique_ptr<BYTE[]> name_ptr; |
359 if (size) { | 359 if (size) { |
360 name_ptr.reset(new BYTE[size]); | 360 name_ptr.reset(new BYTE[size]); |
361 name = reinterpret_cast<OBJECT_NAME_INFORMATION*>(name_ptr.get()); | 361 name = reinterpret_cast<OBJECT_NAME_INFORMATION*>(name_ptr.get()); |
362 | 362 |
363 // Query the name information a second time to get the name of the | 363 // Query the name information a second time to get the name of the |
364 // object referenced by the handle. | 364 // object referenced by the handle. |
365 status = NtQueryObject(handle, ObjectNameInformation, name, size, &size); | 365 status = NtQueryObject(handle, ObjectNameInformation, name, size, &size); |
366 } | 366 } |
367 | 367 |
368 if (STATUS_SUCCESS != status) | 368 if (STATUS_SUCCESS != status) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 ::InterlockedCompareExchangePointer( | 419 ::InterlockedCompareExchangePointer( |
420 reinterpret_cast<PVOID volatile*>(&ntdll), ntdll_local, NULL); | 420 reinterpret_cast<PVOID volatile*>(&ntdll), ntdll_local, NULL); |
421 | 421 |
422 } | 422 } |
423 | 423 |
424 CHECK_NT(ntdll); | 424 CHECK_NT(ntdll); |
425 FARPROC* function_ptr = reinterpret_cast<FARPROC*>(ptr); | 425 FARPROC* function_ptr = reinterpret_cast<FARPROC*>(ptr); |
426 *function_ptr = ::GetProcAddress(ntdll, name); | 426 *function_ptr = ::GetProcAddress(ntdll, name); |
427 CHECK_NT(*function_ptr); | 427 CHECK_NT(*function_ptr); |
428 } | 428 } |
OLD | NEW |