1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/win/src/resolver_64.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,69 @@ 1.4 +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#include "sandbox/win/src/resolver.h" 1.9 + 1.10 +#include "sandbox/win/src/sandbox_nt_util.h" 1.11 + 1.12 +namespace { 1.13 + 1.14 +const BYTE kPushRax = 0x50; 1.15 +const USHORT kMovRax = 0xB848; 1.16 +const ULONG kMovRspRax = 0x24048948; 1.17 +const BYTE kRetNp = 0xC3; 1.18 + 1.19 +#pragma pack(push, 1) 1.20 +struct InternalThunk { 1.21 + // This struct contains roughly the following code: 1.22 + // 00 50 push rax 1.23 + // 01 48b8f0debc9a78563412 mov rax,123456789ABCDEF0h 1.24 + // 0b 48890424 mov qword ptr [rsp],rax 1.25 + // 0f c3 ret 1.26 + // 1.27 + // The code modifies rax, but that should not be an issue for the common 1.28 + // calling conventions. 1.29 + 1.30 + InternalThunk() { 1.31 + push_rax = kPushRax; 1.32 + mov_rax = kMovRax; 1.33 + interceptor_function = 0; 1.34 + mov_rsp_rax = kMovRspRax; 1.35 + ret = kRetNp; 1.36 + }; 1.37 + BYTE push_rax; // = 50 1.38 + USHORT mov_rax; // = 48 B8 1.39 + ULONG_PTR interceptor_function; 1.40 + ULONG mov_rsp_rax; // = 48 89 04 24 1.41 + BYTE ret; // = C3 1.42 +}; 1.43 +#pragma pack(pop) 1.44 + 1.45 +} // namespace. 1.46 + 1.47 +namespace sandbox { 1.48 + 1.49 +size_t ResolverThunk::GetInternalThunkSize() const { 1.50 + return sizeof(InternalThunk); 1.51 +} 1.52 + 1.53 +bool ResolverThunk::SetInternalThunk(void* storage, size_t storage_bytes, 1.54 + const void* original_function, 1.55 + const void* interceptor) { 1.56 + if (storage_bytes < sizeof(InternalThunk)) 1.57 + return false; 1.58 + 1.59 + InternalThunk* thunk = new(storage, NT_PLACE) InternalThunk; 1.60 + thunk->interceptor_function = reinterpret_cast<ULONG_PTR>(interceptor); 1.61 + 1.62 + return true; 1.63 +} 1.64 + 1.65 +NTSTATUS ResolverThunk::ResolveTarget(const void* module, 1.66 + const char* function_name, 1.67 + void** address) { 1.68 + // We don't support sidestep & co. 1.69 + return STATUS_NOT_IMPLEMENTED; 1.70 +} 1.71 + 1.72 +} // namespace sandbox