windows-pr 0.6.6 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,36 @@
1
+ require 'windows/api'
2
+ include Windows
3
+
4
+ module Windows
5
+ module Debug
6
+ API.auto_namespace = 'Windows::Debug'
7
+ API.auto_constant = true
8
+ API.auto_method = true
9
+ API.auto_unicode = false
10
+
11
+ API.new('ContinueDebugEvent', 'LLL', 'B')
12
+ API.new('DebugActiveProcess', 'L', 'B')
13
+ API.new('DebugBreak', 'V', 'V')
14
+ API.new('FatalExit', 'I', 'V')
15
+ API.new('FlushInstructionCache', 'LLL', 'B')
16
+ API.new('GetThreadContext', 'LP', 'B')
17
+ API.new('GetThreadSelectorEntry', 'LLP', 'B')
18
+ API.new('IsDebuggerPresent', 'V', 'B')
19
+ API.new('OutputDebugStringA', 'P', 'V')
20
+ API.new('ReadProcessMemory', 'LLPLP', 'B')
21
+ API.new('SetThreadContext', 'LP', 'B')
22
+ API.new('WaitForDebugEvent', 'PL', 'B')
23
+ API.new('WriteProcessMemory', 'LLPLP', 'B')
24
+
25
+ # Windows XP or later
26
+ begin
27
+ API.new('CheckRemoteDebuggerPresent', 'LP', 'B')
28
+ API.new('DebugActiveProcessStop', 'L', 'B')
29
+ API.new('DebugBreakProcess', 'L', 'B')
30
+ API.new('DebugSetProcessKillOnExit', 'I', 'B')
31
+ rescue Exception
32
+ # Do nothing - not supported on current platform. It's up to you to
33
+ # check for the existence of the constant in your code.
34
+ end
35
+ end
36
+ end
@@ -1,7 +1,13 @@
1
- require 'Win32API'
1
+ require 'windows/api'
2
+ include Windows
2
3
 
3
4
  module Windows
4
5
  module DeviceIO
6
+ API.auto_namespace = 'Windows::DeviceIO'
7
+ API.auto_constant = true
8
+ API.auto_method = true
9
+ API.auto_unicode = false
10
+
5
11
  # Device Types
6
12
  FILE_DEVICE_BEEP = 0x00000001
7
13
  FILE_DEVICE_CD_ROM = 0x00000002
@@ -66,11 +72,7 @@ module Windows
66
72
  METHOD_BUFFERED = 0
67
73
  FILE_ANY_ACCESS = 0
68
74
 
69
- DeviceIoControl = Win32API.new('kernel32', 'DeviceIoControl', 'LLPLPLPP', 'I')
70
-
71
- def DeviceIoControl(dev, code, in_buf, in_buf_size, out_buf, out_buf_size, bytes, overlapped)
72
- DeviceIoControl.call(dev, code, in_buf, in_buf_size, out_buf, out_buf_size, bytes, overlapped) > 0
73
- end
75
+ API.new('DeviceIoControl', 'LLPLPLPP', 'B')
74
76
 
75
77
  # Macros from WinIoCtl.h
76
78
  def CTL_CODE(device, function, method, access)
@@ -85,4 +87,4 @@ module Windows
85
87
  CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 49, 0, FILE_ANY_ACCESS)
86
88
  end
87
89
  end
88
- end
90
+ end
@@ -1,80 +1,25 @@
1
- require 'windows/unicode'
1
+ require 'windows/api'
2
2
 
3
+ # The Windows::Directory module contains functions that are used in directory
4
+ # management. Note that functions that could be applied to files or
5
+ # directories, such as CreateFile(), are probably in the Windows::File
6
+ # module.
7
+ #
3
8
  module Windows
4
9
  module Directory
