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