Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: chrome_elf/create_file/chrome_create_file.cc

Issue 169093007: Modify fileAtPath stat to track if the call was redirected by chrome_elf. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use a count instead of a bool Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "chrome_elf/ntdll_cache.h" 11 #include "chrome_elf/ntdll_cache.h"
12 #include "sandbox/win/src/nt_internals.h" 12 #include "sandbox/win/src/nt_internals.h"
13 13
14 // Record the number of calls we've redirected so far.
15 int g_redirect_count = 0;
robertshield 2014/02/18 23:30:21 This is only used in this file, it can be moved in
Cait (Slow) 2014/02/19 15:43:18 Done.
16
14 namespace { 17 namespace {
15 18
16 // From ShlObj.h in the Windows SDK. 19 // From ShlObj.h in the Windows SDK.
17 #define CSIDL_LOCAL_APPDATA 0x001c 20 #define CSIDL_LOCAL_APPDATA 0x001c
18 21
19 typedef BOOL (WINAPI *PathIsUNCFunction)( 22 typedef BOOL (WINAPI *PathIsUNCFunction)(
20 IN LPCWSTR path); 23 IN LPCWSTR path);
21 24
22 typedef BOOL (WINAPI *PathAppendFunction)( 25 typedef BOOL (WINAPI *PathAppendFunction)(
23 IN LPWSTR path, 26 IN LPWSTR path,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
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++;
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698