Skip to content

Commit

Permalink
Use an alternate mechanism for CreateFile calls in Chrome
Browse files Browse the repository at this point in the history
BUG=334379

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=245464

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=246313

Review URL: https://codereview.chromium.org/138593004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248380 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
caitkp@chromium.org committed Feb 2, 2014
1 parent 46b4e44 commit 2106f5f
Show file tree
Hide file tree
Showing 11 changed files with 805 additions and 4 deletions.
15 changes: 13 additions & 2 deletions base/win/iat_patch_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,23 @@ DWORD ModifyCode(void* old_code, void* new_code, int length) {
}

// Change the page protection so that we can write.
MEMORY_BASIC_INFORMATION memory_info;
DWORD error = NO_ERROR;
DWORD old_page_protection = 0;

if (!VirtualQuery(old_code, &memory_info, sizeof(memory_info))) {
error = GetLastError();
return error;
}

DWORD is_executable = (PAGE_EXECUTE | PAGE_EXECUTE_READ |
PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY) &
memory_info.Protect;

if (VirtualProtect(old_code,
length,
PAGE_READWRITE,
is_executable ? PAGE_EXECUTE_READWRITE :
PAGE_READWRITE,
&old_page_protection)) {

// Write the data.
Expand All @@ -74,7 +86,6 @@ DWORD ModifyCode(void* old_code, void* new_code, int length) {
&old_page_protection);
} else {
error = GetLastError();
NOTREACHED();
}

return error;
Expand Down
2 changes: 1 addition & 1 deletion chrome/chrome_exe.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,9 @@
'../base/base.gyp:base',
'../breakpad/breakpad.gyp:breakpad_handler',
'../breakpad/breakpad.gyp:breakpad_sender',
'../chrome_elf/chrome_elf.gyp:chrome_elf',
'../components/components.gyp:breakpad_component',
'../components/components.gyp:policy',
'../chrome_elf/chrome_elf.gyp:chrome_elf',
'../sandbox/sandbox.gyp:sandbox',
],
'sources': [
Expand Down
1 change: 1 addition & 0 deletions chrome_elf/chrome_elf.def
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
LIBRARY "chrome_elf.dll"

EXPORTS
CreateFileW=CreateFileWRedirect
SignalChromeElf
34 changes: 33 additions & 1 deletion chrome_elf/chrome_elf.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
'msvs_settings': {
'VCLinkerTool': {
'BaseAddress': '0x01c20000',
# Set /SUBSYSTEM:WINDOWS for chrome_elf.dll (for consistency).
# Set /SUBSYSTEM:WINDOWS.
'SubSystem': '2',
'AdditionalDependencies!': [
'user32.lib',
Expand All @@ -46,6 +46,7 @@
'type': 'executable',
'sources': [
'blacklist/test/blacklist_test.cc',
'create_file/chrome_create_file_unittest.cc',
'elf_imports_unittest.cc',
'ntdll_cache_unittest.cc',
],
Expand Down Expand Up @@ -86,10 +87,41 @@
'..',
],
'sources': [
'chrome_elf_constants.cc',
'chrome_elf_constants.h',
'chrome_elf_types.h',
'create_file/chrome_create_file.cc',
'create_file/chrome_create_file.h',
'ntdll_cache.cc',
'ntdll_cache.h',
],
},
], # targets
'conditions': [
['component=="shared_library"', {
'targets': [
{
'target_name': 'chrome_redirects',
'type': 'shared_library',
'include_dirs': [
'..',
],
'sources': [
'chrome_redirects.def',
],
'dependencies': [
'chrome_elf_lib',
],
'msvs_settings': {
'VCLinkerTool': {
'BaseAddress': '0x01c10000',
# Set /SUBSYSTEM:WINDOWS.
'SubSystem': '2',
},
},
},
],
}],
],
}

15 changes: 15 additions & 0 deletions chrome_elf/chrome_elf_constants.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome_elf/chrome_elf_constants.h"

const wchar_t kUserDataDirName[] = L"User Data";
const wchar_t kPreferencesFilename[] = L"Preferences";
const wchar_t kLocalStateFilename[] = L"Local State";

#if defined(GOOGLE_CHROME_BUILD)
const wchar_t kAppDataDirName[] = L"Google\\Chrome";
#else
const wchar_t kAppDataDirName[] = L"Chromium";
#endif
16 changes: 16 additions & 0 deletions chrome_elf/chrome_elf_constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// A handful of resource-like constants related to the ChromeELF.

#ifndef CHROME_ELF_CHROME_ELF_CONSTANTS_H_
#define CHROME_ELF_CHROME_ELF_CONSTANTS_H_

// directory names
extern const wchar_t kAppDataDirName[];
extern const wchar_t kPreferencesFilename[];
extern const wchar_t kLocalStateFilename[];
extern const wchar_t kUserDataDirName[];

#endif // CHROME_ELF_CHROME_ELF_CONSTANTS_H_
8 changes: 8 additions & 0 deletions chrome_elf/chrome_redirects.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; Copyright 2014 The Chromium Authors. All rights reserved.
; Use of this source code is governed by a BSD-style license that can be
; found in the LICENSE file.

LIBRARY "chrome_redirects.dll"

EXPORTS
CreateFileW=CreateFileWRedirect
Loading

0 comments on commit 2106f5f

Please sign in to comment.