5
- CreateDirectory = Win32API.new('kernel32', 'CreateDirectory', 'PP', 'I')
6
- CreateDirectoryW = Win32API.new('kernel32', 'CreateDirectoryW', 'PP', 'I')
7
- CreateDirectoryEx = Win32API.new('kernel32', 'CreateDirectoryEx', 'PPP', 'I')
8
- CreateDirectoryExW = Win32API.new('kernel32', 'CreateDirectoryExW', 'PPP', 'I')
9
- FindCloseChangeNotification = Win32API.new('kernel32', 'FindCloseChangeNotification', 'L', 'I')
10
- FindFirstChangeNotification = Win32API.new('kernel32', 'FindFirstChangeNotification', 'PIL', 'L')
11
- FindNextChangeNotification = Win32API.new('kernel32', 'FindNextChangeNotification', 'PIL', 'I')
12
- GetCurrentDirectory = Win32API.new('kernel32', 'GetCurrentDirectory', 'LP', 'L')
13
- GetCurrentDirectoryW = Win32API.new('kernel32', 'GetCurrentDirectoryW', 'LP', 'L')
14
- ReadDirectoryChangesW = Win32API.new('kernel32', 'ReadDirectoryChangesW', 'LPLILPPP', 'I')
15
- RemoveDirectory = Win32API.new('kernel32', 'RemoveDirectory', 'P', 'I')
16
- RemoveDirectoryW = Win32API.new('kernel32', 'RemoveDirectoryW', 'P', 'I')
17
- SetCurrentDirectory = Win32API.new('kernel32', 'SetCurrentDirectory', 'P', 'I')
18
- SetCurrentDirectoryW = Win32API.new('kernel32', 'SetCurrentDirectoryW', 'P', 'I')
19
-
20
- def CreateDirectory(path, attributes = 0)
21
- CreateDirectory.call(path, attributes) != 0
22
- end
23
-
24
- def CreateDirectoryW(path, attributes)
25
- path = multi_to_wide(path) unless IsTextUnicode(path)
26
- CreateDirectoryW.call(path, attributes) != 0
27
- end
28
-
29
- def CreateDirectoryEx(template, new_dir, attributes)
30
- CreateDirectoryEx.call(template, new_dir, attributes) != 0
31
- end
32
-
33
- def CreateDirectoryExW(template, new_dir, attributes)
34
- new_dir = multi_to_wide(new_dir) unless IsTextUnicode(new_dir)
35
- CreateDirectoryExW.call(template, new_dir, attributes) != 0
36
- end
37
-
38
- def FindCloseChangeNotification(handle)
39
- FindCloseChangeNotification.call(handle) != 0
40
- end
41
-
42
- def FindFirstChangeNotification(path, subtree, filter)
43
- FindFirstChangeNotification.call(path, subtree, filter)
44
- end
45
-
46
- def FindNextChangeNotification(handle)
47
- FindNextChangeNotification.call(handle) != 0
48
- end
49
-
50
- def GetCurrentDirectory(buf_len, buf)
51
- GetCurrentDirectory.call(buf_len, buf)
52
- end
53
-
54
- def GetCurrentDirectoryW(buf_len, buf)
55
- GetCurrentDirectoryW.call(buf_len, buf)
56
- end
57
-
58
- def ReadDirectoryChangesW(handle, buf, buf_len, subtree, filter, bytes, overlapped, routine)
59
- ReadDirectoryChangesW.call(handle, buf, buf_len, subtree, filter, bytes, overlapped, routine) != 0
60
- end
61
-
62
- def RemoveDirectory(path)
63
- RemoveDirectory.call(path) != 0
64
- end
65
-
66
- def RemoveDirectoryW(path)
67
- path = multi_to_wide(path) unless IsTextUnicode(path)
68
- RemoveDirectoryW.call(path) != 0
69
- end
70
-
71
- def SetCurrentDirectory(path)
72
- SetCurrentDirectory.call(path) != 0
73
- end
74
-
75
- def SetCurrentDirectoryW(path)
76
- path = multi_to_wide(path) unless IsTextUnicode(path)
77
- SetCurrentDirectoryW.call(path) != 0
78
- end
10
+ API.auto_namespace = 'Windows::Directory'
11
+ API.auto_constant = true
12
+ API.auto_method = true
13
+ API.auto_unicode = true
14
+
15
+ API.new('CreateDirectory', 'PP', 'B')
16
+ API.new('CreateDirectoryEx', 'PPP', 'B')
17
+ API.new('FindCloseChangeNotification', 'L', 'B')
18
+ API.new('FindFirstChangeNotification', 'PIL', 'L')
19
+ API.new('FindNextChangeNotification', 'PIL', 'B')
20
+ API.new('GetCurrentDirectory', 'LP', 'L')
21
+ API.new('ReadDirectoryChangesW', 'LPLILPPP', 'B') # No ANSI equivalent
22
+ API.new('RemoveDirectory', 'P', 'B')
23
+ API.new('SetCurrentDirectory', 'P', 'B')
79
24
  end
80
25
  end
data/lib/windows/error.rb CHANGED
@@ -1,17 +1,24 @@
1
1
  ############################################################################
2
2
  # error.rb
3
3
  #
4
- # Includes all of the error codes in error.h and some from winerror.h.
4
+ # Includes all of the error codes in error.h, msterr.h and some from
5
+ # winerror.h.
5
6
  #
6
7
  # Adds the following convenience methods:
7
8
  #
8
9
  # get_last_error - Returns a human readable string for the error returned
9
10
  # by the GetLastError() function.
10
11
  ############################################################################
11
- require 'windows/unicode'
12
+ require 'windows/api'
13
+ include Windows
12
14
 
13
15
  module Windows
14
16
  module Error
17
+ API.auto_namespace = 'Windows::Error'
18
+ API.auto_method = true
19
+ API.auto_constant = true
20
+ API.auto_unicode = true
21
+
15
22
  FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100
16
23
  FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200
17
24
  FORMAT_MESSAGE_FROM_STRING = 0x00000400
@@ -229,7 +236,6 @@ module Windows
229
236
  I24_AREA = 0x6
230
237
  I24_CLASS = 0x80
231
238
 
232
-
233
239
  ERRCLASS_OUTRES = 1 # Out of Resource
234
240
  ERRCLASS_TEMPSIT = 2 # Temporary Situation
235
241
  ERRCLASS_AUTH = 3 # Permission problem
@@ -268,42 +274,51 @@ module Windows
268
274
  # From WinError.h
269
275
  ERROR_INVALID_FLAGS = 4100 # 1004L
270
276
  ERROR_NO_UNICODE_TRANSLATION = 4371
