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