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.
5 #include "sandbox/win/src/resolver.h"
7 #include "sandbox/win/src/sandbox_nt_util.h"
11 const BYTE kPushRax
= 0x50;
12 const USHORT kMovRax
= 0xB848;
13 const ULONG kMovRspRax
= 0x24048948;
14 const BYTE kRetNp
= 0xC3;
17 struct InternalThunk
{
18 // This struct contains roughly the following code:
20 // 01 48b8f0debc9a78563412 mov rax,123456789ABCDEF0h
21 // 0b 48890424 mov qword ptr [rsp],rax
24 // The code modifies rax, but that should not be an issue for the common
25 // calling conventions.
30 interceptor_function
= 0;
31 mov_rsp_rax
= kMovRspRax
;
34 BYTE push_rax
; // = 50
35 USHORT mov_rax
; // = 48 B8
36 ULONG_PTR interceptor_function
;
37 ULONG mov_rsp_rax
; // = 48 89 04 24
46 size_t ResolverThunk::GetInternalThunkSize() const {
47 return sizeof(InternalThunk
);
50 bool ResolverThunk::SetInternalThunk(void* storage
, size_t storage_bytes
,
51 const void* original_function
,
52 const void* interceptor
) {
53 if (storage_bytes
< sizeof(InternalThunk
))
56 InternalThunk
* thunk
= new(storage
, NT_PLACE
) InternalThunk
;
57 thunk
->interceptor_function
= reinterpret_cast<ULONG_PTR
>(interceptor
);
62 NTSTATUS
ResolverThunk::ResolveTarget(const void* module
,
63 const char* function_name
,
65 // We don't support sidestep & co.
66 return STATUS_NOT_IMPLEMENTED
;
69 } // namespace sandbox