| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "sandbox/win/src/resolver.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 | |
| 9 // For placement new. This file must not depend on the CRT at runtime, but | |
| 10 // placement operator new is inline. | |
| 11 #include <new> | |
| 12 | |
| 13 #include "sandbox/win/src/sandbox_nt_util.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 #pragma pack(push, 1) | |
| 18 struct InternalThunk { | |
| 19 // This struct contains roughly the following code: | |
| 20 // sub esp, 8 // Create working space | |
| 21 // push edx // Save register | |
| 22 // mov edx, [esp + 0xc] // Get return adddress | |
| 23 // mov [esp + 8], edx // Store return address | |
| 24 // mov dword ptr [esp + 0xc], 0x7c401200 // Store extra argument | |
| 25 // mov dword ptr [esp + 4], 0x40010203 // Store address to jump to | |
| 26 // pop edx // Restore register | |
| 27 // ret // Jump to interceptor | |
| 28 // | |
| 29 // This code only modifies esp and eip so it must work with to normal calling | |
| 30 // convention. It is assembled as: | |
| 31 // | |
| 32 // 00 83ec08 sub esp,8 | |
| 33 // 03 52 push edx | |
| 34 // 04 8b54240c mov edx,dword ptr [esp + 0Ch] | |
| 35 // 08 89542408 mov dword ptr [esp + 8], edx | |
| 36 // 0c c744240c0012407c mov dword ptr [esp + 0Ch], 7C401200h | |
| 37 // 14 c744240403020140 mov dword ptr [esp + 4], 40010203h | |
| 38 // 1c 5a pop edx | |
| 39 // 1d c3 ret | |
| 40 InternalThunk() { | |
| 41 opcodes_1 = 0x5208ec83; | |
| 42 opcodes_2 = 0x0c24548b; | |
| 43 opcodes_3 = 0x08245489; | |
| 44 opcodes_4 = 0x0c2444c7; | |
| 45 opcodes_5 = 0x042444c7; | |
| 46 opcodes_6 = 0xc35a; | |
| 47 extra_argument = 0; | |
| 48 interceptor_function = 0; | |
| 49 }; | |
| 50 ULONG opcodes_1; // = 0x5208ec83 | |
| 51 ULONG opcodes_2; // = 0x0c24548b | |
| 52 ULONG opcodes_3; // = 0x08245489 | |
| 53 ULONG opcodes_4; // = 0x0c2444c7 | |
| 54 ULONG extra_argument; | |
| 55 ULONG opcodes_5; // = 0x042444c7 | |
| 56 ULONG interceptor_function; | |
| 57 USHORT opcodes_6; // = 0xc35a | |
| 58 }; | |
| 59 #pragma pack(pop) | |
| 60 | |
| 61 }; // namespace | |
| 62 | |
| 63 namespace sandbox { | |
| 64 | |
| 65 bool ResolverThunk::SetInternalThunk(void* storage, size_t storage_bytes, | |
| 66 const void* original_function, | |
| 67 const void* interceptor) { | |
| 68 if (storage_bytes < sizeof(InternalThunk)) | |
| 69 return false; | |
| 70 | |
| 71 InternalThunk* thunk = new(storage) InternalThunk; | |
| 72 | |
| 73 #pragma warning(push) | |
| 74 #pragma warning(disable: 4311) | |
| 75 // These casts generate warnings because they are 32 bit specific. | |
| 76 thunk->interceptor_function = reinterpret_cast<ULONG>(interceptor); | |
| 77 thunk->extra_argument = reinterpret_cast<ULONG>(original_function); | |
| 78 #pragma warning(pop) | |
| 79 | |
| 80 return true; | |
| 81 } | |
| 82 | |
| 83 size_t ResolverThunk::GetInternalThunkSize() const { | |
| 84 return sizeof(InternalThunk); | |
| 85 } | |
| 86 | |
| 87 NTSTATUS ResolverThunk::ResolveTarget(const void* module, | |
| 88 const char* function_name, | |
| 89 void** address) { | |
| 90 const void** casted = const_cast<const void**>(address); | |
| 91 return ResolverThunk::ResolveInterceptor(module, function_name, casted); | |
| 92 } | |
| 93 | |
| 94 } // namespace sandbox | |
| OLD | NEW |