Last active
September 24, 2019 20:05
-
-
Save TheVice/eb0494bc5fe4c9881ec7b3b175e189b2 to your computer and use it in GitHub Desktop.
This is an extension of VersionHelpers.h that come with Visual Studio 2013 and above. As in original manifest file in application should be present for work check of Windows 8.1 and above - https://blogs.msdn.microsoft.com/chuckw/2013/09/10/manifest-madness/ .
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; The MIT License (MIT) | |
; Copyright (c) 2017 https://github.com/TheVice/ | |
; Permission is hereby granted, free of charge, to any person obtaining a copy | |
; of this software and associated documentation files (the "Software"), to deal | |
; in the Software without restriction, including without limitation the rights | |
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
; copies of the Software, and to permit persons to whom the Software is | |
; furnished to do so, subject to the following conditions: | |
; The above copyright notice and this permission notice shall be included in all | |
; copies or substantial portions of the Software. | |
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
; SOFTWARE. | |
; For assembly this program use fasm, | |
; that can be found here https://flatassembler.net/ | |
; Sample using: | |
; 1) IsWindowsVersionOrGreater.exe 6 1 7601 1 | |
; 2) IsWindowsVersionOrGreater.exe 6 2 9200 0 | |
; 3) IsWindowsVersionOrGreater.exe 10 0 15063 0 | |
; Program return zero code on true and other values in any other cases | |
; To check return code in Windows Batch use script from this article - https://msdn.microsoft.com/en-us/library/0fwzzxz2(v=vs.120).aspx | |
; For PowerShell - https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/main-and-command-args/main-return-values | |
; For program check return please refer to documentation of your program environment | |
format PE64 console ; GUI | |
entry start | |
include 'win64w.inc' | |
struct OSVERSIONINFOEXW | |
dwOSVersionInfoSize dd ? | |
dwMajorVersion dd ? | |
dwMinorVersion dd ? | |
dwBuildNumber dd ? | |
dwPlatformId dd ? | |
szCSDVersion du 128 dup(?) | |
wServicePackMajor dw ? | |
wServicePackMinor dw ? | |
wSuiteMask dw ? | |
wProductType db ? | |
wReserved db ? | |
ends | |
VER_MINORVERSION = 0x0000001 | |
VER_MAJORVERSION = 0x0000002 | |
VER_BUILDNUMBER = 0x0000004 | |
VER_PLATFORMID = 0x0000008 | |
VER_SERVICEPACKMINOR = 0x0000010 | |
VER_SERVICEPACKMAJOR = 0x0000020 | |
VER_SUITENAME = 0x0000040 | |
VER_PRODUCT_TYPE = 0x0000080 | |
VER_EQUAL = 1 | |
VER_GREATER = 2 | |
VER_GREATER_EQUAL = 3 | |
VER_LESS = 4 | |
VER_LESS_EQUAL = 5 | |
VER_AND = 6 | |
VER_OR = 7 | |
section '.idata' data readable import | |
library kernel32, 'kernel32', \ | |
shell32, 'shell32', \ | |
msvcrt, 'msvcrt' | |
import kernel32, \ | |
VerSetConditionMask, 'VerSetConditionMask', \ | |
VerifyVersionInfo, 'VerifyVersionInfoW', \ | |
LocalFree, 'LocalFree', \ | |
GetCommandLine, 'GetCommandLineW', \ | |
ExitProcess, 'ExitProcess' | |
import shell32, \ | |
CommandLineToArgv, 'CommandLineToArgvW' | |
import msvcrt, \ | |
_wtoi64, '_wtoi64' | |
section '.rsrc' resource data readable | |
directory RT_MANIFEST, _manifest | |
resource _manifest, 1, LANG_NEUTRAL, manifest | |
resdata manifest | |
;file 'settings.manifest' ; https://blogs.msdn.microsoft.com/chuckw/2013/09/10/manifest-madness/ | |
db '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"><application><!-- Windows 8.1 --><supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/><!-- Windows 10 --><supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/></application></compatibility></assembly>' | |
endres | |
section '.text' code readable executable | |
argc = 0 | |
argv = 8 | |
dwlConditionMask = 0 | |
dwTypeMask = 16 | |
lpVersionInformation = 24 | |
LocalFree_failed: | |
mov rcx, -2 | |
jmp exit | |
LocalFree_and_exist_with_failed: | |
mov rcx, [rsp + argv] | |
call [LocalFree] | |
test rax, rax | |
jnz LocalFree_failed | |
jmp failed_exit | |
failed_exit: | |
mov rcx, -1 | |
jmp exit | |
start: | |
sub rsp, 328 ; 16 * 20.5 | |
call [GetCommandLine] | |
lea rdx, [rsp + argc] | |
mov rcx, rax | |
call [CommandLineToArgv] | |
test rax, rax | |
jz failed_exit | |
mov [rsp + argv], rax | |
mov rcx, [rsp + argc] | |
cmp rcx, 4 + 1 ; <exe> 6 2 9200 0 | |
js LocalFree_and_exist_with_failed | |
virtual at rsp + lpVersionInformation | |
osvi OSVERSIONINFOEXW | |
end virtual | |
mov rsi, [rsp + argv] | |
add rsi, 8 | |
mov rcx, [rsi] | |
call [_wtoi64] | |
mov [osvi.dwMajorVersion], eax | |
add rsi, 8 | |
mov rcx, [rsi] | |
call [_wtoi64] | |
mov [osvi.dwMinorVersion], eax | |
add rsi, 8 | |
mov rcx, [rsi] | |
call [_wtoi64] | |
mov [osvi.dwBuildNumber], eax | |
add rsi, 8 | |
mov rcx, [rsi] | |
call [_wtoi64] | |
mov [osvi.wServicePackMajor], ax | |
mov rcx, [rsp + argv] | |
call [LocalFree] | |
test rax, rax | |
jnz LocalFree_failed | |
mov r8, VER_GREATER_EQUAL | |
mov rdx, VER_MAJORVERSION | |
xor rcx, rcx | |
call [VerSetConditionMask] | |
mov r8, VER_GREATER_EQUAL | |
mov rdx, VER_MINORVERSION | |
mov rcx, rax | |
call [VerSetConditionMask] | |
mov r8, VER_GREATER_EQUAL | |
mov rdx, VER_BUILDNUMBER | |
mov rcx, rax | |
call [VerSetConditionMask] | |
mov r8, VER_GREATER_EQUAL | |
mov rdx, VER_SERVICEPACKMAJOR | |
mov rcx, rax | |
call [VerSetConditionMask] | |
mov [rsp + dwlConditionMask], rax | |
mov rax, VER_MAJORVERSION | |
xor rax, VER_MINORVERSION | |
xor rax, VER_BUILDNUMBER | |
xor rax, VER_SERVICEPACKMAJOR | |
mov [rsp + dwTypeMask], rax ; 39 | |
mov [osvi.dwOSVersionInfoSize], sizeof.OSVERSIONINFOEXW ; 284 | |
;mov [osvi.dwMajorVersion], 6 | |
;mov [osvi.dwMinorVersion], 2 | |
;mov [osvi.dwBuildNumber], 9200 | |
;mov [osvi.wServicePackMajor], 0 | |
mov [osvi.wServicePackMinor], 0 | |
mov [osvi.dwPlatformId], 0 | |
mov [osvi.szCSDVersion], 0 | |
mov [osvi.wSuiteMask], 0 | |
mov [osvi.wProductType], 0 | |
mov [osvi.wReserved], 0 | |
mov r8, [rsp + dwlConditionMask] ; 9223372036854874331 | |
mov rdx, [rsp + dwTypeMask] | |
lea rcx, [rsp + lpVersionInformation] | |
call [VerifyVersionInfo] | |
test rax, rax | |
jz failed_exit | |
success_exit: | |
xor rcx, rcx | |
exit: | |
add rsp, 328 - 40 | |
call [ExitProcess] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _WINDOWS10_VERSION_HELPERS_H_ | |
#define _WINDOWS10_VERSION_HELPERS_H_ | |
#if defined(_MSC_VER) && (_MSC_VER >= 1800) | |
#include <VersionHelpers.h> | |
#else | |
#ifdef __cplusplus | |
#define VERSIONHELPERAPI bool | |
#else | |
#define VERSIONHELPERAPI int | |
#endif | |
#endif | |
VERSIONHELPERAPI | |
IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, DWORD dwBuildNumber, WORD wServicePackMajor) | |
{ | |
OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0,{ 0 }, 0, 0, 0, 0, 0}; | |
DWORDLONG const dwlConditionMask = VerSetConditionMask( | |
VerSetConditionMask( | |
VerSetConditionMask( | |
VerSetConditionMask( | |
0, VER_MAJORVERSION, VER_GREATER_EQUAL), | |
VER_MINORVERSION, VER_GREATER_EQUAL), | |
VER_BUILDNUMBER, VER_GREATER_EQUAL), | |
VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); | |
osvi.dwMajorVersion = wMajorVersion; | |
osvi.dwMinorVersion = wMinorVersion; | |
osvi.dwBuildNumber = dwBuildNumber; | |
osvi.wServicePackMajor = wServicePackMajor; | |
return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE; | |
} | |
VERSIONHELPERAPI | |
IsWindows10Version1709OrGreater() | |
{ | |
return IsWindowsVersionOrGreater(10, 0, 16299, 0); | |
} | |
VERSIONHELPERAPI | |
IsWindows10Version1703OrGreater() | |
{ | |
return IsWindowsVersionOrGreater(10, 0, 15063, 0); | |
} | |
VERSIONHELPERAPI | |
IsWindows10Version1607OrGreater() | |
{ | |
return IsWindowsVersionOrGreater(10, 0, 14393, 0); | |
} | |
VERSIONHELPERAPI | |
IsWindows10Version1511OrGreater() | |
{ | |
return IsWindowsVersionOrGreater(10, 0, 10586, 0); | |
} | |
VERSIONHELPERAPI | |
IsWindows10Version1507OrGreater() | |
{ | |
return IsWindowsVersionOrGreater(10, 0, 10240, 0); | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment