| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_frame/vtable_patch_manager.h" | 5 #include "chrome_frame/vtable_patch_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 #include "chrome_frame/function_stub.h" | 9 #include "chrome_frame/function_stub.h" |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // Do some sanity checking of the input arguments. | 23 // Do some sanity checking of the input arguments. |
| 24 if (NULL == unknown || NULL == patches) { | 24 if (NULL == unknown || NULL == patches) { |
| 25 NOTREACHED(); | 25 NOTREACHED(); |
| 26 return E_INVALIDARG; | 26 return E_INVALIDARG; |
| 27 } | 27 } |
| 28 | 28 |
| 29 Vtable vtable = GetIFVTable(unknown); | 29 Vtable vtable = GetIFVTable(unknown); |
| 30 DCHECK(vtable); | 30 DCHECK(vtable); |
| 31 | 31 |
| 32 for (MethodPatchInfo* it = patches; it->index_ != -1; ++it) { | 32 for (MethodPatchInfo* it = patches; it->index_ != -1; ++it) { |
| 33 if (it->stub_ != NULL) { |
| 34 // If this DCHECK fires it means that we are using the same VTable |
| 35 // information to patch two different interfaces. |
| 36 DCHECK(false); |
| 37 DLOG(ERROR) << "Attempting to patch two different VTables with the " |
| 38 << "same VTable information"; |
| 39 continue; |
| 40 } |
| 41 |
| 33 PROC original_fn = vtable[it->index_]; | 42 PROC original_fn = vtable[it->index_]; |
| 34 FunctionStub* stub = FunctionStub::FromCode(original_fn); | 43 FunctionStub* stub = FunctionStub::FromCode(original_fn); |
| 35 if (stub != NULL) { | 44 if (stub != NULL) { |
| 36 DLOG(ERROR) << "attempt to patch a function that's already patched"; | 45 DLOG(ERROR) << "attempt to patch a function that's already patched"; |
| 37 DCHECK(stub->absolute_target() == | 46 DCHECK(stub->absolute_target() == |
| 38 reinterpret_cast<uintptr_t>(it->method_)) << | 47 reinterpret_cast<uintptr_t>(it->method_)) << |
| 39 "patching the same method multiple times with different hooks?"; | 48 "patching the same method multiple times with different hooks?"; |
| 40 continue; | 49 continue; |
| 41 } | 50 } |
| 42 | 51 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 58 } | 67 } |
| 59 } | 68 } |
| 60 } | 69 } |
| 61 | 70 |
| 62 return S_OK; | 71 return S_OK; |
| 63 } | 72 } |
| 64 | 73 |
| 65 HRESULT UnpatchInterfaceMethods(MethodPatchInfo* patches) { | 74 HRESULT UnpatchInterfaceMethods(MethodPatchInfo* patches) { |
| 66 for (MethodPatchInfo* it = patches; it->index_ != -1; ++it) { | 75 for (MethodPatchInfo* it = patches; it->index_ != -1; ++it) { |
| 67 if (it->stub_) { | 76 if (it->stub_) { |
| 68 DCHECK(it->stub_->absolute_target() == | 77 DCHECK(it->stub_->absolute_target() == |
| 69 reinterpret_cast<uintptr_t>(it->method_)); | 78 reinterpret_cast<uintptr_t>(it->method_)); |
| 70 // Modify the stub to just jump directly to the original function. | 79 // Modify the stub to just jump directly to the original function. |
| 71 it->stub_->BypassStub(reinterpret_cast<void*>(it->stub_->argument())); | 80 it->stub_->BypassStub(reinterpret_cast<void*>(it->stub_->argument())); |
| 72 it->stub_ = NULL; | 81 it->stub_ = NULL; |
| 73 // Leave the stub in memory so that we won't break any possible chains. | 82 // Leave the stub in memory so that we won't break any possible chains. |
| 74 } else { | 83 } else { |
| 75 DLOG(WARNING) << "attempt to unpatch a function that wasn't patched"; | 84 DLOG(WARNING) << "attempt to unpatch a function that wasn't patched"; |
| 76 } | 85 } |
| 77 } | 86 } |
| 78 | 87 |
| 79 return S_OK; | 88 return S_OK; |
| 80 } | 89 } |
| 81 | 90 |
| 82 } // namespace vtable_patch | 91 } // namespace vtable_patch |
| OLD | NEW |