Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/host
diff options
context:
space:
mode:
Diffstat (limited to 'src/host')
-rw-r--r--src/host/keccak.c8
-rwxr-xr-xsrc/host/os_getversion.c192
-rwxr-xr-xsrc/host/os_is64bit.c25
3 files changed, 151 insertions, 74 deletions
diff --git a/src/host/keccak.c b/src/host/keccak.c
index d4a3d70..6c97cf4 100644
--- a/src/host/keccak.c
+++ b/src/host/keccak.c
@@ -155,7 +155,7 @@ static void store64(UINT8 *x, UINT64 u)
unsigned int i;
for(i=0; i<8; ++i) {
- x[i] = u;
+ x[i] = u & 0xFF;
u >>= 8;
}
}
@@ -285,8 +285,8 @@ that use the Keccak-f[1600] permutation.
void Keccak(unsigned int rate, unsigned int capacity, const unsigned char *input, unsigned long long int inputByteLen, unsigned char delimitedSuffix, unsigned char *output, unsigned long long int outputByteLen)
{
UINT8 state[200];
- unsigned int rateInBytes = rate/8;
- unsigned int blockSize = 0;
+ unsigned long long int rateInBytes = rate/8;
+ unsigned long long int blockSize = 0;
unsigned int i;
if (((rate + capacity) != 1600) || ((rate % 8) != 0))
@@ -323,7 +323,7 @@ void Keccak(unsigned int rate, unsigned int capacity, const unsigned char *input
/* === Squeeze out all the output blocks === */
while(outputByteLen > 0) {
blockSize = MIN(outputByteLen, rateInBytes);
- memcpy(output, state, blockSize);
+ memcpy(output, state, (size_t)blockSize);
output += blockSize;
outputByteLen -= blockSize;
diff --git a/src/host/os_getversion.c b/src/host/os_getversion.c
index 446848f..609ca04 100755
--- a/src/host/os_getversion.c
+++ b/src/host/os_getversion.c
@@ -63,82 +63,148 @@ int os_getversion(lua_State* L)
SYSTEM_INFO getsysteminfo()
{
- typedef void (WINAPI *GetNativeSystemInfoSig)(LPSYSTEM_INFO);
- GetNativeSystemInfoSig nativeSystemInfo = (GetNativeSystemInfoSig)
- GetProcAddress(GetModuleHandle(TEXT("kernel32")), "GetNativeSystemInfo");
+ static SYSTEM_INFO systemInfo;
+ HMODULE hKrnl32 = GetModuleHandle(TEXT("kernel32"));
+ memset(&systemInfo, 0, sizeof(systemInfo));
+ if (hKrnl32)
+ {
+ typedef void (WINAPI* GetNativeSystemInfoSig)(LPSYSTEM_INFO);
+ GetNativeSystemInfoSig nativeSystemInfo = (GetNativeSystemInfoSig)GetProcAddress(hKrnl32, "GetNativeSystemInfo");
- SYSTEM_INFO systemInfo = {{0}};
- if ( nativeSystemInfo ) nativeSystemInfo(&systemInfo);
- else GetSystemInfo(&systemInfo);
+ if (nativeSystemInfo)
+ nativeSystemInfo(&systemInfo);
+ else
+ GetSystemInfo(&systemInfo);
+ }
return systemInfo;
}
-void getversion(struct OsVersionInfo* info)
-{
- OSVERSIONINFOEX versionInfo = {0};
-
- versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
- GetVersionEx((OSVERSIONINFO*)&versionInfo);
-
- info->majorversion = versionInfo.dwMajorVersion;
- info->minorversion = versionInfo.dwMinorVersion;
- info->revision = versionInfo.wServicePackMajor;
+#ifndef NT_SUCCESS
+# define NT_SUCCESS(x) ((x) >= 0)
+#endif
- if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 0)
- {
- info->description = "Windows 2000";
- }
- else if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 1)
- {
- info->description = "Windows XP";
- }
- else if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 2)
- {
- SYSTEM_INFO systemInfo = getsysteminfo();
- if (versionInfo.wProductType == VER_NT_WORKSTATION &&
- systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
- {
- info->description = "Windows XP Professional x64";
- }
- else if (versionInfo.wSuiteMask & VER_SUITE_WH_SERVER)
- {
- info->description = "Windows Home Server";
- }
- else if (GetSystemMetrics(SM_SERVERR2) == 0)
- {
- info->description = "Windows Server 2003";
- }
- else
- {
- info->description = "Windows Server 2003 R2";
- }
- }
- else if (versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion == 0)
+OSVERSIONINFOEXW const * GetOSVersionInfo()
+{
+ static OSVERSIONINFOEXW* posvix = NULL;
+ if (!posvix)
{
- if (versionInfo.wProductType == VER_NT_WORKSTATION)
+ static OSVERSIONINFOEXW osvix = { sizeof(OSVERSIONINFOEXW), 0, 0, 0, 0,{ 0 } }; // not an error, this has to be the W variety!
+ static LONG(WINAPI * RtlGetVersion)(OSVERSIONINFOEXW*) = NULL;
+ static HMODULE hNtDll = NULL;
+ hNtDll = GetModuleHandle(TEXT("ntdll.dll"));
+ if (hNtDll)
{
- info->description = "Windows Vista";
- }
- else
- {
- info->description = "Windows Server 2008";
+ *(FARPROC*)&RtlGetVersion = GetProcAddress(hNtDll, "RtlGetVersion");
+ if (NULL != RtlGetVersion)
+ {
+ if (NT_SUCCESS(RtlGetVersion(&osvix)))
+ {
+ posvix = &osvix;
+ }
+ }
}
}
- else if (versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion == 1 )
+ return posvix;
+}
+
+void getversion(struct OsVersionInfo* info)
+{
+ static OSVERSIONINFOEXW const* posvix = NULL;
+ static struct OsVersionInfo s_info;
+ s_info.majorversion = 0;
+ s_info.minorversion = 0;
+ s_info.revision = 0;
+ s_info.description = "Windows";
+
+ if (!posvix)
{
- if (versionInfo.wProductType != VER_NT_WORKSTATION)
+ posvix = GetOSVersionInfo();
+ if (posvix)
{
- info->description = "Windows Server 2008 R2";
+ s_info.majorversion = posvix->dwMajorVersion;
+ s_info.minorversion = posvix->dwMinorVersion;
+ s_info.revision = posvix->wServicePackMajor;
+ switch (posvix->dwMajorVersion)
+ {
+ case 5:
+ switch (posvix->dwMinorVersion)
+ {
+ case 0:
+ s_info.description = "Windows 2000";
+ break;
+ case 1:
+ s_info.description = "Windows XP";
+ break;
+ case 2:
+ if (posvix->wProductType == VER_NT_WORKSTATION)
+ s_info.description = "Windows XP x64";
+ else
+ if (posvix->wSuiteMask == VER_SUITE_WH_SERVER)
+ s_info.description = "Windows Home Server";
+ else
+ {
+ if (GetSystemMetrics(SM_SERVERR2) == 0)
+ s_info.description = "Windows Server 2003";
+ else
+ s_info.description = "Windows Server 2003 R2";
+ }
+ break;
+ default:
+ s_info.description = "Windows [5.x]";
+ break;
+ }
+ break;
+ case 6:
+ switch (posvix->dwMinorVersion)
+ {
+ case 0:
+ if (posvix->wProductType == VER_NT_WORKSTATION)
+ s_info.description = "Windows Vista";
+ else
+ s_info.description = "Windows Server 2008";
+ break;
+ case 1:
+ if (posvix->wProductType == VER_NT_WORKSTATION)
+ s_info.description = "Windows 7";
+ else
+ s_info.description = "Windows Server 2008 R2";
+ break;
+ case 2:
+ if (posvix->wProductType == VER_NT_WORKSTATION)
+ s_info.description = "Windows 8";
+ else
+ s_info.description = "Windows Server 2012";
+ break;
+ case 3:
+ if (posvix->wProductType == VER_NT_WORKSTATION)
+ s_info.description = "Windows 8.1";
+ else
+ s_info.description = "Windows Server 2012 R2";
+ break;
+ default:
+ s_info.description = "Windows [6.x]";
+ break;
+ }
+ break;
+ case 10:
+ switch (posvix->dwMinorVersion)
+ {
+ case 0:
+ if (posvix->wProductType == VER_NT_WORKSTATION)
+ s_info.description = "Windows 10";
+ else
+ s_info.description = "Windows Server 2016/2019";
+ break;
+ default:
+ s_info.description = "Windows [10.x]";
+ break;
+ }
+ break;
+ }
}
- else
- {
- info->description = "Windows 7";
- }
- }
- else
- {
- info->description = "Windows";
}
+
+ memmove(info, &s_info, sizeof(struct OsVersionInfo));
}
/*************************************************************/
diff --git a/src/host/os_is64bit.c b/src/host/os_is64bit.c
index 3134751..2537c2e 100755
--- a/src/host/os_is64bit.c
+++ b/src/host/os_is64bit.c
@@ -8,19 +8,30 @@
int os_is64bit(lua_State* L)
{
+#if PLATFORM_WINDOWS
+ HMODULE hKrnl32 = GetModuleHandle(TEXT("kernel32"));
+#endif
+ if (sizeof(void*) == 8) // our premake build is 64-bit, so the runtime environment must be also (at least) 64-bit ...
+ {
+ lua_pushboolean(L, 1);
+ return 1;
+ }
// If this code returns true, then the platform is 64-bit. If it
// returns false, the platform might still be 64-bit, but more
// checking will need to be done on the Lua side of things.
#if PLATFORM_WINDOWS
- typedef BOOL (WINAPI* WowFuncSig)(HANDLE, PBOOL);
- WowFuncSig func = (WowFuncSig)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
- if (func)
+ typedef BOOL(WINAPI* WowFuncSig)(HANDLE, PBOOL);
+ if (hKrnl32)
{
- BOOL isWow = FALSE;
- if (func(GetCurrentProcess(), &isWow))
+ WowFuncSig func = (WowFuncSig)GetProcAddress(hKrnl32, "IsWow64Process");
+ if (func)
{
- lua_pushboolean(L, isWow);
- return 1;
+ BOOL isWow = FALSE;
+ if (func(GetCurrentProcess(), &isWow))
+ {
+ lua_pushboolean(L, isWow);
+ return 1;
+ }
}
}
#endif