Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #include "sandbox/win/src/resolver.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "base/win/pe_image.h" |
michael@0 | 8 | #include "sandbox/win/src/sandbox_nt_util.h" |
michael@0 | 9 | |
michael@0 | 10 | namespace sandbox { |
michael@0 | 11 | |
michael@0 | 12 | NTSTATUS ResolverThunk::Init(const void* target_module, |
michael@0 | 13 | const void* interceptor_module, |
michael@0 | 14 | const char* target_name, |
michael@0 | 15 | const char* interceptor_name, |
michael@0 | 16 | const void* interceptor_entry_point, |
michael@0 | 17 | void* thunk_storage, |
michael@0 | 18 | size_t storage_bytes) { |
michael@0 | 19 | if (NULL == thunk_storage || 0 == storage_bytes || |
michael@0 | 20 | NULL == target_module || NULL == target_name) |
michael@0 | 21 | return STATUS_INVALID_PARAMETER; |
michael@0 | 22 | |
michael@0 | 23 | if (storage_bytes < GetThunkSize()) |
michael@0 | 24 | return STATUS_BUFFER_TOO_SMALL; |
michael@0 | 25 | |
michael@0 | 26 | NTSTATUS ret = STATUS_SUCCESS; |
michael@0 | 27 | if (NULL == interceptor_entry_point) { |
michael@0 | 28 | ret = ResolveInterceptor(interceptor_module, interceptor_name, |
michael@0 | 29 | &interceptor_entry_point); |
michael@0 | 30 | if (!NT_SUCCESS(ret)) |
michael@0 | 31 | return ret; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | ret = ResolveTarget(target_module, target_name, &target_); |
michael@0 | 35 | if (!NT_SUCCESS(ret)) |
michael@0 | 36 | return ret; |
michael@0 | 37 | |
michael@0 | 38 | interceptor_ = interceptor_entry_point; |
michael@0 | 39 | |
michael@0 | 40 | return ret; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | NTSTATUS ResolverThunk::ResolveInterceptor(const void* interceptor_module, |
michael@0 | 44 | const char* interceptor_name, |
michael@0 | 45 | const void** address) { |
michael@0 | 46 | DCHECK_NT(address); |
michael@0 | 47 | if (!interceptor_module) |
michael@0 | 48 | return STATUS_INVALID_PARAMETER; |
michael@0 | 49 | |
michael@0 | 50 | base::win::PEImage pe(interceptor_module); |
michael@0 | 51 | if (!pe.VerifyMagic()) |
michael@0 | 52 | return STATUS_INVALID_IMAGE_FORMAT; |
michael@0 | 53 | |
michael@0 | 54 | *address = pe.GetProcAddress(interceptor_name); |
michael@0 | 55 | |
michael@0 | 56 | if (!(*address)) |
michael@0 | 57 | return STATUS_PROCEDURE_NOT_FOUND; |
michael@0 | 58 | |
michael@0 | 59 | return STATUS_SUCCESS; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | } // namespace sandbox |