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

Unified Diff: base/win/iat_patch_function.cc

Issue 138593004: Use an alternate mechanism for CreateFile calls in Chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: IAT patch clean up Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | build/common.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/win/iat_patch_function.cc
diff --git a/base/win/iat_patch_function.cc b/base/win/iat_patch_function.cc
index a4a89028b870f34aa089951009ce06c6ac6f426c..bcc3bdff22fbbece9d5f3d1da82132dd48724133 100644
--- a/base/win/iat_patch_function.cc
+++ b/base/win/iat_patch_function.cc
@@ -56,11 +56,24 @@ 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();
+ NOTREACHED();
rvargas (doing something else) 2014/01/21 21:19:49 On second thoughts, we should probably just remove
Cait (Slow) 2014/01/21 21:47:19 Done.
+ return error;
+ }
+
+ DWORD is_executable = (PAGE_EXECUTE | PAGE_EXECUTE_READ |
+ PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY) &
+ memory_info.Protect;
rvargas (doing something else) 2014/01/21 20:03:26 tiny nit: one less space here.
Cait (Slow) 2014/01/21 21:47:19 Done.
+
if (VirtualProtect(old_code,
length,
- PAGE_READWRITE,
+ is_executable ? PAGE_EXECUTE_READWRITE :
+ PAGE_READWRITE,
&old_page_protection)) {
// Write the data.
« no previous file with comments | « no previous file | build/common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698