diff options
Diffstat (limited to 'chromium/base/win/iat_patch_function.cc')
-rw-r--r-- | chromium/base/win/iat_patch_function.cc | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/chromium/base/win/iat_patch_function.cc b/chromium/base/win/iat_patch_function.cc index a4a89028b87..21c39950cc3 100644 --- a/chromium/base/win/iat_patch_function.cc +++ b/chromium/base/win/iat_patch_function.cc @@ -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. @@ -74,7 +86,6 @@ DWORD ModifyCode(void* old_code, void* new_code, int length) { &old_page_protection); } else { error = GetLastError(); - NOTREACHED(); } return error; @@ -274,5 +285,10 @@ DWORD IATPatchFunction::Unpatch() { return error; } +void* IATPatchFunction::original_function() const { + DCHECK(is_patched()); + return original_function_; +} + } // namespace win } // namespace base |