windows-pr 0.2.0 → 0.5.3
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 +47 -2
- data/MANIFEST +13 -0
- data/README +11 -0
- data/doc/conversion_guide.txt +2 -2
- data/lib/windows/clipboard.rb +0 -33
- data/lib/windows/console.rb +323 -0
- data/lib/windows/device_io.rb +17 -70
- data/lib/windows/directory.rb +80 -0
- data/lib/windows/error.rb +260 -39
- data/lib/windows/eventlog.rb +120 -0
- data/lib/windows/file.rb +89 -33
- data/lib/windows/handle.rb +0 -16
- data/lib/windows/library.rb +76 -0
- data/lib/windows/limits.rb +13 -0
- data/lib/windows/memory.rb +58 -33
- data/lib/windows/msvcrt/buffer.rb +1 -1
- data/lib/windows/msvcrt/string.rb +46 -0
- data/lib/windows/national.rb +557 -0
- data/lib/windows/path.rb +1 -77
- data/lib/windows/pipe.rb +77 -0
- data/lib/windows/process.rb +171 -0
- data/lib/windows/registry.rb +238 -0
- data/lib/windows/security.rb +89 -0
- data/lib/windows/service.rb +183 -0
- data/lib/windows/shell.rb +88 -0
- data/lib/windows/synchronize.rb +111 -11
- data/lib/windows/system_info.rb +70 -0
- data/lib/windows/unicode.rb +138 -0
- data/lib/windows/window.rb +22 -0
- data/test/tc_clipboard.rb +58 -0
- data/test/tc_console.rb +107 -0
- data/test/tc_eventlog.rb +65 -0
- data/test/tc_file.rb +75 -0
- data/test/tc_memory.rb +51 -0
- data/test/tc_pipe.rb +60 -0
- data/test/tc_process.rb +36 -0
- data/test/tc_registry.rb +36 -0
- data/test/tc_security.rb +111 -0
- data/test/tc_synchronize.rb +44 -6
- data/test/tc_unicode.rb +61 -0
- data/test/ts_all.rb +10 -1
- metadata +34 -5
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'Win32API'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
module EventLog
|
5
|
+
EVENTLOG_SEQUENTIAL_READ = 0x0001
|
6
|
+
EVENTLOG_SEEK_READ = 0x0002
|
7
|
+
EVENTLOG_FORWARDS_READ = 0x0004
|
8
|
+
EVENTLOG_BACKWARDS_READ = 0x0008
|
9
|
+
|
10
|
+
EVENTLOG_SUCCESS = 0x0000
|
11
|
+
EVENTLOG_ERROR_TYPE = 0x0001
|
12
|
+
EVENTLOG_WARNING_TYPE = 0x0002
|
13
|
+
EVENTLOG_INFORMATION_TYPE = 0x0004
|
14
|
+
EVENTLOG_AUDIT_SUCCESS = 0x0008
|
15
|
+
EVENTLOG_AUDIT_FAILURE = 0x0010
|
16
|
+
|
17
|
+
EVENTLOG_FULL_INFO = 0
|
18
|
+
|
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
|
119
|
+
end
|
120
|
+
end
|
data/lib/windows/file.rb
CHANGED
@@ -1,36 +1,4 @@
|
|
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
|
-
# LockFile()
|
19
|
-
# LockFileEx()
|
20
|
-
# ReadFile()
|
21
|
-
# ReadFileEx()
|
22
|
-
# ReOpenFile()
|
23
|
-
# SetFileAttributes()
|
24
|
-
# UnlockFile()
|
25
|
-
# UnlockFileEx()
|
26
|
-
# WriteFile()
|
27
|
-
# WriteFileEx()
|
28
|
-
#
|
29
|
-
# TODO:
|
30
|
-
#
|
31
|
-
# Add remaining file functions.
|
32
|
-
######################################################################
|
33
|
-
require 'Win32API'
|
1
|
+
require 'windows/unicode'
|
34
2
|
|
35
3
|
module Windows
|
36
4
|
module File
|
@@ -169,6 +137,40 @@ module Windows
|
|
169
137
|
OPEN_EXISTING = 3
|
170
138
|
OPEN_ALWAYS = 4
|
171
139
|
TRUNCATE_EXISTING = 5
|
140
|
+
|
141
|
+
# Page file access
|
142
|
+
PAGE_NOACCESS = 0x01
|
143
|
+
PAGE_READONLY = 0x02
|
144
|
+
PAGE_READWRITE = 0x04
|
145
|
+
PAGE_WRITECOPY = 0x08
|
146
|
+
PAGE_EXECUTE = 0x10
|
147
|
+
PAGE_EXECUTE_READ = 0x20
|
148
|
+
PAGE_EXECUTE_READWRITE = 0x40
|
149
|
+
PAGE_EXECUTE_WRITECOPY = 0x80
|
150
|
+
PAGE_GUARD = 0x100
|
151
|
+
PAGE_NOCACHE = 0x200
|
152
|
+
PAGE_WRITECOMBINE = 0x400
|
153
|
+
SEC_FILE = 0x800000
|
154
|
+
SEC_IMAGE = 0x1000000
|
155
|
+
SEC_VLM = 0x2000000
|
156
|
+
SEC_RESERVE = 0x4000000
|
157
|
+
SEC_COMMIT = 0x8000000
|
158
|
+
SEC_NOCACHE = 0x10000000
|
159
|
+
|
160
|
+
SECTION_QUERY = 0x0001
|
161
|
+
SECTION_MAP_WRITE = 0x0002
|
162
|
+
SECTION_MAP_READ = 0x0004
|
163
|
+
SECTION_MAP_EXECUTE = 0x0008
|
164
|
+
SECTION_EXTEND_SIZE = 0x0010
|
165
|
+
|
166
|
+
SECTION_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY |
|
167
|
+
SECTION_MAP_WRITE | SECTION_MAP_READ | SECTION_MAP_EXECUTE |
|
168
|
+
SECTION_EXTEND_SIZE
|
169
|
+
|
170
|
+
FILE_MAP_COPY = SECTION_QUERY
|
171
|
+
FILE_MAP_WRITE = SECTION_MAP_WRITE
|
172
|
+
FILE_MAP_READ = SECTION_MAP_READ
|
173
|
+
FILE_MAP_ALL_ACCESS = SECTION_ALL_ACCESS
|
172
174
|
|
173
175
|
# Errors
|
174
176
|
INVALID_FILE_ATTRIBUTES = -1
|
@@ -178,10 +180,16 @@ module Windows
|
|
178
180
|
CopyFile = Win32API.new('kernel32', 'CopyFile', 'PPI', 'I')
|
179
181
|
CopyFileEx = Win32API.new('kernel32', 'CopyFileEx', 'PPPPPL', 'I')
|
180
182
|
CreateFile = Win32API.new('kernel32', 'CreateFile', 'PLLPLLL', 'L')
|
183
|
+
CreateFileW = Win32API.new('kernel32', 'CreateFileW', 'PLLPLLL', 'L')
|
184
|
+
|
185
|
+
CreateFileMapping = Win32API.new('kernel32', 'CreateFileMapping', 'LPLLLP', 'L')
|
186
|
+
|
181
187
|
CreateHardLink = Win32API.new('kernel32', 'CreateHardLink', 'PPP', 'I')
|
182
188
|
DecryptFile = Win32API.new('advapi32', 'DecryptFile', 'PL', 'I')
|
183
189
|
DeleteFile = Win32API.new('kernel32', 'DeleteFile', 'P', 'I')
|
184
190
|
EncryptFile = Win32API.new('advapi32', 'EncryptFile', 'P', 'I')
|
191
|
+
|
192
|
+
FlushViewOfFile = Win32API.new('kernel32', 'FlushViewOfFile', 'PL', 'I')
|
185
193
|
|
186
194
|
GetBinaryType = Win32API.new('kernel32', 'GetBinaryType', 'PP', 'I')
|
187
195
|
GetFileAttributes = Win32API.new('kernel32', 'GetFileAttributes', 'P', 'L')
|
@@ -189,9 +197,18 @@ module Windows
|
|
189
197
|
GetFileSize = Win32API.new('kernel32', 'GetFileSize', 'LP', 'L')
|
190
198
|
GetFileSizeEx = Win32API.new('kernel32', 'GetFileSizeEx', 'LP', 'L')
|
191
199
|
GetFileType = Win32API.new('kernel32', 'GetFileType', 'L', 'L')
|
200
|
+
GetFullPathName = Win32API.new('kernel32', 'GetFullPathName', 'PLPP', 'L')
|
201
|
+
GetFullPathNameW = Win32API.new('kernel32', 'GetFullPathNameW', 'PLPP', 'L')
|
202
|
+
GetLongPathName = Win32API.new('kernel32', 'GetLongPathName', 'PPL', 'L')
|
203
|
+
GetShortPathName = Win32API.new('kernel32', 'GetShortPathName', 'PPL', 'L')
|
192
204
|
|
193
205
|
LockFile = Win32API.new('kernel32', 'LockFile', 'LLLLL', 'I')
|
194
206
|
LockFileEx = Win32API.new('kernel32', 'LockFileEx', 'LLLLLL', 'I')
|
207
|
+
|
208
|
+
MapViewOfFile = Win32API.new('kernel32', 'MapViewOfFile', 'LLLLL', 'L')
|
209
|
+
MapViewOfFileEx = Win32API.new('kernel32', 'MapViewOfFileEx', 'LLLLLL', 'L')
|
210
|
+
OpenFileMapping = Win32API.new('kernel32', 'OpenFileMapping', 'LIP', 'L')
|
211
|
+
|
195
212
|
ReadFile = Win32API.new('kernel32', 'ReadFile', 'LPLPP', 'I')
|
196
213
|
ReadFileEx = Win32API.new('kernel32', 'ReadFileEx', 'LPLPP', 'I')
|
197
214
|
|
@@ -199,6 +216,9 @@ module Windows
|
|
199
216
|
|
200
217
|
UnlockFile = Win32API.new('kernel32', 'UnlockFile', 'LLLLL', 'I')
|
201
218
|
UnlockFileEx = Win32API.new('kernel32', 'UnlockFileEx', 'LLLLL', 'I')
|
219
|
+
|
220
|
+
UnmapViewOfFile = Win32API.new('kernel32', 'UnmapViewOfFile', 'P', 'I')
|
221
|
+
|
202
222
|
WriteFile = Win32API.new('kernel32', 'WriteFile', 'LPLPP', 'I')
|
203
223
|
WriteFileEx = Win32API.new('kernel32', 'WriteFileEx', 'LPLPP', 'I')
|
204
224
|
|
@@ -214,6 +234,10 @@ module Windows
|
|
214
234
|
CreateFile.call(file, access, share, sec, disp, flags, template)
|
215
235
|
end
|
216
236
|
|
237
|
+
def CreateFileMapping(handle, security, protect, high, low, name)
|
238
|
+
CreateFileMapping.call(handle, security, protect, high, low, name)
|
239
|
+
end
|
240
|
+
|
217
241
|
def CreateHardLink(new_file, old_file, attributes)
|
218
242
|
CreateHardLink.call(new_file, old_file, attributes) > 0
|
219
243
|
end
|
@@ -229,6 +253,10 @@ module Windows
|
|
229
253
|
def EncryptFile(file)
|
230
254
|
EncryptFile.call(file) > 0
|
231
255
|
end
|
256
|
+
|
257
|
+
def FlushViewOfFile(address, bytes)
|
258
|
+
FlushViewOfFile.call(address, bytes) != 0
|
259
|
+
end
|
232
260
|
|
233
261
|
def GetBinaryType(file, type)
|
234
262
|
GetBinaryType.call(file, type) > 0
|
@@ -253,6 +281,18 @@ module Windows
|
|
253
281
|
def GetFileType(handle)
|
254
282
|
GetFileType.call(handle)
|
255
283
|
end
|
284
|
+
|
285
|
+
def GetFullPathName(file, buf, buf_size, part)
|
286
|
+
GetFullPathName.call(file, buf, buf_size, part)
|
287
|
+
end
|
288
|
+
|
289
|
+
def GetLongPathName(short, buf, buf_size)
|
290
|
+
GetLongPathName.call(short, buf, buf_size)
|
291
|
+
end
|
292
|
+
|
293
|
+
def GetShortPathName(long, buf, buf_size)
|
294
|
+
GetShortPathName.call(long, buf, buf_size)
|
295
|
+
end
|
256
296
|
|
257
297
|
def LockFile(handle, off_low, off_high, lock_low, lock_high)
|
258
298
|
LockFile.call(handle, off_low, off_high, lock_low, lock_high) > 0
|
@@ -262,6 +302,18 @@ module Windows
|
|
262
302
|
LockFileEx.call(handle, flags, res, low, high, overlapped) > 0
|
263
303
|
end
|
264
304
|
|
305
|
+
def MapViewOfFile(handle, access, high, low, bytes)
|
306
|
+
MapViewOfFile.call(handle, access, high, low, bytes)
|
307
|
+
end
|
308
|
+
|
309
|
+
def MapViewOfFileEx(handle, access, high, low, bytes, address)
|
310
|
+
MapViewOfFileEx.call(handle, access, high, low, bytes, address)
|
311
|
+
end
|
312
|
+
|
313
|
+
def OpenFileMapping(access, inherit, name)
|
314
|
+
OpenFileMapping.call(access, inherit, name)
|
315
|
+
end
|
316
|
+
|
265
317
|
def ReadFile(file, buf, bytes, bytes_read, overlapped)
|
266
318
|
ReadFile.call(file, buf, bytes, bytes_read, overlapped) > 0
|
267
319
|
end
|
@@ -282,6 +334,10 @@ module Windows
|
|
282
334
|
UnlockFileEx.call(handle, res, low, high, overlapped) > 0
|
283
335
|
end
|
284
336
|
|
337
|
+
def UnmapViewOfFile(address)
|
338
|
+
UnmapViewOfFile.call(address) != 0
|
339
|
+
end
|
340
|
+
|
285
341
|
def WriteFile(handle, buf, bytes, overlapped)
|
286
342
|
WriteFileEx.call(handle, buf, bytes, overlapped) > 0
|
287
343
|
end
|
data/lib/windows/handle.rb
CHANGED
@@ -1,19 +1,3 @@
|
|
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
1
|
require 'Win32API'
|
18
2
|
|
19
3
|
module Windows
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'Win32API'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
module Library
|
5
|
+
DLL_PROCESS_DETACH = 0
|
6
|
+
DLL_PROCESS_ATTACH = 1
|
7
|
+
DLL_THREAD_ATTACH = 2
|
8
|
+
DLL_THREAD_DETACH = 3
|
9
|
+
|
10
|
+
GET_MODULE_HANDLE_EX_FLAG_PIN = 1
|
11
|
+
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT = 2
|
12
|
+
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS = 4
|
13
|
+
|
14
|
+
DONT_RESOLVE_DLL_REFERENCES = 0x00000001
|
15
|
+
LOAD_LIBRARY_AS_DATAFILE = 0x00000002
|
16
|
+
LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008
|
17
|
+
LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x00000010
|
18
|
+
|
19
|
+
DisableThreadLibraryCalls = Win32API.new('kernel32', 'DisableThreadLibraryCalls', 'L', 'I')
|
20
|
+
FreeLibrary = Win32API.new('kernel32', 'FreeLibrary', 'L', 'I')
|
21
|
+
FreeLibraryAndExitThread = Win32API.new('kernel32', 'FreeLibraryAndExitThread', 'LL', 'V')
|
22
|
+
GetDllDirectory = Win32API.new('kernel32', 'GetDllDirectory', 'LP', 'L')
|
23
|
+
GetModuleFileName = Win32API.new('kernel32', 'GetModuleFileName', 'LPL', 'L')
|
24
|
+
GetModuleHandle = Win32API.new('kernel32', 'GetModuleHandle', 'P', 'L')
|
25
|
+
GetModuleHandleEx = Win32API.new('kernel32', 'GetModuleHandleEx', 'LPP', 'I')
|
26
|
+
GetProcAddress = Win32API.new('kernel32', 'GetProcAddress', 'LP', 'L')
|
27
|
+
LoadLibrary = Win32API.new('kernel32', 'LoadLibrary', 'P', 'L')
|
28
|
+
LoadLibraryEx = Win32API.new('kernel32', 'LoadLibraryEx', 'PLL', 'L')
|
29
|
+
LoadModule = Win32API.new('kernel32', 'LoadModule', 'PP', 'L')
|
30
|
+
SetDllDirectory = Win32API.new('kernel32', 'SetDllDirectory', 'P', 'I')
|
31
|
+
|
32
|
+
def DisableThreadLibraryCalls(hmodule)
|
33
|
+
DisableThreadLibraryCalls.call(hmodule) != 0
|
34
|
+
end
|
35
|
+
|
36
|
+
def FreeLibrary(hmodule)
|
37
|
+
FreeLibrary.call(hmodule) != 0
|
38
|
+
end
|
39
|
+
|
40
|
+
def GetDllDirectory(length, buffer)
|
41
|
+
GetDllDirectory.call(length, buffer)
|
42
|
+
end
|
43
|
+
|
44
|
+
def GetModuleFileName(hmodule, file, size)
|
45
|
+
GetModuleFileName.call(hmodule, file, size)
|
46
|
+
end
|
47
|
+
|
48
|
+
def GetModuleHandle(module_name)
|
49
|
+
GetModuleHandle.call(module_name)
|
50
|
+
end
|
51
|
+
|
52
|
+
def GetModuleHandleEx(flags, module_name, hmodule)
|
53
|
+
GetModuleHandleEx.call(flags, module_name, hmodule)
|
54
|
+
end
|
55
|
+
|
56
|
+
def GetProcAddress(hmodule, proc_name)
|
57
|
+
GetProcAddress.call(hmodule, proc_name)
|
58
|
+
end
|
59
|
+
|
60
|
+
def LoadLibrary(library)
|
61
|
+
LoadLibrary.call(library)
|
62
|
+
end
|
63
|
+
|
64
|
+
def LoadLibraryEx(library, file, flags)
|
65
|
+
LoadLibraryEx.call(library, file, flags)
|
66
|
+
end
|
67
|
+
|
68
|
+
def LoadModule(hmodule, param_block)
|
69
|
+
LoadModule.call(hmodule, param_block)
|
70
|
+
end
|
71
|
+
|
72
|
+
def SetDllDirectory(path)
|
73
|
+
SetDllDirectory.call(path)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/windows/memory.rb
CHANGED
@@ -1,28 +1,3 @@
|
|
1
|
-
######################################################################
|
2
|
-
# memory.rb
|
3
|
-
#
|
4
|
-
# Includes the following functions:
|
5
|
-
#
|
6
|
-
# GlobalAlloc()
|
7
|
-
# GlobalDiscard()
|
8
|
-
# GlobalFlags()
|
9
|
-
# GlobalFree()
|
10
|
-
# GlobalHandle()
|
11
|
-
# GlobalLock()
|
12
|
-
# GlobalMemoryStatus()
|
13
|
-
# GlobalMemoryStatusEx()
|
14
|
-
# GlobalReAlloc()
|
15
|
-
# GlobalSize()
|
16
|
-
# GlobalUnlock()
|
17
|
-
#
|
18
|
-
# Defines the following constants:
|
19
|
-
#
|
20
|
-
# GHND
|
21
|
-
# GMEM_FIXED
|
22
|
-
# GMEM_MOVABLE
|
23
|
-
# GMEM_ZEROINIT
|
24
|
-
# GPTR
|
25
|
-
######################################################################
|
26
1
|
require 'Win32API'
|
27
2
|
|
28
3
|
module Windows
|
@@ -34,25 +9,31 @@ module Windows
|
|
34
9
|
GPTR = 0x0040
|
35
10
|
|
36
11
|
GlobalAlloc = Win32API.new('kernel32', 'GlobalAlloc', 'II', 'I')
|
37
|
-
GlobalDiscard = Win32API.new('kernel32', 'GlobalDiscard', 'I', 'I')
|
38
12
|
GlobalFlags = Win32API.new('kernel32', 'GlobalFlags', 'I', 'I')
|
39
13
|
GlobalFree = Win32API.new('kernel32', 'GlobalFree', 'I', 'I')
|
40
14
|
GlobalHandle = Win32API.new('kernel32', 'GlobalHandle', 'P', 'I')
|
41
|
-
GlobalLock = Win32API.new('kernel32', 'GlobalLock', '
|
15
|
+
GlobalLock = Win32API.new('kernel32', 'GlobalLock', 'L', 'L')
|
42
16
|
GlobalMemoryStatus = Win32API.new('kernel32', 'GlobalMemoryStatus', 'P', 'V')
|
43
|
-
GlobalMemoryStatusEx = Win32API.new('kernel32', '
|
17
|
+
GlobalMemoryStatusEx = Win32API.new('kernel32', 'GlobalMemoryStatusEx', 'P', 'V')
|
44
18
|
GlobalReAlloc = Win32API.new('kernel32', 'GlobalReAlloc', 'III', 'I')
|
45
19
|
GlobalSize = Win32API.new('kernel32', 'GlobalSize', 'I', 'I')
|
46
20
|
GlobalUnlock = Win32API.new('kernel32', 'GlobalUnlock', 'I', 'I')
|
21
|
+
VirtualAlloc = Win32API.new('kernel32', 'VirtualAlloc', 'PLLL', 'P')
|
22
|
+
VirtualAllocEx = Win32API.new('kernel32', 'VirtualAllocEx', 'LPLLL', 'P')
|
23
|
+
VirtualFree = Win32API.new('kernel32', 'VirtualFree', 'PLL', 'I')
|
24
|
+
VirtualFreeEx = Win32API.new('kernel32', 'VirtualFreeEx', 'LPLL', 'I')
|
25
|
+
VirtualLock = Win32API.new('kernel32', 'VirtualLock', 'PL', 'I')
|
26
|
+
VirtualProtect = Win32API.new('kernel32', 'VirtualProtect', 'PLLP', 'I')
|
27
|
+
VirtualProtectEx = Win32API.new('kernel32', 'VirtualProtectEx', 'LPLLP', 'I')
|
28
|
+
VirtualQuery = Win32API.new('kernel32', 'VirtualQuery', 'PPL', 'L')
|
29
|
+
VirtualQueryEx = Win32API.new('kernel32', 'VirtualQueryEx', 'LPPL', 'L')
|
30
|
+
VirtualUnlock = Win32API.new('kernel32', 'VirtualUnlock', 'PL', 'I')
|
31
|
+
ZeroMemory = Win32API.new('kernel32', 'RtlZeroMemory', 'PL', 'I')
|
47
32
|
|
48
33
|
def GlobalAlloc(flags, bytes)
|
49
34
|
GlobalAlloc.call(flags, bytes)
|
50
35
|
end
|
51
36
|
|
52
|
-
def GlobalDiscard(handle)
|
53
|
-
GlobalDiscard.call(handle)
|
54
|
-
end
|
55
|
-
|
56
37
|
def GlobalFlags(handle)
|
57
38
|
GlobalFlags.call(handle)
|
58
39
|
end
|
@@ -66,7 +47,7 @@ module Windows
|
|
66
47
|
end
|
67
48
|
|
68
49
|
def GlobalLock(handle)
|
69
|
-
|
50
|
+
GlobalLock.call(handle)
|
70
51
|
end
|
71
52
|
|
72
53
|
def GlobalMemoryStatus(buf)
|
@@ -88,5 +69,49 @@ module Windows
|
|
88
69
|
def GlobalUnlock(handle)
|
89
70
|
GlobalUnlock.call(handle)
|
90
71
|
end
|
72
|
+
|
73
|
+
def VirtualAlloc(address, size, alloc_type, protect)
|
74
|
+
VirtualAlloc.call(address, size, alloc_type, protect)
|
75
|
+
end
|
76
|
+
|
77
|
+
def VirtualAllocEx(handle, address, size, alloc_type, protect)
|
78
|
+
VirtualAllocEx.call(handle, address, size, alloc_type, protect)
|
79
|
+
end
|
80
|
+
|
81
|
+
def VirtualFree(address, size, free_type)
|
82
|
+
VirtualFree.call(address, size, free_type) != 0
|
83
|
+
end
|
84
|
+
|
85
|
+
def VirtualFreeEx(handle, address, size, free_type)
|
86
|
+
VirtualFreeEx.call(handle, address, size, free_type) != 0
|
87
|
+
end
|
88
|
+
|
89
|
+
def VirtualLock(address, size)
|
90
|
+
VirtualLock.call(address, size) != 0
|
91
|
+
end
|
92
|
+
|
93
|
+
def VirtualProtect(address, size, new_protect, old_protect)
|
94
|
+
VirtualProtect.call(address, size, new_protect, old_protect) != 0
|
95
|
+
end
|
96
|
+
|
97
|
+
def VirtualProtectEx(handle, address, size, new_protect, old_protect)
|
98
|
+
VirtualProtect.call(handle, address, size, new_protect, old_protect) != 0
|
99
|
+
end
|
100
|
+
|
101
|
+
def VirtualQuery(address, buffer, length)
|
102
|
+
VirtualQuery.call(address, buffer, length)
|
103
|
+
end
|
104
|
+
|
105
|
+
def VirtualQueryEx(handle, address, buffer, length)
|
106
|
+
VirtualQueryEx.call(handle, address, buffer, length)
|
107
|
+
end
|
108
|
+
|
109
|
+
def VirtualUnlock(address, size)
|
110
|
+
VirtualUnlock.call(address, size) != 0
|
111
|
+
end
|
112
|
+
|
113
|
+
def ZeroMemory(dest, length)
|
114
|
+
ZeroMemory.call(dest, length)
|
115
|
+
end
|
91
116
|
end
|
92
117
|
end
|