security/sandbox/win/src/resolver_64.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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"
     9 namespace {
    11 const BYTE kPushRax = 0x50;
    12 const USHORT kMovRax = 0xB848;
    13 const ULONG kMovRspRax = 0x24048948;
    14 const BYTE kRetNp = 0xC3;
    16 #pragma pack(push, 1)
    17 struct InternalThunk {
    18   // This struct contains roughly the following code:
    19   // 00 50                    push  rax
    20   // 01 48b8f0debc9a78563412  mov   rax,123456789ABCDEF0h
    21   // 0b 48890424              mov   qword ptr [rsp],rax
    22   // 0f c3                    ret
    23   //
    24   // The code modifies rax, but that should not be an issue for the common
    25   // calling conventions.
    27   InternalThunk() {
    28     push_rax = kPushRax;
    29     mov_rax = kMovRax;
    30     interceptor_function = 0;
    31     mov_rsp_rax = kMovRspRax;
    32     ret = kRetNp;
    33   };
    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
    38   BYTE ret;             // = C3
    39 };
    40 #pragma pack(pop)
    42 } // namespace.
    44 namespace sandbox {
    46 size_t ResolverThunk::GetInternalThunkSize() const {
    47   return sizeof(InternalThunk);
    48 }
    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))
    54     return false;
    56   InternalThunk* thunk = new(storage, NT_PLACE) InternalThunk;
    57   thunk->interceptor_function = reinterpret_cast<ULONG_PTR>(interceptor);
    59   return true;
    60 }
    62 NTSTATUS ResolverThunk::ResolveTarget(const void* module,
    63                                       const char* function_name,
    64                                       void** address) {
    65   // We don't support sidestep & co.
    66   return STATUS_NOT_IMPLEMENTED;
    67 }
    69 }  // namespace sandbox

mercurial