WinCommon 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/win_common.rb +6 -4
- data/lib/win_common/constants.rb +30 -0
- data/lib/win_common/errors.rb +14 -0
- data/lib/win_common/functions.rb +41 -0
- data/lib/win_common/libraries.rb +6 -0
- data/lib/win_common/macro.rb +27 -0
- data/lib/win_common/structs.rb +25 -87
- data/lib/win_common/structs_ffi.rb +91 -0
- data/lib/win_common/version.rb +1 -1
- metadata +14 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9a1814af4a4f7c4dc8a69045978139afad8b62e
|
4
|
+
data.tar.gz: 5b99327b4a142f8fb6455df3a75a82d98ed11d34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c24a5f1951e5521e1e33cf4a4bf6de199ecfc20170b2fee1fbd6eee4d436014fe73aa1667f9438a50099bfa841f374b8a04f8b340d70a640a83a4d53e2830d50
|
7
|
+
data.tar.gz: a1d8b307f7816936b7959043e3ed83eb767b09a82ae0d310accba753fc1a4c4c20ac12bf57d1a2d75d9372e7ab65616fc89d936134d0c77ae64b2d47650acf62
|
data/lib/win_common.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
require 'fiddle'
|
2
|
+
require 'fiddle/import'
|
3
|
+
|
1
4
|
require_relative 'win_common/version'
|
2
5
|
require_relative 'win_common/constants'
|
3
6
|
require_relative 'win_common/errors'
|
7
|
+
require_relative 'win_common/libraries'
|
8
|
+
require_relative 'win_common/structs'
|
9
|
+
require_relative 'win_common/macro'
|
4
10
|
require_relative 'win_common/functions'
|
5
|
-
|
6
|
-
module WinCommon
|
7
|
-
|
8
|
-
end
|
data/lib/win_common/constants.rb
CHANGED
@@ -2,5 +2,35 @@ module WinCommon
|
|
2
2
|
module Constants
|
3
3
|
FALSE = 0
|
4
4
|
TRUE = 1
|
5
|
+
SpecVersion = {
|
6
|
+
:WIN32_WINNT_NT4 => 0x0400,
|
7
|
+
:WIN32_WINNT_WIN2K => 0x0500,
|
8
|
+
:WIN32_WINNT_WINXP => 0x0501,
|
9
|
+
:WIN32_WINNT_WS03 => 0x0502,
|
10
|
+
:WIN32_WINNT_VISTA => 0x0600,
|
11
|
+
:WIN32_WINNT_WIN7 => 0x0601,
|
12
|
+
:WIN32_WINNT_WIN8 => 0x0602,
|
13
|
+
:WIN32_WINNT_WINBLUE => 0x0603
|
14
|
+
}
|
15
|
+
VER_MINORVERSION = 0x0000001
|
16
|
+
VER_MAJORVERSION = 0x0000002
|
17
|
+
VER_BUILDNUMBER = 0x0000004
|
18
|
+
VER_PLATFORMID = 0x0000008
|
19
|
+
VER_SERVICEPACKMINOR = 0x0000010
|
20
|
+
VER_SERVICEPACKMAJOR = 0x0000020
|
21
|
+
VER_SUITENAME = 0x0000040
|
22
|
+
VER_PRODUCT_TYPE = 0x0000080
|
23
|
+
VER_PLATFORM_WIN32s = 0
|
24
|
+
VER_PLATFORM_WIN32_WINDOWS = 1
|
25
|
+
VER_PLATFORM_WIN32_NT = 2
|
26
|
+
VER_EQUAL = 1
|
27
|
+
VER_GREATER = 2
|
28
|
+
VER_GREATER_EQUAL = 3
|
29
|
+
VER_LESS = 4
|
30
|
+
VER_LESS_EQUAL = 5
|
31
|
+
VER_AND = 6
|
32
|
+
VER_OR = 7
|
33
|
+
VER_CONDITION_MASK = 7
|
34
|
+
VER_NUM_BITS_PER_CONDITION_MASK = 3
|
5
35
|
end
|
6
36
|
end
|
data/lib/win_common/errors.rb
CHANGED
@@ -2,6 +2,20 @@ module WinCommon
|
|
2
2
|
module Errors
|
3
3
|
class WinCommonError < RuntimeError; end
|
4
4
|
end
|
5
|
+
|
6
|
+
module Constants
|
7
|
+
FACILITY_NULL = 0x00
|
8
|
+
FACILITY_RPC = 0x01
|
9
|
+
FACILITY_DISPATCH = 0x02
|
10
|
+
FACILITY_STORAGE = 0x03
|
11
|
+
FACILITY_ITF = 0x04
|
12
|
+
FACILITY_WIN32 = 0x07
|
13
|
+
FACILITY_WINDOWS = 0x08
|
14
|
+
FACILITY_SSPI = 0x09
|
15
|
+
FACILITY_CONTROL = 0x0A
|
16
|
+
FACILITY_CERT = 0x0B
|
17
|
+
FACILITY_INTERNET = 0x0C
|
18
|
+
end
|
5
19
|
end
|
6
20
|
|
7
21
|
require_relative 'errors/hresult'
|
data/lib/win_common/functions.rb
CHANGED
@@ -1,5 +1,46 @@
|
|
1
1
|
module WinCommon
|
2
2
|
module Functions
|
3
3
|
|
4
|
+
GetLastError = Fiddle::Function.new( Libraries::Kernel32['GetLastError'], [], Fiddle::TYPE_LONG )
|
5
|
+
VerifyVersionInfo = Fiddle::Function.new( Libraries::Kernel32['VerifyVersionInfoW'],
|
6
|
+
[Fiddle::TYPE_VOIDP, -Fiddle::TYPE_LONG, -Fiddle::TYPE_LONG_LONG], Fiddle::TYPE_INT )
|
7
|
+
VerSetConditionMask = Fiddle::Function.new( Libraries::Kernel32['VerSetConditionMask'],
|
8
|
+
[-Fiddle::TYPE_LONG_LONG, -Fiddle::TYPE_LONG, -Fiddle::TYPE_CHAR], Fiddle::TYPE_LONG_LONG )
|
9
|
+
|
10
|
+
def self.IsWindowsVersionOrGreater?(wMajorVersion, wMinorVersion, wServicePackMajor = 0)
|
11
|
+
osvi = Structs::OSVERSIONINFOEXW.malloc
|
12
|
+
osvi.dwOSVersionInfoSize = Structs::OSVERSIONINFOEXW.size
|
13
|
+
osvi.dwMajorVersion = wMajorVersion
|
14
|
+
osvi.dwMinorVersion = wMinorVersion
|
15
|
+
osvi.wServicePackMajor = wServicePackMajor
|
16
|
+
|
17
|
+
dwlConditionMask = VerSetConditionMask.call(VerSetConditionMask.call(VerSetConditionMask.call(0,
|
18
|
+
Constants::VER_MAJORVERSION, Constants::VER_GREATER_EQUAL),
|
19
|
+
Constants::VER_MINORVERSION, Constants::VER_GREATER_EQUAL),
|
20
|
+
Constants::VER_SERVICEPACKMAJOR, Constants::VER_GREATER_EQUAL)
|
21
|
+
|
22
|
+
dwTypeMask = Constants::VER_MAJORVERSION | Constants::VER_MINORVERSION | Constants::VER_SERVICEPACKMAJOR
|
23
|
+
VerifyVersionInfo.call(osvi, dwTypeMask, dwlConditionMask) != Constants::FALSE
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.IsWindows7OrGreater?
|
27
|
+
win7 = Constants::SpecVersion[:WIN32_WINNT_WIN7]
|
28
|
+
IsWindowsVersionOrGreater?(Macro::HIBYTE(win7), Macro::LOBYTE(win7), 0)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.IsWindows7SP1OrGreater?
|
32
|
+
win7 = Constants::SpecVersion[:WIN32_WINNT_WIN7]
|
33
|
+
IsWindowsVersionOrGreater?(Macro::HIBYTE(win7), Macro::LOBYTE(win7), 1)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.IsWindows8OrGreater?
|
37
|
+
win8 = Constants::SpecVersion[:WIN32_WINNT_WIN8]
|
38
|
+
IsWindowsVersionOrGreater?(Macro::HIBYTE(win8), Macro::LOBYTE(win8), 0)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.IsWindows8Point1OrGreater?
|
42
|
+
winBlue = Constants::SpecVersion[:WIN32_WINNT_WINBLUE]
|
43
|
+
IsWindowsVersionOrGreater?(Macro::HIBYTE(winBlue), Macro::LOBYTE(winBlue), 0)
|
44
|
+
end
|
4
45
|
end
|
5
46
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module WinCommon
|
2
|
+
module Macro
|
3
|
+
def self.LOWORD(dword)
|
4
|
+
dword & 0xFFFF
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.HIWORD(dword)
|
8
|
+
(dword >> 16) & 0xFFFF
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.LOBYTE(word)
|
12
|
+
word & 0xFF
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.HIBYTE(word)
|
16
|
+
(word >> 8) & 0xFF
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.SpecVersion(version)
|
20
|
+
Constants::SpecVersion(version)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.HRESULT_FROM_WIN32(error)
|
24
|
+
error <= 0 ? error : ((error & 0x0000FFFF) | (Constants::FACILITY_WIN32 << 16) | 0x80000000)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/win_common/structs.rb
CHANGED
@@ -1,91 +1,29 @@
|
|
1
1
|
module WinCommon
|
2
2
|
module Structs
|
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
|
-
:data3 => :ushort,
|
29
|
-
:data4 => [ :uchar, 8 ]
|
30
|
-
})
|
31
|
-
|
32
|
-
def from_str(guid)
|
33
|
-
data = [guid.gsub(/[{\-}]/, '')].pack('H*').unpack('L>S>2C8')
|
34
|
-
self[:data1] = data[0]
|
35
|
-
self[:data2] = data[1]
|
36
|
-
self[:data3] = data[2]
|
37
|
-
3.upto(data.count - 1) do |i|
|
38
|
-
self[:data4][i-3] = data[i]
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def to_s
|
43
|
-
str = "%08X-%04X-%04X-%02X%02X-" % [self[:data1], self[:data2], self[:data3], self[:data4][0], self[:data4][1]]
|
44
|
-
2.upto(7) do |i|
|
45
|
-
str << "%02X" % self[:data4][i]
|
46
|
-
end
|
47
|
-
str
|
48
|
-
end
|
49
|
-
|
50
|
-
def to_ref
|
51
|
-
self.ptr
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
IID = GUID
|
56
|
-
CLSID = GUID
|
57
|
-
FMTID = GUID
|
58
|
-
|
59
|
-
class WideString
|
60
|
-
extend FFI::DataConverter
|
61
|
-
native_type FFI::Type::POINTER
|
62
|
-
def self.to_native(value, context)
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.from_native(pointer, context)
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.size
|
69
|
-
FFI.type_size(FFI::Type::POINTER)
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.reference_required?
|
73
|
-
false
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
module Typedefs
|
79
|
-
FFI.typedef Structs::POINT.ptr, :PPOINT
|
80
|
-
FFI.typedef Structs::SIZE.ptr, :PSIZE
|
81
|
-
FFI.typedef Structs::FILETIME.ptr, :PFILETIME
|
82
|
-
FFI.typedef Structs::GUID.ptr, :LPGUID
|
83
|
-
FFI.typedef Structs::GUID.ptr, :LPCGUID
|
84
|
-
FFI.typedef Structs::IID.ptr, :LPIID
|
85
|
-
FFI.typedef Structs::CLSID.ptr, :LPCLSID
|
86
|
-
FFI.typedef Structs::FMTID.ptr, :LPFMTID
|
87
|
-
FFI.typedef Structs::GUID.by_ref(:in), :REFGUID
|
88
|
-
FFI.typedef Structs::IID.by_ref(:in), :REFIID
|
89
|
-
FFI.typedef Structs::CLSID.by_ref(:in), :REFCLSID
|
3
|
+
OSVERSIONINFOEXW = Fiddle::CStructBuilder.create(Fiddle::CStruct,
|
4
|
+
[-Fiddle::TYPE_LONG,
|
5
|
+
-Fiddle::TYPE_LONG,
|
6
|
+
-Fiddle::TYPE_LONG,
|
7
|
+
-Fiddle::TYPE_LONG,
|
8
|
+
-Fiddle::TYPE_LONG,
|
9
|
+
[Fiddle::TYPE_SHORT, 128],
|
10
|
+
-Fiddle::TYPE_SHORT,
|
11
|
+
-Fiddle::TYPE_SHORT,
|
12
|
+
-Fiddle::TYPE_SHORT,
|
13
|
+
-Fiddle::TYPE_CHAR,
|
14
|
+
-Fiddle::TYPE_CHAR
|
15
|
+
],
|
16
|
+
['dwOSVersionInfoSize',
|
17
|
+
'dwMajorVersion',
|
18
|
+
'dwMinorVersion',
|
19
|
+
'dwBuildNumber',
|
20
|
+
'dwPlatformId',
|
21
|
+
'szCSDVersion',
|
22
|
+
'wServicePackMajor',
|
23
|
+
'wServicePackMinor',
|
24
|
+
'wSuiteMask',
|
25
|
+
'wProductType',
|
26
|
+
'wReserved'
|
27
|
+
])
|
90
28
|
end
|
91
29
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module WinCommon
|
2
|
+
module Structs
|
3
|
+
class POINT < FFI::Struct
|
4
|
+
layout({
|
5
|
+
:x => :LONG,
|
6
|
+
:y => :LONG
|
7
|
+
})
|
8
|
+
end
|
9
|
+
|
10
|
+
class SIZE < FFI::Struct
|
11
|
+
layout({
|
12
|
+
:cx => :LONG,
|
13
|
+
:cy => :LONG
|
14
|
+
})
|
15
|
+
end
|
16
|
+
|
17
|
+
class FILETIME < FFI::Struct
|
18
|
+
layout({
|
19
|
+
:dwLowDateTime => :DWORD,
|
20
|
+
:dwHighDateTime => :DWORD
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
24
|
+
class GUID < FFI::Struct
|
25
|
+
layout({
|
26
|
+
:data1 => :ulong,
|
27
|
+
:data2 => :ushort,
|
28
|
+
:data3 => :ushort,
|
29
|
+
:data4 => [ :uchar, 8 ]
|
30
|
+
})
|
31
|
+
|
32
|
+
def from_str(guid)
|
33
|
+
data = [guid.gsub(/[{\-}]/, '')].pack('H*').unpack('L>S>2C8')
|
34
|
+
self[:data1] = data[0]
|
35
|
+
self[:data2] = data[1]
|
36
|
+
self[:data3] = data[2]
|
37
|
+
3.upto(data.count - 1) do |i|
|
38
|
+
self[:data4][i-3] = data[i]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
str = "%08X-%04X-%04X-%02X%02X-" % [self[:data1], self[:data2], self[:data3], self[:data4][0], self[:data4][1]]
|
44
|
+
2.upto(7) do |i|
|
45
|
+
str << "%02X" % self[:data4][i]
|
46
|
+
end
|
47
|
+
str
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_ref
|
51
|
+
self.ptr
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
IID = GUID
|
56
|
+
CLSID = GUID
|
57
|
+
FMTID = GUID
|
58
|
+
|
59
|
+
class WideString
|
60
|
+
extend FFI::DataConverter
|
61
|
+
native_type FFI::Type::POINTER
|
62
|
+
def self.to_native(value, context)
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.from_native(pointer, context)
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.size
|
69
|
+
FFI.type_size(FFI::Type::POINTER)
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.reference_required?
|
73
|
+
false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
module Typedefs
|
79
|
+
FFI.typedef Structs::POINT.ptr, :PPOINT
|
80
|
+
FFI.typedef Structs::SIZE.ptr, :PSIZE
|
81
|
+
FFI.typedef Structs::FILETIME.ptr, :PFILETIME
|
82
|
+
FFI.typedef Structs::GUID.ptr, :LPGUID
|
83
|
+
FFI.typedef Structs::GUID.ptr, :LPCGUID
|
84
|
+
FFI.typedef Structs::IID.ptr, :LPIID
|
85
|
+
FFI.typedef Structs::CLSID.ptr, :LPCLSID
|
86
|
+
FFI.typedef Structs::FMTID.ptr, :LPFMTID
|
87
|
+
FFI.typedef Structs::GUID.by_ref(:in), :REFGUID
|
88
|
+
FFI.typedef Structs::IID.by_ref(:in), :REFIID
|
89
|
+
FFI.typedef Structs::CLSID.by_ref(:in), :REFCLSID
|
90
|
+
end
|
91
|
+
end
|
data/lib/win_common/version.rb
CHANGED
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: WinCommon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dāvis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Library for commonly used Windows constants, data types, typedefs, structures
|
@@ -46,9 +46,9 @@ executables: []
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
-
-
|
50
|
-
-
|
51
|
-
-
|
49
|
+
- .gitignore
|
50
|
+
- .travis.yml
|
51
|
+
- .yardopts
|
52
52
|
- Gemfile
|
53
53
|
- README.md
|
54
54
|
- Rakefile
|
@@ -60,7 +60,10 @@ files:
|
|
60
60
|
- lib/win_common/errors.rb
|
61
61
|
- lib/win_common/errors/hresult.rb
|
62
62
|
- lib/win_common/functions.rb
|
63
|
+
- lib/win_common/libraries.rb
|
64
|
+
- lib/win_common/macro.rb
|
63
65
|
- lib/win_common/structs.rb
|
66
|
+
- lib/win_common/structs_ffi.rb
|
64
67
|
- lib/win_common/typedefs.rb
|
65
68
|
- lib/win_common/version.rb
|
66
69
|
- spec/spec_helper.rb
|
@@ -76,12 +79,12 @@ require_paths:
|
|
76
79
|
- lib
|
77
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
78
81
|
requirements:
|
79
|
-
- -
|
82
|
+
- - '>='
|
80
83
|
- !ruby/object:Gem::Version
|
81
84
|
version: '0'
|
82
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
86
|
requirements:
|
84
|
-
- -
|
87
|
+
- - '>='
|
85
88
|
- !ruby/object:Gem::Version
|
86
89
|
version: '0'
|
87
90
|
requirements: []
|