OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // Implementation of NtMapViewOfSection intercept for 32 bit builds. | 5 // Implementation of NtMapViewOfSection intercept for 32 bit builds. |
6 // | 6 // |
7 // TODO(robertshield): Implement the 64 bit intercept. | 7 // TODO(robertshield): Implement the 64 bit intercept. |
8 | 8 |
9 #include "chrome_elf/blacklist/blacklist_interceptions.h" | 9 #include "chrome_elf/blacklist/blacklist_interceptions.h" |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 } | 44 } |
45 | 45 |
46 // TODO(robertshield): Some of the helper functions below overlap somewhat with | 46 // TODO(robertshield): Some of the helper functions below overlap somewhat with |
47 // code in sandbox_nt_util.cc. See if they can be unified. | 47 // code in sandbox_nt_util.cc. See if they can be unified. |
48 | 48 |
49 // Native reimplementation of PSAPIs GetMappedFileName. | 49 // Native reimplementation of PSAPIs GetMappedFileName. |
50 base::string16 GetBackingModuleFilePath(PVOID address) { | 50 base::string16 GetBackingModuleFilePath(PVOID address) { |
51 DCHECK_NT(g_nt_query_virtual_memory_func); | 51 DCHECK_NT(g_nt_query_virtual_memory_func); |
52 | 52 |
53 // We'll start with something close to max_path characters for the name. | 53 // We'll start with something close to max_path characters for the name. |
54 ULONG buffer_bytes = MAX_PATH * 2; | 54 SIZE_T buffer_bytes = MAX_PATH * 2; |
55 std::vector<BYTE> buffer_data(buffer_bytes); | 55 std::vector<BYTE> buffer_data(buffer_bytes); |
56 | 56 |
57 for (;;) { | 57 for (;;) { |
58 MEMORY_SECTION_NAME* section_name = | 58 MEMORY_SECTION_NAME* section_name = |
59 reinterpret_cast<MEMORY_SECTION_NAME*>(&buffer_data[0]); | 59 reinterpret_cast<MEMORY_SECTION_NAME*>(&buffer_data[0]); |
60 | 60 |
61 if (!section_name) | 61 if (!section_name) |
62 break; | 62 break; |
63 | 63 |
64 ULONG returned_bytes; | 64 SIZE_T returned_bytes; |
65 NTSTATUS ret = g_nt_query_virtual_memory_func( | 65 NTSTATUS ret = g_nt_query_virtual_memory_func( |
66 NtCurrentProcess, address, MemorySectionName, section_name, | 66 NtCurrentProcess, address, MemorySectionName, section_name, |
67 buffer_bytes, &returned_bytes); | 67 buffer_bytes, &returned_bytes); |
68 | 68 |
69 if (STATUS_BUFFER_OVERFLOW == ret) { | 69 if (STATUS_BUFFER_OVERFLOW == ret) { |
70 // Retry the call with the given buffer size. | 70 // Retry the call with the given buffer size. |
71 buffer_bytes = returned_bytes + 1; | 71 buffer_bytes = returned_bytes + 1; |
72 buffer_data.resize(buffer_bytes); | 72 buffer_data.resize(buffer_bytes); |
73 section_name = NULL; | 73 section_name = NULL; |
74 continue; | 74 continue; |
(...skipping 13 matching lines...) Expand all Loading... |
88 bool IsModuleValidImageSection(HANDLE section, | 88 bool IsModuleValidImageSection(HANDLE section, |
89 PVOID *base, | 89 PVOID *base, |
90 PLARGE_INTEGER offset, | 90 PLARGE_INTEGER offset, |
91 PSIZE_T view_size) { | 91 PSIZE_T view_size) { |
92 DCHECK_NT(g_nt_query_section_func); | 92 DCHECK_NT(g_nt_query_section_func); |
93 | 93 |
94 if (!section || !base || !view_size || offset) | 94 if (!section || !base || !view_size || offset) |
95 return false; | 95 return false; |
96 | 96 |
97 SECTION_BASIC_INFORMATION basic_info; | 97 SECTION_BASIC_INFORMATION basic_info; |
98 SIZE_T bytes_returned; | 98 ULONG bytes_returned; |
99 NTSTATUS ret = g_nt_query_section_func(section, SectionBasicInformation, | 99 NTSTATUS ret = g_nt_query_section_func(section, SectionBasicInformation, |
100 &basic_info, sizeof(basic_info), | 100 &basic_info, sizeof(basic_info), |
101 &bytes_returned); | 101 &bytes_returned); |
102 | 102 |
103 if (!NT_SUCCESS(ret) || sizeof(basic_info) != bytes_returned) | 103 if (!NT_SUCCESS(ret) || sizeof(basic_info) != bytes_returned) |
104 return false; | 104 return false; |
105 | 105 |
106 if (!(basic_info.Attributes & SEC_IMAGE)) | 106 if (!(basic_info.Attributes & SEC_IMAGE)) |
107 return false; | 107 return false; |
108 | 108 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 NTSTATUS WINAPI BlNtMapViewOfSection64( | 267 NTSTATUS WINAPI BlNtMapViewOfSection64( |
268 HANDLE section, HANDLE process, PVOID *base, ULONG_PTR zero_bits, | 268 HANDLE section, HANDLE process, PVOID *base, ULONG_PTR zero_bits, |
269 SIZE_T commit_size, PLARGE_INTEGER offset, PSIZE_T view_size, | 269 SIZE_T commit_size, PLARGE_INTEGER offset, PSIZE_T view_size, |
270 SECTION_INHERIT inherit, ULONG allocation_type, ULONG protect) { | 270 SECTION_INHERIT inherit, ULONG allocation_type, ULONG protect) { |
271 return BlNtMapViewOfSection(g_nt_map_view_of_section_func, section, process, | 271 return BlNtMapViewOfSection(g_nt_map_view_of_section_func, section, process, |
272 base, zero_bits, commit_size, offset, view_size, | 272 base, zero_bits, commit_size, offset, view_size, |
273 inherit, allocation_type, protect); | 273 inherit, allocation_type, protect); |
274 } | 274 } |
275 #endif | 275 #endif |
276 } // namespace blacklist | 276 } // namespace blacklist |
OLD | NEW |