277
+
278
+ E_INVALIDARG = 2147942487 # 0x80070057L
279
+ E_NOINTERFACE = 2147500034 # 0x80004002L
280
+ E_NOTIMPL = 2147500033 # 0x80004001L
281
+ E_OUTOFMEMORY = 2147942414 # 0x8007000EL
282
+ E_UNEXPECTED = 2147549183 # 0x8000FFFFL
283
+
284
+ RPC_E_TIMEOUT = 2147549471 # 0x8001011FL
285
+
286
+ CO_E_NOT_SUPPORTED = 2147500065 # 0x80004021L
287
+
288
+ CLASS_E_NOAGGREGATION = 2147746064 # 0x80040110L
289
+
290
+ # Registry errors
291
+ REGDB_E_CLASSNOTREG = 2147746132 # 0x80040154L
292
+
293
+ # msterr.h
294
+ SCHED_S_TASK_READY = 267008 # 0x00041300L
295
+ SCHED_S_TASK_RUNNING = 267009 # 0x00041301L
296
+ SCHED_S_TASK_DISABLED = 267010 # 0x00041302L
297
+ SCHED_S_TASK_HAS_NOT_RUN = 267011 # 0x00041303L
298
+ SCHED_S_TASK_HAS_NO_MORE_RUNS = 267012 # 0x00041304L
299
+ SCHED_S_TASK_NOT_SCHEDULED = 267013 # 0x00041305L
300
+ SCHED_S_TASK_TERMINATED = 267014 # 0x00041306L
301
+ SCHED_S_TASK_NO_VALID_TRIGGERS = 267015 # 0x00041307L
302
+ SCHED_S_EVENT_TRIGGER = 267016 # 0x00041308L
303
+ SCHED_E_TRIGGER_NOT_FOUND = 267017 # 0x00041309L
304
+ SCHED_E_TASK_NOT_READY = 267018 # 0x0004130AL
305
+ SCHED_E_TASK_NOT_RUNNING = 267019 # 0x0004130BL
306
+ SCHED_E_SERVICE_NOT_INSTALLED = 267020 # 0x0004130CL
307
+ SCHED_E_CANNOT_OPEN_TASK = 267021 # 0x0004130DL
308
+ SCHED_E_INVALID_TASK = 267022 # 0x0004130EL
309
+ SCHED_E_ACCOUNT_INFORMATION_NOT_SET = 267023 # 0x0004130FL
310
+ SCHED_E_ACCOUNT_NAME_NOT_FOUND = 267024 # 0x00041310L
311
+ SCHED_E_ACCOUNT_DBASE_CORRUPT = 267025 # 0x00041311L
312
+ SCHED_E_NO_SECURITY_SERVICES = 267026 # 0x00041312L
313
+ SCHED_E_UNKNOWN_OBJECT_VERSION = 267027 # 0x00041313L
271
314
 
272
- GetLastError = Win32API.new('kernel32', 'GetLastError', 'V', 'L')
273
- SetLastError = Win32API.new('kernel32', 'SetLastError', 'L', 'V')
274
- SetErrorMode = Win32API.new('kernel32', 'SetErrorMode', 'I', 'I')
275
- FormatMessage = Win32API.new('kernel32', 'FormatMessage', 'LLLLPLP', 'L')
276
- FormatMessageW = Win32API.new('kernel32', 'FormatMessageW', 'LLLLPLP', 'L')
277
-
278
- begin
279
- SetLastErrorEx = Win32API.new('user32', 'SetLastErrorEx', 'LL', 'V')
280
- rescue Exception
281
- end
282
-
283
- def GetLastError
284
- GetLastError.call
285
- end
286
-
287
- def SetLastError(error)
288
- SetLastError.call(error)
289
- end
290
-
291
- def SetErrorMode(mode)
292
- SetErrorMode.call(mode)
293
- end
294
-
295
- def FormatMessage(flags, src, msg_id, lang_id, buf, size, args)
296
- FormatMessage.call(flags, src, msg_id, lang_id, buf, size, args)
297
- end
298
-
299
- def FormatMessageW(flags, src, msg_id, lang_id, buf, size, args)
300
- FormatMessageW.call(flags, src, msg_id, lang_id, buf, size, args)
301
- end
315
+ API.new('GetLastError', 'V', 'L')
316
+ API.new('SetLastError', 'L', 'V')
317
+ API.new('SetErrorMode', 'I', 'I')
318
+ API.new('FormatMessage', 'LLLLPLP', 'L')
302
319
 
303
320
  begin
304
- def SetLastErrorEx(error, type=0)
305
- SetLastErrorEx.call(error, type)
306
- end
321
+ API.new('SetLastErrorEx', 'LL', 'V', 'user32')
307
322
  rescue Exception
308
323
  # VC++ 7.0 or later
309
324
  end
@@ -1,7 +1,13 @@
1
- require 'Win32API'
1
+ require 'windows/api'
2
+ include Windows
2
3
 
3
4
  module Windows
4
5
  module EventLog
6
+ API.auto_namespace = 'Windows::EventLog'
7
+ API.auto_constant = true
8
+ API.auto_method = true
9
+ API.auto_unicode = true
10
+
5
11
  EVENTLOG_SEQUENTIAL_READ = 0x0001
6
12
  EVENTLOG_SEEK_READ = 0x0002
7
13
  EVENTLOG_FORWARDS_READ = 0x0004
