| 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 <assert.h> | 7 #include <assert.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 page_executable = page_executable && VirtualProtect(&g_thunk_storage, | 379 page_executable = page_executable && VirtualProtect(&g_thunk_storage, |
| 380 sizeof(g_thunk_storage), | 380 sizeof(g_thunk_storage), |
| 381 PAGE_EXECUTE_READ, | 381 PAGE_EXECUTE_READ, |
| 382 &old_protect); | 382 &old_protect); |
| 383 | 383 |
| 384 AddDllsFromRegistryToBlacklist(); | 384 AddDllsFromRegistryToBlacklist(); |
| 385 | 385 |
| 386 return NT_SUCCESS(ret) && page_executable; | 386 return NT_SUCCESS(ret) && page_executable; |
| 387 } | 387 } |
| 388 | 388 |
| 389 bool AddDllsFromRegistryToBlacklist() { | 389 void AddDllsFromRegistryToBlacklist() { |
| 390 HKEY key = NULL; | 390 HKEY key = NULL; |
| 391 LONG result = ::RegOpenKeyEx(HKEY_CURRENT_USER, | 391 LONG result = ::RegOpenKeyEx(HKEY_CURRENT_USER, |
| 392 kRegistryFinchListPath, | 392 kRegistryFinchListPath, |
| 393 0, | 393 0, |
| 394 KEY_QUERY_VALUE | KEY_SET_VALUE, | 394 KEY_QUERY_VALUE | KEY_SET_VALUE, |
| 395 &key); | 395 &key); |
| 396 | 396 |
| 397 if (result != ERROR_SUCCESS) | 397 if (result != ERROR_SUCCESS) |
| 398 return false; | 398 return; |
| 399 | 399 |
| 400 // We add dlls from the registry to the blacklist, and then clear registry. | 400 // We add dlls from the registry to the blacklist. |
| 401 DWORD value_len; | 401 DWORD value_len; |
| 402 DWORD name_len = MAX_PATH; | 402 DWORD name_len = MAX_PATH; |
| 403 std::vector<wchar_t> name_buffer(name_len); | 403 std::vector<wchar_t> name_buffer(name_len); |
| 404 for (int i = 0; result == ERROR_SUCCESS; ++i) { | 404 for (int i = 0; result == ERROR_SUCCESS; ++i) { |
| 405 name_len = MAX_PATH; | 405 name_len = MAX_PATH; |
| 406 value_len = 0; | 406 value_len = 0; |
| 407 result = ::RegEnumValue( | 407 result = ::RegEnumValue( |
| 408 key, i, &name_buffer[0], &name_len, NULL, NULL, NULL, &value_len); | 408 key, i, &name_buffer[0], &name_len, NULL, NULL, NULL, &value_len); |
| 409 if (result != ERROR_SUCCESS) |
| 410 break; |
| 411 |
| 409 name_len = name_len + 1; | 412 name_len = name_len + 1; |
| 410 value_len = value_len + 1; | 413 value_len = value_len + 1; |
| 411 std::vector<wchar_t> value_buffer(value_len); | 414 std::vector<wchar_t> value_buffer(value_len); |
| 412 result = ::RegEnumValue(key, i, &name_buffer[0], &name_len, NULL, NULL, | 415 result = ::RegEnumValue(key, i, &name_buffer[0], &name_len, NULL, NULL, |
| 413 reinterpret_cast<BYTE*>(&value_buffer[0]), | 416 reinterpret_cast<BYTE*>(&value_buffer[0]), |
| 414 &value_len); | 417 &value_len); |
| 418 if (result != ERROR_SUCCESS) |
| 419 break; |
| 415 value_buffer[value_len - 1] = L'\0'; | 420 value_buffer[value_len - 1] = L'\0'; |
| 416 | 421 AddDllToBlacklist(&value_buffer[0]); |
| 417 if (result == ERROR_SUCCESS) { | |
| 418 AddDllToBlacklist(&value_buffer[0]); | |
| 419 } | |
| 420 } | 422 } |
| 421 | 423 |
| 422 // Delete the finch registry key to clear the values. | |
| 423 result = ::RegDeleteKey(key, L""); | |
| 424 | |
| 425 ::RegCloseKey(key); | 424 ::RegCloseKey(key); |
| 426 return result == ERROR_SUCCESS; | 425 return; |
| 427 } | 426 } |
| 428 | 427 |
| 429 } // namespace blacklist | 428 } // namespace blacklist |
| OLD | NEW |