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

Side by Side Diff: base/iat_patch.cc

Issue 21434: Don't unpatch an unloaded module. We verify if the original function address ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/iat_patch.h" 5 #include "base/iat_patch.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 7
8 namespace iat_patch { 8 namespace iat_patch {
9 9
10 struct InterceptFunctionInformation { 10 struct InterceptFunctionInformation {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 198
199 if (NO_ERROR == error) { 199 if (NO_ERROR == error) {
200 DCHECK_NE(original_function_, intercept_function_); 200 DCHECK_NE(original_function_, intercept_function_);
201 intercept_function_ = new_function; 201 intercept_function_ = new_function;
202 } 202 }
203 203
204 return error; 204 return error;
205 } 205 }
206 206
207 DWORD IATPatchFunction::Unpatch() { 207 DWORD IATPatchFunction::Unpatch() {
208 DWORD error = RestoreImportedFunction(intercept_function_, 208 DWORD error = 0;
209 original_function_, 209 MEMORY_BASIC_INFORMATION memory_info = {0};
210 iat_thunk_); 210
211 // If the module has already unloaded, no point trying to unpatch.
212 if (!VirtualQuery(original_function_, &memory_info,
213 sizeof(memory_info))) {
214 error = GetLastError();
215 NOTREACHED();
216 return error;
217 }
Dean McNamee 2009/02/18 11:35:38 Shouldn't you set all of the functions to NULL her
218
219 if ((memory_info.State & MEM_COMMIT) != MEM_COMMIT) {
220 NOTREACHED();
221 return ERROR_ACCESS_DENIED;
222 }
223
224 error = RestoreImportedFunction(intercept_function_,
225 original_function_,
226 iat_thunk_);
211 DCHECK(NO_ERROR == error); 227 DCHECK(NO_ERROR == error);
212 228
213 // Hands off the intercept if we fail to unpatch. 229 // Hands off the intercept if we fail to unpatch.
214 // If IATPatchFunction::Unpatch fails during RestoreImportedFunction 230 // If IATPatchFunction::Unpatch fails during RestoreImportedFunction
215 // it means that we cannot safely unpatch the import address table 231 // it means that we cannot safely unpatch the import address table
216 // patch. In this case its better to be hands off the intercept as 232 // patch. In this case its better to be hands off the intercept as
217 // trying to unpatch again in the destructor of IATPatchFunction is 233 // trying to unpatch again in the destructor of IATPatchFunction is
218 // not going to be any safer 234 // not going to be any safer
219 intercept_function_ = NULL; 235 intercept_function_ = NULL;
220 original_function_ = NULL; 236 original_function_ = NULL;
221 iat_thunk_ = NULL; 237 iat_thunk_ = NULL;
222 238
223 return error; 239 return error;
224 } 240 }
225 241
226 } // namespace iat_patch 242 } // namespace iat_patch
227 243
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698