win-ffi-core 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/win-ffi/core.rb +6 -3
- data/lib/win-ffi/core/enum/error/set_last_error_ex_code.rb +12 -0
- data/lib/win-ffi/core/lib_base.rb +33 -30
- data/lib/win-ffi/core/macro/util.rb +64 -28
- data/lib/win-ffi/core/string_utils.rb +30 -0
- data/lib/win-ffi/core/struct.rb +13 -13
- data/lib/win-ffi/core/struct/guid.rb +5 -5
- data/lib/win-ffi/core/struct/large_integer.rb +16 -0
- data/lib/win-ffi/core/struct/luid.rb +4 -3
- data/lib/win-ffi/core/struct/point.rb +7 -3
- data/lib/win-ffi/core/struct/points.rb +10 -0
- data/lib/win-ffi/core/struct/rect.rb +13 -18
- data/lib/win-ffi/core/struct/security_attributes.rb +9 -4
- data/lib/win-ffi/core/struct/size.rb +3 -3
- data/lib/win-ffi/core/struct/sizel.rb +16 -0
- data/lib/win-ffi/core/struct/ularge_integer.rb +19 -0
- data/lib/win-ffi/core/typedef/core.rb +66 -25
- data/lib/win-ffi/core/version.rb +1 -1
- data/lib/win-ffi/core/wide_inline_string.rb +9 -3
- data/lib/win-ffi/core/wide_string_pointer.rb +5 -5
- data/lib/win-ffi/kernel32.rb +0 -9
- data/lib/win-ffi/kernel32/enum/{version → system_info}/win32_winnt.rb +1 -1
- data/lib/win-ffi/kernel32/struct/{os_version_info_ex.rb → system_info/os_version_info_ex.rb} +13 -15
- data/lib/win-ffi/logger.rb +5 -0
- metadata +26 -8
- data/lib/win-ffi/core/enum/firmware_type.rb +0 -13
- data/lib/win-ffi/core/enum/load_resource_flags.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84c34e7d82bb265d59757931a899f9589f8ebc45
|
4
|
+
data.tar.gz: e58ab70df06d667c8604b5d39f63a2ee35a690cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b162af1f9b1c7074557a4fa6b4f6ec86004020f86b6eba7bf93ed4930942221cf9e0097e66163268cd23e3fb1395c5d6962da9942717cb4ac49c2a0eab57b94
|
7
|
+
data.tar.gz: ac005be4cc3e2c593815074facbd23e838c092cc5632f50cfa6d5310a636c733b17f3d11176bc81ed6a7e88c72acadeaed63da107c761a1ad73744b3ddd1a3c1
|
data/README.md
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
# WinFFI
|
1
|
+
# WinFFI Core
|
2
2
|
|
3
|
-
[](https://gitter.im/P3t3rU5/win-ffi-core?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
4
|
|
5
|
-
WinFFI is
|
5
|
+
WinFFI Core is the core gem for all WinFFI components. It defines some common functionality to all WinFFI component gems
|
6
6
|
This gem is work in progress
|
7
7
|
To install:
|
8
8
|
|
9
9
|
```
|
10
|
-
gem install win-ffi
|
10
|
+
gem install win-ffi-core
|
11
11
|
```
|
12
12
|
|
13
13
|
# License
|
14
14
|
|
15
15
|
(The MIT License)
|
16
16
|
|
17
|
-
Copyright ©
|
17
|
+
Copyright © 2016 Pedro Miranda
|
18
18
|
|
19
19
|
Permission is hereby granted, free of charge, to any person obtaining
|
20
20
|
a copy of this software and associated documentation files (the
|
@@ -33,4 +33,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
33
33
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
34
34
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
35
35
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
36
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
36
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/win-ffi/core.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
|
1
|
+
require 'win-ffi/logger'
|
2
2
|
require 'win-ffi/core/version'
|
3
|
+
|
4
|
+
require 'ffi-additions/struct'
|
5
|
+
|
6
|
+
require 'win-ffi/core/lib_base'
|
3
7
|
require 'win-ffi/core/string_utils'
|
4
8
|
require 'win-ffi/core/boolean_utils'
|
5
9
|
require 'win-ffi/core/macro/util'
|
6
|
-
require 'win-ffi/core/lib_base'
|
7
10
|
|
8
11
|
module WinFFI
|
9
|
-
|
12
|
+
MAX_PATH = 260
|
10
13
|
end
|
@@ -1,16 +1,10 @@
|
|
1
1
|
require 'ffi'
|
2
|
-
require '
|
2
|
+
require 'win-ffi/core/version'
|
3
3
|
|
4
4
|
module WinFFI
|
5
|
-
|
6
|
-
@logger.info "WinFFI #{VERSION}"
|
7
|
-
def self.logger
|
8
|
-
@logger
|
9
|
-
end
|
5
|
+
LOGGER.info "WinFFI v#{WinFFI::VERSION}"
|
10
6
|
|
11
|
-
WinFFI.logger.debug 'Getting Encoding...'
|
12
7
|
@encoding = (__ENCODING__.name =~ /ASCII/ ? 'A' : 'W')
|
13
|
-
WinFFI.logger.debug 'Got Encoding: ' + @encoding
|
14
8
|
|
15
9
|
def self.encoding
|
16
10
|
@encoding
|
@@ -23,20 +17,30 @@ module WinFFI
|
|
23
17
|
module LibBase
|
24
18
|
extend FFI::Library
|
25
19
|
ffi_convention :stdcall
|
20
|
+
end
|
21
|
+
end
|
26
22
|
|
23
|
+
require 'win-ffi/core/struct'
|
24
|
+
require 'win-ffi/core/typedef/core'
|
25
|
+
|
26
|
+
module WinFFI
|
27
|
+
module LibBase
|
27
28
|
def encoded_function(name, *args, ruby_name: nil)
|
28
29
|
ruby_name = name unless ruby_name
|
29
30
|
attach_function ruby_name, name + WinFFI.encoding, *args
|
30
31
|
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
def define_prefix(prefix, target_enum, without_underscore = false)
|
34
|
+
target_enum.to_h.each do |k, v|
|
35
|
+
name = "#{prefix}#{without_underscore ? '' : '_'}#{k}"
|
36
|
+
const_set(name, v) unless const_defined? name
|
35
37
|
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
end
|
39
|
+
|
40
|
+
def define_suffix(suffix, target_enum, without_underscore = false)
|
41
|
+
target_enum.to_h.each do |k, v|
|
42
|
+
name = "#{k}#{without_underscore ? '' : '_'}#{suffix}"
|
43
|
+
const_set(name, v) unless const_defined? name
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
@@ -44,35 +48,34 @@ module WinFFI
|
|
44
48
|
c.extend FFI::Library
|
45
49
|
instance_variables.each do |v|
|
46
50
|
value = instance_variable_get(v)
|
47
|
-
value = value.dup unless value.is_a?(
|
51
|
+
value = value.dup unless value.is_a?(Integer) || value.is_a?(Symbol)
|
48
52
|
c.instance_variable_set(v, value)
|
49
53
|
end
|
50
54
|
end
|
51
55
|
end
|
56
|
+
extend LibBase
|
57
|
+
end
|
52
58
|
|
53
|
-
|
54
|
-
|
55
|
-
require 'win-ffi/kernel32/struct/os_version_info_ex'
|
56
|
-
|
59
|
+
module WinFFI
|
57
60
|
module Kernel32
|
58
61
|
extend LibBase
|
59
62
|
|
60
|
-
ffi_lib 'kernel32'
|
63
|
+
ffi_lib 'kernel32', 'KernelBase'
|
64
|
+
end
|
65
|
+
|
66
|
+
require 'win-ffi/kernel32/struct/system_info/os_version_info_ex'
|
61
67
|
|
62
|
-
|
68
|
+
module Kernel32
|
69
|
+
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms724451(v=vs.85).aspx
|
70
|
+
# BOOL WINAPI GetVersionEx( _Inout_ LPOSVERSIONINFO lpVersionInfo )
|
63
71
|
encoded_function 'GetVersionEx', [OSVERSIONINFOEX.ptr], :bool
|
64
72
|
end
|
65
73
|
|
66
|
-
|
67
|
-
Architecture = RbConfig::CONFIG['arch'] # "i386-mingw32" | "x64-mingw32"
|
68
|
-
WinFFI.logger.debug 'Got Architecture: ' + Architecture
|
74
|
+
Architecture = FFI::Platform::CPU # "i386-mingw32" | "x64-mingw32"
|
69
75
|
|
70
|
-
WinFFI.logger.debug 'Getting Windows Version...'
|
71
76
|
WindowsVersion = OSVERSIONINFOEX.new.get!
|
72
|
-
WinFFI.logger.debug "Got Windows Version: #{WindowsVersion.hex}-> #{WindowsVersion.to_s}"
|
73
77
|
|
74
78
|
WindowsVersion.major, WindowsVersion.minor, WindowsVersion.build = `ver`.match(/\d+\.\d+\.\d+/)[0].split('.').map(&:to_i)
|
75
79
|
|
76
|
-
|
77
|
-
end
|
78
|
-
|
80
|
+
LOGGER.info "#{WindowsVersion.to_s} #{Architecture} #{__ENCODING__.to_s}"
|
81
|
+
end
|
@@ -1,38 +1,74 @@
|
|
1
|
+
require 'win-ffi/core'
|
2
|
+
|
1
3
|
module WinFFI
|
2
|
-
|
3
|
-
|
4
|
-
|
4
|
+
HANDLE = WinFFI.find_type(:handle)
|
5
|
+
class << self
|
6
|
+
def MAKEWORD(a, b)
|
7
|
+
((a & 0xff) | ((b & 0xff) << 8))
|
8
|
+
end
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
|
10
|
+
def MAKELONG(a, b)
|
11
|
+
((a & 0xffff) | ((b & 0xffff) << 16))
|
12
|
+
end
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
14
|
+
def MAKELCID(lgid, srtid) # ulong
|
15
|
+
srtid << 16 | lgid
|
16
|
+
end
|
13
17
|
|
14
|
-
|
15
|
-
l
|
16
|
-
|
18
|
+
#define LOWORD(_dw) ((WORD)(((DWORD_PTR)(_dw)) & 0xffff))
|
19
|
+
def LOWORD(l)
|
20
|
+
l & 0xffff
|
21
|
+
end
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
#define HIWORD(_dw) ((WORD)((((DWORD_PTR)(_dw)) >> 16) & 0xffff))
|
24
|
+
def HIWORD(l)
|
25
|
+
l >> 16
|
26
|
+
end
|
21
27
|
|
22
|
-
|
23
|
-
w >> 8
|
24
|
-
end
|
28
|
+
#define LODWORD(_qw) ((DWORD)(_qw))
|
25
29
|
|
26
|
-
|
27
|
-
pt.x = loword(pts)
|
28
|
-
pt.y = hiword(pts)
|
29
|
-
end
|
30
|
+
#define HIDWORD(_qw) ((DWORD)(((_qw) >> 32) & 0xffffffff))
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
#define LOBYTE(w) ((BYTE)(((DWORD_PTR)(w)) & 0xff))
|
33
|
+
def LOBYTE(w)
|
34
|
+
w & 0xff
|
35
|
+
end
|
36
|
+
|
37
|
+
#define HIBYTE(w) ((BYTE)((((DWORD_PTR)(w)) >> 8) & 0xff))
|
38
|
+
def HIBYTE(w)
|
39
|
+
w >> 8
|
40
|
+
end
|
41
|
+
|
42
|
+
#define HandleToULong( h ) ((ULONG)(ULONG_PTR)(h) )
|
43
|
+
def HandleToULong(h)
|
44
|
+
h.address
|
45
|
+
end
|
46
|
+
|
47
|
+
#define HandleToLong( h ) ((LONG)(LONG_PTR) (h) )
|
48
|
+
def HandleToLong(h)
|
49
|
+
h.address
|
50
|
+
end
|
34
51
|
|
35
|
-
|
36
|
-
|
37
|
-
|
52
|
+
#define ULongToHandle( ul ) ((HANDLE)(ULONG_PTR) (ul) )
|
53
|
+
def ULongToHandle(ul)
|
54
|
+
FFI::Pointer.new(HANDLE, ul)
|
55
|
+
end
|
56
|
+
|
57
|
+
#define LongToHandle( h ) ((HANDLE)(LONG_PTR) (h) )
|
58
|
+
def LongToHandle(h)
|
59
|
+
FFI::Pointer.new(HANDLE, h)
|
60
|
+
end
|
61
|
+
|
62
|
+
#define PtrToUlong( p ) ((ULONG)(ULONG_PTR) (p) )
|
63
|
+
#define PtrToLong( p ) ((LONG)(LONG_PTR) (p) )
|
64
|
+
#define PtrToUint( p ) ((UINT)(UINT_PTR) (p) )
|
65
|
+
#define PtrToInt( p ) ((INT)(INT_PTR) (p) )
|
66
|
+
#define PtrToUshort( p ) ((unsigned short)(ULONG_PTR)(p) )
|
67
|
+
#define PtrToShort( p ) ((short)(LONG_PTR)(p) )
|
68
|
+
#define IntToPtr( i ) ((VOID *)(INT_PTR)((int)i))
|
69
|
+
#define UIntToPtr( ui ) ((VOID *)(UINT_PTR)((unsigned int)ui))
|
70
|
+
#define LongToPtr( l ) ((VOID *)(LONG_PTR)((long)l))
|
71
|
+
#define ULongToPtr( ul ) ((VOID *)(ULONG_PTR)((unsigned long)ul))
|
72
|
+
|
73
|
+
end
|
38
74
|
end
|
@@ -1,6 +1,36 @@
|
|
1
1
|
module WinFFI
|
2
2
|
module StringUtils
|
3
|
+
refine ::String.singleton_class do
|
4
|
+
if WinFFI.encoding == 'A'
|
5
|
+
def from_byte_array(array)
|
6
|
+
array[0, array.index(0) || array.length].pack('C*').encode(Encoding::UTF_8)
|
7
|
+
end
|
8
|
+
|
9
|
+
def from_pointer(pointer, _)
|
10
|
+
pointer.read_string
|
11
|
+
end
|
12
|
+
else
|
13
|
+
def from_byte_array(array)
|
14
|
+
array = array[0, array.index(0) || array.length]
|
15
|
+
array.pack('S*').force_encoding(Encoding::UTF_16LE).encode(Encoding::UTF_8)
|
16
|
+
end
|
17
|
+
|
18
|
+
def from_pointer(pointer, size)
|
19
|
+
from_byte_array pointer.read_array_of_uint16(size)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
3
24
|
refine ::String do
|
25
|
+
if WinFFI.encoding == 'W'
|
26
|
+
def to_byte_array
|
27
|
+
FFI::MemoryPointer.new(WinFFI.find_type(:tchar), @size).write_string(string)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
def to_byte_array
|
31
|
+
FFI::MemoryPointer.new(WinFFI.find_type(:tchar), @size).write_array_of_uint16(string.unpack('S*'))
|
32
|
+
end
|
33
|
+
end
|
4
34
|
|
5
35
|
def to_utf8
|
6
36
|
encode('utf-8')
|
data/lib/win-ffi/core/struct.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
require 'ffi'
|
2
|
-
require 'win-ffi/core/lib_base'
|
1
|
+
require 'win-ffi/core/string_utils'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
3
|
+
using WinFFI::StringUtils
|
4
|
+
|
5
|
+
module FFIAdditions
|
6
|
+
class Struct
|
7
|
+
def self.encoded_setter(name)
|
8
|
+
define_method("#{name}=", ->(string) do
|
9
|
+
if WinFFI.encoding == 'A'
|
10
|
+
(to_ptr + offset_of(name)).write_string(string)
|
11
|
+
else
|
12
|
+
(to_ptr + offset_of(name)).write_array_of_uint16(string.to_w.unpack('S*'))
|
13
13
|
end
|
14
|
-
end
|
14
|
+
end)
|
15
15
|
end
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module WinFFI
|
2
2
|
# https://msdn.microsoft.com/en-us/library/windows/desktop/aa373931(v=vs.85).aspx
|
3
|
-
class GUID <
|
4
|
-
layout :
|
5
|
-
:
|
6
|
-
:
|
7
|
-
:
|
3
|
+
class GUID < FFIAdditions::Struct
|
4
|
+
layout Data1: :dword,
|
5
|
+
Data2: :word,
|
6
|
+
Data3: :word,
|
7
|
+
Data4: [:byte, 8]
|
8
8
|
|
9
9
|
def from_str(guid)
|
10
10
|
data = [guid.gsub(/[{\-}]/, '')].pack('H*').unpack('L>S>2C8')
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module WinFFI
|
2
|
+
# https://msdn.microsoft.com/en-us/library/windows/desktop/aa383713(v=vs.85).aspx
|
3
|
+
# class LARGE_INTEGER_STRUCT < FFIAdditions::Struct
|
4
|
+
# layout LowPart: :dword,
|
5
|
+
# HighPart: :long
|
6
|
+
# end
|
7
|
+
#
|
8
|
+
# class LARGE_INTEGER < FFIAdditions::Union
|
9
|
+
# layout s: LARGE_INTEGER_STRUCT,
|
10
|
+
# u: LARGE_INTEGER_STRUCT
|
11
|
+
# end
|
12
|
+
|
13
|
+
class LARGE_INTEGER < FFIAdditions::Struct
|
14
|
+
layout QuadPart: :long_long
|
15
|
+
end
|
16
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module WinFFI
|
2
2
|
if WindowsVersion >= :xp
|
3
|
+
# Locally Unique Identifier
|
3
4
|
# https://msdn.microsoft.com/en-us/library/windows/desktop/aa379261(v=vs.85).aspx
|
4
|
-
class LUID <
|
5
|
-
layout
|
6
|
-
:
|
5
|
+
class LUID < FFIAdditions::Struct
|
6
|
+
layout LowPart: :dword,
|
7
|
+
HighPart: :long
|
7
8
|
end
|
8
9
|
end
|
9
10
|
end
|
@@ -1,22 +1,12 @@
|
|
1
|
+
require 'win-ffi/core'
|
2
|
+
|
1
3
|
module WinFFI
|
2
4
|
# https://msdn.microsoft.com/en-us/library/windows/desktop/dd162897(v=vs.85).aspx
|
3
|
-
class RECT <
|
4
|
-
layout :
|
5
|
-
:
|
6
|
-
:
|
7
|
-
:
|
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
|
5
|
+
class RECT < FFIAdditions::Struct
|
6
|
+
layout left: :long,
|
7
|
+
top: :long,
|
8
|
+
right: :long,
|
9
|
+
bottom: :long
|
20
10
|
|
21
11
|
def width
|
22
12
|
right - left
|
@@ -35,7 +25,12 @@ module WinFFI
|
|
35
25
|
end
|
36
26
|
|
37
27
|
def to_s
|
38
|
-
"(left = #{left}, top = #{top}, width = #{
|
28
|
+
"(left = #{left}, top = #{top}, width = #{right - left}, height = #{bottom - top})"
|
29
|
+
end
|
30
|
+
|
31
|
+
def ==(other)
|
32
|
+
return false unless other.is_a?(self.class)
|
33
|
+
left == other.left && top == other.top && right == other.right&& bottom == other.bottom
|
39
34
|
end
|
40
35
|
end
|
41
36
|
end
|
@@ -1,7 +1,12 @@
|
|
1
1
|
module WinFFI
|
2
|
-
class SECURITY_ATTRIBUTES <
|
3
|
-
layout
|
4
|
-
:
|
5
|
-
|
2
|
+
class SECURITY_ATTRIBUTES < FFIAdditions::Struct
|
3
|
+
layout nLength: :dword,
|
4
|
+
lpSecurityDescriptor: :pointer,
|
5
|
+
bInheritHandle: :bool
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
self[:nLength] = self.size
|
10
|
+
end
|
6
11
|
end
|
7
12
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module WinFFI
|
2
2
|
# https://msdn.microsoft.com/en-us/library/windows/desktop/dd145106(v=vs.85).aspx
|
3
|
-
class SIZE <
|
4
|
-
layout :
|
5
|
-
:
|
3
|
+
class SIZE < FFIAdditions::Struct
|
4
|
+
layout cx: :long,
|
5
|
+
cy: :long
|
6
6
|
|
7
7
|
def to_s
|
8
8
|
"Size x=#{x}, y=#{y}"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module WinFFI
|
2
|
+
# https://msdn.microsoft.com/en-us/library/windows/desktop/dd145106(v=vs.85).aspx
|
3
|
+
class SIZEL < FFIAdditions::Struct
|
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,19 @@
|
|
1
|
+
require 'win-ffi/kernel32'
|
2
|
+
|
3
|
+
module WinFFI
|
4
|
+
module Kernel32
|
5
|
+
# class ULARGE_INTEGER_UNION < FFIAdditions::Struct
|
6
|
+
# layout LowPart: :dword,
|
7
|
+
# HighPart: :dword
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# class ULARGE_INTEGER < FFIAdditions::Union
|
11
|
+
# layout s: ULARGE_INTEGER_UNION,
|
12
|
+
# u: ULARGE_INTEGER_UNION
|
13
|
+
# end
|
14
|
+
|
15
|
+
class ULARGE_INTEGER < FFIAdditions::Struct
|
16
|
+
layout QuadPart: :ulong_long
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,30 +1,71 @@
|
|
1
|
-
require 'win-ffi/core/lib_base'
|
2
|
-
|
3
1
|
module WinFFI
|
4
2
|
module LibBase
|
5
3
|
typedef (WinFFI.encoding == 'A' ? :char : :ushort), :tchar
|
6
|
-
typedef :ushort,
|
7
|
-
typedef :
|
8
|
-
typedef :
|
9
|
-
typedef :
|
10
|
-
typedef :
|
11
|
-
typedef :
|
12
|
-
typedef :
|
13
|
-
typedef :
|
14
|
-
typedef :
|
15
|
-
typedef :
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
4
|
+
typedef :ushort, :wchar
|
5
|
+
typedef :ushort, :atom
|
6
|
+
typedef :uchar, :byte
|
7
|
+
typedef :ushort, :word
|
8
|
+
typedef :ulong, :dword
|
9
|
+
typedef :int64, :dword64
|
10
|
+
typedef :ulong_long, :dword_long
|
11
|
+
typedef :ulong_long, :dwordlong
|
12
|
+
typedef :ulong_long, :ulonglong
|
13
|
+
typedef :uint64, :dword64
|
14
|
+
typedef :uint, :wparam
|
15
|
+
typedef :long, :lparam
|
16
|
+
typedef :long, :lresult
|
17
|
+
typedef :long, :hresult
|
18
|
+
typedef :ushort, :langid
|
19
|
+
typedef :size_t, :ulong_ptr
|
20
|
+
typedef :ulong, :lcid
|
21
|
+
|
22
|
+
typedef :dword, :colorref
|
23
|
+
|
24
|
+
typedef :pointer, :handle
|
25
|
+
typedef :pointer, :hbitmap
|
26
|
+
typedef :pointer, :hbrush
|
27
|
+
typedef :pointer, :hhook
|
28
|
+
typedef :pointer, :hdc
|
29
|
+
typedef :pointer, :hevent
|
30
|
+
typedef :pointer, :hglobal
|
31
|
+
typedef :pointer, :hicon
|
32
|
+
typedef :pointer, :hinstance
|
33
|
+
typedef :pointer, :hmenu
|
34
|
+
typedef :pointer, :hmodule
|
35
|
+
typedef :pointer, :hpen
|
36
|
+
typedef :pointer, :hwnd
|
37
|
+
typedef :pointer, :humpd
|
38
|
+
|
39
|
+
typedef :pointer, :puint
|
40
|
+
typedef :pointer, :plong
|
41
|
+
typedef :pointer, :pulong
|
42
|
+
typedef :pointer, :pshort
|
43
|
+
typedef :pointer, :pushort
|
44
|
+
typedef :pointer, :puchar
|
45
|
+
typedef :pointer, :psz
|
46
|
+
typedef :pointer, :pfloat
|
47
|
+
|
48
|
+
typedef :pointer, :pbool
|
49
|
+
typedef :pointer, :lpbool
|
50
|
+
|
51
|
+
typedef :pointer, :pbyte
|
52
|
+
typedef :pointer, :lpbyte
|
53
|
+
typedef :pointer, :ppbyte
|
54
|
+
|
55
|
+
typedef :pointer, :pint
|
56
|
+
typedef :pointer, :lpint
|
57
|
+
|
58
|
+
typedef :pointer, :pword
|
59
|
+
typedef :pointer, :lpword
|
60
|
+
|
61
|
+
typedef :pointer, :lplong
|
62
|
+
|
63
|
+
typedef :pointer, :pdword
|
64
|
+
typedef :pointer, :lpdword
|
65
|
+
|
66
|
+
typedef :pointer, :lpvoid
|
67
|
+
typedef :pointer, :lpcvoid
|
68
|
+
|
69
|
+
typedef :pointer, :callback
|
29
70
|
end
|
30
71
|
end
|
data/lib/win-ffi/core/version.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
require 'win-ffi/core'
|
2
|
+
require 'win-ffi/core/string_utils'
|
3
|
+
|
4
|
+
using WinFFI::StringUtils
|
5
|
+
|
1
6
|
module WinFFI
|
2
7
|
class WideInlineString
|
3
8
|
include FFI::DataConverter
|
@@ -9,12 +14,13 @@ module WinFFI
|
|
9
14
|
@native_type = FFI::ArrayType.new(WinFFI.find_type(:tchar), size)
|
10
15
|
end
|
11
16
|
|
12
|
-
|
13
|
-
|
17
|
+
|
18
|
+
def to_native(value, _context)
|
19
|
+
value.to_byte_array
|
14
20
|
end
|
15
21
|
|
16
22
|
def from_native(value, _context)
|
17
|
-
|
23
|
+
String.from_byte_array(value.to_a)
|
18
24
|
end
|
19
25
|
|
20
26
|
alias_method :length, :size
|
@@ -3,17 +3,17 @@ module WinFFI
|
|
3
3
|
extend FFI::DataConverter
|
4
4
|
native_type FFI::Type::POINTER
|
5
5
|
# TODO
|
6
|
-
|
6
|
+
def initialize(size)
|
7
|
+
@size = size
|
8
|
+
end
|
7
9
|
|
8
10
|
def to_native(value, _context)
|
9
|
-
|
11
|
+
value.address
|
10
12
|
end
|
11
13
|
|
12
14
|
def from_native(pointer, _context)
|
13
|
-
|
15
|
+
pointer.read_bytes(@size)
|
14
16
|
end
|
15
17
|
|
16
|
-
end
|
17
|
-
|
18
18
|
end
|
19
19
|
end
|
data/lib/win-ffi/kernel32.rb
CHANGED
data/lib/win-ffi/kernel32/struct/{os_version_info_ex.rb → system_info/os_version_info_ex.rb}
RENAMED
@@ -1,25 +1,23 @@
|
|
1
1
|
require 'win-ffi/core/wide_inline_string'
|
2
2
|
|
3
|
-
require 'win-ffi/
|
4
|
-
|
5
|
-
require 'win-ffi/kernel32/enum/version/win32_winnt'
|
3
|
+
require 'win-ffi/kernel32/enum/system_info/win32_winnt'
|
6
4
|
|
7
5
|
module WinFFI
|
8
|
-
class OSVERSIONINFOEX <
|
6
|
+
class OSVERSIONINFOEX < FFIAdditions::Struct
|
9
7
|
|
10
8
|
include Kernel32, Comparable
|
11
9
|
|
12
|
-
layout
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
:
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
10
|
+
layout dwOSVersionInfoSize: :ulong,
|
11
|
+
dwMajorVersion: :ulong,
|
12
|
+
dwMinorVersion: :ulong,
|
13
|
+
dwBuildNumber: :ulong,
|
14
|
+
dwPlatformId: :ulong,
|
15
|
+
szCSDVersion: WideInlineString.new(128),
|
16
|
+
wServicePackMajor: :ushort,
|
17
|
+
wServicePackMinor: :ushort,
|
18
|
+
wSuiteMask: :ushort,
|
19
|
+
wProductType: :uchar,
|
20
|
+
wReserved: :uchar
|
23
21
|
|
24
22
|
def initialize
|
25
23
|
super
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: win-ffi-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- P3t3rU5
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -30,6 +30,20 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 1.9.10
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: ffi-additions
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: facets
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,25 +82,29 @@ files:
|
|
68
82
|
- README.md
|
69
83
|
- lib/win-ffi/core.rb
|
70
84
|
- lib/win-ffi/core/boolean_utils.rb
|
71
|
-
- lib/win-ffi/core/enum/
|
72
|
-
- lib/win-ffi/core/enum/load_resource_flags.rb
|
85
|
+
- lib/win-ffi/core/enum/error/set_last_error_ex_code.rb
|
73
86
|
- lib/win-ffi/core/lib_base.rb
|
74
87
|
- lib/win-ffi/core/macro/util.rb
|
75
88
|
- lib/win-ffi/core/string_utils.rb
|
76
89
|
- lib/win-ffi/core/struct.rb
|
77
90
|
- lib/win-ffi/core/struct/guid.rb
|
91
|
+
- lib/win-ffi/core/struct/large_integer.rb
|
78
92
|
- lib/win-ffi/core/struct/luid.rb
|
79
93
|
- lib/win-ffi/core/struct/point.rb
|
94
|
+
- lib/win-ffi/core/struct/points.rb
|
80
95
|
- lib/win-ffi/core/struct/rect.rb
|
81
96
|
- lib/win-ffi/core/struct/security_attributes.rb
|
82
97
|
- lib/win-ffi/core/struct/size.rb
|
98
|
+
- lib/win-ffi/core/struct/sizel.rb
|
99
|
+
- lib/win-ffi/core/struct/ularge_integer.rb
|
83
100
|
- lib/win-ffi/core/typedef/core.rb
|
84
101
|
- lib/win-ffi/core/version.rb
|
85
102
|
- lib/win-ffi/core/wide_inline_string.rb
|
86
103
|
- lib/win-ffi/core/wide_string_pointer.rb
|
87
104
|
- lib/win-ffi/kernel32.rb
|
88
|
-
- lib/win-ffi/kernel32/enum/
|
89
|
-
- lib/win-ffi/kernel32/struct/os_version_info_ex.rb
|
105
|
+
- lib/win-ffi/kernel32/enum/system_info/win32_winnt.rb
|
106
|
+
- lib/win-ffi/kernel32/struct/system_info/os_version_info_ex.rb
|
107
|
+
- lib/win-ffi/logger.rb
|
90
108
|
homepage: https://github.com/P3t3rU5/win-ffi-core
|
91
109
|
licenses:
|
92
110
|
- MIT
|
@@ -96,7 +114,7 @@ post_install_message: |
|
|
96
114
|
Thanks for choosing WinFFI.
|
97
115
|
|
98
116
|
==========================================================================
|
99
|
-
1.0.
|
117
|
+
1.0.1 Changes:
|
100
118
|
- Refactored Directory Structure
|
101
119
|
|
102
120
|
==========================================================================
|
@@ -120,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
138
|
version: '0'
|
121
139
|
requirements: []
|
122
140
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.6.
|
141
|
+
rubygems_version: 2.6.8
|
124
142
|
signing_key:
|
125
143
|
specification_version: 4
|
126
144
|
summary: FFI definitions for Windows API
|
@@ -1,47 +0,0 @@
|
|
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
|