Chromium Code Reviews| Index: chrome_elf/blacklist/blacklist.cc |
| diff --git a/chrome_elf/blacklist/blacklist.cc b/chrome_elf/blacklist/blacklist.cc |
| index a168c9a044c4ff0a5a54efa57eeeb6556ddcab3b..e68bf2f04de25fffe8089cdbdac3277e59baf81c 100644 |
| --- a/chrome_elf/blacklist/blacklist.cc |
| +++ b/chrome_elf/blacklist/blacklist.cc |
| @@ -7,6 +7,8 @@ |
| #include <assert.h> |
| #include <string.h> |
| +#include <vector> |
| + |
| #include "base/basictypes.h" |
| #include "chrome_elf/blacklist/blacklist_interceptions.h" |
| #include "chrome_elf/chrome_elf_constants.h" |
| @@ -342,7 +344,61 @@ bool Initialize(bool force) { |
| RecordSuccessfulThunkSetup(&key); |
| + AddDllsFromRegistryToBlacklist(); |
| + |
| return NT_SUCCESS(ret) && page_executable; |
| } |
| +bool AddDllsFromRegistryToBlacklist() { |
| + HKEY key = NULL; |
| + LONG result = ::RegOpenKeyEx(HKEY_CURRENT_USER, |
| + kRegistryFinchListPath, |
| + 0, |
| + KEY_QUERY_VALUE | KEY_SET_VALUE, |
| + &key); |
| + |
| + if (result != ERROR_SUCCESS) |
| + return false; |
| + |
| + int num_dlls = 0; |
| + int longest_name = 0; |
| + ::RegQueryInfoKey(key, NULL, NULL, NULL, NULL, NULL, NULL, |
| + reinterpret_cast<DWORD*>(&num_dlls), |
| + reinterpret_cast<DWORD*>(&longest_name), |
| + NULL, NULL, NULL); |
| + |
| + // Collect dlls so that we can delete them after the enumeration. |
| + std::vector<std::wstring> dll_names; |
| + for (int i = 0; i < num_dlls; ++i) { |
| + DWORD name_len = longest_name + 1; |
| + DWORD value_len = 0; |
| + assert(name_len > 0); |
| + std::vector<wchar_t> name_buffer(name_len); |
| + result = ::RegEnumValue( |
| + key, i, &name_buffer[0], &name_len, NULL, NULL, NULL, &value_len); |
| + name_len = name_len + 1; |
| + value_len = value_len + 1; |
| + assert(value_len > 0); |
| + std::vector<wchar_t> value_buffer(value_len); |
| + result = ::RegEnumValue(key, i, &name_buffer[0], &name_len, NULL, NULL, |
|
robertshield
2014/06/03 03:03:00
name_len was increased by 1 on line 379, but I don
|
| + reinterpret_cast<BYTE*>(&value_buffer[0]), |
| + &value_len); |
| + value_buffer[value_len] = L'\0'; |
|
robertshield
2014/06/03 03:03:00
if value_buffer.size() is value_len, then the last
krstnmnlsn
2014/06/03 19:30:16
Done.
|
| + |
| + if (result == ERROR_SUCCESS) { |
| + AddDllToBlacklist(&value_buffer[0]); |
| + } |
| + |
| + std::wstring name_str(name_buffer.begin(), name_buffer.end()); |
| + dll_names.push_back(name_str); |
|
robertshield
2014/06/03 03:03:00
nit:
dll_names.push_back(std::wstring(name_buffer.
krstnmnlsn
2014/06/03 19:30:16
Done.
|
| + } |
| + |
| + for (int i = 0; i < num_dlls; ++i) { |
| + ::RegDeleteValue(key, dll_names[i].c_str()); |
| + } |
| + |
| + ::RegCloseKey(key); |
| + return true; |
| +} |
| + |
| } // namespace blacklist |