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

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

Issue 183833004: Make chrome_elf use thunks instead of function pointers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use thunk instead of lookup table Created 6 years, 9 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/chrome_elf_util.h" 11 #include "chrome_elf/chrome_elf_util.h"
12 #include "chrome_elf/ntdll_cache.h" 12 #include "chrome_elf/ntdll_cache.h"
13 #include "sandbox/win/src/interception_internal.h"
13 #include "sandbox/win/src/nt_internals.h" 14 #include "sandbox/win/src/nt_internals.h"
14 15
15 namespace { 16 namespace {
16 17
17 // From ShlObj.h in the Windows SDK. 18 // From ShlObj.h in the Windows SDK.
18 #define CSIDL_LOCAL_APPDATA 0x001c 19 #define CSIDL_LOCAL_APPDATA 0x001c
19 20
20 typedef BOOL (WINAPI *PathIsUNCFunction)( 21 typedef BOOL (WINAPI *PathIsUNCFunction)(
21 IN LPCWSTR path); 22 IN LPCWSTR path);
22 23
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 else 178 else
178 flags |= FILE_NON_DIRECTORY_FILE; 179 flags |= FILE_NON_DIRECTORY_FILE;
179 180
180 181
181 if (flags_and_attributes & FILE_FLAG_OPEN_REPARSE_POINT) 182 if (flags_and_attributes & FILE_FLAG_OPEN_REPARSE_POINT)
182 flags |= FILE_OPEN_REPARSE_POINT; 183 flags |= FILE_OPEN_REPARSE_POINT;
183 184
184 if (flags_and_attributes & FILE_FLAG_OPEN_NO_RECALL) 185 if (flags_and_attributes & FILE_FLAG_OPEN_NO_RECALL)
185 flags |= FILE_OPEN_NO_RECALL; 186 flags |= FILE_OPEN_NO_RECALL;
186 187
187 if (!g_ntdll_lookup["NtCreateFile"] || 188 if (!g_ntdll_lookup["RtlInitUnicodeString"])
188 !g_ntdll_lookup["RtlInitUnicodeString"]) { 189 return INVALID_HANDLE_VALUE;
190
191 NtCreateFileFunction create_file;
192 char thunk_buffer[sizeof(sandbox::ThunkData)] = {};
robertshield 2014/03/17 22:21:27 Please add a comment that explains that this is fo
Cait (Slow) 2014/03/18 00:23:10 Done.
193
194 if (g_nt_thunk_storage.data[0] != 0) {
195 create_file = reinterpret_cast<NtCreateFileFunction>(&g_nt_thunk_storage);
196 memcpy(&thunk_buffer, &g_nt_thunk_storage, sizeof(sandbox::ThunkData));
197 } else if (g_ntdll_lookup["NtCreateFile"]) {
198 create_file =
199 reinterpret_cast<NtCreateFileFunction>(g_ntdll_lookup["NtCreateFile"]);
200 } else {
189 return INVALID_HANDLE_VALUE; 201 return INVALID_HANDLE_VALUE;
190 } 202 }
191 203
192 NtCreateFileFunction create_file =
193 reinterpret_cast<NtCreateFileFunction>(g_ntdll_lookup["NtCreateFile"]);
194
195 RtlInitUnicodeStringFunction init_unicode_string = 204 RtlInitUnicodeStringFunction init_unicode_string =
196 reinterpret_cast<RtlInitUnicodeStringFunction>( 205 reinterpret_cast<RtlInitUnicodeStringFunction>(
197 g_ntdll_lookup["RtlInitUnicodeString"]); 206 g_ntdll_lookup["RtlInitUnicodeString"]);
198 207
199 UNICODE_STRING path_unicode_string; 208 UNICODE_STRING path_unicode_string;
200 209
201 // Format the path into an NT path. Arguably this should be done with 210 // Format the path into an NT path. Arguably this should be done with
202 // RtlDosPathNameToNtPathName_U, but afaict this is equivalent for 211 // RtlDosPathNameToNtPathName_U, but afaict this is equivalent for
203 // local paths. Using this with a UNC path name will almost certainly 212 // local paths. Using this with a UNC path name will almost certainly
204 // break in interesting ways. 213 // break in interesting ways.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 LPCWSTR file_name = g_path_find_filename_func(file_path); 299 LPCWSTR file_name = g_path_find_filename_func(file_path);
291 300
292 bool in_userdata_dir = !!g_path_is_prefix_func(local_appdata_path, file_path); 301 bool in_userdata_dir = !!g_path_is_prefix_func(local_appdata_path, file_path);
293 bool is_settings_file = wcscmp(file_name, kPreferencesFilename) == 0 || 302 bool is_settings_file = wcscmp(file_name, kPreferencesFilename) == 0 ||
294 wcscmp(file_name, kLocalStateFilename) == 0; 303 wcscmp(file_name, kLocalStateFilename) == 0;
295 304
296 // Check if we are trying to access the Preferences in the UserData dir. If 305 // Check if we are trying to access the Preferences in the UserData dir. If
297 // so, then redirect the call to bypass kernel32. 306 // so, then redirect the call to bypass kernel32.
298 return in_userdata_dir && is_settings_file; 307 return in_userdata_dir && is_settings_file;
299 } 308 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698