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 #include "chrome_elf/blacklist/blacklist.h" | 5 #include "chrome_elf/blacklist/blacklist.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "chrome_elf/blacklist/blacklist_interceptions.h" | 10 #include "chrome_elf/blacklist/blacklist_interceptions.h" |
11 #include "sandbox/win/src/interception_internal.h" | 11 #include "sandbox/win/src/interception_internal.h" |
12 #include "sandbox/win/src/internal_types.h" | 12 #include "sandbox/win/src/internal_types.h" |
13 #include "sandbox/win/src/sandbox_utils.h" | 13 #include "sandbox/win/src/sandbox_utils.h" |
14 #include "sandbox/win/src/service_resolver.h" | 14 #include "sandbox/win/src/service_resolver.h" |
15 #include "version.h" // NOLINT | 15 #include "version.h" // NOLINT |
16 | 16 |
17 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx | 17 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
18 extern "C" IMAGE_DOS_HEADER __ImageBase; | 18 extern "C" IMAGE_DOS_HEADER __ImageBase; |
19 | 19 |
20 namespace blacklist{ | 20 namespace blacklist{ |
21 | 21 |
22 const wchar_t* g_troublesome_dlls[kTroublesomeDllsMaxCount] = {}; | 22 const wchar_t* g_troublesome_dlls[kTroublesomeDllsMaxCount] = { |
23 int g_troublesome_dlls_cur_index = 0; | 23 // Keep this null pointer here to mark the end of the list. |
| 24 NULL, |
| 25 }; |
24 | 26 |
25 const wchar_t kRegistryBeaconPath[] = L"SOFTWARE\\Google\\Chrome\\BLBeacon"; | 27 const wchar_t kRegistryBeaconPath[] = L"SOFTWARE\\Google\\Chrome\\BLBeacon"; |
26 const wchar_t kBeaconVersion[] = L"version"; | 28 const wchar_t kBeaconVersion[] = L"version"; |
27 const wchar_t kBeaconState[] = L"state"; | 29 const wchar_t kBeaconState[] = L"state"; |
28 | 30 |
29 } // namespace blacklist | 31 } // namespace blacklist |
30 | 32 |
31 // Allocate storage for thunks in a page of this module to save on doing | 33 // Allocate storage for thunks in a page of this module to save on doing |
32 // an extra allocation at run time. | 34 // an extra allocation at run time. |
33 #pragma section(".crthunk",read,execute) | 35 #pragma section(".crthunk",read,execute) |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 kBeaconState, | 228 kBeaconState, |
227 0, | 229 0, |
228 REG_DWORD, | 230 REG_DWORD, |
229 reinterpret_cast<LPBYTE>(&blacklist_state), | 231 reinterpret_cast<LPBYTE>(&blacklist_state), |
230 sizeof(blacklist_state)); | 232 sizeof(blacklist_state)); |
231 ::RegCloseKey(key); | 233 ::RegCloseKey(key); |
232 | 234 |
233 return (result == ERROR_SUCCESS); | 235 return (result == ERROR_SUCCESS); |
234 } | 236 } |
235 | 237 |
| 238 int BlacklistSize() { |
| 239 int size = -1; |
| 240 while(blacklist::g_troublesome_dlls[++size] != NULL); |
| 241 |
| 242 return size; |
| 243 } |
| 244 |
236 bool AddDllToBlacklist(const wchar_t* dll_name) { | 245 bool AddDllToBlacklist(const wchar_t* dll_name) { |
237 if (g_troublesome_dlls_cur_index >= kTroublesomeDllsMaxCount) | 246 int blacklist_size = BlacklistSize(); |
| 247 // We need to leave one space at the end for the null pointer. |
| 248 if (blacklist_size + 1 >= kTroublesomeDllsMaxCount) |
238 return false; | 249 return false; |
239 for (int i = 0; i < g_troublesome_dlls_cur_index; ++i) { | 250 for (int i=0; i < blacklist_size; ++i) { |
240 if (!wcscmp(g_troublesome_dlls[i], dll_name)) | 251 if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) |
241 return true; | 252 return true; |
242 } | 253 } |
243 | 254 |
244 // Copy string to blacklist. | 255 // Copy string to blacklist. |
245 wchar_t* str_buffer = new wchar_t[wcslen(dll_name) + 1]; | 256 wchar_t* str_buffer = new wchar_t[wcslen(dll_name) + 1]; |
246 wcscpy(str_buffer, dll_name); | 257 wcscpy(str_buffer, dll_name); |
247 | 258 |
248 g_troublesome_dlls[g_troublesome_dlls_cur_index] = str_buffer; | 259 g_troublesome_dlls[blacklist_size] = str_buffer; |
249 g_troublesome_dlls_cur_index++; | |
250 return true; | 260 return true; |
251 } | 261 } |
252 | 262 |
253 bool RemoveDllFromBlacklist(const wchar_t* dll_name) { | 263 bool RemoveDllFromBlacklist(const wchar_t* dll_name) { |
254 for (int i = 0; i < g_troublesome_dlls_cur_index; ++i) { | 264 int blacklist_size = BlacklistSize(); |
255 if (!wcscmp(g_troublesome_dlls[i], dll_name)) { | 265 for (int i = 0; i < blacklist_size; ++i) { |
| 266 if (!_wcsicmp(g_troublesome_dlls[i], dll_name)) { |
256 // Found the thing to remove. Delete it then replace it with the last | 267 // Found the thing to remove. Delete it then replace it with the last |
257 // element. | 268 // element. |
258 g_troublesome_dlls_cur_index--; | |
259 delete[] g_troublesome_dlls[i]; | 269 delete[] g_troublesome_dlls[i]; |
260 g_troublesome_dlls[i] = g_troublesome_dlls[g_troublesome_dlls_cur_index]; | 270 g_troublesome_dlls[i] = g_troublesome_dlls[blacklist_size - 1]; |
261 g_troublesome_dlls[g_troublesome_dlls_cur_index] = NULL; | 271 g_troublesome_dlls[blacklist_size - 1] = NULL; |
262 return true; | 272 return true; |
263 } | 273 } |
264 } | 274 } |
265 return false; | 275 return false; |
266 } | 276 } |
267 | 277 |
268 bool Initialize(bool force) { | 278 bool Initialize(bool force) { |
269 #if defined(_WIN64) | 279 #if defined(_WIN64) |
270 // TODO(robertshield): Implement 64-bit support by providing 64-bit | 280 // TODO(robertshield): Implement 64-bit support by providing 64-bit |
271 // interceptors. | 281 // interceptors. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 // Mark the thunk storage as executable and prevent any future writes to it. | 351 // Mark the thunk storage as executable and prevent any future writes to it. |
342 BOOL page_executable = VirtualProtect(&g_thunk_storage, | 352 BOOL page_executable = VirtualProtect(&g_thunk_storage, |
343 sizeof(g_thunk_storage), | 353 sizeof(g_thunk_storage), |
344 PAGE_EXECUTE_READ, | 354 PAGE_EXECUTE_READ, |
345 &old_protect); | 355 &old_protect); |
346 | 356 |
347 return NT_SUCCESS(ret) && page_executable; | 357 return NT_SUCCESS(ret) && page_executable; |
348 } | 358 } |
349 | 359 |
350 } // namespace blacklist | 360 } // namespace blacklist |
OLD | NEW |