forked from somma/_MyLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Wow64Util.cpp
214 lines (177 loc) · 5.71 KB
/
Wow64Util.cpp
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
///////////////////////////////////////////////////////////////////////////////
// (C) Copyright 2004. Yoo Byung In.
//
// Any part of this source code can not be copied with
// any method without prior written permission from
// the author or authorized person.
//
// File Name : Wow64Util.cpp
// Author : Yoo, Byung In (hanlife7@hanmail.net)
// Descrtption : implementation of the CWow64Util class.
//
// Revision History
// Date Name Description
// 2004-02-18 Yoo, Byung In (hanlife7@hanmail.net) Created
//
///////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Wow64Util.h"
//////////////////////////////////////////////////////////////////////
// Destructor
//////////////////////////////////////////////////////////////////////
CWow64Util::~CWow64Util()
{
if( m_hKernel32 ) FreeLibrary( m_hKernel32 );
if( m_hUser32 ) FreeLibrary( m_hUser32 );
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
CWow64Util::CWow64Util()
{
m_pfnGetNativeSystemInfo = NULL;
m_pfnIsWow64Process = NULL;
m_pfnWow64EnableWow64FsRedirection = NULL;
m_pfnGetSystemWow64Directory = NULL;
m_pfnIsWow64Message = NULL;
m_hKernel32 = LoadLibrary( TEXT("Kernel32.DLL"));
m_hUser32 = LoadLibrary( TEXT("User32.DLL") );
if( m_hKernel32 )
{
m_pfnGetNativeSystemInfo = (LPFN_GetNativeSystemInfo)GetProcAddress(m_hKernel32, "GetNativeSystemInfo");
m_pfnIsWow64Process = (LPFN_IsWow64Process)GetProcAddress(m_hKernel32, "IsWow64Process");
m_pfnWow64EnableWow64FsRedirection = (LPFN_Wow64EnableWow64FsRedirection)GetProcAddress(m_hKernel32, "Wow64EnableWow64FsRedirection");
m_pfnGetSystemWow64Directory = (LPFN_GetSystemWow64Directory)GetProcAddress(m_hKernel32, "GetSystemWow64Directory");
}
if( m_hUser32 )
{
m_pfnIsWow64Message = (LPFN_IsWow64Message)GetProcAddress(m_hUser32, "IsWow64Message");
}
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
BOOL CWow64Util::IsWow64Process( VOID )
{
BOOL bRtVal = FALSE;
if( m_pfnIsWow64Process )
{
m_pfnIsWow64Process(GetCurrentProcess(), &bRtVal);
}
return bRtVal;
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
BOOL CWow64Util::IsWow64Process( HANDLE hProcess )
{
BOOL bRtVal = FALSE;
if( NULL == hProcess ) hProcess = GetCurrentProcess();
if( m_pfnIsWow64Process)
{
m_pfnIsWow64Process(hProcess, &bRtVal);
}
return bRtVal;
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
BOOL CWow64Util::IsWow64Process( DWORD pid )
{
BOOL bRtVal = FALSE;
HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
if (INVALID_HANDLE_VALUE == hProc)
{
return FALSE;
}
return IsWow64Process(hProc);
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
BOOL CWow64Util::IsWow64Message( )
{
BOOL bRtVal = FALSE;
if( m_pfnIsWow64Message)
{
bRtVal = m_pfnIsWow64Message();
}
return bRtVal;
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
BOOL CWow64Util::IsProcessorIA64( )
{
BOOL bRtVal = FALSE;
SYSTEM_INFO SystemInfo;
GetWow64SystemInfo( &SystemInfo );
if( SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
{
bRtVal = TRUE;
}
return bRtVal;
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
BOOL CWow64Util::IsProcessorAMD64( )
{
BOOL bRtVal = FALSE;
SYSTEM_INFO SystemInfo;
GetWow64SystemInfo( &SystemInfo );
if( SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 )
{
bRtVal = TRUE;
}
return bRtVal;
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
BOOL CWow64Util::TurnOnWow64FSRedirection()
{
BOOL bRtVal = FALSE;
if( m_pfnWow64EnableWow64FsRedirection )
{
bRtVal = m_pfnWow64EnableWow64FsRedirection(TRUE);
}
return bRtVal;
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
BOOL CWow64Util::TurnOffWow64FSRedirection()
{
BOOL bRtVal = FALSE;
if( m_pfnWow64EnableWow64FsRedirection )
{
bRtVal = m_pfnWow64EnableWow64FsRedirection(FALSE);
}
return bRtVal;
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
UINT CWow64Util::GetWow64SystemDirectory( LPTSTR lpBuffer, UINT uSize )
{
UINT uRtVal = 0;
if( m_pfnGetSystemWow64Directory )
{
uRtVal = m_pfnGetSystemWow64Directory ( lpBuffer, uSize );
}
return uRtVal;
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
VOID CWow64Util::GetWow64SystemInfo( LPSYSTEM_INFO lpSystemInfo )
{
if(m_pfnGetNativeSystemInfo)
{
m_pfnGetNativeSystemInfo(lpSystemInfo);
}
}
//////////////////////////////////////////////////////////////////////
// END OF SOURCE
//////////////////////////////////////////////////////////////////////