windows-pr 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +438 -429
- data/README +5 -1
- data/lib/windows/clipboard.rb +61 -61
- data/lib/windows/com.rb +192 -192
- data/lib/windows/com/accessibility.rb +16 -16
- data/lib/windows/directory.rb +27 -27
- data/lib/windows/error.rb +498 -484
- data/lib/windows/eventlog.rb +80 -80
- data/lib/windows/filesystem.rb +15 -15
- data/lib/windows/handle.rb +23 -23
- data/lib/windows/library.rb +44 -44
- data/lib/windows/mailslot.rb +24 -24
- data/lib/windows/memory.rb +128 -128
- data/lib/windows/msvcrt/io.rb +73 -73
- data/lib/windows/msvcrt/string.rb +182 -182
- data/lib/windows/nio.rb +50 -50
- data/lib/windows/ntfs/winternl.rb +117 -110
- data/lib/windows/process.rb +176 -176
- data/lib/windows/socket.rb +86 -86
- data/lib/windows/system_info.rb +229 -229
- data/lib/windows/thread.rb +64 -64
- data/lib/windows/unicode.rb +155 -155
- data/lib/windows/wsa.rb +102 -102
- data/test/tc_msvcrt_buffer.rb +11 -7
- data/test/tc_ntfs_winternl.rb +48 -44
- data/test/tc_unicode.rb +83 -83
- data/windows-pr.gemspec +34 -34
- metadata +50 -63
data/lib/windows/thread.rb
CHANGED
@@ -1,64 +1,64 @@
|
|
1
|
-
require 'windows/api'
|
2
|
-
|
3
|
-
module Windows
|
4
|
-
module Thread
|
5
|
-
API.auto_namespace = 'Windows::Thread'
|
6
|
-
API.auto_constant = true
|
7
|
-
API.auto_method = true
|
8
|
-
API.auto_unicode = true
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
SYNCHRONIZE = 0x00100000
|
13
|
-
THREAD_ALL_ACCESS = 0x1F03FF
|
14
|
-
THREAD_DIRECT_IMPERSONATION = 0x0200
|
15
|
-
THREAD_GET_CONTEXT = 0x0008
|
16
|
-
THREAD_IMPERSONATE = 0x0100
|
17
|
-
THREAD_QUERY_INFORMATION = 0x0040
|
18
|
-
THREAD_SET_CONTEXT = 0x0010
|
19
|
-
THREAD_SET_INFORMATION = 0x0020
|
20
|
-
THREAD_SET_THREAD_TOKEN = 0x0080
|
21
|
-
THREAD_SUSPEND_RESUME = 0x0002
|
22
|
-
THREAD_TERMINATE = 0x0001
|
23
|
-
|
24
|
-
THREAD_PRIORITY_ABOVE_NORMAL = 1
|
25
|
-
THREAD_PRIORITY_BELOW_NORMAL = -1
|
26
|
-
THREAD_PRIORITY_HIGHEST = 2
|
27
|
-
THREAD_PRIORITY_IDLE = -15
|
28
|
-
THREAD_PRIORITY_LOWEST = -2
|
29
|
-
THREAD_PRIORITY_NORMAL = 0
|
30
|
-
THREAD_PRIORITY_TIME_CRITICAL = 15
|
31
|
-
|
32
|
-
API.new('CreateRemoteThread', 'LPLLPLP', 'L')
|
33
|
-
API.new('CreateThread', 'PLKPLP', 'L')
|
34
|
-
API.new('ExitThread', 'L', 'V')
|
35
|
-
API.new('GetCurrentThread', 'V', 'L')
|
36
|
-
API.new('GetCurrentThreadId', 'V', 'L')
|
37
|
-
API.new('GetExitCodeThread', 'LP', 'B')
|
38
|
-
API.new('GetThreadPriority', 'L', 'I')
|
39
|
-
API.new('GetThreadPriorityBoost', 'LP', 'B')
|
40
|
-
API.new('GetThreadTimes', 'LPPPP', 'B')
|
41
|
-
API.new('OpenThread', 'LIL', 'L')
|
42
|
-
API.new('ResumeThread', 'L', 'L')
|
43
|
-
API.new('SetThreadAffinityMask', 'LP', 'P')
|
44
|
-
API.new('SetThreadIdealProcessor', 'LL', 'L')
|
45
|
-
API.new('SetThreadPriority', 'LI', 'B')
|
46
|
-
API.new('SetThreadPriorityBoost', 'LI', 'B')
|
47
|
-
API.new('Sleep', 'L', 'V')
|
48
|
-
API.new('SleepEx', 'LI', 'L')
|
49
|
-
API.new('SuspendThread', 'L', 'L')
|
50
|
-
API.new('SwitchToThread', 'V', 'B')
|
51
|
-
API.new('TerminateThread', 'LL', 'B')
|
52
|
-
API.new('TlsAlloc', 'V', 'L')
|
53
|
-
API.new('TlsFree', 'L', 'B')
|
54
|
-
API.new('TlsGetValue', 'L', 'L')
|
55
|
-
API.new('TlsSetValue', 'LL', 'B')
|
56
|
-
|
57
|
-
begin
|
58
|
-
API.new('AttachThreadInput', 'LLI', 'B', 'user32')
|
59
|
-
API.new('GetThreadIOPendingFlag', 'LP', 'B')
|
60
|
-
rescue Win32::API::LoadLibraryError
|
61
|
-
# Windows XP or later
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
1
|
+
require 'windows/api'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
module Thread
|
5
|
+
API.auto_namespace = 'Windows::Thread'
|
6
|
+
API.auto_constant = true
|
7
|
+
API.auto_method = true
|
8
|
+
API.auto_unicode = true
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
SYNCHRONIZE = 0x00100000
|
13
|
+
THREAD_ALL_ACCESS = 0x1F03FF
|
14
|
+
THREAD_DIRECT_IMPERSONATION = 0x0200
|
15
|
+
THREAD_GET_CONTEXT = 0x0008
|
16
|
+
THREAD_IMPERSONATE = 0x0100
|
17
|
+
THREAD_QUERY_INFORMATION = 0x0040
|
18
|
+
THREAD_SET_CONTEXT = 0x0010
|
19
|
+
THREAD_SET_INFORMATION = 0x0020
|
20
|
+
THREAD_SET_THREAD_TOKEN = 0x0080
|
21
|
+
THREAD_SUSPEND_RESUME = 0x0002
|
22
|
+
THREAD_TERMINATE = 0x0001
|
23
|
+
|
24
|
+
THREAD_PRIORITY_ABOVE_NORMAL = 1
|
25
|
+
THREAD_PRIORITY_BELOW_NORMAL = -1
|
26
|
+
THREAD_PRIORITY_HIGHEST = 2
|
27
|
+
THREAD_PRIORITY_IDLE = -15
|
28
|
+
THREAD_PRIORITY_LOWEST = -2
|
29
|
+
THREAD_PRIORITY_NORMAL = 0
|
30
|
+
THREAD_PRIORITY_TIME_CRITICAL = 15
|
31
|
+
|
32
|
+
API.new('CreateRemoteThread', 'LPLLPLP', 'L')
|
33
|
+
API.new('CreateThread', 'PLKPLP', 'L')
|
34
|
+
API.new('ExitThread', 'L', 'V')
|
35
|
+
API.new('GetCurrentThread', 'V', 'L')
|
36
|
+
API.new('GetCurrentThreadId', 'V', 'L')
|
37
|
+
API.new('GetExitCodeThread', 'LP', 'B')
|
38
|
+
API.new('GetThreadPriority', 'L', 'I')
|
39
|
+
API.new('GetThreadPriorityBoost', 'LP', 'B')
|
40
|
+
API.new('GetThreadTimes', 'LPPPP', 'B')
|
41
|
+
API.new('OpenThread', 'LIL', 'L')
|
42
|
+
API.new('ResumeThread', 'L', 'L')
|
43
|
+
API.new('SetThreadAffinityMask', 'LP', 'P')
|
44
|
+
API.new('SetThreadIdealProcessor', 'LL', 'L')
|
45
|
+
API.new('SetThreadPriority', 'LI', 'B')
|
46
|
+
API.new('SetThreadPriorityBoost', 'LI', 'B')
|
47
|
+
API.new('Sleep', 'L', 'V')
|
48
|
+
API.new('SleepEx', 'LI', 'L')
|
49
|
+
API.new('SuspendThread', 'L', 'L')
|
50
|
+
API.new('SwitchToThread', 'V', 'B')
|
51
|
+
API.new('TerminateThread', 'LL', 'B')
|
52
|
+
API.new('TlsAlloc', 'V', 'L')
|
53
|
+
API.new('TlsFree', 'L', 'B')
|
54
|
+
API.new('TlsGetValue', 'L', 'L')
|
55
|
+
API.new('TlsSetValue', 'LL', 'B')
|
56
|
+
|
57
|
+
begin
|
58
|
+
API.new('AttachThreadInput', 'LLI', 'B', 'user32')
|
59
|
+
API.new('GetThreadIOPendingFlag', 'LP', 'B')
|
60
|
+
rescue Win32::API::LoadLibraryError
|
61
|
+
# Windows XP or later
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/windows/unicode.rb
CHANGED
@@ -1,155 +1,155 @@
|
|
1
|
-
# encoding: ascii-8bit
|
2
|
-
require 'windows/api'
|
3
|
-
require 'windows/msvcrt/string'
|
4
|
-
require 'windows/error'
|
5
|
-
|
6
|
-
module Windows
|
7
|
-
module Unicode
|
8
|
-
include Windows::MSVCRT::String
|
9
|
-
include Windows::Error
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
API.auto_namespace = 'Windows::Unicode'
|
14
|
-
API.auto_constant = true
|
15
|
-
API.auto_method = true
|
16
|
-
API.auto_unicode = false
|
17
|
-
|
18
|
-
CP_ACP = 0
|
19
|
-
CP_OEMCP = 1
|
20
|
-
CP_MACCP = 2
|
21
|
-
CP_THREAD_ACP = 3
|
22
|
-
CP_SYMBOL = 42
|
23
|
-
CP_UTF7 = 65000
|
24
|
-
CP_UTF8 = 65001
|
25
|
-
|
26
|
-
MB_PRECOMPOSED = 0x00000001
|
27
|
-
MB_COMPOSITE = 0x00000002
|
28
|
-
MB_USEGLYPHCHARS = 0x00000004
|
29
|
-
MB_ERR_INVALID_CHARS = 0x00000008
|
30
|
-
|
31
|
-
WC_COMPOSITECHECK = 0x00000200
|
32
|
-
WC_DISCARDNS = 0x00000010
|
33
|
-
WC_SEPCHARS = 0x00000020
|
34
|
-
WC_DEFAULTCHAR = 0x00000040
|
35
|
-
WC_NO_BEST_FIT_CHARS = 0x00000400
|
36
|
-
|
37
|
-
ANSI_CHARSET = 0
|
38
|
-
DEFAULT_CHARSET = 1
|
39
|
-
SYMBOL_CHARSET = 2
|
40
|
-
SHIFTJIS_CHARSET = 128
|
41
|
-
HANGEUL_CHARSET = 129
|
42
|
-
HANGUL_CHARSET = 129
|
43
|
-
GB2312_CHARSET = 134
|
44
|
-
CHINESEBIG5_CHARSET = 136
|
45
|
-
OEM_CHARSET = 255
|
46
|
-
JOHAB_CHARSET = 130
|
47
|
-
HEBREW_CHARSET = 177
|
48
|
-
ARABIC_CHARSET = 178
|
49
|
-
GREEK_CHARSET = 161
|
50
|
-
TURKISH_CHARSET = 162
|
51
|
-
VIETNAMESE_CHARSET = 163
|
52
|
-
THAI_CHARSET = 222
|
53
|
-
EASTEUROPE_CHARSET = 238
|
54
|
-
RUSSIAN_CHARSET = 204
|
55
|
-
|
56
|
-
IS_TEXT_UNICODE_ASCII16 = 0x0001
|
57
|
-
IS_TEXT_UNICODE_REVERSE_ASCII16 = 0x0010
|
58
|
-
IS_TEXT_UNICODE_STATISTICS = 0x0002
|
59
|
-
IS_TEXT_UNICODE_REVERSE_STATISTICS = 0x0020
|
60
|
-
IS_TEXT_UNICODE_CONTROLS = 0x0004
|
61
|
-
IS_TEXT_UNICODE_REVERSE_CONTROLS = 0x0040
|
62
|
-
IS_TEXT_UNICODE_SIGNATURE = 0x0008
|
63
|
-
IS_TEXT_UNICODE_REVERSE_SIGNATURE = 0x0080
|
64
|
-
IS_TEXT_UNICODE_ILLEGAL_CHARS = 0x0100
|
65
|
-
IS_TEXT_UNICODE_ODD_LENGTH = 0x0200
|
66
|
-
IS_TEXT_UNICODE_DBCS_LEADBYTE = 0x0400
|
67
|
-
IS_TEXT_UNICODE_NULL_BYTES = 0x1000
|
68
|
-
IS_TEXT_UNICODE_UNICODE_MASK = 0x000F
|
69
|
-
IS_TEXT_UNICODE_REVERSE_MASK = 0x00F0
|
70
|
-
IS_TEXT_UNICODE_NOT_UNICODE_MASK = 0x0F00
|
71
|
-
IS_TEXT_UNICODE_NOT_ASCII_MASK = 0xF000
|
72
|
-
|
73
|
-
TCI_SRCCHARSET = 1
|
74
|
-
TCI_SRCCODEPAGE = 2
|
75
|
-
TCI_SRCFONTSIG = 3
|
76
|
-
TCI_SRCLOCALE = 0x100
|
77
|
-
|
78
|
-
API.new('GetTextCharset', 'L', 'I', 'gdi32')
|
79
|
-
API.new('GetTextCharsetInfo', 'LPL', 'I', 'gdi32')
|
80
|
-
API.new('IsDBCSLeadByte', 'P', 'B')
|
81
|
-
API.new('IsDBCSLeadByteEx', 'IP', 'B')
|
82
|
-
API.new('IsTextUnicode', 'SIP', 'B', 'advapi32')
|
83
|
-
API.new('MultiByteToWideChar', 'ILSIPI', 'I')
|
84
|
-
API.new('TranslateCharsetInfo', 'PPL', 'B', 'gdi32')
|
85
|
-
API.new('WideCharToMultiByte', 'ILSIPIPP', 'I')
|
86
|
-
|
87
|
-
# Convenient wrapper methods
|
88
|
-
|
89
|
-
# Maps a
|
90
|
-
# specified +encoding+. If no encoding is specified, then CP_UTF8
|
91
|
-
# is used if $KCODE (or the encoding name in Ruby 1.9.x) is set to UTF8.
|
92
|
-
# Otherwise, CP_ACP is used.
|
93
|
-
#
|
94
|
-
# If the function fails it simply returns the string as-is.
|
95
|
-
#
|
96
|
-
def multi_to_wide(string, encoding=nil)
|
97
|
-
return nil unless string
|
98
|
-
raise TypeError unless string.is_a?(String)
|
99
|
-
return string if IsTextUnicode(string, string.size, nil)
|
100
|
-
|
101
|
-
unless encoding
|
102
|
-
if RUBY_VERSION.to_f >= 1.9
|
103
|
-
encoding = (string.encoding.name == 'UTF-8') ? CP_UTF8 : CP_ACP
|
104
|
-
else
|
105
|
-
encoding = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
int = MultiByteToWideChar(encoding, 0, string, -1, nil, 0)
|
110
|
-
|
111
|
-
# Trailing nulls are retained
|
112
|
-
if int > 0
|
113
|
-
buf = ' ' * int * 2
|
114
|
-
MultiByteToWideChar(encoding, 0, string, -1, buf, int)
|
115
|
-
buf
|
116
|
-
else
|
117
|
-
raise ArgumentError, get_last_error
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
# Maps a wide character string to a new character string using the
|
122
|
-
# specified +encoding+. If no encoding is specified, then CP_UTF8
|
123
|
-
# is used if $KCODE (or the encoding name in Ruby 1.9.x) is set to UTF8.
|
124
|
-
# Otherwise, CP_ACP is used.
|
125
|
-
#
|
126
|
-
# If the function fails it simply returns the string as-is.
|
127
|
-
#
|
128
|
-
def wide_to_multi(wstring, encoding=nil)
|
129
|
-
return nil unless wstring
|
130
|
-
raise TypeError unless wstring.is_a?(String)
|
131
|
-
|
132
|
-
unless encoding
|
133
|
-
if RUBY_VERSION.to_f >= 1.9
|
134
|
-
encoding = (wstring.encoding.name == 'UTF-8') ? CP_UTF8 : CP_ACP
|
135
|
-
else
|
136
|
-
encoding = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# Add a trailing double null if necessary
|
141
|
-
wstring << "\000\000" if wstring[-1].chr != "\000"
|
142
|
-
|
143
|
-
int = WideCharToMultiByte(encoding, 0, wstring, -1, 0, 0, nil, nil)
|
144
|
-
|
145
|
-
# Trailing nulls are stripped
|
146
|
-
if int > 0
|
147
|
-
buf = ' ' * int
|
148
|
-
WideCharToMultiByte(encoding, 0, wstring, -1, buf, strlen(buf), nil, nil)
|
149
|
-
buf[ /^[^\0]*/ ]
|
150
|
-
else
|
151
|
-
raise ArgumentError, get_last_error
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
require 'windows/api'
|
3
|
+
require 'windows/msvcrt/string'
|
4
|
+
require 'windows/error'
|
5
|
+
|
6
|
+
module Windows
|
7
|
+
module Unicode
|
8
|
+
include Windows::MSVCRT::String
|
9
|
+
include Windows::Error
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
API.auto_namespace = 'Windows::Unicode'
|
14
|
+
API.auto_constant = true
|
15
|
+
API.auto_method = true
|
16
|
+
API.auto_unicode = false
|
17
|
+
|
18
|
+
CP_ACP = 0
|
19
|
+
CP_OEMCP = 1
|
20
|
+
CP_MACCP = 2
|
21
|
+
CP_THREAD_ACP = 3
|
22
|
+
CP_SYMBOL = 42
|
23
|
+
CP_UTF7 = 65000
|
24
|
+
CP_UTF8 = 65001
|
25
|
+
|
26
|
+
MB_PRECOMPOSED = 0x00000001
|
27
|
+
MB_COMPOSITE = 0x00000002
|
28
|
+
MB_USEGLYPHCHARS = 0x00000004
|
29
|
+
MB_ERR_INVALID_CHARS = 0x00000008
|
30
|
+
|
31
|
+
WC_COMPOSITECHECK = 0x00000200
|
32
|
+
WC_DISCARDNS = 0x00000010
|
33
|
+
WC_SEPCHARS = 0x00000020
|
34
|
+
WC_DEFAULTCHAR = 0x00000040
|
35
|
+
WC_NO_BEST_FIT_CHARS = 0x00000400
|
36
|
+
|
37
|
+
ANSI_CHARSET = 0
|
38
|
+
DEFAULT_CHARSET = 1
|
39
|
+
SYMBOL_CHARSET = 2
|
40
|
+
SHIFTJIS_CHARSET = 128
|
41
|
+
HANGEUL_CHARSET = 129
|
42
|
+
HANGUL_CHARSET = 129
|
43
|
+
GB2312_CHARSET = 134
|
44
|
+
CHINESEBIG5_CHARSET = 136
|
45
|
+
OEM_CHARSET = 255
|
46
|
+
JOHAB_CHARSET = 130
|
47
|
+
HEBREW_CHARSET = 177
|
48
|
+
ARABIC_CHARSET = 178
|
49
|
+
GREEK_CHARSET = 161
|
50
|
+
TURKISH_CHARSET = 162
|
51
|
+
VIETNAMESE_CHARSET = 163
|
52
|
+
THAI_CHARSET = 222
|
53
|
+
EASTEUROPE_CHARSET = 238
|
54
|
+
RUSSIAN_CHARSET = 204
|
55
|
+
|
56
|
+
IS_TEXT_UNICODE_ASCII16 = 0x0001
|
57
|
+
IS_TEXT_UNICODE_REVERSE_ASCII16 = 0x0010
|
58
|
+
IS_TEXT_UNICODE_STATISTICS = 0x0002
|
59
|
+
IS_TEXT_UNICODE_REVERSE_STATISTICS = 0x0020
|
60
|
+
IS_TEXT_UNICODE_CONTROLS = 0x0004
|
61
|
+
IS_TEXT_UNICODE_REVERSE_CONTROLS = 0x0040
|
62
|
+
IS_TEXT_UNICODE_SIGNATURE = 0x0008
|
63
|
+
IS_TEXT_UNICODE_REVERSE_SIGNATURE = 0x0080
|
64
|
+
IS_TEXT_UNICODE_ILLEGAL_CHARS = 0x0100
|
65
|
+
IS_TEXT_UNICODE_ODD_LENGTH = 0x0200
|
66
|
+
IS_TEXT_UNICODE_DBCS_LEADBYTE = 0x0400
|
67
|
+
IS_TEXT_UNICODE_NULL_BYTES = 0x1000
|
68
|
+
IS_TEXT_UNICODE_UNICODE_MASK = 0x000F
|
69
|
+
IS_TEXT_UNICODE_REVERSE_MASK = 0x00F0
|
70
|
+
IS_TEXT_UNICODE_NOT_UNICODE_MASK = 0x0F00
|
71
|
+
IS_TEXT_UNICODE_NOT_ASCII_MASK = 0xF000
|
72
|
+
|
73
|
+
TCI_SRCCHARSET = 1
|
74
|
+
TCI_SRCCODEPAGE = 2
|
75
|
+
TCI_SRCFONTSIG = 3
|
76
|
+
TCI_SRCLOCALE = 0x100
|
77
|
+
|
78
|
+
API.new('GetTextCharset', 'L', 'I', 'gdi32')
|
79
|
+
API.new('GetTextCharsetInfo', 'LPL', 'I', 'gdi32')
|
80
|
+
API.new('IsDBCSLeadByte', 'P', 'B')
|
81
|
+
API.new('IsDBCSLeadByteEx', 'IP', 'B')
|
82
|
+
API.new('IsTextUnicode', 'SIP', 'B', 'advapi32')
|
83
|
+
API.new('MultiByteToWideChar', 'ILSIPI', 'I')
|
84
|
+
API.new('TranslateCharsetInfo', 'PPL', 'B', 'gdi32')
|
85
|
+
API.new('WideCharToMultiByte', 'ILSIPIPP', 'I')
|
86
|
+
|
87
|
+
# Convenient wrapper methods
|
88
|
+
|
89
|
+
# Maps a character string to a UTF-16 (wide) character string using the
|
90
|
+
# specified +encoding+. If no encoding is specified, then CP_UTF8
|
91
|
+
# is used if $KCODE (or the encoding name in Ruby 1.9.x) is set to UTF8.
|
92
|
+
# Otherwise, CP_ACP is used.
|
93
|
+
#
|
94
|
+
# If the function fails it simply returns the string as-is.
|
95
|
+
#
|
96
|
+
def multi_to_wide(string, encoding=nil)
|
97
|
+
return nil unless string
|
98
|
+
raise TypeError unless string.is_a?(String)
|
99
|
+
return string if IsTextUnicode(string, string.size, nil)
|
100
|
+
|
101
|
+
unless encoding
|
102
|
+
if RUBY_VERSION.to_f >= 1.9
|
103
|
+
encoding = (string.encoding.name == 'UTF-8') ? CP_UTF8 : CP_ACP
|
104
|
+
else
|
105
|
+
encoding = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
int = MultiByteToWideChar(encoding, 0, string, -1, nil, 0)
|
110
|
+
|
111
|
+
# Trailing nulls are retained
|
112
|
+
if int > 0
|
113
|
+
buf = ' ' * int * 2
|
114
|
+
MultiByteToWideChar(encoding, 0, string, -1, buf, int)
|
115
|
+
buf
|
116
|
+
else
|
117
|
+
raise ArgumentError, get_last_error
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# Maps a wide character string to a new character string using the
|
122
|
+
# specified +encoding+. If no encoding is specified, then CP_UTF8
|
123
|
+
# is used if $KCODE (or the encoding name in Ruby 1.9.x) is set to UTF8.
|
124
|
+
# Otherwise, CP_ACP is used.
|
125
|
+
#
|
126
|
+
# If the function fails it simply returns the string as-is.
|
127
|
+
#
|
128
|
+
def wide_to_multi(wstring, encoding=nil)
|
129
|
+
return nil unless wstring
|
130
|
+
raise TypeError unless wstring.is_a?(String)
|
131
|
+
|
132
|
+
unless encoding
|
133
|
+
if RUBY_VERSION.to_f >= 1.9
|
134
|
+
encoding = (wstring.encoding.name == 'UTF-8') ? CP_UTF8 : CP_ACP
|
135
|
+
else
|
136
|
+
encoding = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# Add a trailing double null if necessary
|
141
|
+
wstring << "\000\000" if wstring[-1].chr != "\000"
|
142
|
+
|
143
|
+
int = WideCharToMultiByte(encoding, 0, wstring, -1, 0, 0, nil, nil)
|
144
|
+
|
145
|
+
# Trailing nulls are stripped
|
146
|
+
if int > 0
|
147
|
+
buf = ' ' * int
|
148
|
+
WideCharToMultiByte(encoding, 0, wstring, -1, buf, strlen(buf), nil, nil)
|
149
|
+
buf[ /^[^\0]*/ ]
|
150
|
+
else
|
151
|
+
raise ArgumentError, get_last_error
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
data/lib/windows/wsa.rb
CHANGED
@@ -1,102 +1,102 @@
|
|
1
|
-
require 'windows/api'
|
2
|
-
|
3
|
-
module Windows
|
4
|
-
module WSA
|
5
|
-
API.auto_namespace = 'Windows::WSA'
|
6
|
-
API.auto_constant = true
|
7
|
-
API.auto_method = true
|
8
|
-
API.auto_unicode = true
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
# Constants
|
13
|
-
|
14
|
-
WSA_FLAG_OVERLAPPED = 0x01
|
15
|
-
WSA_FLAG_MULTIPOINT_C_ROOT = 0x02
|
16
|
-
WSA_FLAG_MULTIPOINT_C_LEAF = 0x04
|
17
|
-
WSA_FLAG_MULTIPOINT_D_ROOT = 0x08
|
18
|
-
WSA_FLAG_MULTIPOINT_D_LEAF = 0x10
|
19
|
-
WSA_FLAG_ACCESS_SYSTEM_SECURITY = 0x40
|
20
|
-
WSA_FLAG_NO_HANDLE_INHERIT = 0x80
|
21
|
-
|
22
|
-
RNRSERVICE_REGISTER = 0
|
23
|
-
RNRSERVICE_DEREGISTER = 1
|
24
|
-
RNRSERVICE_DELETE = 2
|
25
|
-
|
26
|
-
# Functions
|
27
|
-
|
28
|
-
API.new('WSAAccept', 'LPPKP', 'L', 'ws2_32')
|
29
|
-
API.new('WSAAddressToString', 'PLPPP', 'I', 'ws2_32')
|
30
|
-
API.new('WSAAsyncGetHostByAddr', 'LISIIPI', 'L', 'ws2_32')
|
31
|
-
API.new('WSAAsyncGetHostByName', 'LISPI', 'L', 'ws2_32')
|
32
|
-
API.new('WSAAsyncGetProtoByName', 'LISPI', 'L', 'ws2_32')
|
33
|
-
API.new('WSAAsyncGetProtoByNumber', 'LISPI', 'L', 'ws2_32')
|
34
|
-
API.new('WSAAsyncGetServByName', 'LISSPI', 'L', 'ws2_32')
|
35
|
-
API.new('WSAAsyncGetServByPort', 'LIISPI', 'L', 'ws2_32')
|
36
|
-
API.new('WSAAsyncSelect', 'LLIL', 'I', 'ws2_32')
|
37
|
-
API.new('WSACancelAsyncRequest', 'L', 'I', 'ws2_32')
|
38
|
-
API.new('WSACleanup', 'V', 'I', 'ws2_32')
|
39
|
-
API.new('WSACloseEvent', 'I', 'B', 'ws2_32')
|
40
|
-
API.new('WSAConnect', 'LPIPPPP', 'I', 'ws2_32')
|
41
|
-
API.new('WSACreateEvent', 'V', 'L', 'ws2_32')
|
42
|
-
API.new('WSADuplicateSocket', 'LLP', 'I', 'ws2_32')
|
43
|
-
API.new('WSAEnumNetworkEvents', 'LLP', 'I', 'ws2_32')
|
44
|
-
API.new('WSAEnumProtocols', 'PPP', 'I', 'ws2_32')
|
45
|
-
API.new('WSAEventSelect', 'LLL', 'I', 'ws2_32')
|
46
|
-
API.new('WSAGetLastError', 'V', 'I', 'ws2_32')
|
47
|
-
API.new('WSAGetOverlappedResult', 'LPPIP', 'B', 'ws2_32')
|
48
|
-
API.new('WSAGetQOSByName', 'LPP', 'B', 'ws2_32')
|
49
|
-
API.new('WSAGetServiceClassInfo', 'PPPP', 'I', 'ws2_32')
|
50
|
-
API.new('WSAGetServiceClassNameByClassId', 'PPP', 'I', 'ws2_32')
|
51
|
-
API.new('WSAHtonl', 'LLP', 'I', 'ws2_32')
|
52
|
-
API.new('WSAHtons', 'LIP', 'I', 'ws2_32')
|
53
|
-
API.new('WSAInstallServiceClass', 'P', 'I', 'ws2_32')
|
54
|
-
API.new('WSAIoctl', 'LLPLPLPPP', 'I', 'ws2_32')
|
55
|
-
API.new('WSAJoinLeaf', 'LPIPPPPL', 'L', 'ws2_32')
|
56
|
-
API.new('WSALookupServiceBegin', 'PLP', 'I', 'ws2_32')
|
57
|
-
API.new('WSALookupServiceEnd', 'L', 'I', 'ws2_32')
|
58
|
-
API.new('WSALookupServiceNext', 'LLPP', 'I', 'ws2_32')
|
59
|
-
API.new('WSANtohl', 'LLP', 'I', 'ws2_32')
|
60
|
-
API.new('WSANtohs', 'LIP', 'I', 'ws2_32')
|
61
|
-
API.new('WSAProviderConfigChange', 'PPP', 'I', 'ws2_32')
|
62
|
-
API.new('WSARecv', 'LPLPPPP', 'I', 'ws2_32')
|
63
|
-
API.new('WSARecvDisconnect', 'LP', 'I', 'ws2_32')
|
64
|
-
API.new('WSARecvEx', 'LPIP', 'I', 'mswsock')
|
65
|
-
API.new('WSARecvFrom', 'LPLPPPPPP', 'I', 'ws2_32')
|
66
|
-
API.new('WSARemoveServiceClass', 'P', 'I', 'ws2_32')
|
67
|
-
API.new('WSAResetEvent', 'L', 'B', 'ws2_32')
|
68
|
-
API.new('WSASend', 'LPLPLPP', 'I', 'ws2_32')
|
69
|
-
API.new('WSASendDisconnect', 'LP', 'I', 'ws2_32')
|
70
|
-
API.new('WSASendTo', 'LPLPLPIPP', 'I', 'ws2_32')
|
71
|
-
API.new('WSASetEvent', 'L', 'B', 'ws2_32')
|
72
|
-
API.new('WSASetLastError', 'I', 'V', 'ws2_32')
|
73
|
-
API.new('WSASetService', 'PIL', 'I', 'ws2_32')
|
74
|
-
API.new('WSAStartup', 'LP', 'I', 'ws2_32')
|
75
|
-
API.new('WSASocket', 'IIIPLL', 'L', 'ws2_32')
|
76
|
-
API.new('WSAStringToAddress', 'PIPPP', 'I', 'ws2_32')
|
77
|
-
API.new('WSAWaitForMultipleEvents', 'LPILI', 'L', 'ws2_32')
|
78
|
-
|
79
|
-
begin
|
80
|
-
API.new('WSAConnectByList', 'LPPPPPPP', 'B', 'ws2_32')
|
81
|
-
API.new('WSAConnectByName', 'LPPPPPPP', 'B', 'ws2_32')
|
82
|
-
API.new('WSADeleteSocketPeerTargetName', 'LPLPP', 'L', 'fwpuclnt')
|
83
|
-
API.new('WSAEnumNameSpaceProvidersEx', 'PP', 'I', 'ws2_32')
|
84
|
-
API.new('WSAPoll', 'PLI', 'I', 'ws2_32')
|
85
|
-
API.new('WSAQuerySocketSecurity', 'LPLPPPP', 'I', 'fwpuclnt')
|
86
|
-
API.new('WSARevertImpersonation', 'V', 'I', 'fwpuclnt')
|
87
|
-
API.new('WSASendMsg', 'LPLPPP', 'I', 'ws2_32')
|
88
|
-
API.new('WSASetSocketPeerTargetName', 'LPLPP', 'I', 'fwpuclnt')
|
89
|
-
API.new('WSASetSocketSecurity', 'LPLPP', 'I', 'fwpuclnt')
|
90
|
-
rescue Win32::API::LoadLibraryError
|
91
|
-
# Vista or later
|
92
|
-
end
|
93
|
-
|
94
|
-
begin
|
95
|
-
API.new('WSAEnumNameSpaceProviders', 'PP', 'I', 'ws2_32')
|
96
|
-
API.new('WSAImpersonateSocketPeer', 'LPL', 'I', 'fwpuclnt')
|
97
|
-
API.new('WSANSPIoctl', 'LLPLPLPP', 'I', 'ws2_32')
|
98
|
-
rescue Win32::API::LoadLibraryError
|
99
|
-
# XP or later
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
1
|
+
require 'windows/api'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
module WSA
|
5
|
+
API.auto_namespace = 'Windows::WSA'
|
6
|
+
API.auto_constant = true
|
7
|
+
API.auto_method = true
|
8
|
+
API.auto_unicode = true
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# Constants
|
13
|
+
|
14
|
+
WSA_FLAG_OVERLAPPED = 0x01
|
15
|
+
WSA_FLAG_MULTIPOINT_C_ROOT = 0x02
|
16
|
+
WSA_FLAG_MULTIPOINT_C_LEAF = 0x04
|
17
|
+
WSA_FLAG_MULTIPOINT_D_ROOT = 0x08
|
18
|
+
WSA_FLAG_MULTIPOINT_D_LEAF = 0x10
|
19
|
+
WSA_FLAG_ACCESS_SYSTEM_SECURITY = 0x40
|
20
|
+
WSA_FLAG_NO_HANDLE_INHERIT = 0x80
|
21
|
+
|
22
|
+
RNRSERVICE_REGISTER = 0
|
23
|
+
RNRSERVICE_DEREGISTER = 1
|
24
|
+
RNRSERVICE_DELETE = 2
|
25
|
+
|
26
|
+
# Functions
|
27
|
+
|
28
|
+
API.new('WSAAccept', 'LPPKP', 'L', 'ws2_32')
|
29
|
+
API.new('WSAAddressToString', 'PLPPP', 'I', 'ws2_32')
|
30
|
+
API.new('WSAAsyncGetHostByAddr', 'LISIIPI', 'L', 'ws2_32')
|
31
|
+
API.new('WSAAsyncGetHostByName', 'LISPI', 'L', 'ws2_32')
|
32
|
+
API.new('WSAAsyncGetProtoByName', 'LISPI', 'L', 'ws2_32')
|
33
|
+
API.new('WSAAsyncGetProtoByNumber', 'LISPI', 'L', 'ws2_32')
|
34
|
+
API.new('WSAAsyncGetServByName', 'LISSPI', 'L', 'ws2_32')
|
35
|
+
API.new('WSAAsyncGetServByPort', 'LIISPI', 'L', 'ws2_32')
|
36
|
+
API.new('WSAAsyncSelect', 'LLIL', 'I', 'ws2_32')
|
37
|
+
API.new('WSACancelAsyncRequest', 'L', 'I', 'ws2_32')
|
38
|
+
API.new('WSACleanup', 'V', 'I', 'ws2_32')
|
39
|
+
API.new('WSACloseEvent', 'I', 'B', 'ws2_32')
|
40
|
+
API.new('WSAConnect', 'LPIPPPP', 'I', 'ws2_32')
|
41
|
+
API.new('WSACreateEvent', 'V', 'L', 'ws2_32')
|
42
|
+
API.new('WSADuplicateSocket', 'LLP', 'I', 'ws2_32')
|
43
|
+
API.new('WSAEnumNetworkEvents', 'LLP', 'I', 'ws2_32')
|
44
|
+
API.new('WSAEnumProtocols', 'PPP', 'I', 'ws2_32')
|
45
|
+
API.new('WSAEventSelect', 'LLL', 'I', 'ws2_32')
|
46
|
+
API.new('WSAGetLastError', 'V', 'I', 'ws2_32')
|
47
|
+
API.new('WSAGetOverlappedResult', 'LPPIP', 'B', 'ws2_32')
|
48
|
+
API.new('WSAGetQOSByName', 'LPP', 'B', 'ws2_32')
|
49
|
+
API.new('WSAGetServiceClassInfo', 'PPPP', 'I', 'ws2_32')
|
50
|
+
API.new('WSAGetServiceClassNameByClassId', 'PPP', 'I', 'ws2_32')
|
51
|
+
API.new('WSAHtonl', 'LLP', 'I', 'ws2_32')
|
52
|
+
API.new('WSAHtons', 'LIP', 'I', 'ws2_32')
|
53
|
+
API.new('WSAInstallServiceClass', 'P', 'I', 'ws2_32')
|
54
|
+
API.new('WSAIoctl', 'LLPLPLPPP', 'I', 'ws2_32')
|
55
|
+
API.new('WSAJoinLeaf', 'LPIPPPPL', 'L', 'ws2_32')
|
56
|
+
API.new('WSALookupServiceBegin', 'PLP', 'I', 'ws2_32')
|
57
|
+
API.new('WSALookupServiceEnd', 'L', 'I', 'ws2_32')
|
58
|
+
API.new('WSALookupServiceNext', 'LLPP', 'I', 'ws2_32')
|
59
|
+
API.new('WSANtohl', 'LLP', 'I', 'ws2_32')
|
60
|
+
API.new('WSANtohs', 'LIP', 'I', 'ws2_32')
|
61
|
+
API.new('WSAProviderConfigChange', 'PPP', 'I', 'ws2_32')
|
62
|
+
API.new('WSARecv', 'LPLPPPP', 'I', 'ws2_32')
|
63
|
+
API.new('WSARecvDisconnect', 'LP', 'I', 'ws2_32')
|
64
|
+
API.new('WSARecvEx', 'LPIP', 'I', 'mswsock')
|
65
|
+
API.new('WSARecvFrom', 'LPLPPPPPP', 'I', 'ws2_32')
|
66
|
+
API.new('WSARemoveServiceClass', 'P', 'I', 'ws2_32')
|
67
|
+
API.new('WSAResetEvent', 'L', 'B', 'ws2_32')
|
68
|
+
API.new('WSASend', 'LPLPLPP', 'I', 'ws2_32')
|
69
|
+
API.new('WSASendDisconnect', 'LP', 'I', 'ws2_32')
|
70
|
+
API.new('WSASendTo', 'LPLPLPIPP', 'I', 'ws2_32')
|
71
|
+
API.new('WSASetEvent', 'L', 'B', 'ws2_32')
|
72
|
+
API.new('WSASetLastError', 'I', 'V', 'ws2_32')
|
73
|
+
API.new('WSASetService', 'PIL', 'I', 'ws2_32')
|
74
|
+
API.new('WSAStartup', 'LP', 'I', 'ws2_32')
|
75
|
+
API.new('WSASocket', 'IIIPLL', 'L', 'ws2_32')
|
76
|
+
API.new('WSAStringToAddress', 'PIPPP', 'I', 'ws2_32')
|
77
|
+
API.new('WSAWaitForMultipleEvents', 'LPILI', 'L', 'ws2_32')
|
78
|
+
|
79
|
+
begin
|
80
|
+
API.new('WSAConnectByList', 'LPPPPPPP', 'B', 'ws2_32')
|
81
|
+
API.new('WSAConnectByName', 'LPPPPPPP', 'B', 'ws2_32')
|
82
|
+
API.new('WSADeleteSocketPeerTargetName', 'LPLPP', 'L', 'fwpuclnt')
|
83
|
+
API.new('WSAEnumNameSpaceProvidersEx', 'PP', 'I', 'ws2_32')
|
84
|
+
API.new('WSAPoll', 'PLI', 'I', 'ws2_32')
|
85
|
+
API.new('WSAQuerySocketSecurity', 'LPLPPPP', 'I', 'fwpuclnt')
|
86
|
+
API.new('WSARevertImpersonation', 'V', 'I', 'fwpuclnt')
|
87
|
+
API.new('WSASendMsg', 'LPLPPP', 'I', 'ws2_32')
|
88
|
+
API.new('WSASetSocketPeerTargetName', 'LPLPP', 'I', 'fwpuclnt')
|
89
|
+
API.new('WSASetSocketSecurity', 'LPLPP', 'I', 'fwpuclnt')
|
90
|
+
rescue Win32::API::LoadLibraryError
|
91
|
+
# Vista or later
|
92
|
+
end
|
93
|
+
|
94
|
+
begin
|
95
|
+
API.new('WSAEnumNameSpaceProviders', 'PP', 'I', 'ws2_32')
|
96
|
+
API.new('WSAImpersonateSocketPeer', 'LPL', 'I', 'fwpuclnt')
|
97
|
+
API.new('WSANSPIoctl', 'LLPLPLPP', 'I', 'ws2_32')
|
98
|
+
rescue Win32::API::LoadLibraryError
|
99
|
+
# XP or later
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|