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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 NTSTATUS ret = STATUS_UNSUCCESSFUL; | 299 NTSTATUS ret = STATUS_UNSUCCESSFUL; |
300 __try { | 300 __try { |
301 do { | 301 do { |
302 if (in_object->RootDirectory != static_cast<HANDLE>(0) && !root) | 302 if (in_object->RootDirectory != static_cast<HANDLE>(0) && !root) |
303 break; | 303 break; |
304 if (NULL == in_object->ObjectName) | 304 if (NULL == in_object->ObjectName) |
305 break; | 305 break; |
306 if (NULL == in_object->ObjectName->Buffer) | 306 if (NULL == in_object->ObjectName->Buffer) |
307 break; | 307 break; |
308 | 308 |
309 size_t size = in_object->ObjectName->Length + sizeof(wchar_t); | 309 ret = AllocAndCopyUnicodeString(in_object->ObjectName, out_name); |
310 *out_name = new(NT_ALLOC) wchar_t[size/sizeof(wchar_t)]; | |
311 if (NULL == *out_name) | |
312 break; | |
313 | |
314 ret = CopyData(*out_name, in_object->ObjectName->Buffer, | |
315 size - sizeof(wchar_t)); | |
316 if (!NT_SUCCESS(ret)) | 310 if (!NT_SUCCESS(ret)) |
317 break; | 311 break; |
318 | 312 |
319 (*out_name)[size / sizeof(wchar_t) - 1] = L'\0'; | |
320 | |
321 if (attributes) | 313 if (attributes) |
322 *attributes = in_object->Attributes; | 314 *attributes = in_object->Attributes; |
323 | 315 |
324 if (root) | 316 if (root) |
325 *root = in_object->RootDirectory; | 317 *root = in_object->RootDirectory; |
326 ret = STATUS_SUCCESS; | 318 ret = STATUS_SUCCESS; |
327 } while (false); | 319 } while (false); |
328 } __except(EXCEPTION_EXECUTE_HANDLER) { | 320 } __except(EXCEPTION_EXECUTE_HANDLER) { |
329 ret = GetExceptionCode(); | 321 ret = GetExceptionCode(); |
330 } | 322 } |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 | 602 |
611 if (file_info->FileName[0] != kPathPrefix[0] || | 603 if (file_info->FileName[0] != kPathPrefix[0] || |
612 file_info->FileName[1] != kPathPrefix[1] || | 604 file_info->FileName[1] != kPathPrefix[1] || |
613 file_info->FileName[2] != kPathPrefix[2] || | 605 file_info->FileName[2] != kPathPrefix[2] || |
614 file_info->FileName[3] != kPathPrefix[3]) | 606 file_info->FileName[3] != kPathPrefix[3]) |
615 return false; | 607 return false; |
616 | 608 |
617 return true; | 609 return true; |
618 } | 610 } |
619 | 611 |
| 612 NTSTATUS AllocAndCopyUnicodeString(const UNICODE_STRING* in_string, |
| 613 wchar_t** out_string) { |
| 614 if (!in_string) |
| 615 return STATUS_INVALID_PARAMETER; |
| 616 |
| 617 size_t size = in_string->Length + sizeof(wchar_t); |
| 618 *out_string = new(NT_ALLOC) wchar_t[size/sizeof(wchar_t)]; |
| 619 if (NULL == *out_string) |
| 620 return STATUS_UNSUCCESSFUL; |
| 621 |
| 622 NTSTATUS ret = CopyData(*out_string, in_string->Buffer, |
| 623 size - sizeof(wchar_t)); |
| 624 if (!NT_SUCCESS(ret)) |
| 625 return ret; |
| 626 |
| 627 (*out_string)[size / sizeof(wchar_t) - 1] = L'\0'; |
| 628 return STATUS_SUCCESS; |
| 629 } |
| 630 |
620 } // namespace sandbox | 631 } // namespace sandbox |
621 | 632 |
622 void* operator new(size_t size, sandbox::AllocationType type, | 633 void* operator new(size_t size, sandbox::AllocationType type, |
623 void* near_to) { | 634 void* near_to) { |
624 using namespace sandbox; | 635 using namespace sandbox; |
625 | 636 |
626 void* result = NULL; | 637 void* result = NULL; |
627 if (NT_ALLOC == type) { | 638 if (NT_ALLOC == type) { |
628 if (InitHeap()) { | 639 if (InitHeap()) { |
629 // Use default flags for the allocation. | 640 // Use default flags for the allocation. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 UNREFERENCED_PARAMETER(type); | 681 UNREFERENCED_PARAMETER(type); |
671 return buffer; | 682 return buffer; |
672 } | 683 } |
673 | 684 |
674 void __cdecl operator delete(void* memory, void* buffer, | 685 void __cdecl operator delete(void* memory, void* buffer, |
675 sandbox::AllocationType type) { | 686 sandbox::AllocationType type) { |
676 UNREFERENCED_PARAMETER(memory); | 687 UNREFERENCED_PARAMETER(memory); |
677 UNREFERENCED_PARAMETER(buffer); | 688 UNREFERENCED_PARAMETER(buffer); |
678 UNREFERENCED_PARAMETER(type); | 689 UNREFERENCED_PARAMETER(type); |
679 } | 690 } |
OLD | NEW |