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 #include "sandbox/win/src/sandbox_nt_util.h" | 5 #include "sandbox/win/src/sandbox_nt_util.h" |
6 | 6 |
7 #include "base/win/pe_image.h" | 7 #include "base/win/pe_image.h" |
8 #include "sandbox/win/src/sandbox_factory.h" | 8 #include "sandbox/win/src/sandbox_factory.h" |
9 #include "sandbox/win/src/target_services.h" | 9 #include "sandbox/win/src/target_services.h" |
10 | 10 |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 | 378 |
379 HANDLE query_section; | 379 HANDLE query_section; |
380 | 380 |
381 NTSTATUS ret = g_nt.DuplicateObject(NtCurrentProcess, section, | 381 NTSTATUS ret = g_nt.DuplicateObject(NtCurrentProcess, section, |
382 NtCurrentProcess, &query_section, | 382 NtCurrentProcess, &query_section, |
383 SECTION_QUERY, 0, 0); | 383 SECTION_QUERY, 0, 0); |
384 if (!NT_SUCCESS(ret)) | 384 if (!NT_SUCCESS(ret)) |
385 return false; | 385 return false; |
386 | 386 |
387 SECTION_BASIC_INFORMATION basic_info; | 387 SECTION_BASIC_INFORMATION basic_info; |
388 SIZE_T bytes_returned; | 388 ULONG bytes_returned; |
389 ret = g_nt.QuerySection(query_section, SectionBasicInformation, &basic_info, | 389 ret = g_nt.QuerySection(query_section, SectionBasicInformation, &basic_info, |
390 sizeof(basic_info), &bytes_returned); | 390 sizeof(basic_info), &bytes_returned); |
391 | 391 |
392 VERIFY_SUCCESS(g_nt.Close(query_section)); | 392 VERIFY_SUCCESS(g_nt.Close(query_section)); |
393 | 393 |
394 if (!NT_SUCCESS(ret) || sizeof(basic_info) != bytes_returned) | 394 if (!NT_SUCCESS(ret) || sizeof(basic_info) != bytes_returned) |
395 return false; | 395 return false; |
396 | 396 |
397 if (!(basic_info.Attributes & SEC_IMAGE)) | 397 if (!(basic_info.Attributes & SEC_IMAGE)) |
398 return false; | 398 return false; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 } while (false); | 462 } while (false); |
463 } __except(EXCEPTION_EXECUTE_HANDLER) { | 463 } __except(EXCEPTION_EXECUTE_HANDLER) { |
464 } | 464 } |
465 | 465 |
466 return out_name; | 466 return out_name; |
467 #pragma warning(pop) | 467 #pragma warning(pop) |
468 } | 468 } |
469 | 469 |
470 UNICODE_STRING* GetBackingFilePath(PVOID address) { | 470 UNICODE_STRING* GetBackingFilePath(PVOID address) { |
471 // We'll start with something close to max_path charactes for the name. | 471 // We'll start with something close to max_path charactes for the name. |
472 ULONG buffer_bytes = MAX_PATH * 2; | 472 SIZE_T buffer_bytes = MAX_PATH * 2; |
473 | 473 |
474 for (;;) { | 474 for (;;) { |
475 MEMORY_SECTION_NAME* section_name = reinterpret_cast<MEMORY_SECTION_NAME*>( | 475 MEMORY_SECTION_NAME* section_name = reinterpret_cast<MEMORY_SECTION_NAME*>( |
476 new(NT_ALLOC) char[buffer_bytes]); | 476 new(NT_ALLOC) char[buffer_bytes]); |
477 | 477 |
478 if (!section_name) | 478 if (!section_name) |
479 return NULL; | 479 return NULL; |
480 | 480 |
481 ULONG returned_bytes; | 481 SIZE_T returned_bytes; |
482 NTSTATUS ret = g_nt.QueryVirtualMemory(NtCurrentProcess, address, | 482 NTSTATUS ret = g_nt.QueryVirtualMemory(NtCurrentProcess, address, |
483 MemorySectionName, section_name, | 483 MemorySectionName, section_name, |
484 buffer_bytes, &returned_bytes); | 484 buffer_bytes, &returned_bytes); |
485 | 485 |
486 if (STATUS_BUFFER_OVERFLOW == ret) { | 486 if (STATUS_BUFFER_OVERFLOW == ret) { |
487 // Retry the call with the given buffer size. | 487 // Retry the call with the given buffer size. |
488 operator delete(section_name, NT_ALLOC); | 488 operator delete(section_name, NT_ALLOC); |
489 section_name = NULL; | 489 section_name = NULL; |
490 buffer_bytes = returned_bytes; | 490 buffer_bytes = returned_bytes; |
491 continue; | 491 continue; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 UNREFERENCED_PARAMETER(type); | 670 UNREFERENCED_PARAMETER(type); |
671 return buffer; | 671 return buffer; |
672 } | 672 } |
673 | 673 |
674 void __cdecl operator delete(void* memory, void* buffer, | 674 void __cdecl operator delete(void* memory, void* buffer, |
675 sandbox::AllocationType type) { | 675 sandbox::AllocationType type) { |
676 UNREFERENCED_PARAMETER(memory); | 676 UNREFERENCED_PARAMETER(memory); |
677 UNREFERENCED_PARAMETER(buffer); | 677 UNREFERENCED_PARAMETER(buffer); |
678 UNREFERENCED_PARAMETER(type); | 678 UNREFERENCED_PARAMETER(type); |
679 } | 679 } |
OLD | NEW |