@@ -16,105 +22,18 @@ module Windows
16
22
 
17
23
  EVENTLOG_FULL_INFO = 0
18
24
 
19
- BackupEventLog = Win32API.new('advapi32', 'BackupEventLog', 'LP', 'I')
20
- BackupEventLogW = Win32API.new('advapi32', 'BackupEventLogW', 'LP', 'I')
21
- ClearEventLog = Win32API.new('advapi32', 'ClearEventLog', 'LP', 'I')
22
- ClearEventLogW = Win32API.new('advapi32', 'ClearEventLogW', 'LP', 'I')
23
- CloseEventLog = Win32API.new('advapi32', 'CloseEventLog', 'L', 'I')
24
- DeregisterEventSource = Win32API.new('advapi32', 'DeregisterEventSource', 'L', 'I')
25
- GetEventLogInformation = Win32API.new('advapi32', 'GetEventLogInformation', 'LLPLP', 'I')
26
- GetNumberOfEventLogRecords = Win32API.new('advapi32', 'GetNumberOfEventLogRecords', 'LP', 'I')
27
- GetOldestEventLogRecord = Win32API.new('advapi32', 'GetOldestEventLogRecord', 'LP', 'I')
28
- NotifyChangeEventLog = Win32API.new('advapi32', 'NotifyChangeEventLog', 'LL', 'I')
29
- OpenBackupEventLog = Win32API.new('advapi32', 'OpenBackupEventLog', 'PP', 'L')
30
- OpenBackupEventLogW = Win32API.new('advapi32', 'OpenBackupEventLogW', 'PP', 'L')
31
- OpenEventLog = Win32API.new('advapi32', 'OpenEventLog', 'PP', 'L')
32
- OpenEventLogW = Win32API.new('advapi32', 'OpenEventLogW', 'PP', 'L')
33
- ReadEventLog = Win32API.new('advapi32', 'ReadEventLog', 'LLLPLPP', 'I')
34
- ReadEventLogW = Win32API.new('advapi32', 'ReadEventLogW', 'LLLPLPP', 'I')
35
- RegisterEventSource = Win32API.new('advapi32', 'RegisterEventSource', 'PP', 'L')
36
- RegisterEventSourceW = Win32API.new('advapi32', 'RegisterEventSourceW', 'PP', 'L')
37
- ReportEvent = Win32API.new('advapi32', 'ReportEvent', 'LIILPILPP', 'I')
38
- ReportEventW = Win32API.new('advapi32', 'ReportEventW', 'LIILPILPP', 'I')
39
-
40
- def BackupEventLog(handle, file)
41
- BackupEventLog.call(handle, file) != 0
42
- end
43
-
44
- def BackupEventLogW(handle, file)
45
- BackupEventLogW.call(handle, file) != 0
46
- end
47
-
48
- def ClearEventLog(handle, file = 0)
49
- ClearEventLog.call(handle, file) != 0
50
- end
51
-
52
- def ClearEventLogW(handle, file = 0)
53
- ClearEventLogW.call(handle, file) != 0
54
- end
55
-
56
- def CloseEventLog(handle)
57
- CloseEventLog.call(handle) != 0
58
- end
59
-
60
- def DeregisterEventSource(handle)
61
- DeregisterEventSource.call(handle) != 0
62
- end
63
-
64
- def GetEventLogInformation(handle, level, buf, buf_size, bytes)
65
- GetEventLogInformation.call(handle, level, buf, buf_size, bytes) != 0
66
- end
67
-
68
- def GetNumberOfEventLogRecords(handle, num)
69
- GetNumberOfEventLogRecords.call(handle, num) != 0
70
- end
71
-
72
- def GetOldestEventLogRecord(handle, rec)
73
- GetOldestEventLogRecord.call(handle, rec) != 0
74
- end
75
-
76
- def NotifyChangeEventLog(handle, event)
77
- NotifyChangeEventLog.call(handle, event) != 0
78
- end
79
-
80
- def OpenBackupEventLog(server, file)
81
- OpenBackupEventLog.call(server, file)
82
- end
83
-
84
- def OpenBackupEventLogW(server, file)
85
- OpenBackupEventLogW.call(server, file)
86
- end
87
-
88
- def OpenEventLog(server, source)
89
- OpenEventLog.call(server, source)
90
- end
91
-
92
- def OpenEventLogW(server, source)
93
- OpenEventLogW.call(server, source)
94
- end
95
-
96
- def ReadEventLog(handle, flags, offset, buf, bytes, bytes_read, min_bytes)
97
- ReadEventLog.call(handle, flags, offset, buf, bytes, bytes_read, min_bytes) != 0
98
- end
99
-
100
- def ReadEventLogW(handle, flags, offset, buf, bytes, bytes_read, min_bytes)
101
- ReadEventLogW.call(handle, flags, offset, buf, bytes, bytes_read, min_bytes) != 0
102
- end
103
-
104
- def RegisterEventSource(server, source)
105
- RegisterEventSource.call(server, source)
106
- end
107
-
108
- def RegisterEventSourceW(server, source)
109
- RegisterEventSourceW.call(server, source)
110
- end
111
-
112
- def ReportEvent(handle, type, cat, id, sid, num, size, strings, raw)
113
- ReportEvent.call(handle, type, cat, id, sid, num, size, strings, raw) != 0
114
- end
115
-
116
- def ReportEventW(handle, type, cat, id, sid, num, size, strings, raw)
117
- ReportEventW.call(handle, type, cat, id, sid, num, size, strings, raw) != 0
118
- end
25
+ API.new('BackupEventLog', 'LP', 'B', 'advapi32')
26
+ API.new('ClearEventLog', 'LP', 'B', 'advapi32')
27
+ API.new('CloseEventLog', 'L', 'B', 'advapi32')
28
+ API.new('DeregisterEventSource', 'L', 'B', 'advapi32')
29
+ API.new('GetEventLogInformation', 'LLPLP', 'B', 'advapi32')
30
+ API.new('GetNumberOfEventLogRecords', 'LP', 'B', 'advapi32')
31
+ API.new('GetOldestEventLogRecord', 'LP', 'B', 'advapi32')
32
+ API.new('NotifyChangeEventLog', 'LL', 'B', 'advapi32')
33
+ API.new('OpenBackupEventLog', 'PP', 'L', 'advapi32')
34
+ API.new('OpenEventLog', 'PP', 'L', 'advapi32')
35
+ API.new('ReadEventLog', 'LLLPLPP', 'B', 'advapi32')
36
+ API.new('RegisterEventSource', 'PP', 'L', 'advapi32')
37
+ API.new('ReportEvent', 'LIILPILPP', 'B', 'advapi32')
119
38
  end
