windows-pr 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,290 @@
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'
34
+
35
+ module Windows
36
+ module File
37
+ # File Attributes
38
+ FILE_ATTRIBUTE_READONLY = 0x00000001
39
+ FILE_ATTRIBUTE_HIDDEN = 0x00000002
40
+ FILE_ATTRIBUTE_SYSTEM = 0x00000004
41
+ FILE_ATTRIBUTE_DIRECTORY = 0x00000010
42
+ FILE_ATTRIBUTE_ARCHIVE = 0x00000020
43
+ FILE_ATTRIBUTE_ENCRYPTED = 0x00000040
44
+ FILE_ATTRIBUTE_NORMAL = 0x00000080
45
+ FILE_ATTRIBUTE_TEMPORARY = 0x00000100
46
+ FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200
47
+ FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400
48
+ FILE_ATTRIBUTE_COMPRESSED = 0x00000800
49
+ FILE_ATTRIBUTE_OFFLINE = 0x00001000
50
+ FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000
51
+
52
+ # File types
53
+ FILE_TYPE_UNKNOWN = 0x0000
54
+ FILE_TYPE_DISK = 0x0001
55
+ FILE_TYPE_CHAR = 0x0002
56
+ FILE_TYPE_PIPE = 0x0003
57
+ FILE_TYPE_REMOTE = 0x8000
58
+
59
+ # File security and access rights
60
+ APPLICATION_ERROR_MASK = 0x20000000
61
+ ERROR_SEVERITY_SUCCESS = 0x00000000
62
+ ERROR_SEVERITY_INFORMATIONAL = 0x40000000
63
+ ERROR_SEVERITY_WARNING = 0x80000000
64
+ ERROR_SEVERITY_ERROR = 0xc0000000
65
+ COMPRESSION_FORMAT_NONE = 0
66
+ COMPRESSION_FORMAT_DEFAULT = 1
67
+ COMPRESSION_FORMAT_LZNT1 = 2
68
+ COMPRESSION_ENGINE_STANDARD = 0
69
+ COMPRESSION_ENGINE_MAXIMUM = 256
70
+ ACCESS_ALLOWED_ACE_TYPE = 0
71
+ ACCESS_DENIED_ACE_TYPE = 1
72
+ ANYSIZE_ARRAY = 1
73
+ SYSTEM_AUDIT_ACE_TYPE = 2
74
+ SYSTEM_ALARM_ACE_TYPE = 3
75
+ OBJECT_INHERIT_ACE = 1
76
+ CONTAINER_INHERIT_ACE = 2
77
+ NO_PROPAGATE_INHERIT_ACE = 4
78
+ INHERIT_ONLY_ACE = 8
79
+ VALID_INHERIT_FLAGS = 16
80
+ SUCCESSFUL_ACCESS_ACE_FLAG = 64
81
+ FAILED_ACCESS_ACE_FLAG = 128
82
+ DELETE = 0x00010000
83
+ READ_CONTROL = 0x20000
84
+ WRITE_DAC = 0x40000
85
+ WRITE_OWNER = 0x80000
86
+ SYNCHRONIZE = 0x100000
87
+ STANDARD_RIGHTS_REQUIRED = 0xf0000
88
+ STANDARD_RIGHTS_READ = 0x20000
89
+ STANDARD_RIGHTS_WRITE = 0x20000
90
+ STANDARD_RIGHTS_EXECUTE = 0x20000
91
+ STANDARD_RIGHTS_ALL = 0x1f0000
92
+ SPECIFIC_RIGHTS_ALL = 0xffff
93
+ ACCESS_SYSTEM_SECURITY = 0x1000000
94
+ MAXIMUM_ALLOWED = 0x2000000
95
+ GENERIC_READ = 0x80000000
96
+ GENERIC_WRITE = 0x40000000
97
+ GENERIC_EXECUTE = 0x20000000
98
+ GENERIC_ALL = 0x10000000
99
+ FILE_READ_DATA = 1
100
+ FILE_LIST_DIRECTORY = 1
101
+ FILE_WRITE_DATA = 2
102
+ FILE_ADD_FILE = 2
103
+ FILE_APPEND_DATA = 4
104
+ FILE_ADD_SUBDIRECTORY = 4
105
+ FILE_CREATE_PIPE_INSTANCE = 4
106
+ FILE_READ_EA = 8
107
+ FILE_READ_PROPERTIES = 8
108
+ FILE_WRITE_EA = 16
109
+ FILE_WRITE_PROPERTIES = 16
110
+ FILE_EXECUTE = 32
111
+ FILE_TRAVERSE = 32
112
+ FILE_DELETE_CHILD = 64
113
+ FILE_READ_ATTRIBUTES = 128
114
+ FILE_WRITE_ATTRIBUTES = 256
115
+
116
+ FILE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x1ff)
117
+
118
+ FILE_GENERIC_READ = (STANDARD_RIGHTS_READ|FILE_READ_DATA|
119
+ FILE_READ_ATTRIBUTES|FILE_READ_EA|SYNCHRONIZE)
120
+
121
+ FILE_GENERIC_WRITE = (STANDARD_RIGHTS_WRITE|FILE_WRITE_DATA|
122
+ FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA|FILE_APPEND_DATA|SYNCHRONIZE)
123
+
124
+ FILE_GENERIC_EXECUTE = (STANDARD_RIGHTS_EXECUTE|FILE_READ_ATTRIBUTES|
125
+ FILE_EXECUTE|SYNCHRONIZE)
126
+
127
+ FILE_SHARE_READ = 1
128
+ FILE_SHARE_WRITE = 2
129
+ FILE_SHARE_DELETE = 4
130
+ FILE_NOTIFY_CHANGE_FILE_NAME = 1
131
+ FILE_NOTIFY_CHANGE_DIR_NAME = 2
132
+ FILE_NOTIFY_CHANGE_ATTRIBUTES = 4
133
+ FILE_NOTIFY_CHANGE_SIZE = 8
134
+ FILE_NOTIFY_CHANGE_LAST_WRITE = 16
135
+ FILE_NOTIFY_CHANGE_LAST_ACCESS = 32
136
+ FILE_NOTIFY_CHANGE_CREATION = 64
137
+ FILE_NOTIFY_CHANGE_SECURITY = 256
138
+ MAILSLOT_NO_MESSAGE = -1
139
+ MAILSLOT_WAIT_FOREVER = -1
140
+ FILE_CASE_SENSITIVE_SEARCH = 1
141
+ FILE_CASE_PRESERVED_NAMES = 2
142
+ FILE_UNICODE_ON_DISK = 4
143
+ FILE_PERSISTENT_ACLS = 8
144
+ FILE_FILE_COMPRESSION = 16
145
+ FILE_VOLUME_QUOTAS = 32
146
+ FILE_SUPPORTS_SPARSE_FILES = 64
147
+ FILE_SUPPORTS_REPARSE_POINTS = 128
148
+ FILE_SUPPORTS_REMOTE_STORAGE = 256
149
+ FILE_VOLUME_IS_COMPRESSED = 0x8000
150
+ FILE_SUPPORTS_OBJECT_IDS = 0x10000
151
+ FILE_SUPPORTS_ENCRYPTION = 0x20000
152
+
153
+ # File flags
154
+ FILE_FLAG_WRITE_THROUGH = 0x80000000
155
+ FILE_FLAG_OVERLAPPED = 0x40000000
156
+ FILE_FLAG_NO_BUFFERING = 0x20000000
157
+ FILE_FLAG_RANDOM_ACCESS = 0x10000000
158
+ FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000
159
+ FILE_FLAG_DELETE_ON_CLOSE = 0x04000000
160
+ FILE_FLAG_BACKUP_SEMANTICS = 0x02000000
161
+ FILE_FLAG_POSIX_SEMANTICS = 0x01000000
162
+ FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000
163
+ FILE_FLAG_OPEN_NO_RECALL = 0x00100000
164
+ FILE_FLAG_FIRST_PIPE_INSTANCE = 0x00080000
165
+
166
+ # Errors
167
+ INVALID_FILE_ATTRIBUTES = -1
168
+ INVALID_FILE_SIZE = 0xFFFFFFFF
169
+
170
+ CopyFile = Win32API.new('kernel32', 'CopyFile', 'PPI', 'I')
171
+ CopyFileEx = Win32API.new('kernel32', 'CopyFileEx', 'PPPPPL', 'I')
172
+ CreateFile = Win32API.new('kernel32', 'CreateFile', 'PLLPLLL', 'L')
173
+ CreateHardLink = Win32API.new('kernel32', 'CreateHardLink', 'PPP', 'I')
174
+ DecryptFile = Win32API.new('kernel32', 'DecryptFile', 'PL', 'I')
175
+ DeleteFile = Win32API.new('kernel32', 'DeleteFile', 'P', 'I')
176
+ EncryptFile = Win32API.new('kernel32', 'EncryptFile', 'P', 'I')
177
+
178
+ GetBinaryType = Win32API.new('kernel32', 'GetBinaryType', 'PL', 'I')
179
+ GetFileAttributes = Win32API.new('kernel32', 'GetFileAttributes', 'P', 'L')
180
+ GetFileAttributesEx = Win32API.new('kernel32', 'GetFileAttributes', 'PPP', 'I')
181
+ GetFileSize = Win32API.new('kernel32', 'GetFileSize', 'LP', 'L')
182
+ GetFileSizeEx = Win32API.new('kernel32', 'GetFileSizeEx', 'LP', 'L')
183
+ GetFileType = Win32API.new('kernel32', 'GetFileType', 'L', 'L')
184
+
185
+ LockFile = Win32API.new('kernel32', 'LockFile', 'LLLLL', 'I')
186
+ LockFileEx = Win32API.new('kernel32', 'LockFileEx', 'LLLLLL', 'I')
187
+ ReadFile = Win32API.new('kernel32', 'ReadFile', 'LPLPP', 'I')
188
+ ReadFileEx = Win32API.new('kernel32', 'ReadFileEx', 'LPLPP', 'I')
189
+ ReOpenFile = Win32API.new('kernel32', 'ReOpenFile', 'LLLL', 'L')
190
+
191
+ SetFileAttributes = Win32API.new('kernel32', 'SetFileAttributes', 'PL', 'I')
192
+
193
+ UnlockFile = Win32API.new('kernel32', 'UnlockFile', 'LLLLL', 'I')
194
+ UnlockFileEx = Win32API.new('kernel32', 'UnlockFileEx', 'LLLLL', 'I')
195
+ WriteFile = Win32API.new('kernel32', 'WriteFile', 'LPLPP', 'I')
196
+ WriteFileEx = Win32API.new('kernel32', 'WriteFileEx', 'LPLPP', 'I')
197
+
198
+ def CopyFile(curr_file, new_file, bail)
199
+ CopyFile.call(curr_file, new_file, bail) > 0
200
+ end
201
+
202
+ def CopyFileEx(curr_file, new_file, routine, data, cancel, flags)
203
+ CopyFileEx.call(curr_file, new_file, routine, data, cancel, flags) > 0
204
+ end
205
+
206
+ def CreateFile(file, access, share, sec, disp, flags, template)
207
+ CreateFile.call(file, access, share, sec, disp, flags, template)
208
+ end
209
+
210
+ def CreateHardLink(new_file, old_file, attributes)
211
+ CreateHardLink.call(new_file, old_file, attributes) > 0
212
+ end
213
+
214
+ def DecryptFile(file, res = 0)
215
+ DecryptFile.call(file, res)
216
+ end
217
+
218
+ def DeleteFile(file)
219
+ DeleteFile.call(file) > 0
220
+ end
221
+
222
+ def EncryptFile(file)
223
+ EncryptFile.call(file) > 0
224
+ end
225
+
226
+ def GetBinaryType(file, type)
227
+ GetBinaryType.call(file, type) > 0
228
+ end
229
+
230
+ def GetFileAttributes(file)
231
+ GetFileAttributes.call(file)
232
+ end
233
+
234
+ def GetFileAttributesEx(file, level_id, info)
235
+ GetFileAttributesEx.call(file, level_id, info)
236
+ end
237
+
238
+ def GetFileSize(handle, size)
239
+ GetFileSize.call(handle, size)
240
+ end
241
+
242
+ def GetFileSizeEx(handle, size)
243
+ GetFileSizeEx.call(handle, size) > 0
244
+ end
245
+
246
+ def GetFileType(handle)
247
+ GetFileType.call(handle)
248
+ end
249
+
250
+ def LockFile(handle, off_low, off_high, lock_low, lock_high)
251
+ LockFile.call(handle, off_low, off_high, lock_low, lock_high) > 0
252
+ end
253
+
254
+ def LockFileEx(handle, flags, res, low, high, overlapped)
255
+ LockFileEx.call(handle, flags, res, low, high, overlapped) > 0
256
+ end
257
+
258
+ def ReadFile(file, buf, bytes, bytes_read, overlapped)
259
+ ReadFile.call(file, buf, bytes, bytes_read, overlapped) > 0
260
+ end
261
+
262
+ def ReadFileEx(file, buf, bytes, overlapped, routine)
263
+ ReadFileEx.call(file, buf, bytes, overlapped, routine) > 0
264
+ end
265
+
266
+ def ReOpenFile(handle, access, mode, flags)
267
+ ReOpenFile.call(handle, access, mode, flags)
268
+ end
269
+
270
+ def SetFileAttributes(file, attributes)
271
+ SetFileAttributes.call(file, attributes) > 0
272
+ end
273
+
274
+ def UnlockFile(handle, off_low, off_high, bytes_low, bytes_high)
275
+ UnlockFile.call(handle, off_low, off_high, bytes_low, bytes_high) > 0
276
+ end
277
+
278
+ def UnlockFileEx(handle, res, low, high, overlapped)
279
+ UnlockFileEx.call(handle, res, low, high, overlapped) > 0
280
+ end
281
+
282
+ def WriteFile(handle, buf, bytes, overlapped)
283
+ WriteFileEx.call(handle, buf, bytes, overlapped) > 0
284
+ end
285
+
286
+ def WriteFileEx(handle, buf, bytes, overlapped, routine)
287
+ WriteFileEx.call(handle, buf, bytes, overlapped, routine) > 0
288
+ end
289
+ end
290
+ 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
@@ -0,0 +1,92 @@
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
+ require 'Win32API'
27
+
28
+ module Windows
29
+ module Memory
30
+ GHND = 0x0042
31
+ GMEM_FIXED = 0x0000
32
+ GMEM_MOVABLE = 0002
33
+ GMEM_ZEROINIT = 0x0040
34
+ GPTR = 0x0040
35
+
36
+ GlobalAlloc = Win32API.new('kernel32', 'GlobalAlloc', 'II', 'I')
37
+ GlobalDiscard = Win32API.new('kernel32', 'GlobalDiscard', 'I', 'I')
38
+ GlobalFlags = Win32API.new('kernel32', 'GlobalFlags', 'I', 'I')
39
+ GlobalFree = Win32API.new('kernel32', 'GlobalFree', 'I', 'I')
40
+ GlobalHandle = Win32API.new('kernel32', 'GlobalHandle', 'P', 'I')
41
+ GlobalLock = Win32API.new('kernel32', 'GlobalLock', 'I', 'P')
42
+ GlobalMemoryStatus = Win32API.new('kernel32', 'GlobalMemoryStatus', 'P', 'V')
43
+ GlobalMemoryStatusEx = Win32API.new('kernel32', 'GlobalMemoryStatus', 'P', 'V')
44
+ GlobalReAlloc = Win32API.new('kernel32', 'GlobalReAlloc', 'III', 'I')
45
+ GlobalSize = Win32API.new('kernel32', 'GlobalSize', 'I', 'I')
46
+ GlobalUnlock = Win32API.new('kernel32', 'GlobalUnlock', 'I', 'I')
47
+
48
+ def GlobalAlloc(flags, bytes)
49
+ GlobalAlloc.call(flags, bytes)
50
+ end
51
+
52
+ def GlobalDiscard(handle)
53
+ GlobalDiscard.call(handle)
54
+ end
55
+
56
+ def GlobalFlags(handle)
57
+ GlobalFlags.call(handle)
58
+ end
59
+
60
+ def GlobalFree(handle)
61
+ GlobalFree.call(handle)
62
+ end
63
+
64
+ def GlobalHandle(handle)
65
+ GlobalHandle.call(handle)
66
+ end
67
+
68
+ def GlobalLock(handle)
69
+ GlobalHandle.call(handle)
70
+ end
71
+
72
+ def GlobalMemoryStatus(buf)
73
+ GlobalMemoryStatus.call(buf)
74
+ end
75
+
76
+ def GlobalMemoryStatusEx(buf)
77
+ GlobalMemoryStatusEx.call(buf)
78
+ end
79
+
80
+ def GlobalReAlloc(handle, bytes, flags)
81
+ GlobalReAlloc.call(handle, bytes, flags)
82
+ end
83
+
84
+ def GlobalSize(handle)
85
+ GlobalSize.call(handle)
86
+ end
87
+
88
+ def GlobalUnlock(handle)
89
+ GlobalUnlock.call(handle)
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,48 @@
1
+ require 'Win32API'
2
+
3
+ module Windows
4
+ module MSVCRT
5
+ module Buffer
6
+ Memcpy = Win32API.new('msvcrt', 'memcpy', 'PLL', 'P')
7
+ Memccpy = Win32API.new('msvcrt', '_memccpy', 'PPIL', 'P')
8
+ Memchr = Win32API.new('msvcrt', 'memchr', 'PIL', 'P')
9
+ Memcmp = Win32API.new('msvcrt', 'memcmp', 'PPL', 'I')
10
+ Memicmp = Win32API.new('msvcrt', '_memicmp', 'PPL', 'I')
11
+ Memmove = Win32API.new('msvcrt', 'memmove', 'PPL', 'P')
12
+ Memset = Win32API.new('msvcrt', 'memset', 'PLL', 'P')
13
+ Swab = Win32API.new('msvcrt', '_swab', 'PPI', 'V')
14
+
15
+ def memcpy(dest, src, size)
16
+ Memcpy.call(dest, src, size)
17
+ end
18
+
19
+ def memccpy(dest, src, char, count)
20
+ Memccpy.call(dest, src, char, count)
21
+ end
22
+
23
+ def memchr(buf, char, count)
24
+ Memchr.call(buf, char, count)
25
+ end
26
+
27
+ def memcmp(buf1, buf2, count)
28
+ Memcmp.call(buf1, buf2, count)
29
+ end
30
+
31
+ def memicmp(buf1, buf2, count)
32
+ Memicmp.call(buf1, buf2, count)
33
+ end
34
+
35
+ def memmove(dest, src, count)
36
+ Memmove.call(dest, src, count)
37
+ end
38
+
39
+ def memset(dest, char, count)
40
+ Memset.call(dest, char, count)
41
+ end
42
+
43
+ def swab(src, dest, count)
44
+ Swab.call(src, dest, count)
45
+ end
46
+ end
47
+ end
48
+ end