win-ffi-core 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +36 -0
- data/lib/win-ffi/core.rb +10 -0
- data/lib/win-ffi/core/boolean_utils.rb +34 -0
- data/lib/win-ffi/core/enum/firmware_type.rb +13 -0
- data/lib/win-ffi/core/enum/load_resource_flags.rb +47 -0
- data/lib/win-ffi/core/lib_base.rb +78 -0
- data/lib/win-ffi/core/macro/util.rb +38 -0
- data/lib/win-ffi/core/string_utils.rb +24 -0
- data/lib/win-ffi/core/struct.rb +17 -0
- data/lib/win-ffi/core/struct/guid.rb +27 -0
- data/lib/win-ffi/core/struct/luid.rb +9 -0
- data/lib/win-ffi/core/struct/point.rb +10 -0
- data/lib/win-ffi/core/struct/rect.rb +41 -0
- data/lib/win-ffi/core/struct/security_attributes.rb +7 -0
- data/lib/win-ffi/core/struct/size.rb +16 -0
- data/lib/win-ffi/core/typedef/core.rb +30 -0
- data/lib/win-ffi/core/version.rb +3 -0
- data/lib/win-ffi/core/wide_inline_string.rb +22 -0
- data/lib/win-ffi/core/wide_string_pointer.rb +19 -0
- data/lib/win-ffi/kernel32.rb +10 -0
- data/lib/win-ffi/kernel32/enum/version/win32_winnt.rb +22 -0
- data/lib/win-ffi/kernel32/struct/os_version_info_ex.rb +79 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 07b6199ff2041ec04c908e4a28715ede253489fd
|
4
|
+
data.tar.gz: 2bd9bf4e101580882935b128134bdea1225ca506
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad1362955f00d9cf9870f2ca1660028bb0f214491875aa4b5f9ff2bccf9b743ee4a70f9532e4959c77c0a2789d897bf8bdc874a52472a4a0545e9fa259127838
|
7
|
+
data.tar.gz: 5eb7492aa46d63f6e001ce6e9d6f2f5aca78e422db0cbbda98716a4a6981a86d6382046e5fcc24abb38c8b67dd66c2f6dfef85557342d00b16ae921ccaa7cc96
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# WinFFI
|
2
|
+
|
3
|
+
[![Join the chat at https://gitter.im/P3t3rU5/winffi](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/P3t3rU5/winffi?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
|
+
|
5
|
+
WinFFI is a gem to use the windows API using the ffi gem inspired by windows-pr gem.
|
6
|
+
This gem is work in progress
|
7
|
+
To install:
|
8
|
+
|
9
|
+
```
|
10
|
+
gem install win-ffi
|
11
|
+
```
|
12
|
+
|
13
|
+
# License
|
14
|
+
|
15
|
+
(The MIT License)
|
16
|
+
|
17
|
+
Copyright © 2013 Pedro Miranda
|
18
|
+
|
19
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
20
|
+
a copy of this software and associated documentation files (the
|
21
|
+
'Software'), to deal in the Software without restriction, including
|
22
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
23
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
24
|
+
permit persons to whom the Software is furnished to do so, subject to
|
25
|
+
the following conditions:
|
26
|
+
|
27
|
+
The above copyright notice and this permission notice shall be
|
28
|
+
included in all copies or substantial portions of the Software.
|
29
|
+
|
30
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
31
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
32
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
33
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
34
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
35
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
36
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/win-ffi/core.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module WinFFI
|
2
|
+
module BooleanUtils
|
3
|
+
refine ::TrueClass do
|
4
|
+
|
5
|
+
def to_native
|
6
|
+
1
|
7
|
+
end
|
8
|
+
|
9
|
+
alias_method :to_n, :to_native
|
10
|
+
alias_method :to_c, :to_native
|
11
|
+
end
|
12
|
+
|
13
|
+
refine ::FalseClass do
|
14
|
+
|
15
|
+
def to_native
|
16
|
+
0
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method :to_n, :to_native
|
20
|
+
alias_method :to_c, :to_native
|
21
|
+
end
|
22
|
+
|
23
|
+
refine ::NilClass do
|
24
|
+
|
25
|
+
def to_native
|
26
|
+
0
|
27
|
+
end
|
28
|
+
|
29
|
+
alias_method :to_n, :to_native
|
30
|
+
alias_method :to_c, :to_native
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'win-ffi/core/lib_base'
|
2
|
+
|
3
|
+
module WinFFI
|
4
|
+
extend LibBase
|
5
|
+
|
6
|
+
LoadResourceFlags = enum :load_resource_flags,
|
7
|
+
[
|
8
|
+
:DEFAULTCOLOR, 0x00000000, # The default flag; it does nothing. All it means is "not :MONOCHROME".
|
9
|
+
|
10
|
+
:MONOCHROME, 0x00000001, # Loads the image in black and white.
|
11
|
+
:COLOR, 0x00000002,
|
12
|
+
:COPYRETURNORG, 0x00000004,
|
13
|
+
:COPYDELETEORG, 0x00000008,
|
14
|
+
:LOADFROMFILE, 0x00000010, # Loads the stand-alone image from the file specified by lpszName (icon, cursor, or
|
15
|
+
# bitmap file).
|
16
|
+
:LOADTRANSPARENT, 0x00000020, # Retrieves the color value of the first pixel in the image and replaces the
|
17
|
+
# corresponding entry in the color table with the default window_class color (COLOR_WINDOW). All pixels in the image
|
18
|
+
# that use that entry become the default window_class color. This value applies only to images that have corresponding
|
19
|
+
# color tables.
|
20
|
+
:DEFAULTSIZE, 0x00000040, # Uses the width or height specified by the system metric values for cursors or icons,
|
21
|
+
# if the cxDesired or cyDesired values are set to zero. If this flag is not specified and cxDesired and
|
22
|
+
# cyDesired are set to zero, the function uses the actual resource size. If the resource contains multiple
|
23
|
+
# images, the function uses the size of the first image.
|
24
|
+
:VGACOLOR, 0x00000080, # Uses true VGA colors.
|
25
|
+
:LOADMAP3DCOLORS, 0x00001000, # Searches the color table for the image and replaces the following shades of gray
|
26
|
+
# with the corresponding 3-D color.
|
27
|
+
#Dk Gray, RGB(128,128,128) with COLOR_3DSHADOW
|
28
|
+
#Gray, RGB(192,192,192) with COLOR_3DFACE
|
29
|
+
#Lt Gray, RGB(223,223,223) with COLOR_3DLIGHT
|
30
|
+
# Do not use this option if you are loading a bitmap with a color depth greater than 8bpp.
|
31
|
+
|
32
|
+
:CREATEDIBSECTION, 0x00002000, # When the uType parameter specifies IMAGE_BITMAP, causes the function to return
|
33
|
+
# a DIB section bitmap rather than a compatible bitmap. This flag is useful for loading a bitmap without mapping
|
34
|
+
# it to the colors of the display device.
|
35
|
+
# Do not use this option if you are loading a bitmap with a color depth greater than 8bpp.
|
36
|
+
# If fuLoad includes both the :LOADTRANSPARENT and :LOADMAP3DCOLORS values, :LOADTRANSPARENT takes precedence.
|
37
|
+
# However, the color table entry is replaced with COLOR_3DFACE rather than COLOR_WINDOW.
|
38
|
+
:COPYFROMRESOURCE, 0x00004000,
|
39
|
+
:SHARED, 0x00008000, # Shares the image handle if the image is loaded multiple times. If :SHARED is not set, a
|
40
|
+
# second call to LoadImage for the same resource will load the image again and return a different handle.
|
41
|
+
# When you use this flag, the system will destroy the resource when it is no longer needed.
|
42
|
+
# Do not use :SHARED for images that have non-standard sizes, that may change after loading, or that are loaded
|
43
|
+
# from a file. When loading a system icon or cursor, you must use :SHARED or the function will fail to load the
|
44
|
+
# resource. This function finds the first image in the cache with the requested resource name, regardless of the
|
45
|
+
# size requested.
|
46
|
+
]
|
47
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
module WinFFI
|
5
|
+
@logger = Logger.new(STDOUT)
|
6
|
+
@logger.info "WinFFI #{VERSION}"
|
7
|
+
def self.logger
|
8
|
+
@logger
|
9
|
+
end
|
10
|
+
|
11
|
+
WinFFI.logger.debug 'Getting Encoding...'
|
12
|
+
@encoding = (__ENCODING__.name =~ /ASCII/ ? 'A' : 'W')
|
13
|
+
WinFFI.logger.debug 'Got Encoding: ' + @encoding
|
14
|
+
|
15
|
+
def self.encoding
|
16
|
+
@encoding
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.encoding=(encoding)
|
20
|
+
@encoding = encoding
|
21
|
+
end
|
22
|
+
|
23
|
+
module LibBase
|
24
|
+
extend FFI::Library
|
25
|
+
ffi_convention :stdcall
|
26
|
+
|
27
|
+
def encoded_function(name, *args, ruby_name: nil)
|
28
|
+
ruby_name = name unless ruby_name
|
29
|
+
attach_function ruby_name, name + WinFFI.encoding, *args
|
30
|
+
end
|
31
|
+
|
32
|
+
if WinFFI.encoding == 'A'
|
33
|
+
def self.string_from_byte_array(array)
|
34
|
+
array[0, array.index(0) || array.length].pack('C*').encode(Encoding::UTF_8)
|
35
|
+
end
|
36
|
+
else
|
37
|
+
def self.string_from_byte_array(array)
|
38
|
+
array = array[0, array.index(0) || array.length]
|
39
|
+
array.pack('S*').force_encoding(Encoding::UTF_16LE).encode(Encoding::UTF_8)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.extended(c)
|
44
|
+
c.extend FFI::Library
|
45
|
+
instance_variables.each do |v|
|
46
|
+
value = instance_variable_get(v)
|
47
|
+
value = value.dup unless value.is_a?(Fixnum) || value.is_a?(Symbol)
|
48
|
+
c.instance_variable_set(v, value)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
require 'win-ffi/core/typedef/core'
|
54
|
+
|
55
|
+
require 'win-ffi/kernel32/struct/os_version_info_ex'
|
56
|
+
|
57
|
+
module Kernel32
|
58
|
+
extend LibBase
|
59
|
+
|
60
|
+
ffi_lib 'kernel32'
|
61
|
+
|
62
|
+
#BOOL WINAPI GetVersionEx( _Inout_ LPOSVERSIONINFO lpVersionInfo )
|
63
|
+
encoded_function 'GetVersionEx', [OSVERSIONINFOEX.ptr], :bool
|
64
|
+
end
|
65
|
+
|
66
|
+
WinFFI.logger.debug 'Getting Architecture...'
|
67
|
+
Architecture = RbConfig::CONFIG['arch'] # "i386-mingw32" | "x64-mingw32"
|
68
|
+
WinFFI.logger.debug 'Got Architecture: ' + Architecture
|
69
|
+
|
70
|
+
WinFFI.logger.debug 'Getting Windows Version...'
|
71
|
+
WindowsVersion = OSVERSIONINFOEX.new.get!
|
72
|
+
WinFFI.logger.debug "Got Windows Version: #{WindowsVersion.hex}-> #{WindowsVersion.to_s}"
|
73
|
+
|
74
|
+
WindowsVersion.major, WindowsVersion.minor, WindowsVersion.build = `ver`.match(/\d+\.\d+\.\d+/)[0].split('.').map(&:to_i)
|
75
|
+
|
76
|
+
@logger.info "#{WindowsVersion.to_s} #{Architecture} #{__ENCODING__.to_s}"
|
77
|
+
end
|
78
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module WinFFI
|
2
|
+
def makeword(a, b)
|
3
|
+
((a & 0xff) | ((b & 0xff) << 8))
|
4
|
+
end
|
5
|
+
|
6
|
+
def makelong(a, b)
|
7
|
+
((a & 0xffff) | ((b & 0xffff) << 16))
|
8
|
+
end
|
9
|
+
|
10
|
+
def loword(l)
|
11
|
+
l & 0xffff
|
12
|
+
end
|
13
|
+
|
14
|
+
def hiword(l)
|
15
|
+
l >> 16
|
16
|
+
end
|
17
|
+
|
18
|
+
def lobyte(w)
|
19
|
+
w & 0xff
|
20
|
+
end
|
21
|
+
|
22
|
+
def hibyte(w)
|
23
|
+
w >> 8
|
24
|
+
end
|
25
|
+
|
26
|
+
def points_to_point(pt, pts)
|
27
|
+
pt.x = loword(pts)
|
28
|
+
pt.y = hiword(pts)
|
29
|
+
end
|
30
|
+
|
31
|
+
def point_to_points(pt)
|
32
|
+
makelong(pt.x, pt.y)
|
33
|
+
end
|
34
|
+
|
35
|
+
alias_method :makelresult, :makelong
|
36
|
+
alias_method :makelparam, :makelong
|
37
|
+
alias_method :makewparam, :makelong
|
38
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module WinFFI
|
2
|
+
module StringUtils
|
3
|
+
refine ::String do
|
4
|
+
|
5
|
+
def to_utf8
|
6
|
+
encode('utf-8')
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_w
|
10
|
+
encode('utf-16LE')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
refine ::Object do
|
15
|
+
def to_utf8
|
16
|
+
to_s.to_utf8
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_w
|
20
|
+
to_s.to_w
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'win-ffi/core/lib_base'
|
3
|
+
|
4
|
+
module WinFFI
|
5
|
+
extend LibBase
|
6
|
+
class FFIStruct < FFI::Struct
|
7
|
+
def self.layout(*args)
|
8
|
+
super
|
9
|
+
members.each do |name|
|
10
|
+
unless method_defined?(name)
|
11
|
+
define_method name, ->{ self[name] }
|
12
|
+
define_method "#{name}=", ->(v){ self[name] = v }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module WinFFI
|
2
|
+
# https://msdn.microsoft.com/en-us/library/windows/desktop/aa373931(v=vs.85).aspx
|
3
|
+
class GUID < FFIStruct
|
4
|
+
layout :Data1, :dword,
|
5
|
+
:Data2, :word,
|
6
|
+
:Data3, :word,
|
7
|
+
:Data4, [:byte, 8]
|
8
|
+
|
9
|
+
def from_str(guid)
|
10
|
+
data = [guid.gsub(/[{\-}]/, '')].pack('H*').unpack('L>S>2C8')
|
11
|
+
self.Data1 = data[0]
|
12
|
+
self.Data2 = data[1]
|
13
|
+
self.Data3 = data[2]
|
14
|
+
3.upto(data.count - 1) do |i|
|
15
|
+
self.Data4[i - 3] = data[i]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
str = "%08X-%04X-%04X-%02X%02X-" % [self.Data1, self.Data2, self.Data3, self.Data4[0], self.Data4[1]]
|
21
|
+
2.upto(7) do |i|
|
22
|
+
str << "%02X" % self.Data4[i]
|
23
|
+
end
|
24
|
+
str
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module WinFFI
|
2
|
+
# https://msdn.microsoft.com/en-us/library/windows/desktop/dd162897(v=vs.85).aspx
|
3
|
+
class RECT < FFIStruct
|
4
|
+
layout :left, :long,
|
5
|
+
:top, :long,
|
6
|
+
:right, :long,
|
7
|
+
:bottom, :long
|
8
|
+
|
9
|
+
# def initialize(left, top, right, bottom)
|
10
|
+
# self.left, self.top, self.right, self.bottom = left, top, right, bottom
|
11
|
+
# end
|
12
|
+
|
13
|
+
def area
|
14
|
+
width * height
|
15
|
+
end
|
16
|
+
|
17
|
+
def perimeter
|
18
|
+
2 * width + 2 * height
|
19
|
+
end
|
20
|
+
|
21
|
+
def width
|
22
|
+
right - left
|
23
|
+
end
|
24
|
+
|
25
|
+
def width=(v)
|
26
|
+
self.right = left + v
|
27
|
+
end
|
28
|
+
|
29
|
+
def height
|
30
|
+
bottom - top
|
31
|
+
end
|
32
|
+
|
33
|
+
def height=(v)
|
34
|
+
self.bottom = top + v
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
"(left = #{left}, top = #{top}, width = #{width}, height = #{height})"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module WinFFI
|
2
|
+
# https://msdn.microsoft.com/en-us/library/windows/desktop/dd145106(v=vs.85).aspx
|
3
|
+
class SIZE < FFIStruct
|
4
|
+
layout :cx, :long,
|
5
|
+
:cy, :long
|
6
|
+
|
7
|
+
def to_s
|
8
|
+
"Size x=#{x}, y=#{y}"
|
9
|
+
end
|
10
|
+
|
11
|
+
alias_method :x, :cx
|
12
|
+
alias_method :x=, :cx=
|
13
|
+
alias_method :y, :cy
|
14
|
+
alias_method :y=, :cy=
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'win-ffi/core/lib_base'
|
2
|
+
|
3
|
+
module WinFFI
|
4
|
+
module LibBase
|
5
|
+
typedef (WinFFI.encoding == 'A' ? :char : :ushort), :tchar
|
6
|
+
typedef :ushort, :atom
|
7
|
+
typedef :uchar, :byte
|
8
|
+
typedef :ushort, :word
|
9
|
+
typedef :uint, :dword
|
10
|
+
typedef :uint, :colorref
|
11
|
+
typedef :uint, :wparam
|
12
|
+
typedef :long, :lparam
|
13
|
+
typedef :long, :lresult
|
14
|
+
typedef :long, :hresult
|
15
|
+
typedef :ushort, :langid
|
16
|
+
%i'
|
17
|
+
handle
|
18
|
+
hbitmap
|
19
|
+
hbrush
|
20
|
+
hdc
|
21
|
+
hglobal
|
22
|
+
hicon
|
23
|
+
hinstance
|
24
|
+
hmodule
|
25
|
+
hwnd
|
26
|
+
'.each do |s|
|
27
|
+
typedef :pointer, s
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module WinFFI
|
2
|
+
class WideInlineString
|
3
|
+
include FFI::DataConverter
|
4
|
+
|
5
|
+
attr_reader :size, :native_type
|
6
|
+
|
7
|
+
def initialize(size)
|
8
|
+
@size = size
|
9
|
+
@native_type = FFI::ArrayType.new(WinFFI.find_type(:tchar), size)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_native(_value, _context)
|
13
|
+
raise NotImplementedError
|
14
|
+
end
|
15
|
+
|
16
|
+
def from_native(value, _context)
|
17
|
+
LibBase.string_from_byte_array(value.to_a)
|
18
|
+
end
|
19
|
+
|
20
|
+
alias_method :length, :size
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module WinFFI
|
2
|
+
class WideStringPointer
|
3
|
+
extend FFI::DataConverter
|
4
|
+
native_type FFI::Type::POINTER
|
5
|
+
# TODO
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def to_native(value, _context)
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
def from_native(pointer, _context)
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'win-ffi/kernel32'
|
2
|
+
|
3
|
+
module WinFFI
|
4
|
+
module Kernel32
|
5
|
+
# _WIN32_WINNT version constants
|
6
|
+
WIN32_WINNT = enum :win32_winnt, [
|
7
|
+
:NT4, 0x0400,
|
8
|
+
:WIN2K, 0x0500,
|
9
|
+
:WINXP, 0x0501,
|
10
|
+
:WS03, 0x0502,
|
11
|
+
:WIN6, 0x0600,
|
12
|
+
:VISTA, 0x0600,
|
13
|
+
:WS08, 0x0600,
|
14
|
+
:LONGHORN, 0x0600,
|
15
|
+
:WIN7, 0x0601,
|
16
|
+
:WIN8, 0x0602,
|
17
|
+
:WINBLUE, 0x0603,
|
18
|
+
:WINTHRESHOLD, 0x0A00, # ABRACADABRA_THRESHOLD
|
19
|
+
:WIN10, 0x0A00 # ABRACADABRA_THRESHOLD
|
20
|
+
]
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'win-ffi/core/wide_inline_string'
|
2
|
+
|
3
|
+
require 'win-ffi/core/struct'
|
4
|
+
|
5
|
+
require 'win-ffi/kernel32/enum/version/win32_winnt'
|
6
|
+
|
7
|
+
module WinFFI
|
8
|
+
class OSVERSIONINFOEX < FFIStruct
|
9
|
+
|
10
|
+
include Kernel32, Comparable
|
11
|
+
|
12
|
+
layout :dwOSVersionInfoSize, :ulong,
|
13
|
+
:dwMajorVersion, :ulong,
|
14
|
+
:dwMinorVersion, :ulong,
|
15
|
+
:dwBuildNumber, :ulong,
|
16
|
+
:dwPlatformId, :ulong,
|
17
|
+
:szCSDVersion, WideInlineString.new(128),
|
18
|
+
:wServicePackMajor, :ushort,
|
19
|
+
:wServicePackMinor, :ushort,
|
20
|
+
:wSuiteMask, :ushort,
|
21
|
+
:wProductType, :uchar,
|
22
|
+
:wReserved, :uchar
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
super
|
26
|
+
self[:dwOSVersionInfoSize] = size
|
27
|
+
end
|
28
|
+
|
29
|
+
def get!
|
30
|
+
Kernel32.GetVersionEx(self)
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def major; dwMajorVersion end
|
35
|
+
def minor; dwMinorVersion end
|
36
|
+
def build; dwBuildNumber end
|
37
|
+
def sp; wServicePackMajor end
|
38
|
+
|
39
|
+
def major=(major)
|
40
|
+
self.dwMajorVersion = major
|
41
|
+
end
|
42
|
+
|
43
|
+
def minor=(minor); self.dwMinorVersion = minor end
|
44
|
+
|
45
|
+
def build=(build); self.dwBuildNumber = build end
|
46
|
+
|
47
|
+
def hex; (major << 8) + minor end
|
48
|
+
|
49
|
+
def <=>(version)
|
50
|
+
hex <=> WIN32_WINNT[case version
|
51
|
+
when '2000', 2000 then :WIN2K
|
52
|
+
when 'xp', :xp then :WINXP
|
53
|
+
when 'server2003', :server2003, 2003 then :WS03
|
54
|
+
when 'vista', :vista, 'longhorn', :longhorn then :VISTA
|
55
|
+
when '7', 7 then :WIN7
|
56
|
+
when '8', 8 then :WIN8
|
57
|
+
when '8.1', 8.1, 'blue', :blue then :WINBLUE
|
58
|
+
when '10', 10, 'thresold', :thresold then :WIN10
|
59
|
+
when Integer then version
|
60
|
+
else raise ArgumentError, 'Unknown Version'
|
61
|
+
end]
|
62
|
+
end
|
63
|
+
|
64
|
+
def name
|
65
|
+
case hex
|
66
|
+
when WIN32_WINNT[:WIN2K]...WIN32_WINNT[:WINXP] then 'Windows 2000'
|
67
|
+
when WIN32_WINNT[:WINXP]...WIN32_WINNT[:VISTA] then 'Windows XP'
|
68
|
+
when WIN32_WINNT[:VISTA]...WIN32_WINNT[:WIN7] then 'Windows Vista'
|
69
|
+
when WIN32_WINNT[:WIN7]...WIN32_WINNT[:WIN8] then 'Windows 7'
|
70
|
+
when WIN32_WINNT[:WIN8]...WIN32_WINNT[:WINBLUE] then 'Windows 8'
|
71
|
+
when WIN32_WINNT[:WINBLUE]...WIN32_WINNT[:WIN10] then 'Windows 8.1'
|
72
|
+
when WIN32_WINNT[:WIN10] then 'Windows 10'
|
73
|
+
else 'Unknown'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def to_s; "#{name} v#{major}.#{minor}.#{build} SP#{sp}" end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: win-ffi-core
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- P3t3rU5
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.9.10
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.9'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.9.10
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: facets
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '3'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.4'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.4'
|
61
|
+
description: FFI definitions for Windows API.
|
62
|
+
email:
|
63
|
+
- pedro.at.miranda@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- README.md
|
69
|
+
- lib/win-ffi/core.rb
|
70
|
+
- lib/win-ffi/core/boolean_utils.rb
|
71
|
+
- lib/win-ffi/core/enum/firmware_type.rb
|
72
|
+
- lib/win-ffi/core/enum/load_resource_flags.rb
|
73
|
+
- lib/win-ffi/core/lib_base.rb
|
74
|
+
- lib/win-ffi/core/macro/util.rb
|
75
|
+
- lib/win-ffi/core/string_utils.rb
|
76
|
+
- lib/win-ffi/core/struct.rb
|
77
|
+
- lib/win-ffi/core/struct/guid.rb
|
78
|
+
- lib/win-ffi/core/struct/luid.rb
|
79
|
+
- lib/win-ffi/core/struct/point.rb
|
80
|
+
- lib/win-ffi/core/struct/rect.rb
|
81
|
+
- lib/win-ffi/core/struct/security_attributes.rb
|
82
|
+
- lib/win-ffi/core/struct/size.rb
|
83
|
+
- lib/win-ffi/core/typedef/core.rb
|
84
|
+
- lib/win-ffi/core/version.rb
|
85
|
+
- lib/win-ffi/core/wide_inline_string.rb
|
86
|
+
- lib/win-ffi/core/wide_string_pointer.rb
|
87
|
+
- lib/win-ffi/kernel32.rb
|
88
|
+
- lib/win-ffi/kernel32/enum/version/win32_winnt.rb
|
89
|
+
- lib/win-ffi/kernel32/struct/os_version_info_ex.rb
|
90
|
+
homepage: https://github.com/P3t3rU5/win-ffi-core
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message: |
|
95
|
+
+----------------------------------------------------------------------------+
|
96
|
+
Thanks for choosing WinFFI.
|
97
|
+
|
98
|
+
==========================================================================
|
99
|
+
1.0.0 Changes:
|
100
|
+
- Refactored Directory Structure
|
101
|
+
|
102
|
+
==========================================================================
|
103
|
+
|
104
|
+
If you find any bugs, please report them on
|
105
|
+
https://github.com/P3t3rU5/win-ffi-core/issues
|
106
|
+
|
107
|
+
+----------------------------------------------------------------------------+
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.6.1
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: FFI definitions for Windows API
|
127
|
+
test_files: []
|