OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/create_file/chrome_create_file.h" | 5 #include "chrome_elf/create_file/chrome_create_file.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "chrome_elf/chrome_elf_constants.h" | 10 #include "chrome_elf/chrome_elf_constants.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 IN HANDLE token, | 36 IN HANDLE token, |
37 IN DWORD flags, | 37 IN DWORD flags, |
38 OUT LPWSTR path); | 38 OUT LPWSTR path); |
39 | 39 |
40 PathIsUNCFunction g_path_is_unc_func; | 40 PathIsUNCFunction g_path_is_unc_func; |
41 PathAppendFunction g_path_append_func; | 41 PathAppendFunction g_path_append_func; |
42 PathIsPrefixFunction g_path_is_prefix_func; | 42 PathIsPrefixFunction g_path_is_prefix_func; |
43 PathFindFileName g_path_find_filename_func; | 43 PathFindFileName g_path_find_filename_func; |
44 SHGetFolderPathFunction g_get_folder_func; | 44 SHGetFolderPathFunction g_get_folder_func; |
45 | 45 |
46 // Record the number of calls we've redirected so far. | |
47 int g_redirect_count = 0; | |
48 | |
46 // Populates the g_*_func pointers to functions which will be used in | 49 // Populates the g_*_func pointers to functions which will be used in |
47 // ShouldBypass(). Chrome_elf cannot have a load-time dependency on shell32 or | 50 // ShouldBypass(). Chrome_elf cannot have a load-time dependency on shell32 or |
48 // shlwapi as this would induce a load-time dependency on user32.dll. Instead, | 51 // shlwapi as this would induce a load-time dependency on user32.dll. Instead, |
49 // the addresses of the functions we need are retrieved the first time this | 52 // the addresses of the functions we need are retrieved the first time this |
50 // method is called, and cached to avoid subsequent calls to GetProcAddress(). | 53 // method is called, and cached to avoid subsequent calls to GetProcAddress(). |
51 // It is assumed that the host process will never unload these functions. | 54 // It is assumed that the host process will never unload these functions. |
52 // Returns true if all the functions needed are present. | 55 // Returns true if all the functions needed are present. |
53 bool PopulateShellFunctions() { | 56 bool PopulateShellFunctions() { |
54 // Early exit if functions have already been populated. | 57 // Early exit if functions have already been populated. |
55 if (g_path_is_unc_func && g_path_append_func && | 58 if (g_path_is_unc_func && g_path_append_func && |
(...skipping 29 matching lines...) Expand all Loading... | |
85 | 88 |
86 HANDLE WINAPI CreateFileWRedirect( | 89 HANDLE WINAPI CreateFileWRedirect( |
87 LPCWSTR file_name, | 90 LPCWSTR file_name, |
88 DWORD desired_access, | 91 DWORD desired_access, |
89 DWORD share_mode, | 92 DWORD share_mode, |
90 LPSECURITY_ATTRIBUTES security_attributes, | 93 LPSECURITY_ATTRIBUTES security_attributes, |
91 DWORD creation_disposition, | 94 DWORD creation_disposition, |
92 DWORD flags_and_attributes, | 95 DWORD flags_and_attributes, |
93 HANDLE template_file) { | 96 HANDLE template_file) { |
94 if (ShouldBypass(file_name)) { | 97 if (ShouldBypass(file_name)) { |
98 g_redirect_count++; | |
gab
2014/02/19 15:43:40
nit: pre-increment
Cait (Slow)
2014/02/19 16:28:06
Done.
| |
95 return CreateFileNTDLL(file_name, | 99 return CreateFileNTDLL(file_name, |
96 desired_access, | 100 desired_access, |
97 share_mode, | 101 share_mode, |
98 security_attributes, | 102 security_attributes, |
99 creation_disposition, | 103 creation_disposition, |
100 flags_and_attributes, | 104 flags_and_attributes, |
101 template_file); | 105 template_file); |
102 } | 106 } |
103 return CreateFile(file_name, | 107 return CreateFile(file_name, |
104 desired_access, | 108 desired_access, |
105 share_mode, | 109 share_mode, |
106 security_attributes, | 110 security_attributes, |
107 creation_disposition, | 111 creation_disposition, |
108 flags_and_attributes, | 112 flags_and_attributes, |
109 template_file); | 113 template_file); |
110 | 114 |
111 } | 115 } |
112 | 116 |
117 int GetRedirectCount() { | |
118 return g_redirect_count; | |
119 } | |
120 | |
113 HANDLE CreateFileNTDLL( | 121 HANDLE CreateFileNTDLL( |
114 LPCWSTR file_name, | 122 LPCWSTR file_name, |
115 DWORD desired_access, | 123 DWORD desired_access, |
116 DWORD share_mode, | 124 DWORD share_mode, |
117 LPSECURITY_ATTRIBUTES security_attributes, | 125 LPSECURITY_ATTRIBUTES security_attributes, |
118 DWORD creation_disposition, | 126 DWORD creation_disposition, |
119 DWORD flags_and_attributes, | 127 DWORD flags_and_attributes, |
120 HANDLE template_file) { | 128 HANDLE template_file) { |
121 HANDLE file_handle = INVALID_HANDLE_VALUE; | 129 HANDLE file_handle = INVALID_HANDLE_VALUE; |
122 NTSTATUS result = STATUS_UNSUCCESSFUL; | 130 NTSTATUS result = STATUS_UNSUCCESSFUL; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 LPCWSTR file_name = g_path_find_filename_func(file_path); | 295 LPCWSTR file_name = g_path_find_filename_func(file_path); |
288 | 296 |
289 bool in_userdata_dir = !!g_path_is_prefix_func(local_appdata_path, file_path); | 297 bool in_userdata_dir = !!g_path_is_prefix_func(local_appdata_path, file_path); |
290 bool is_settings_file = wcscmp(file_name, kPreferencesFilename) == 0 || | 298 bool is_settings_file = wcscmp(file_name, kPreferencesFilename) == 0 || |
291 wcscmp(file_name, kLocalStateFilename) == 0; | 299 wcscmp(file_name, kLocalStateFilename) == 0; |
292 | 300 |
293 // Check if we are trying to access the Preferences in the UserData dir. If | 301 // Check if we are trying to access the Preferences in the UserData dir. If |
294 // so, then redirect the call to bypass kernel32. | 302 // so, then redirect the call to bypass kernel32. |
295 return in_userdata_dir && is_settings_file; | 303 return in_userdata_dir && is_settings_file; |
296 } | 304 } |
OLD | NEW |