forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelayLoadLibrary.cpp
More file actions
126 lines (111 loc) · 3.1 KB
/
DelayLoadLibrary.cpp
File metadata and controls
126 lines (111 loc) · 3.1 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "CommonCorePch.h"
#include "core\DelayLoadLibrary.h"
DelayLoadLibrary::DelayLoadLibrary()
{
m_hModule = nullptr;
m_isInit = false;
}
DelayLoadLibrary::~DelayLoadLibrary()
{
if (m_hModule)
{
FreeLibrary(m_hModule);
m_hModule = nullptr;
}
}
void DelayLoadLibrary::Ensure(DWORD dwFlags)
{
if (!m_isInit)
{
m_hModule = LoadLibraryEx(GetLibraryName(), nullptr, dwFlags);
m_isInit = true;
}
}
void DelayLoadLibrary::EnsureFromSystemDirOnly()
{
Ensure(LOAD_LIBRARY_SEARCH_SYSTEM32);
}
FARPROC DelayLoadLibrary::GetFunction(__in LPCSTR lpFunctionName)
{
if (m_hModule)
{
return GetProcAddress(m_hModule, lpFunctionName);
}
return nullptr;
}
bool DelayLoadLibrary::IsAvailable()
{
return m_hModule != nullptr;
}
#if PDATA_ENABLED
static NtdllLibrary NtdllLibraryObject;
NtdllLibrary* NtdllLibrary::Instance = &NtdllLibraryObject;
LPCTSTR NtdllLibrary::GetLibraryName() const
{
return L"ntdll.dll";
}
_Success_(return == 0)
DWORD NtdllLibrary::AddGrowableFunctionTable( _Out_ PVOID * DynamicTable,
_In_reads_(MaximumEntryCount) PRUNTIME_FUNCTION FunctionTable,
_In_ DWORD EntryCount,
_In_ DWORD MaximumEntryCount,
_In_ ULONG_PTR RangeBase,
_In_ ULONG_PTR RangeEnd )
{
if(m_hModule)
{
if(addGrowableFunctionTable == NULL)
{
addGrowableFunctionTable = (PFnRtlAddGrowableFunctionTable)GetFunction("RtlAddGrowableFunctionTable");
if(addGrowableFunctionTable == NULL)
{
Assert(false);
return 1;
}
}
return addGrowableFunctionTable(DynamicTable,
FunctionTable,
EntryCount,
MaximumEntryCount,
RangeBase,
RangeEnd);
}
return 1;
}
VOID NtdllLibrary::DeleteGrowableFunctionTable( _In_ PVOID DynamicTable )
{
if(m_hModule)
{
if(deleteGrowableFunctionTable == NULL)
{
deleteGrowableFunctionTable = (PFnRtlDeleteGrowableFunctionTable)GetFunction("RtlDeleteGrowableFunctionTable");
if(deleteGrowableFunctionTable == NULL)
{
Assert(false);
return;
}
}
deleteGrowableFunctionTable(DynamicTable);
}
}
VOID NtdllLibrary::GrowFunctionTable(_Inout_ PVOID DynamicTable, _In_ ULONG NewEntryCount)
{
if (m_hModule)
{
if (growFunctionTable == nullptr)
{
growFunctionTable = (PFnRtlGrowFunctionTable)GetFunction("RtlGrowFunctionTable");
if (growFunctionTable == nullptr)
{
Assert(false);
return;
}
}
growFunctionTable(DynamicTable, NewEntryCount);
}
}
#endif