windows-pr 0.3.0-mswin32
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.
- data/CHANGES +11 -0
- data/MANIFEST +23 -0
- data/README +117 -0
- data/doc/conversion_guide.txt +25 -0
- data/lib/windows/clipboard.rb +105 -0
- data/lib/windows/device_io.rb +141 -0
- data/lib/windows/error.rb +332 -0
- data/lib/windows/file.rb +305 -0
- data/lib/windows/filesystem.rb +16 -0
- data/lib/windows/handle.rb +47 -0
- data/lib/windows/limits.rb +13 -0
- data/lib/windows/memory.rb +92 -0
- data/lib/windows/msvcrt/buffer.rb +48 -0
- data/lib/windows/msvcrt/file.rb +18 -0
- data/lib/windows/path.rb +372 -0
- data/lib/windows/security.rb +89 -0
- data/lib/windows/sound.rb +52 -0
- data/lib/windows/synchronize.rb +61 -0
- data/test/tc_error.rb +57 -0
- data/test/tc_msvcrt_buffer.rb +71 -0
- data/test/tc_path.rb +97 -0
- data/test/tc_security.rb +111 -0
- data/test/tc_synchronize.rb +43 -0
- data/test/ts_all.rb +10 -0
- metadata +69 -0
@@ -0,0 +1,332 @@
|
|
1
|
+
############################################################################
|
2
|
+
# error.rb
|
3
|
+
#
|
4
|
+
# Includes the following functions:
|
5
|
+
#
|
6
|
+
# GetLastError()
|
7
|
+
# FormatError()
|
8
|
+
# SetErrorMode()
|
9
|
+
# SetLastError()
|
10
|
+
# SetLastErrorex()
|
11
|
+
#
|
12
|
+
# Defines the following constants:
|
13
|
+
#
|
14
|
+
# FORMAT_MESSAGE_ALLOCATE_BUFFER
|
15
|
+
# FORMAT_MESSAGE_IGNORE_INSERTS
|
16
|
+
# FORMAT_MESSAGE_FROM_STRING
|
17
|
+
# FORMAT_MESSAGE_FROM_HMODULE
|
18
|
+
# FORMAT_MESSAGE_FROM_SYSTEM
|
19
|
+
# FORMAT_MESSAGE_ARGUMENT_ARRAY
|
20
|
+
# FORMAT_MESSAGE_MAX_WIDTH_MASK
|
21
|
+
#
|
22
|
+
# SEM_FAILCRITICALERRORS
|
23
|
+
# SEM_NOALIGNMENTFAULTEXCEPT
|
24
|
+
# SEM_NOGPFAULTERRORBOX
|
25
|
+
# SEM_NOOPENFILEERRORBOX
|
26
|
+
#
|
27
|
+
# All of the error codes in error.h.
|
28
|
+
#
|
29
|
+
# Adds the following convenience methods:
|
30
|
+
#
|
31
|
+
# get_last_error - Returns a human readable string for the error returned
|
32
|
+
# by the GetLastError() function.
|
33
|
+
############################################################################
|
34
|
+
require "Win32API"
|
35
|
+
|
36
|
+
module Windows
|
37
|
+
module Error
|
38
|
+
FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100
|
39
|
+
FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200
|
40
|
+
FORMAT_MESSAGE_FROM_STRING = 0x00000400
|
41
|
+
FORMAT_MESSAGE_FROM_HMODULE = 0x00000800
|
42
|
+
FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
|
43
|
+
FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000
|
44
|
+
FORMAT_MESSAGE_MAX_WIDTH_MASK = 0x000000FF
|
45
|
+
|
46
|
+
SEM_FAILCRITICALERRORS = 0x0001
|
47
|
+
SEM_NOALIGNMENTFAULTEXCEPT = 0x0004
|
48
|
+
SEM_NOGPFAULTERRORBOX = 0x0002
|
49
|
+
SEM_NOOPENFILEERRORBOX = 0x8000
|
50
|
+
|
51
|
+
NO_ERROR = 0
|
52
|
+
ERROR_INVALID_FUNCTION = 1
|
53
|
+
ERROR_FILE_NOT_FOUND = 2
|
54
|
+
ERROR_PATH_NOT_FOUND = 3
|
55
|
+
ERROR_TOO_MANY_OPEN_FILES = 4
|
56
|
+
ERROR_ACCESS_DENIED = 5
|
57
|
+
ERROR_INVALID_HANDLE = 6
|
58
|
+
ERROR_ARENA_TRASHED = 7
|
59
|
+
ERROR_NOT_ENOUGH_MEMORY = 8
|
60
|
+
ERROR_INVALID_BLOCK = 9
|
61
|
+
ERROR_BAD_ENVIRONMENT = 10
|
62
|
+
ERROR_BAD_FORMAT = 11
|
63
|
+
ERROR_INVALID_ACCESS = 12
|
64
|
+
ERROR_INVALID_DATA = 13
|
65
|
+
ERROR_INVALID_DRIVE = 15
|
66
|
+
ERROR_CURRENT_DIRECTORY = 16
|
67
|
+
ERROR_NOT_SAME_DEVICE = 17
|
68
|
+
ERROR_NO_MORE_FILES = 18
|
69
|
+
|
70
|
+
ERROR_WRITE_PROTECT = 19
|
71
|
+
ERROR_BAD_UNIT = 20
|
72
|
+
ERROR_NOT_READY = 21
|
73
|
+
ERROR_BAD_COMMAND = 22
|
74
|
+
ERROR_CRC = 23
|
75
|
+
ERROR_BAD_LENGTH = 24
|
76
|
+
ERROR_SEEK = 25
|
77
|
+
ERROR_NOT_DOS_DISK = 26
|
78
|
+
ERROR_SECTOR_NOT_FOUND = 27
|
79
|
+
ERROR_OUT_OF_PAPER = 28
|
80
|
+
ERROR_WRITE_FAULT = 29
|
81
|
+
ERROR_READ_FAULT = 30
|
82
|
+
ERROR_GEN_FAILURE = 31
|
83
|
+
|
84
|
+
ERROR_SHARING_VIOLATION = 32
|
85
|
+
ERROR_LOCK_VIOLATION = 33
|
86
|
+
ERROR_WRONG_DISK = 34
|
87
|
+
ERROR_FCB_UNAVAILABLE = 35
|
88
|
+
ERROR_SHARING_BUFFER_EXCEEDED = 36
|
89
|
+
|
90
|
+
ERROR_NOT_SUPPORTED = 50
|
91
|
+
|
92
|
+
ERROR_FILE_EXISTS = 80
|
93
|
+
ERROR_DUP_FCB = 81
|
94
|
+
ERROR_CANNOT_MAKE = 82
|
95
|
+
ERROR_FAIL_I24 = 83
|
96
|
+
|
97
|
+
ERROR_OUT_OF_STRUCTURES = 84
|
98
|
+
ERROR_ALREADY_ASSIGNED = 85
|
99
|
+
ERROR_INVALID_PASSWORD = 86
|
100
|
+
ERROR_INVALID_PARAMETER = 87
|
101
|
+
ERROR_NET_WRITE_FAULT = 88
|
102
|
+
|
103
|
+
ERROR_NO_PROC_SLOTS = 89 # no process slots available
|
104
|
+
ERROR_NOT_FROZEN = 90
|
105
|
+
ERR_TSTOVFL = 91 # timer service table overflow
|
106
|
+
ERR_TSTDUP = 92 # timer service table duplicate
|
107
|
+
ERROR_NO_ITEMS = 93 # There were no items to operate upon
|
108
|
+
ERROR_INTERRUPT = 95 # interrupted system call
|
109
|
+
|
110
|
+
ERROR_TOO_MANY_SEMAPHORES = 100
|
111
|
+
ERROR_EXCL_SEM_ALREADY_OWNED = 101
|
112
|
+
ERROR_SEM_IS_SET = 102
|
113
|
+
ERROR_TOO_MANY_SEM_REQUESTS = 103
|
114
|
+
ERROR_INVALID_AT_INTERRUPT_TIME = 104
|
115
|
+
|
116
|
+
ERROR_SEM_OWNER_DIED = 105 # waitsem found owner died
|
117
|
+
ERROR_SEM_USER_LIMIT = 106 # too many procs have this sem
|
118
|
+
ERROR_DISK_CHANGE = 107 # insert disk b into drive a
|
119
|
+
ERROR_DRIVE_LOCKED = 108 # drive locked by another process
|
120
|
+
ERROR_BROKEN_PIPE = 109 # write on pipe with no reader
|
121
|
+
|
122
|
+
ERROR_OPEN_FAILED = 110 # open/created failed
|
123
|
+
ERROR_DISK_FULL = 112 # not enough space
|
124
|
+
ERROR_NO_MORE_SEARCH_HANDLES = 113 # can't allocate
|
125
|
+
ERROR_INVALID_TARGET_HANDLE = 114 # handle in DOSDUPHANDLE is invalid
|
126
|
+
ERROR_PROTECTION_VIOLATION = 115 # bad user virtual address
|
127
|
+
ERROR_VIOKBD_REQUEST = 116
|
128
|
+
ERROR_INVALID_CATEGORY = 117 # category for DEVIOCTL not defined
|
129
|
+
ERROR_INVALID_VERIFY_SWITCH = 118 # invalid value
|
130
|
+
ERROR_BAD_DRIVER_LEVEL = 119 # DosDevIOCTL not level four
|
131
|
+
ERROR_CALL_NOT_IMPLEMENTED = 120
|
132
|
+
ERROR_SEM_TIMEOUT = 121 # timeout from semaphore function
|
133
|
+
ERROR_INSUFFICIENT_BUFFER = 122
|
134
|
+
|
135
|
+
ERROR_INVALID_NAME = 123 # illegal char or malformed file system name
|
136
|
+
ERROR_INVALID_LEVEL = 124 # unimplemented level for info retrieval
|
137
|
+
ERROR_NO_VOLUME_LABEL = 125 # no volume label found
|
138
|
+
ERROR_MOD_NOT_FOUND = 126 # w_getprocaddr, w_getmodhandle
|
139
|
+
ERROR_PROC_NOT_FOUND = 127 # w_getprocaddr
|
140
|
+
|
141
|
+
ERROR_WAIT_NO_CHILDREN = 128 # CWait finds to children
|
142
|
+
ERROR_CHILD_NOT_COMPLETE = 129 # CWait children not dead yet
|
143
|
+
|
144
|
+
ERROR_DIRECT_ACCESS_HANDLE = 130 # invalid for direct disk access
|
145
|
+
ERROR_NEGATIVE_SEEK = 131 # tried to seek negative offset
|
146
|
+
ERROR_SEEK_ON_DEVICE = 132 # tried to seek on device or pipe
|
147
|
+
|
148
|
+
ERROR_IS_JOIN_TARGET = 133
|
149
|
+
ERROR_IS_JOINED = 134
|
150
|
+
ERROR_IS_SUBSTED = 135
|
151
|
+
ERROR_NOT_JOINED = 136
|
152
|
+
ERROR_NOT_SUBSTED = 137
|
153
|
+
ERROR_JOIN_TO_JOIN = 138
|
154
|
+
ERROR_SUBST_TO_SUBST = 139
|
155
|
+
ERROR_JOIN_TO_SUBST = 140
|
156
|
+
ERROR_SUBST_TO_JOIN = 141
|
157
|
+
ERROR_BUSY_DRIVE = 142
|
158
|
+
ERROR_SAME_DRIVE = 143
|
159
|
+
ERROR_DIR_NOT_ROOT = 144
|
160
|
+
ERROR_DIR_NOT_EMPTY = 145
|
161
|
+
ERROR_IS_SUBST_PATH = 146
|
162
|
+
ERROR_IS_JOIN_PATH = 147
|
163
|
+
ERROR_PATH_BUSY = 148
|
164
|
+
ERROR_IS_SUBST_TARGET = 149
|
165
|
+
ERROR_SYSTEM_TRACE = 150 # system trace error
|
166
|
+
ERROR_INVALID_EVENT_COUNT = 151 # DosMuxSemWait errors
|
167
|
+
ERROR_TOO_MANY_MUXWAITERS = 152
|
168
|
+
ERROR_INVALID_LIST_FORMAT = 153
|
169
|
+
ERROR_LABEL_TOO_LONG = 154
|
170
|
+
ERROR_TOO_MANY_TCBS = 155
|
171
|
+
ERROR_SIGNAL_REFUSED = 156
|
172
|
+
ERROR_DISCARDED = 157
|
173
|
+
ERROR_NOT_LOCKED = 158
|
174
|
+
ERROR_BAD_THREADID_ADDR = 159
|
175
|
+
ERROR_BAD_ARGUMENTS = 160
|
176
|
+
ERROR_BAD_PATHNAME = 161
|
177
|
+
ERROR_SIGNAL_PENDING = 162
|
178
|
+
ERROR_UNCERTAIN_MEDIA = 163
|
179
|
+
ERROR_MAX_THRDS_REACHED = 164
|
180
|
+
ERROR_MONITORS_NOT_SUPPORTED = 165
|
181
|
+
|
182
|
+
ERROR_INVALID_SEGMENT_NUMBER = 180
|
183
|
+
ERROR_INVALID_CALLGATE = 181
|
184
|
+
ERROR_INVALID_ORDINAL = 182
|
185
|
+
ERROR_ALREADY_EXISTS = 183
|
186
|
+
ERROR_NO_CHILD_PROCESS = 184
|
187
|
+
ERROR_CHILD_ALIVE_NOWAIT = 185
|
188
|
+
ERROR_INVALID_FLAG_NUMBER = 186
|
189
|
+
ERROR_SEM_NOT_FOUND = 187
|
190
|
+
|
191
|
+
ERROR_INVALID_STARTING_CODESEG = 188
|
192
|
+
ERROR_INVALID_STACKSEG = 189
|
193
|
+
ERROR_INVALID_MODULETYPE = 190
|
194
|
+
ERROR_INVALID_EXE_SIGNATURE = 191
|
195
|
+
ERROR_EXE_MARKED_INVALID = 192
|
196
|
+
ERROR_BAD_EXE_FORMAT = 193
|
197
|
+
ERROR_ITERATED_DATA_EXCEEDS_64k = 194
|
198
|
+
ERROR_INVALID_MINALLOCSIZE = 195
|
199
|
+
ERROR_DYNLINK_FROM_INVALID_RING = 196
|
200
|
+
ERROR_IOPL_NOT_ENABLED = 197
|
201
|
+
ERROR_INVALID_SEGDPL = 198
|
202
|
+
ERROR_AUTODATASEG_EXCEEDS_64k = 199
|
203
|
+
ERROR_RING2SEG_MUST_BE_MOVABLE = 200
|
204
|
+
ERROR_RELOC_CHAIN_XEEDS_SEGLIM = 201
|
205
|
+
ERROR_INFLOOP_IN_RELOC_CHAIN = 202
|
206
|
+
|
207
|
+
ERROR_ENVVAR_NOT_FOUND = 203
|
208
|
+
ERROR_NOT_CURRENT_CTRY = 204
|
209
|
+
ERROR_NO_SIGNAL_SENT = 205
|
210
|
+
ERROR_FILENAME_EXCED_RANGE = 206 # if filename > 8.3
|
211
|
+
ERROR_RING2_STACK_IN_USE = 207 # for FAPI
|
212
|
+
ERROR_META_EXPANSION_TOO_LONG = 208 # if "*a" > 8.3
|
213
|
+
|
214
|
+
ERROR_INVALID_SIGNAL_NUMBER = 209
|
215
|
+
ERROR_THREAD_1_INACTIVE = 210
|
216
|
+
ERROR_INFO_NOT_AVAIL = 211 #@@ PTM 5550
|
217
|
+
ERROR_LOCKED = 212
|
218
|
+
ERROR_BAD_DYNALINK = 213 #@@ PTM 5760
|
219
|
+
ERROR_TOO_MANY_MODULES = 214
|
220
|
+
ERROR_NESTING_NOT_ALLOWED = 215
|
221
|
+
|
222
|
+
ERROR_USER_DEFINED_BASE = 0xF000
|
223
|
+
|
224
|
+
ERROR_I24_WRITE_PROTECT = 0
|
225
|
+
ERROR_I24_BAD_UNIT = 1
|
226
|
+
ERROR_I24_NOT_READY = 2
|
227
|
+
ERROR_I24_BAD_COMMAND = 3
|
228
|
+
ERROR_I24_CRC = 4
|
229
|
+
ERROR_I24_BAD_LENGTH = 5
|
230
|
+
ERROR_I24_SEEK = 6
|
231
|
+
ERROR_I24_NOT_DOS_DISK = 7
|
232
|
+
ERROR_I24_SECTOR_NOT_FOUND = 8
|
233
|
+
ERROR_I24_OUT_OF_PAPER = 9
|
234
|
+
ERROR_I24_WRITE_FAULT = 0x0A
|
235
|
+
ERROR_I24_READ_FAULT = 0x0B
|
236
|
+
ERROR_I24_GEN_FAILURE = 0x0C
|
237
|
+
ERROR_I24_DISK_CHANGE = 0x0D
|
238
|
+
ERROR_I24_WRONG_DISK = 0x0F
|
239
|
+
ERROR_I24_UNCERTAIN_MEDIA = 0x10
|
240
|
+
ERROR_I24_CHAR_CALL_INTERRUPTED = 0x11
|
241
|
+
ERROR_I24_NO_MONITOR_SUPPORT = 0x12
|
242
|
+
ERROR_I24_INVALID_PARAMETER = 0x13
|
243
|
+
|
244
|
+
ALLOWED_FAIL = 0x0001
|
245
|
+
ALLOWED_ABORT = 0x0002
|
246
|
+
ALLOWED_RETRY = 0x0004
|
247
|
+
ALLOWED_IGNORE = 0x0008
|
248
|
+
|
249
|
+
I24_OPERATION = 0x1
|
250
|
+
I24_AREA = 0x6
|
251
|
+
I24_CLASS = 0x80
|
252
|
+
|
253
|
+
|
254
|
+
ERRCLASS_OUTRES = 1 # Out of Resource
|
255
|
+
ERRCLASS_TEMPSIT = 2 # Temporary Situation
|
256
|
+
ERRCLASS_AUTH = 3 # Permission problem
|
257
|
+
ERRCLASS_INTRN = 4 # Internal System Error
|
258
|
+
ERRCLASS_HRDFAIL = 5 # Hardware Failure
|
259
|
+
ERRCLASS_SYSFAIL = 6 # System Failure
|
260
|
+
ERRCLASS_APPERR = 7 # Application Error
|
261
|
+
ERRCLASS_NOTFND = 8 # Not Found
|
262
|
+
ERRCLASS_BADFMT = 9 # Bad Format
|
263
|
+
ERRCLASS_LOCKED = 10 # Locked
|
264
|
+
ERRCLASS_MEDIA = 11 # Media Failure
|
265
|
+
ERRCLASS_ALREADY = 12 # Collision with Existing Item
|
266
|
+
ERRCLASS_UNK = 13 # Unknown/other
|
267
|
+
ERRCLASS_CANT = 14
|
268
|
+
ERRCLASS_TIME = 15
|
269
|
+
|
270
|
+
ERRACT_RETRY = 1 # Retry
|
271
|
+
ERRACT_DLYRET = 2 # Delay Retry, retry after pause
|
272
|
+
ERRACT_USER = 3 # Ask user to regive info
|
273
|
+
ERRACT_ABORT = 4 # abort with clean up
|
274
|
+
ERRACT_PANIC = 5 # abort immediately
|
275
|
+
ERRACT_IGNORE = 6 # ignore
|
276
|
+
ERRACT_INTRET = 7 # Retry after User Intervention
|
277
|
+
|
278
|
+
ERRLOC_UNK = 1 # No appropriate value
|
279
|
+
ERRLOC_DISK = 2 # Random Access Mass Storage
|
280
|
+
ERRLOC_NET = 3 # Network
|
281
|
+
ERRLOC_SERDEV = 4 # Serial Device
|
282
|
+
ERRLOC_MEM = 5 # Memory
|
283
|
+
|
284
|
+
TC_NORMAL = 0
|
285
|
+
TC_HARDERR = 1
|
286
|
+
TC_GP_TRAP = 2
|
287
|
+
TC_SIGNAL = 3
|
288
|
+
|
289
|
+
GetLastError = Win32API.new('kernel32', 'GetLastError', 'V', 'L')
|
290
|
+
SetLastError = Win32API.new('kernel32', 'GetLastError', 'L', 'V')
|
291
|
+
SetLastErrorEx = Win32API.new('kernel32', 'GetLastError', 'LL', 'V')
|
292
|
+
SetErrorMode = Win32API.new('kernel32', 'SetErrorMode', 'I', 'I')
|
293
|
+
FormatMessage = Win32API.new('kernel32', 'FormatMessage', 'LPLLPLP', 'L')
|
294
|
+
|
295
|
+
def GetLastError
|
296
|
+
GetLastError.call
|
297
|
+
end
|
298
|
+
|
299
|
+
def SetLastError(error)
|
300
|
+
SetLastError.call(error)
|
301
|
+
end
|
302
|
+
|
303
|
+
def SetLastErrorEx(error, type=0)
|
304
|
+
SetLastErrorEx.call(error, type)
|
305
|
+
end
|
306
|
+
|
307
|
+
def SetErrorMode(mode)
|
308
|
+
SetErrorMode.call(mode)
|
309
|
+
end
|
310
|
+
|
311
|
+
def FormatMessage(flags, src, msg_id, lang_id, buf, size, args)
|
312
|
+
FormatMessage.call(flags, src, msg_id, lang_id, buf, size, args)
|
313
|
+
end
|
314
|
+
|
315
|
+
# Convenience method that wraps FormatMessage with some sane defaults and
|
316
|
+
# returns a human readable string.
|
317
|
+
#
|
318
|
+
def get_last_error(err_num = GetLastError.call)
|
319
|
+
buf = 0.chr * 260
|
320
|
+
FormatMessage.call(
|
321
|
+
FORMAT_MESSAGE_FROM_SYSTEM + FORMAT_MESSAGE_ARGUMENT_ARRAY,
|
322
|
+
0,
|
323
|
+
err_num,
|
324
|
+
0,
|
325
|
+
buf,
|
326
|
+
buf.length,
|
327
|
+
0
|
328
|
+
)
|
329
|
+
buf.split(0.chr).first.chomp
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
data/lib/windows/file.rb
ADDED
@@ -0,0 +1,305 @@
|
|
1
|
+
######################################################################
|
2
|
+
# file.rb
|
3
|
+
#
|
4
|
+
# Defines the following functions:
|
5
|
+
#
|
6
|
+
# CopyFile()
|
7
|
+
# CopyFileEx()
|
8
|
+
# CreateFile()
|
9
|
+
# CreateHardLink()
|
10
|
+
# DecryptFile()
|
11
|
+
# DeleteFile()
|
12
|
+
# EncryptFile()
|
13
|
+
# GetFileAttributes()
|
14
|
+
# GetFileAttributesEx()
|
15
|
+
# GetFileSize()
|
16
|
+
# GetFileSizeEx()
|
17
|
+
# GetFileType()
|
18
|
+
# GetLongPathName()
|
19
|
+
# GetShortPathName()
|
20
|
+
# LockFile()
|
21
|
+
# LockFileEx()
|
22
|
+
# ReadFile()
|
23
|
+
# ReadFileEx()
|
24
|
+
# ReOpenFile()
|
25
|
+
# SetFileAttributes()
|
26
|
+
# UnlockFile()
|
27
|
+
# UnlockFileEx()
|
28
|
+
# WriteFile()
|
29
|
+
# WriteFileEx()
|
30
|
+
#
|
31
|
+
# TODO:
|
32
|
+
#
|
33
|
+
# Add remaining file functions.
|
34
|
+
######################################################################
|
35
|
+
require 'Win32API'
|
36
|
+
|
37
|
+
module Windows
|
38
|
+
module File
|
39
|
+
# File Attributes
|
40
|
+
FILE_ATTRIBUTE_READONLY = 0x00000001
|
41
|
+
FILE_ATTRIBUTE_HIDDEN = 0x00000002
|
42
|
+
FILE_ATTRIBUTE_SYSTEM = 0x00000004
|
43
|
+
FILE_ATTRIBUTE_DIRECTORY = 0x00000010
|
44
|
+
FILE_ATTRIBUTE_ARCHIVE = 0x00000020
|
45
|
+
FILE_ATTRIBUTE_ENCRYPTED = 0x00000040
|
46
|
+
FILE_ATTRIBUTE_NORMAL = 0x00000080
|
47
|
+
FILE_ATTRIBUTE_TEMPORARY = 0x00000100
|
48
|
+
FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200
|
49
|
+
FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400
|
50
|
+
FILE_ATTRIBUTE_COMPRESSED = 0x00000800
|
51
|
+
FILE_ATTRIBUTE_OFFLINE = 0x00001000
|
52
|
+
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000
|
53
|
+
|
54
|
+
# File types
|
55
|
+
FILE_TYPE_UNKNOWN = 0x0000
|
56
|
+
FILE_TYPE_DISK = 0x0001
|
57
|
+
FILE_TYPE_CHAR = 0x0002
|
58
|
+
FILE_TYPE_PIPE = 0x0003
|
59
|
+
FILE_TYPE_REMOTE = 0x8000
|
60
|
+
|
61
|
+
# File security and access rights
|
62
|
+
APPLICATION_ERROR_MASK = 0x20000000
|
63
|
+
ERROR_SEVERITY_SUCCESS = 0x00000000
|
64
|
+
ERROR_SEVERITY_INFORMATIONAL = 0x40000000
|
65
|
+
ERROR_SEVERITY_WARNING = 0x80000000
|
66
|
+
ERROR_SEVERITY_ERROR = 0xc0000000
|
67
|
+
COMPRESSION_FORMAT_NONE = 0
|
68
|
+
COMPRESSION_FORMAT_DEFAULT = 1
|
69
|
+
COMPRESSION_FORMAT_LZNT1 = 2
|
70
|
+
COMPRESSION_ENGINE_STANDARD = 0
|
71
|
+
COMPRESSION_ENGINE_MAXIMUM = 256
|
72
|
+
ACCESS_ALLOWED_ACE_TYPE = 0
|
73
|
+
ACCESS_DENIED_ACE_TYPE = 1
|
74
|
+
ANYSIZE_ARRAY = 1
|
75
|
+
SYSTEM_AUDIT_ACE_TYPE = 2
|
76
|
+
SYSTEM_ALARM_ACE_TYPE = 3
|
77
|
+
OBJECT_INHERIT_ACE = 1
|
78
|
+
CONTAINER_INHERIT_ACE = 2
|
79
|
+
NO_PROPAGATE_INHERIT_ACE = 4
|
80
|
+
INHERIT_ONLY_ACE = 8
|
81
|
+
VALID_INHERIT_FLAGS = 16
|
82
|
+
SUCCESSFUL_ACCESS_ACE_FLAG = 64
|
83
|
+
FAILED_ACCESS_ACE_FLAG = 128
|
84
|
+
DELETE = 0x00010000
|
85
|
+
READ_CONTROL = 0x20000
|
86
|
+
WRITE_DAC = 0x40000
|
87
|
+
WRITE_OWNER = 0x80000
|
88
|
+
SYNCHRONIZE = 0x100000
|
89
|
+
STANDARD_RIGHTS_REQUIRED = 0xf0000
|
90
|
+
STANDARD_RIGHTS_READ = 0x20000
|
91
|
+
STANDARD_RIGHTS_WRITE = 0x20000
|
92
|
+
STANDARD_RIGHTS_EXECUTE = 0x20000
|
93
|
+
STANDARD_RIGHTS_ALL = 0x1f0000
|
94
|
+
SPECIFIC_RIGHTS_ALL = 0xffff
|
95
|
+
ACCESS_SYSTEM_SECURITY = 0x1000000
|
96
|
+
MAXIMUM_ALLOWED = 0x2000000
|
97
|
+
GENERIC_READ = 0x80000000
|
98
|
+
GENERIC_WRITE = 0x40000000
|
99
|
+
GENERIC_EXECUTE = 0x20000000
|
100
|
+
GENERIC_ALL = 0x10000000
|
101
|
+
FILE_READ_DATA = 1
|
102
|
+
FILE_LIST_DIRECTORY = 1
|
103
|
+
FILE_WRITE_DATA = 2
|
104
|
+
FILE_ADD_FILE = 2
|
105
|
+
FILE_APPEND_DATA = 4
|
106
|
+
FILE_ADD_SUBDIRECTORY = 4
|
107
|
+
FILE_CREATE_PIPE_INSTANCE = 4
|
108
|
+
FILE_READ_EA = 8
|
109
|
+
FILE_READ_PROPERTIES = 8
|
110
|
+
FILE_WRITE_EA = 16
|
111
|
+
FILE_WRITE_PROPERTIES = 16
|
112
|
+
FILE_EXECUTE = 32
|
113
|
+
FILE_TRAVERSE = 32
|
114
|
+
FILE_DELETE_CHILD = 64
|
115
|
+
FILE_READ_ATTRIBUTES = 128
|
116
|
+
FILE_WRITE_ATTRIBUTES = 256
|
117
|
+
|
118
|
+
FILE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x1ff)
|
119
|
+
|
120
|
+
FILE_GENERIC_READ = (STANDARD_RIGHTS_READ|FILE_READ_DATA|
|
121
|
+
FILE_READ_ATTRIBUTES|FILE_READ_EA|SYNCHRONIZE)
|
122
|
+
|
123
|
+
FILE_GENERIC_WRITE = (STANDARD_RIGHTS_WRITE|FILE_WRITE_DATA|
|
124
|
+
FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA|FILE_APPEND_DATA|SYNCHRONIZE)
|
125
|
+
|
126
|
+
FILE_GENERIC_EXECUTE = (STANDARD_RIGHTS_EXECUTE|FILE_READ_ATTRIBUTES|
|
127
|
+
FILE_EXECUTE|SYNCHRONIZE)
|
128
|
+
|
129
|
+
FILE_SHARE_READ = 1
|
130
|
+
FILE_SHARE_WRITE = 2
|
131
|
+
FILE_SHARE_DELETE = 4
|
132
|
+
FILE_NOTIFY_CHANGE_FILE_NAME = 1
|
133
|
+
FILE_NOTIFY_CHANGE_DIR_NAME = 2
|
134
|
+
FILE_NOTIFY_CHANGE_ATTRIBUTES = 4
|
135
|
+
FILE_NOTIFY_CHANGE_SIZE = 8
|
136
|
+
FILE_NOTIFY_CHANGE_LAST_WRITE = 16
|
137
|
+
FILE_NOTIFY_CHANGE_LAST_ACCESS = 32
|
138
|
+
FILE_NOTIFY_CHANGE_CREATION = 64
|
139
|
+
FILE_NOTIFY_CHANGE_SECURITY = 256
|
140
|
+
MAILSLOT_NO_MESSAGE = -1
|
141
|
+
MAILSLOT_WAIT_FOREVER = -1
|
142
|
+
FILE_CASE_SENSITIVE_SEARCH = 1
|
143
|
+
FILE_CASE_PRESERVED_NAMES = 2
|
144
|
+
FILE_UNICODE_ON_DISK = 4
|
145
|
+
FILE_PERSISTENT_ACLS = 8
|
146
|
+
FILE_FILE_COMPRESSION = 16
|
147
|
+
FILE_VOLUME_QUOTAS = 32
|
148
|
+
FILE_SUPPORTS_SPARSE_FILES = 64
|
149
|
+
FILE_SUPPORTS_REPARSE_POINTS = 128
|
150
|
+
FILE_SUPPORTS_REMOTE_STORAGE = 256
|
151
|
+
FILE_VOLUME_IS_COMPRESSED = 0x8000
|
152
|
+
FILE_SUPPORTS_OBJECT_IDS = 0x10000
|
153
|
+
FILE_SUPPORTS_ENCRYPTION = 0x20000
|
154
|
+
|
155
|
+
# File flags
|
156
|
+
FILE_FLAG_WRITE_THROUGH = 0x80000000
|
157
|
+
FILE_FLAG_OVERLAPPED = 0x40000000
|
158
|
+
FILE_FLAG_NO_BUFFERING = 0x20000000
|
159
|
+
FILE_FLAG_RANDOM_ACCESS = 0x10000000
|
160
|
+
FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000
|
161
|
+
FILE_FLAG_DELETE_ON_CLOSE = 0x04000000
|
162
|
+
FILE_FLAG_BACKUP_SEMANTICS = 0x02000000
|
163
|
+
FILE_FLAG_POSIX_SEMANTICS = 0x01000000
|
164
|
+
FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000
|
165
|
+
FILE_FLAG_OPEN_NO_RECALL = 0x00100000
|
166
|
+
FILE_FLAG_FIRST_PIPE_INSTANCE = 0x00080000
|
167
|
+
|
168
|
+
# File creation disposition
|
169
|
+
CREATE_NEW = 1
|
170
|
+
CREATE_ALWAYS = 2
|
171
|
+
OPEN_EXISTING = 3
|
172
|
+
OPEN_ALWAYS = 4
|
173
|
+
TRUNCATE_EXISTING = 5
|
174
|
+
|
175
|
+
# Errors
|
176
|
+
INVALID_FILE_ATTRIBUTES = -1
|
177
|
+
INVALID_HANDLE_VALUE = -1
|
178
|
+
INVALID_FILE_SIZE = 0xFFFFFFFF
|
179
|
+
|
180
|
+
CopyFile = Win32API.new('kernel32', 'CopyFile', 'PPI', 'I')
|
181
|
+
CopyFileEx = Win32API.new('kernel32', 'CopyFileEx', 'PPPPPL', 'I')
|
182
|
+
CreateFile = Win32API.new('kernel32', 'CreateFile', 'PLLPLLL', 'L')
|
183
|
+
CreateHardLink = Win32API.new('kernel32', 'CreateHardLink', 'PPP', 'I')
|
184
|
+
DecryptFile = Win32API.new('advapi32', 'DecryptFile', 'PL', 'I')
|
185
|
+
DeleteFile = Win32API.new('kernel32', 'DeleteFile', 'P', 'I')
|
186
|
+
EncryptFile = Win32API.new('advapi32', 'EncryptFile', 'P', 'I')
|
187
|
+
|
188
|
+
GetBinaryType = Win32API.new('kernel32', 'GetBinaryType', 'PP', 'I')
|
189
|
+
GetFileAttributes = Win32API.new('kernel32', 'GetFileAttributes', 'P', 'L')
|
190
|
+
GetFileAttributesEx = Win32API.new('kernel32', 'GetFileAttributesEx', 'PPP', 'I')
|
191
|
+
GetFileSize = Win32API.new('kernel32', 'GetFileSize', 'LP', 'L')
|
192
|
+
GetFileSizeEx = Win32API.new('kernel32', 'GetFileSizeEx', 'LP', 'L')
|
193
|
+
GetFileType = Win32API.new('kernel32', 'GetFileType', 'L', 'L')
|
194
|
+
GetLongPathName = Win32API.new('kernel32', 'GetLongPathName', 'PPL', 'L')
|
195
|
+
GetShortPathName = Win32API.new('kernel32', 'GetShortPathName', 'PPL', 'L')
|
196
|
+
|
197
|
+
LockFile = Win32API.new('kernel32', 'LockFile', 'LLLLL', 'I')
|
198
|
+
LockFileEx = Win32API.new('kernel32', 'LockFileEx', 'LLLLLL', 'I')
|
199
|
+
ReadFile = Win32API.new('kernel32', 'ReadFile', 'LPLPP', 'I')
|
200
|
+
ReadFileEx = Win32API.new('kernel32', 'ReadFileEx', 'LPLPP', 'I')
|
201
|
+
|
202
|
+
SetFileAttributes = Win32API.new('kernel32', 'SetFileAttributes', 'PL', 'I')
|
203
|
+
|
204
|
+
UnlockFile = Win32API.new('kernel32', 'UnlockFile', 'LLLLL', 'I')
|
205
|
+
UnlockFileEx = Win32API.new('kernel32', 'UnlockFileEx', 'LLLLL', 'I')
|
206
|
+
WriteFile = Win32API.new('kernel32', 'WriteFile', 'LPLPP', 'I')
|
207
|
+
WriteFileEx = Win32API.new('kernel32', 'WriteFileEx', 'LPLPP', 'I')
|
208
|
+
|
209
|
+
def CopyFile(curr_file, new_file, bail)
|
210
|
+
CopyFile.call(curr_file, new_file, bail) > 0
|
211
|
+
end
|
212
|
+
|
213
|
+
def CopyFileEx(curr_file, new_file, routine, data, cancel, flags)
|
214
|
+
CopyFileEx.call(curr_file, new_file, routine, data, cancel, flags) > 0
|
215
|
+
end
|
216
|
+
|
217
|
+
def CreateFile(file, access, share, sec, disp, flags, template)
|
218
|
+
CreateFile.call(file, access, share, sec, disp, flags, template)
|
219
|
+
end
|
220
|
+
|
221
|
+
def CreateHardLink(new_file, old_file, attributes)
|
222
|
+
CreateHardLink.call(new_file, old_file, attributes) > 0
|
223
|
+
end
|
224
|
+
|
225
|
+
def DecryptFile(file, res = 0)
|
226
|
+
DecryptFile.call(file, res)
|
227
|
+
end
|
228
|
+
|
229
|
+
def DeleteFile(file)
|
230
|
+
DeleteFile.call(file) > 0
|
231
|
+
end
|
232
|
+
|
233
|
+
def EncryptFile(file)
|
234
|
+
EncryptFile.call(file) > 0
|
235
|
+
end
|
236
|
+
|
237
|
+
def GetBinaryType(file, type)
|
238
|
+
GetBinaryType.call(file, type) > 0
|
239
|
+
end
|
240
|
+
|
241
|
+
def GetFileAttributes(file)
|
242
|
+
GetFileAttributes.call(file)
|
243
|
+
end
|
244
|
+
|
245
|
+
def GetFileAttributesEx(file, level_id, info)
|
246
|
+
GetFileAttributesEx.call(file, level_id, info)
|
247
|
+
end
|
248
|
+
|
249
|
+
def GetFileSize(handle, size)
|
250
|
+
GetFileSize.call(handle, size)
|
251
|
+
end
|
252
|
+
|
253
|
+
def GetFileSizeEx(handle, size)
|
254
|
+
GetFileSizeEx.call(handle, size) > 0
|
255
|
+
end
|
256
|
+
|
257
|
+
def GetFileType(handle)
|
258
|
+
GetFileType.call(handle)
|
259
|
+
end
|
260
|
+
|
261
|
+
def GetLongPathName(short, buf, buf_size)
|
262
|
+
GetLongPathName.call(short, buf, buf_size)
|
263
|
+
end
|
264
|
+
|
265
|
+
def GetShortPathName(long, buf, buf_size)
|
266
|
+
GetShortPathName.call(long, buf, buf_size)
|
267
|
+
end
|
268
|
+
|
269
|
+
def LockFile(handle, off_low, off_high, lock_low, lock_high)
|
270
|
+
LockFile.call(handle, off_low, off_high, lock_low, lock_high) > 0
|
271
|
+
end
|
272
|
+
|
273
|
+
def LockFileEx(handle, flags, res, low, high, overlapped)
|
274
|
+
LockFileEx.call(handle, flags, res, low, high, overlapped) > 0
|
275
|
+
end
|
276
|
+
|
277
|
+
def ReadFile(file, buf, bytes, bytes_read, overlapped)
|
278
|
+
ReadFile.call(file, buf, bytes, bytes_read, overlapped) > 0
|
279
|
+
end
|
280
|
+
|
281
|
+
def ReadFileEx(file, buf, bytes, overlapped, routine)
|
282
|
+
ReadFileEx.call(file, buf, bytes, overlapped, routine) > 0
|
283
|
+
end
|
284
|
+
|
285
|
+
def SetFileAttributes(file, attributes)
|
286
|
+
SetFileAttributes.call(file, attributes) > 0
|
287
|
+
end
|
288
|
+
|
289
|
+
def UnlockFile(handle, off_low, off_high, bytes_low, bytes_high)
|
290
|
+
UnlockFile.call(handle, off_low, off_high, bytes_low, bytes_high) > 0
|
291
|
+
end
|
292
|
+
|
293
|
+
def UnlockFileEx(handle, res, low, high, overlapped)
|
294
|
+
UnlockFileEx.call(handle, res, low, high, overlapped) > 0
|
295
|
+
end
|
296
|
+
|
297
|
+
def WriteFile(handle, buf, bytes, overlapped)
|
298
|
+
WriteFileEx.call(handle, buf, bytes, overlapped) > 0
|
299
|
+
end
|
300
|
+
|
301
|
+
def WriteFileEx(handle, buf, bytes, overlapped, routine)
|
302
|
+
WriteFileEx.call(handle, buf, bytes, overlapped, routine) > 0
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'Win32API'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
module FileSystem
|
5
|
+
GetDiskFreeSpace = Win32API.new('kernel32', 'GetDiskFreeSpace', 'PPPPP', 'I')
|
6
|
+
GetDiskFreeSpaceEx = Win32API.new('kernel32', 'GetDiskFreeSpaceEx', 'PPPP', 'I')
|
7
|
+
|
8
|
+
def GetDiskFreeSpace(path, sectors, bytes, free, total)
|
9
|
+
GetDiskFreeSpace.call(path, sectors, bytes, free, total) > 0
|
10
|
+
end
|
11
|
+
|
12
|
+
def GetDiskFreeSpaceEx(path, free_bytes, total_bytes, total_free)
|
13
|
+
GetDiskFreeSpaceEx.call(path, free_bytes, total_bytes, total_free) > 0
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#####################################################################
|
2
|
+
# handle.rb
|
3
|
+
#
|
4
|
+
# Defines the following functions:
|
5
|
+
#
|
6
|
+
# CloseHandle()
|
7
|
+
# DuplicateHandle()
|
8
|
+
# GetHandleInformation()
|
9
|
+
# SetHandleInformation()
|
10
|
+
#
|
11
|
+
# Defines the following constants
|
12
|
+
#
|
13
|
+
# INVALID_HANDLE_VALUE
|
14
|
+
# HANDLE_FLAG_INHERIT
|
15
|
+
# HANDLE_FLAG_PROTECT_FROM_CLOSE
|
16
|
+
######################################################################
|
17
|
+
require 'Win32API'
|
18
|
+
|
19
|
+
module Windows
|
20
|
+
module Handle
|
21
|
+
INVALID_HANDLE_VALUE = -1
|
22
|
+
|
23
|
+
HANDLE_FLAG_INHERIT = 0x00000001
|
24
|
+
HANDLE_FLAG_PROTECT_FROM_CLOSE = 0x00000002
|
25
|
+
|
26
|
+
CloseHandle = Win32API.new('kernel32', 'CloseHandle', 'L', 'I')
|
27
|
+
DuplicateHandle = Win32API.new('kernel32', 'DuplicateHandle', 'LLLLLIL', 'I')
|
28
|
+
GetHandleInformation = Win32API.new('kernel32', 'GetHandleInformation', 'LL', 'I')
|
29
|
+
SetHandleInformation = Win32API.new('kernel32', 'SetHandleInformation', 'LLL', 'I')
|
30
|
+
|
31
|
+
def CloseHandle(handle)
|
32
|
+
CloseHandle.call(handle) != 0
|
33
|
+
end
|
34
|
+
|
35
|
+
def DuplicateHandle(sphandle, shandle, thandle, access, ihandle, opts)
|
36
|
+
DuplicateHandle.call(sphandle, shandle, thandle, access, ihandle, opts) != 0
|
37
|
+
end
|
38
|
+
|
39
|
+
def GetHandleInformation(handle, flags)
|
40
|
+
GetHandleInformation.call(handle, flags) != 0
|
41
|
+
end
|
42
|
+
|
43
|
+
def SetHandleInformation(handle, mask, flags)
|
44
|
+
SetHandleInformation.call(handle, mask, flags) != 0
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|