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" | |
6 | |
5 #include <windows.h> | 7 #include <windows.h> |
6 | 8 |
7 #include "chrome_elf/blacklist/blacklist.h" | 9 #include "base/files/file.h" |
10 #include "base/files/scoped_temp_dir.h" | |
11 #include "base/path_service.h" | |
12 #include "chrome_elf/chrome_elf_reg.h" | |
8 #include "chrome_elf/chrome_elf_util.h" | 13 #include "chrome_elf/chrome_elf_util.h" |
9 | 14 |
10 extern "C" void InitBlacklistTestDll() { | 15 namespace { |
16 | |
17 void GetIpcOverrides() { | |
robertshield
2016/04/20 15:45:47
thinking about this, it looks like the test exe is
penny
2016/05/28 01:34:22
See main comment in reply.
(Excellent idea. Work
| |
18 wchar_t path[MAX_PATH] = {}; | |
19 ::wsprintf(path, L"chrome_elf_test_%u\\", ::GetCurrentProcessId()); | |
robertshield
2016/04/20 15:45:47
PIDs get reused alarmingly frequently, please also
penny
2016/05/28 01:34:22
See main comment in reply.
(PID reuse isn't an is
| |
20 | |
21 base::FilePath ipc_file; | |
22 if (!base::PathService::Get(base::DIR_TEMP, &ipc_file)) | |
23 return; | |
24 ipc_file = ipc_file.Append(path); | |
25 ipc_file = ipc_file.Append(L"chrome_elf_tests.txt"); | |
26 base::File file(ipc_file, base::File::FLAG_OPEN | base::File::FLAG_READ); | |
27 if (!file.IsValid()) | |
28 return; | |
29 | |
30 DWORD size = static_cast<DWORD>(file.GetLength()); | |
31 base::string16 content; | |
32 content.resize(size); | |
33 if (-1 == file.Read(0, (char*)content.c_str(), size)) { | |
robertshield
2016/04/20 15:45:47
no c-style casts
also casting wchar_t* to char* s
penny
2016/05/28 01:34:22
See main comment in reply.
Acknowledged.
| |
34 file.Close(); | |
35 return; | |
36 } | |
37 content.append(L"\0"); | |
38 | |
39 size_t index = content.find(L"hkcu="); | |
40 if (index != base::string16::npos) { | |
41 const wchar_t* ptr = content.c_str() + index; | |
robertshield
2016/04/20 15:45:47
content.begin() + index
penny
2016/05/28 01:34:22
Acknowledged.
| |
42 ptr = ::wcschr(ptr, L'\"'); | |
robertshield
2016/04/20 15:45:47
why not use one of the find() variants that takes
penny
2016/05/28 01:34:22
Acknowledged.
| |
43 if (ptr != nullptr) { | |
44 ptr++; | |
45 std::vector<wchar_t>(str); | |
46 while (*ptr != L'\"') { | |
47 str.push_back(*ptr); | |
48 ptr++; | |
49 } | |
robertshield
2016/04/20 15:45:47
I think you can replace most of this with:
size_t
penny
2016/05/28 01:34:22
See main comment in reply.
Your idea would have l
| |
50 str.push_back(L'\0'); | |
51 base::string16 substr(str.begin(), str.end()); | |
52 nt::HKCU_override.assign(substr); | |
53 } | |
54 } | |
55 | |
56 index = content.find(L"hklm="); | |
57 if (index != base::string16::npos) { | |
58 const wchar_t* ptr = content.c_str() + index; | |
59 ptr = ::wcschr(ptr, L'\"'); | |
60 if (ptr != nullptr) { | |
61 ptr++; | |
62 std::vector<wchar_t>(str); | |
63 while (*ptr != L'\"') { | |
64 str.push_back(*ptr); | |
65 ptr++; | |
66 } | |
robertshield
2016/04/20 15:45:47
ditto for simplification suggestion.
penny
2016/05/28 01:34:22
Done.
| |
67 str.push_back(L'\0'); | |
68 base::string16 substr(str.begin(), str.end()); | |
69 nt::HKLM_override.assign(substr); | |
70 } | |
71 } | |
72 | |
73 file.Close(); | |
74 return; | |
75 } | |
76 | |
77 } // namespace | |
78 | |
79 extern "C" __declspec(dllexport) void InitTestDll() { | |
80 // Make sure we've got the latest registry overrides. | |
81 GetIpcOverrides(); | |
11 } | 82 } |
12 | 83 |
13 BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) { | 84 BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) { |
14 if (reason == DLL_PROCESS_ATTACH) { | 85 if (reason == DLL_PROCESS_ATTACH) { |
86 GetIpcOverrides(); | |
15 InitializeProcessType(); | 87 InitializeProcessType(); |
16 blacklist::Initialize(true); // force always on, no beacon | 88 blacklist::Initialize(true); // force always on, no beacon |
17 } | 89 } |
18 | 90 |
19 return TRUE; | 91 return TRUE; |
20 } | 92 } |
OLD | NEW |