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

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: Address comments, add scoped ptr 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
« no previous file with comments | « chrome_elf/chrome_elf.gyp ('k') | chrome_elf/create_file/chrome_create_file_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 else 199 else
199 flags |= FILE_NON_DIRECTORY_FILE; 200 flags |= FILE_NON_DIRECTORY_FILE;
200 201
201 202
202 if (flags_and_attributes & FILE_FLAG_OPEN_REPARSE_POINT) 203 if (flags_and_attributes & FILE_FLAG_OPEN_REPARSE_POINT)
203 flags |= FILE_OPEN_REPARSE_POINT; 204 flags |= FILE_OPEN_REPARSE_POINT;
204 205
205 if (flags_and_attributes & FILE_FLAG_OPEN_NO_RECALL) 206 if (flags_and_attributes & FILE_FLAG_OPEN_NO_RECALL)
206 flags |= FILE_OPEN_NO_RECALL; 207 flags |= FILE_OPEN_NO_RECALL;
207 208
208 if (!g_ntdll_lookup["NtCreateFile"] || 209 if (!g_ntdll_lookup["RtlInitUnicodeString"])
209 !g_ntdll_lookup["RtlInitUnicodeString"]) { 210 return INVALID_HANDLE_VALUE;
211
212 NtCreateFileFunction create_file;
213 char thunk_buffer[sizeof(sandbox::ThunkData)] = {};
214
215 if (g_nt_thunk_storage.data[0] != 0) {
216 create_file = reinterpret_cast<NtCreateFileFunction>(&g_nt_thunk_storage);
217 // Copy the thunk data to a buffer on the stack for debugging purposes.
218 memcpy(&thunk_buffer, &g_nt_thunk_storage, sizeof(sandbox::ThunkData));
219 } else if (g_ntdll_lookup["NtCreateFile"]) {
220 create_file =
221 reinterpret_cast<NtCreateFileFunction>(g_ntdll_lookup["NtCreateFile"]);
222 } else {
210 return INVALID_HANDLE_VALUE; 223 return INVALID_HANDLE_VALUE;
211 } 224 }
212 225
213 NtCreateFileFunction create_file =
214 reinterpret_cast<NtCreateFileFunction>(g_ntdll_lookup["NtCreateFile"]);
215
216 RtlInitUnicodeStringFunction init_unicode_string = 226 RtlInitUnicodeStringFunction init_unicode_string =
217 reinterpret_cast<RtlInitUnicodeStringFunction>( 227 reinterpret_cast<RtlInitUnicodeStringFunction>(
218 g_ntdll_lookup["RtlInitUnicodeString"]); 228 g_ntdll_lookup["RtlInitUnicodeString"]);
219 229
220 UNICODE_STRING path_unicode_string; 230 UNICODE_STRING path_unicode_string;
221 231
222 // Format the path into an NT path. Arguably this should be done with 232 // Format the path into an NT path. Arguably this should be done with
223 // RtlDosPathNameToNtPathName_U, but afaict this is equivalent for 233 // RtlDosPathNameToNtPathName_U, but afaict this is equivalent for
224 // local paths. Using this with a UNC path name will almost certainly 234 // local paths. Using this with a UNC path name will almost certainly
225 // break in interesting ways. 235 // break in interesting ways.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 LPCWSTR file_name = g_path_find_filename_func(file_path); 321 LPCWSTR file_name = g_path_find_filename_func(file_path);
312 322
313 bool in_userdata_dir = !!g_path_is_prefix_func(local_appdata_path, file_path); 323 bool in_userdata_dir = !!g_path_is_prefix_func(local_appdata_path, file_path);
314 bool is_settings_file = wcscmp(file_name, kPreferencesFilename) == 0 || 324 bool is_settings_file = wcscmp(file_name, kPreferencesFilename) == 0 ||
315 wcscmp(file_name, kLocalStateFilename) == 0; 325 wcscmp(file_name, kLocalStateFilename) == 0;
316 326
317 // Check if we are trying to access the Preferences in the UserData dir. If 327 // Check if we are trying to access the Preferences in the UserData dir. If
318 // so, then redirect the call to bypass kernel32. 328 // so, then redirect the call to bypass kernel32.
319 return in_userdata_dir && is_settings_file; 329 return in_userdata_dir && is_settings_file;
320 } 330 }
OLDNEW
« no previous file with comments | « chrome_elf/chrome_elf.gyp ('k') | chrome_elf/create_file/chrome_create_file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698