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 <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "chrome/install_static/install_util.h" | 9 #include "chrome/install_static/install_util.h" |
10 #include "chrome_elf/nt_registry/nt_registry.h" | 10 #include "chrome_elf/nt_registry/nt_registry.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 void GetIpcOverrides() { | 14 void GetIpcOverrides() { |
15 DWORD buffer_size = ::GetEnvironmentVariableW(L"hkcu_override", nullptr, 0); | 15 DWORD buffer_size = ::GetEnvironmentVariableW(L"hkcu_override", nullptr, 0); |
16 if (buffer_size > 0) { | 16 if (buffer_size > 0) { |
17 wchar_t* content = new wchar_t[buffer_size]; | 17 std::wstring content; |
grt (UTC plus 2)
2016/09/30 09:32:16
nit: construct the string with the desired size:
penny
2016/10/01 01:44:25
Nice one. It's unfortunate there's no constructor
grt (UTC plus 2)
2016/10/02 20:10:54
resize(buffer_size) zero-fills it as well, so the
| |
18 content.resize(buffer_size); | |
18 buffer_size = | 19 buffer_size = |
19 ::GetEnvironmentVariableW(L"hkcu_override", content, buffer_size); | 20 ::GetEnvironmentVariableW(L"hkcu_override", &content[0], buffer_size); |
20 if (buffer_size) | 21 if (buffer_size) |
21 ::wcsncpy(nt::HKCU_override, content, nt::g_kRegMaxPathLen - 1); | 22 nt::SetTestingOverride(nt::HKCU, content); |
22 delete[] content; | |
23 } | 23 } |
24 | 24 |
25 buffer_size = ::GetEnvironmentVariableW(L"hklm_override", nullptr, 0); | 25 buffer_size = ::GetEnvironmentVariableW(L"hklm_override", nullptr, 0); |
26 if (buffer_size > 0) { | 26 if (buffer_size > 0) { |
27 wchar_t* content = new wchar_t[buffer_size]; | 27 std::wstring content; |
28 content.resize(buffer_size); | |
28 buffer_size = | 29 buffer_size = |
29 ::GetEnvironmentVariableW(L"hklm_override", content, buffer_size); | 30 ::GetEnvironmentVariableW(L"hklm_override", &content[0], buffer_size); |
30 if (buffer_size) | 31 if (buffer_size) |
31 ::wcsncpy(nt::HKLM_override, content, nt::g_kRegMaxPathLen - 1); | 32 nt::SetTestingOverride(nt::HKLM, content); |
32 delete[] content; | |
33 } | 33 } |
34 | 34 |
35 return; | 35 return; |
36 } | 36 } |
37 | 37 |
38 } // namespace | 38 } // namespace |
39 | 39 |
40 extern "C" __declspec(dllexport) void InitTestDll() { | 40 extern "C" __declspec(dllexport) void InitTestDll() { |
41 // Make sure we've got the latest registry overrides. | 41 // Make sure we've got the latest registry overrides. |
42 GetIpcOverrides(); | 42 GetIpcOverrides(); |
43 } | 43 } |
44 | 44 |
45 BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) { | 45 BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) { |
46 if (reason == DLL_PROCESS_ATTACH) { | 46 if (reason == DLL_PROCESS_ATTACH) { |
47 GetIpcOverrides(); | 47 GetIpcOverrides(); |
48 install_static::InitializeProcessType(); | 48 install_static::InitializeProcessType(); |
49 blacklist::Initialize(true); // force always on, no beacon | 49 blacklist::Initialize(true); // force always on, no beacon |
50 } | 50 } |
51 | 51 |
52 return TRUE; | 52 return TRUE; |
53 } | 53 } |
OLD | NEW |