blob: 30c8ef50816ef5f29eea7df284ea415034e5b596 (
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
|
///////////////////////////////////////////////////////////////////////////////
///
/// Written 2012, Oliver Schneider (assarbad.net) - PUBLIC DOMAIN/CC0
///
/// Original filename: wow64.c
/// Project : WinDirStat
/// Author(s) : Oliver Schneider
///
/// Purpose : Lua function, implemented in C, to check whether the
/// current process is running as WOW64 process.
///
///////////////////////////////////////////////////////////////////////////////
#include <Windows.h>
#include <tchar.h>
#include <lua.h>
static int luaC_iswow64_(lua_State* L)
{
static int *pcachedResult = NULL;
if(!pcachedResult)
{
typedef BOOL (WINAPI *TFNIsWow64Process) (HANDLE, PBOOL);
static int cachedResult = 0;
HMODULE hKernel32 = GetModuleHandle(TEXT("kernel32.dll"));
if(hKernel32)
{
TFNIsWow64Process pfnIsWow64Process = (TFNIsWow64Process)GetProcAddress(hKernel32, "IsWow64Process");
if(pfnIsWow64Process)
{
BOOL bIsWow64 = FALSE;
// Ignore result, instead presume it's not WOW64
(void)pfnIsWow64Process(GetCurrentProcess(), &bIsWow64);
cachedResult = (bIsWow64) ? 1 : 0;
}
}
pcachedResult = &cachedResult;
}
if(!pcachedResult)
{
lua_pushnil(L);
return 1;
}
lua_pushboolean(L, *pcachedResult);
return 1;
}
LUA_API const luaL_Reg wow64_funcs[] = {
{"iswow64", luaC_iswow64_},
{NULL, NULL}
};
|