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