120
39
  end
data/lib/windows/file.rb CHANGED
@@ -1,8 +1,14 @@
1
1
  require 'windows/unicode'
2
+ include Windows
2
3
 
3
4
  module Windows
4
5
  module File
5
6
  include Windows::Unicode
7
+
8
+ API.auto_namespace = 'Windows::File'
9
+ API.auto_constant = true
10
+ API.auto_method = true
11
+ API.auto_unicode = true
6
12
 
7
13
  # File Attributes
8
14
  FILE_ATTRIBUTE_READONLY = 0x00000001
@@ -83,16 +89,28 @@ module Windows
83
89
  FILE_READ_ATTRIBUTES = 128
84
90
  FILE_WRITE_ATTRIBUTES = 256
85
91
 
86
- FILE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x1ff)
92
+ FILE_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1ff
87
93
 
88
- FILE_GENERIC_READ = (STANDARD_RIGHTS_READ|FILE_READ_DATA|
89
- FILE_READ_ATTRIBUTES|FILE_READ_EA|SYNCHRONIZE)
94
+ FILE_GENERIC_READ =
95
+ STANDARD_RIGHTS_READ |
96
+ FILE_READ_DATA |
97
+ FILE_READ_ATTRIBUTES |
98
+ FILE_READ_EA |
99
+ SYNCHRONIZE
90
100
 
91
- FILE_GENERIC_WRITE = (STANDARD_RIGHTS_WRITE|FILE_WRITE_DATA|
92
- FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA|FILE_APPEND_DATA|SYNCHRONIZE)
101
+ FILE_GENERIC_WRITE =
102
+ STANDARD_RIGHTS_WRITE |
103
+ FILE_WRITE_DATA |
104
+ FILE_WRITE_ATTRIBUTES |
105
+ FILE_WRITE_EA |
106
+ FILE_APPEND_DATA |
107
+ SYNCHRONIZE
93
108
 
94
- FILE_GENERIC_EXECUTE = (STANDARD_RIGHTS_EXECUTE|FILE_READ_ATTRIBUTES|
95
- FILE_EXECUTE|SYNCHRONIZE)
109
+ FILE_GENERIC_EXECUTE =
110
+ STANDARD_RIGHTS_EXECUTE |
111
+ FILE_READ_ATTRIBUTES |
112
+ FILE_EXECUTE |
113
+ SYNCHRONIZE
96
114
 
97
115
  FILE_SHARE_READ = 1
98
116
  FILE_SHARE_WRITE = 2
@@ -146,301 +164,47 @@ module Windows
146
164
  SECTION_MAP_EXECUTE = 0x0008
147
165
  SECTION_EXTEND_SIZE = 0x0010
148
166
 
149
- SECTION_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY |
150
- SECTION_MAP_WRITE | SECTION_MAP_READ | SECTION_MAP_EXECUTE |
167
+ SECTION_ALL_ACCESS =
168
+ STANDARD_RIGHTS_REQUIRED |
169
+ SECTION_QUERY |
170
+ SECTION_MAP_WRITE |
171
+ SECTION_MAP_READ |
172
+ SECTION_MAP_EXECUTE |
151
173
  SECTION_EXTEND_SIZE
152
174
 
153
175
  # Errors
154
- INVALID_FILE_ATTRIBUTES = -1
155
- INVALID_HANDLE_VALUE = -1
156
- INVALID_FILE_SIZE = 0xFFFFFFFF
176
+ INVALID_FILE_ATTRIBUTES = -1
177
+ INVALID_HANDLE_VALUE = -1
178
+ INVALID_FILE_SIZE = 0xFFFFFFFF
157
179
 
158
180
  # Misc
159
181
  LOCKFILE_EXCLUSIVE_LOCK = 0x00000001
160
182
  LOCKFILE_FAIL_IMMEDIATELY = 0x00000002
161
183
 
162
- CopyFile = Win32API.new('kernel32', 'CopyFile', 'PPI', 'I')
163
- CopyFileA = Win32API.new('kernel32', 'CopyFileA', 'PPI', 'I')
164
- CopyFileW = Win32API.new('kernel32', 'CopyFileW', 'PPI', 'I')
165
-
166
- CopyFileEx = Win32API.new('kernel32', 'CopyFileEx', 'PPPPPL', 'I')
167
- CopyFileExA = Win32API.new('kernel32', 'CopyFileExA', 'PPPPPL', 'I')
168
- CopyFileExW = Win32API.new('kernel32', 'CopyFileExW', 'PPPPPL', 'I')
169
-
170
- CreateFile = Win32API.new('kernel32', 'CreateFile', 'PLLPLLL', 'L')
171
- CreateFileA = Win32API.new('kernel32', 'CreateFileA', 'PLLPLLL', 'L')
172
- CreateFileW = Win32API.new('kernel32', 'CreateFileW', 'PLLPLLL', 'L')
173
-
174
- CreateHardLink = Win32API.new('kernel32', 'CreateHardLink', 'PPP', 'I')
175
- CreateHardLinkA = Win32API.new('kernel32', 'CreateHardLinkA', 'PPP', 'I')
176
- CreateHardLinkW = Win32API.new('kernel32', 'CreateHardLinkW', 'PPP', 'I')
177
-
178
- DecryptFile = Win32API.new('advapi32', 'DecryptFile', 'PL', 'I')
179
- DecryptFileA = Win32API.new('advapi32', 'DecryptFileA', 'PL', 'I')
180
- DecryptFileW = Win32API.new('advapi32', 'DecryptFileW', 'PL', 'I')
181
-
182
- DeleteFile = Win32API.new('kernel32', 'DeleteFile', 'P', 'I')
183
- DeleteFileA = Win32API.new('kernel32', 'DeleteFileA', 'P', 'I')
184
- DeleteFileW = Win32API.new('kernel32', 'DeleteFileW', 'P', 'I')
185
-
186
- EncryptFile = Win32API.new('advapi32', 'EncryptFile', 'P', 'I')
187
- EncryptFileA = Win32API.new('advapi32', 'EncryptFileA', 'P', 'I')
188
- EncryptFileW = Win32API.new('advapi32', 'EncryptFileW', 'P', 'I')
189
-
190
- GetBinaryType = Win32API.new('kernel32', 'GetBinaryType', 'PP', 'I')
191
- GetBinaryTypeA = Win32API.new('kernel32', 'GetBinaryTypeA', 'PP', 'I')
192
- GetBinaryTypeW = Win32API.new('kernel32', 'GetBinaryTypeW', 'PP', 'I')
193
-
194
- GetFileAttributes = Win32API.new('kernel32', 'GetFileAttributes', 'P', 'L')
195
- GetFileAttributesA = Win32API.new('kernel32', 'GetFileAttributesA', 'P', 'L')
196
- GetFileAttributesW = Win32API.new('kernel32', 'GetFileAttributesW', 'P', 'L')
197
-
198
- GetFileAttributesEx = Win32API.new('kernel32', 'GetFileAttributesEx', 'PPP', 'I')
199
- GetFileAttributesExA = Win32API.new('kernel32', 'GetFileAttributesExA', 'PPP', 'I')
200
- GetFileAttributesExW = Win32API.new('kernel32', 'GetFileAttributesExW', 'PPP', 'I')
201
-
202
- GetFileSize = Win32API.new('kernel32', 'GetFileSize', 'LP', 'L')
203
- GetFileSizeEx = Win32API.new('kernel32', 'GetFileSizeEx', 'LP', 'L')
204
- GetFileType = Win32API.new('kernel32', 'GetFileType', 'L', 'L')
205
-
206
- GetFullPathName = Win32API.new('kernel32', 'GetFullPathName', 'PLPP', 'L')
207
- GetFullPathNameA = Win32API.new('kernel32', 'GetFullPathNameA', 'PLPP', 'L')
208
- GetFullPathNameW = Win32API.new('kernel32', 'GetFullPathNameW', 'PLPP', 'L')
209
-
210
- GetLongPathName = Win32API.new('kernel32', 'GetLongPathName', 'PPL', 'L')
211
- GetLongPathNameA = Win32API.new('kernel32', 'GetLongPathNameA', 'PPL', 'L')
212
- GetLongPathNameW = Win32API.new('kernel32', 'GetLongPathNameW', 'PPL', 'L')
213
-
214
- GetShortPathName = Win32API.new('kernel32', 'GetShortPathName', 'PPL', 'L')
215
- GetShortPathNameA = Win32API.new('kernel32', 'GetShortPathNameA', 'PPL', 'L')
216
- GetShortPathNameW = Win32API.new('kernel32', 'GetShortPathNameW', 'PPL', 'L')
217
-
218
- LockFile = Win32API.new('kernel32', 'LockFile', 'LLLLL', 'I')
219
- LockFileEx = Win32API.new('kernel32', 'LockFileEx', 'LLLLLL', 'I')
220
-
221
- ReadFile = Win32API.new('kernel32', 'ReadFile', 'LPLPP', 'I')
222
- ReadFileEx = Win32API.new('kernel32', 'ReadFileEx', 'LPLPP', 'I')
223
-
224
- SetFileAttributes = Win32API.new('kernel32', 'SetFileAttributes', 'PL', 'I')
225
- SetFileAttributesA = Win32API.new('kernel32', 'SetFileAttributesA', 'PL', 'I')
226
- SetFileAttributesW = Win32API.new('kernel32', 'SetFileAttributesW', 'PL', 'I')
227
-
228
- UnlockFile = Win32API.new('kernel32', 'UnlockFile', 'LLLLL', 'I')
229
- UnlockFileEx = Win32API.new('kernel32', 'UnlockFileEx', 'LLLLL', 'I')
230
-
231
- WriteFile = Win32API.new('kernel32', 'WriteFile', 'LPLPP', 'I')
232
- WriteFileEx = Win32API.new('kernel32', 'WriteFileEx', 'LPLPP', 'I')
233
-
234
- def CopyFile(curr_file, new_file, bail)
235
- CopyFile.call(curr_file, new_file, bail) > 0
236
- end
237
-
238
- def CopyFileA(curr_file, new_file, bail)
239
- CopyFileA.call(curr_file, new_file, bail) > 0
240
- end
241
-
242
- def CopyFileW(curr_file, new_file, bail)
243
- CopyFileW.call(curr_file, new_file, bail) > 0
244
- end
245
-
246
- def CopyFileEx(curr_file, new_file, routine, data, cancel, flags)
247
- CopyFileEx.call(curr_file, new_file, routine, data, cancel, flags) > 0
248
- end
249
-
250
- def CopyFileExA(curr_file, new_file, routine, data, cancel, flags)
251
- CopyFileExA.call(curr_file, new_file, routine, data, cancel, flags) > 0
252
- end
253
-
254
- def CopyFileExW(curr_file, new_file, routine, data, cancel, flags)
255
- CopyFileExW.call(curr_file, new_file, routine, data, cancel, flags) > 0
256
- end
257
-
258
- def CreateFile(file, access, share, sec, disp, flags, template)
259
- CreateFile.call(file, access, share, sec, disp, flags, template)
260
- end
261
-
262
- def CreateFileA(file, access, share, sec, disp, flags, template)
263
- CreateFileA.call(file, access, share, sec, disp, flags, template)
264
- end
265
-
266
- def CreateFileW(file, access, share, sec, disp, flags, template)
267
- CreateFileW.call(file, access, share, sec, disp, flags, template)
268
- end
269
-
270
- def CreateHardLink(new_file, old_file, attributes)
271
- CreateHardLink.call(new_file, old_file, attributes) > 0
272
- end
273
-
274
- def CreateHardLinkA(new_file, old_file, attributes)
275
- CreateHardLinkA.call(new_file, old_file, attributes) > 0
276
- end
277
-
278
- def CreateHardLinkW(new_file, old_file, attributes)
279
- CreateHardLinkW.call(new_file, old_file, attributes) > 0
280
- end
281
-
282
- def DecryptFile(file, res = 0)
283
- DecryptFile.call(file, res)
284
- end
285
-
286
- def DecryptFileA(file, res = 0)
287
- DecryptFileA.call(file, res)
288
- end
289
-
290
- def DecryptFileW(file, res = 0)
291
- DecryptFileW.call(file, res)
292
- end
293
-
294
- def DeleteFile(file)
295
- DeleteFile.call(file) > 0
296
- end
297
-
298
- def DeleteFileA(file)
299
- DeleteFileA.call(file) > 0
300
- end
301
-
302
- def DeleteFileW(file)
303
- DeleteFileW.call(file) > 0
304
- end
305
-
306
- def EncryptFile(file)
307
- EncryptFile.call(file) > 0
308
- end
309
-
310
- def EncryptFileA(file)
311
- EncryptFileA.call(file) > 0
312
- end
313
-
314
- def EncryptFileW(file)
315
- EncryptFileW.call(file) > 0
316
- end
317
-
318
- def GetBinaryType(file, type)
319
- GetBinaryType.call(file, type) > 0
320
- end
321
-
322
- def GetBinaryTypeA(file, type)
323
- GetBinaryTypeA.call(file, type) > 0
324
- end
325
-
326
- def GetBinaryTypeW(file, type)
327
- GetBinaryTypeW.call(file, type) > 0
328
- end
329
-
330
- def GetFileAttributes(file)
331
- GetFileAttributes.call(file)
332
- end
333
-
334
- def GetFileAttributesA(file)
335
- GetFileAttributesA.call(file)
336
- end
337
-
338
- def GetFileAttributesW(file)
339
- GetFileAttributesW.call(file)
340
- end
341
-
342
- def GetFileAttributesEx(file, level_id, info)
343
- GetFileAttributesEx.call(file, level_id, info)
344
- end
345
-
346
- def GetFileAttributesExA(file, level_id, info)
347
- GetFileAttributesExA.call(file, level_id, info)
348
- end
349
-
350
- def GetFileAttributesExW(file, level_id, info)
351
- GetFileAttributesExW.call(file, level_id, info)
352
- end
353
-
354
- def GetFileSize(handle, size)
355
- GetFileSize.call(handle, size)
356
- end
357
-
358
- def GetFileSizeEx(handle, size)
359
- GetFileSizeEx.call(handle, size) > 0
360
- end
361
-
362
- def GetFileType(handle)
363
- GetFileType.call(handle)
364
- end
365
-
366
- def GetFullPathName(file, buf, buf_size, part)
367
- GetFullPathName.call(file, buf, buf_size, part)
368
- end
369
-
370
- def GetFullPathNameA(file, buf, buf_size, part)
371
- GetFullPathNameA.call(file, buf, buf_size, part)
372
- end
373
-
374
- def GetFullPathNameW(file, buf, buf_size, part)
375
- GetFullPathNameW.call(file, buf, buf_size, part)
376
- end
377
-
378
- def GetLongPathName(short, buf, buf_size)
379
- GetLongPathName.call(short, buf, buf_size)
380
- end
381
-
382
- def GetLongPathNameA(short, buf, buf_size)
383
- GetLongPathNameA.call(short, buf, buf_size)
384
- end
385
-
386
- def GetLongPathNameW(short, buf, buf_size)
387
- GetLongPathNameW.call(short, buf, buf_size)
388
- end
389
-
390
- def GetShortPathName(long, buf, buf_size)
391
- GetShortPathName.call(long, buf, buf_size)
392
- end
393
-
394
- def GetShortPathNameA(long, buf, buf_size)
395
- GetShortPathNameA.call(long, buf, buf_size)
396
- end
397
-
398
- def GetShortPathNameW(long, buf, buf_size)
399
- GetShortPathNameW.call(long, buf, buf_size)
400
- end
401
-
402
- def LockFile(handle, off_low, off_high, lock_low, lock_high)
403
- LockFile.call(handle, off_low, off_high, lock_low, lock_high) > 0
404
- end
405
-
406
- def LockFileEx(handle, flags, res, low, high, overlapped)
407
- LockFileEx.call(handle, flags, res, low, high, overlapped) > 0
408
- end
409
-
410
- def ReadFile(file, buf, bytes, bytes_read, overlapped)
411
- ReadFile.call(file, buf, bytes, bytes_read, overlapped) > 0
412
- end
413
-
414
- def ReadFileEx(file, buf, bytes, overlapped, routine)
415
- ReadFileEx.call(file, buf, bytes, overlapped, routine) > 0
416
- end
417
-
418
- def SetFileAttributes(file, attributes)
419
- SetFileAttributes.call(file, attributes) > 0
420
- end
421
-
422
- def SetFileAttributesA(file, attributes)
423
- SetFileAttributesA.call(file, attributes) > 0
424
- end
425
-
426
- def SetFileAttributesW(file, attributes)
427
- SetFileAttributesW.call(file, attributes) > 0
428
- end
429
-
430
- def UnlockFile(handle, off_low, off_high, bytes_low, bytes_high)
431
- UnlockFile.call(handle, off_low, off_high, bytes_low, bytes_high) > 0
432
- end
433
-
434
- def UnlockFileEx(handle, res, low, high, overlapped)
435
- UnlockFileEx.call(handle, res, low, high, overlapped) > 0
436
- end
437
-
438
- def WriteFile(handle, buf, bytes, overlapped)
439
- WriteFile.call(handle, buf, bytes, overlapped) > 0
440
- end
441
-
442
- def WriteFileEx(handle, buf, bytes, overlapped, routine)
443
- WriteFileEx.call(handle, buf, bytes, overlapped, routine) > 0
444
- end
184
+ API.new('CopyFile', 'PPI', 'B')
185
+ API.new('CopyFileEx', 'PPPPPL', 'B')
186
+ API.new('CreateFile', 'PLLPLLL', 'L')
187
+ API.new('CreateHardLink', 'PPP', 'B')
188
+ API.new('DecryptFile', 'PL', 'B', 'advapi32')
189
+ API.new('DeleteFile', 'P', 'B')
190
+ API.new('EncryptFile', 'P', 'B', 'advapi32')
191
+ API.new('GetBinaryType', 'PP', 'B')
192
+ API.new('GetFileAttributes', 'P', 'L')
193
+ API.new('GetFileAttributesEx', 'PPP', 'I')
194
+ API.new('GetFileSize', 'LP', 'L')
195
+ API.new('GetFileSizeEx', 'LP', 'B')
196
+ API.new('GetFileType', 'L', 'L')
197
+ API.new('GetFullPathName', 'PLPP', 'L')
198
+ API.new('GetLongPathName', 'PPL', 'L')
199
+ API.new('GetShortPathName', 'PPL', 'L')
200
+ API.new('LockFile', 'LLLLL', 'B')
201
+ API.new('LockFileEx', 'LLLLLL', 'B')
202
+ API.new('ReadFile', 'LPLPP', 'B')
203
+ API.new('ReadFileEx', 'LPLPP', 'B')
204
+ API.new('SetFileAttributes', 'PL', 'B')
205
+ API.new('UnlockFile', 'LLLLL', 'B')
206
+ API.new('UnlockFileEx', 'LLLLL', 'B')
207
+ API.new('WriteFile', 'LPLPP', 'B')
208
+ API.new('WriteFileEx', 'LPLPP', 'B')
445
209
  end
446
210
  end