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.
@@ -1,7 +1,13 @@
1
- require 'Win32API'
1
+ require 'windows/api'
2
+ include Windows
2
3
 
3
4
  module Windows
4
5
  module FileMapping
6
+ API.auto_namespace = 'Windows::FileMapping'
7
+ API.auto_constant = true
8
+ API.auto_method = true
9
+ API.auto_unicode = true
10
+
5
11
  FILE_MAP_COPY = 0x0001
6
12
  FILE_MAP_WRITE = 0x0002
7
13
  FILE_MAP_READ = 0x0004
@@ -25,35 +31,11 @@ module Windows
25
31
  SEC_COMMIT = 0x8000000
26
32
  SEC_NOCACHE = 0x10000000
27
33
 
28
- CreateFileMapping = Win32API.new('kernel32', 'CreateFileMapping', 'LPLLLP', 'L')
29
- FlushViewOfFile = Win32API.new('kernel32', 'FlushViewOfFile', 'PL', 'I')
30
- MapViewOfFile = Win32API.new('kernel32', 'MapViewOfFile', 'LLLLL', 'L')
31
- MapViewOfFileEx = Win32API.new('kernel32', 'MapViewOfFileEx', 'LLLLLL', 'L')
32
- OpenFileMapping = Win32API.new('kernel32', 'OpenFileMapping', 'LIP', 'L')
33
- UnmapViewOfFile = Win32API.new('kernel32', 'UnmapViewOfFile', 'P', 'I')
34
-
35
- def CreateFileMapping(handle, security, protect, high, low, name)
36
- CreateFileMapping.call(handle, security, protect, high, low, name)
37
- end
38
-
39
- def FlushViewOfFile(address, bytes)
40
- FlushViewOfFile.call(address, bytes) != 0
41
- end
42
-
43
- def MapViewOfFile(handle, access, high, low, bytes)
44
- MapViewOfFile.call(handle, access, high, low, bytes)
45
- end
46
-
47
- def MapViewOfFileEx(handle, access, high, low, bytes, address)
48
- MapViewOfFileEx.call(handle, access, high, low, bytes, address)
49
- end
50
-
51
- def OpenFileMapping(access, inherit, name)
52
- OpenFileMapping.call(access, inherit, name)
53
- end
54
-
55
- def UnmapViewOfFile(address)
56
- UnmapViewOfFile.call(address) != 0
57
- end
34
+ API.new('CreateFileMapping', 'LPLLLP', 'L')
35
+ API.new('FlushViewOfFile', 'PL', 'B')
36
+ API.new('MapViewOfFile', 'LLLLL', 'L')
37
+ API.new('MapViewOfFileEx', 'LLLLLL', 'L')
38
+ API.new('OpenFileMapping', 'LIP', 'L')
39
+ API.new('UnmapViewOfFile', 'P', 'B')
58
40
  end
59
- end
41
+ end
@@ -1,16 +1,14 @@
1
- require 'Win32API'
1
+ require 'windows/api'
2
+ include Windows
2
3
 
3
4
  module Windows
4
5
  module FileSystem
5
- GetDiskFreeSpace = Win32API.new('kernel32', 'GetDiskFreeSpace', 'PPPPP', 'I')
6
- GetDiskFreeSpaceEx = Win32API.new('kernel32', 'GetDiskFreeSpaceEx', 'PPPP', 'I')
6
+ API.auto_namespace = 'Windows::FileSystem'
7
+ API.auto_constant = true
8
+ API.auto_method = true
9
+ API.auto_unicode = true
7
10
 
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
11
+ API.new('GetDiskFreeSpace', 'PPPPP', 'B')
12
+ API.new('GetDiskFreeSpaceEx', 'PPPP', 'B')
15
13
  end
16
14
  end
@@ -1,19 +1,23 @@
1
- require 'Win32API'
1
+ require 'windows/api'
2
+ include Windows
2
3
 
3
4
  module Windows
4
5
  module Handle
5
- INVALID_HANDLE_VALUE = -1
6
-
6
+ API.auto_namespace = 'Windows::Handle'
7
+ API.auto_constant = false # Due to some functions with leading '_'.
8
+ API.auto_method = false
9
+ API.auto_unicode = false
10
+
11
+ INVALID_HANDLE_VALUE = -1
7
12
  HANDLE_FLAG_INHERIT = 0x00000001
8
13
  HANDLE_FLAG_PROTECT_FROM_CLOSE = 0x00000002
9
14
 
10
- CloseHandle = Win32API.new('kernel32', 'CloseHandle', 'L', 'I')
11
- DuplicateHandle = Win32API.new('kernel32', 'DuplicateHandle', 'LLLLLIL', 'I')
12
- GetHandleInformation = Win32API.new('kernel32', 'GetHandleInformation', 'LL', 'I')
13
- SetHandleInformation = Win32API.new('kernel32', 'SetHandleInformation', 'LLL', 'I')
14
-
15
- GetOSFHandle = Win32API.new('msvcrt', '_get_osfhandle', 'I', 'L')
16
- OpenOSFHandle = Win32API.new('msvcrt', '_open_osfhandle', 'LI', 'I')
15
+ CloseHandle = API.new('CloseHandle', 'L', 'I')
16
+ DuplicateHandle = API.new('DuplicateHandle', 'LLLLLIL', 'I')
17
+ GetHandleInformation = API.new('GetHandleInformation', 'LL', 'I')
18
+ SetHandleInformation = API.new('SetHandleInformation', 'LLL', 'I')
19
+ GetOSFHandle = API.new('_get_osfhandle', 'I', 'L', 'msvcrt')
20
+ OpenOSFHandle = API.new('_open_osfhandle', 'LI', 'I', 'msvcrt')
17
21
 
18
22
  def CloseHandle(handle)
19
23
  CloseHandle.call(handle) != 0
@@ -39,4 +43,4 @@ module Windows
39
43
  OpenOSFHandle.call(handle, flags)
40
44
  end
41
45
  end
42
- end
46
+ end
@@ -1,7 +1,13 @@
1
- require 'Win32API'
1
+ require 'windows/api'
2
+ include Windows
2
3
 
3
4
  module Windows
4
5
  module Library
6
+ API.auto_namespace = 'Windows::Library'
7
+ API.auto_constant = true
8
+ API.auto_method = true
9
+ API.auto_unicode = true
10
+
5
11
  DLL_PROCESS_DETACH = 0
6
12
  DLL_PROCESS_ATTACH = 1
7
13
  DLL_THREAD_ATTACH = 2
@@ -16,72 +22,24 @@ module Windows
16
22
  LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008
17
23
  LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x00000010
18
24
 
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
- GetModuleFileName = Win32API.new('kernel32', 'GetModuleFileName', 'LPL', 'L')
23
- GetModuleHandle = Win32API.new('kernel32', 'GetModuleHandle', 'P', 'L')
24
- GetProcAddress = Win32API.new('kernel32', 'GetProcAddress', 'LP', 'L')
25
- LoadLibrary = Win32API.new('kernel32', 'LoadLibrary', 'P', 'L')
26
- LoadLibraryEx = Win32API.new('kernel32', 'LoadLibraryEx', 'PLL', 'L')
27
- LoadModule = Win32API.new('kernel32', 'LoadModule', 'PP', 'L')
28
-
25
+ API.new('DisableThreadLibraryCalls', 'L', 'B')
26
+ API.new('FreeLibrary', 'L', 'B')
27
+ API.new('FreeLibraryAndExitThread', 'LL', 'V')
28
+ API.new('GetModuleFileName', 'LPL', 'L')
29
+ API.new('GetModuleHandle', 'P', 'L')
30
+ API.new('GetProcAddress', 'LP', 'L')
31
+ API.new('LoadLibrary', 'P', 'L')
32
+ API.new('LoadLibraryEx', 'PLL', 'L')
33
+ API.new('LoadModule', 'PP', 'L')
34
+
29
35
  # Windows XP or later
30
36
  begin
31
- GetDllDirectory = Win32API.new('kernel32', 'GetDllDirectory', 'LP', 'L')
32
- GetModuleHandleEx = Win32API.new('kernel32', 'GetModuleHandleEx', 'LPP', 'I')
33
- SetDllDirectory = Win32API.new('kernel32', 'SetDllDirectory', 'P', 'I')
37
+ API.new('GetDllDirectory', 'LP', 'L')
38
+ API.new('GetModuleHandleEx', 'LPP', 'I')
39
+ API.new('SetDllDirectory', 'P', 'I')
34
40
  rescue Exception
35
41
  # Do nothing - not supported on current platform. It's up to you to
36
42
  # check for the existence of the constant in your code.
37
43
  end
38
-
39
- def DisableThreadLibraryCalls(hmodule)
40
- DisableThreadLibraryCalls.call(hmodule) != 0
41
- end
42
-
43
- def FreeLibrary(hmodule)
44
- FreeLibrary.call(hmodule) != 0
45
- end
46
-
47
- def GetModuleFileName(hmodule, file, size)
48
- GetModuleFileName.call(hmodule, file, size)
49
- end
50
-
51
- def GetModuleHandle(module_name)
52
- GetModuleHandle.call(module_name)
53
- end
54
-
55
- def GetProcAddress(hmodule, proc_name)
56
- GetProcAddress.call(hmodule, proc_name)
57
- end
58
-
59
- def LoadLibrary(library)
60
- LoadLibrary.call(library)
61
- end
62
-
63
- def LoadLibraryEx(library, file, flags)
64
- LoadLibraryEx.call(library, file, flags)
65
- end
66
-
67
- def LoadModule(hmodule, param_block)
68
- LoadModule.call(hmodule, param_block)
69
- end
70
-
71
- begin
72
- def SetDllDirectory(path)
73
- SetDllDirectory.call(path)
74
- end
75
-
76
- def GetModuleHandleEx(flags, module_name, hmodule)
77
- GetModuleHandleEx.call(flags, module_name, hmodule)
78
- end
79
-
80
- def GetDllDirectory(length, buffer)
81
- GetDllDirectory.call(length, buffer)
82
- end
83
- rescue Exception
84
- # Windows XP or later
85
- end
86
44
  end
87
- end
45
+ end
@@ -1,7 +1,13 @@
1
- require 'Win32API'
1
+ require 'windows/api'
2
+ include Windows
2
3
 
3
4
  module Windows
4
5
  module Memory
6
+ API.auto_namespace = 'Windows::Memory'
7
+ API.auto_constant = true
8
+ API.auto_method = true
9
+ API.auto_unicode = false
10
+
5
11
  GHND = 0x0042
6
12
  GMEM_FIXED = 0x0000
7
13
  GMEM_MOVABLE = 0002
@@ -16,110 +22,26 @@ module Windows
16
22
  MEM_TOP_DOWN = 0x100000
17
23
  MEM_WRITE_WATCH = 0x200000
18
24
 
19
- GlobalAlloc = Win32API.new('kernel32', 'GlobalAlloc', 'II', 'I')
20
- GlobalFlags = Win32API.new('kernel32', 'GlobalFlags', 'I', 'I')
21
- GlobalFree = Win32API.new('kernel32', 'GlobalFree', 'I', 'I')
22
- GlobalHandle = Win32API.new('kernel32', 'GlobalHandle', 'P', 'I')
23
- GlobalLock = Win32API.new('kernel32', 'GlobalLock', 'L', 'L')
24
- GlobalMemoryStatus = Win32API.new('kernel32', 'GlobalMemoryStatus', 'P', 'V')
25
- GlobalMemoryStatusEx = Win32API.new('kernel32', 'GlobalMemoryStatusEx', 'P', 'V')
26
- GlobalReAlloc = Win32API.new('kernel32', 'GlobalReAlloc', 'III', 'I')
27
- GlobalSize = Win32API.new('kernel32', 'GlobalSize', 'I', 'I')
28
- GlobalUnlock = Win32API.new('kernel32', 'GlobalUnlock', 'I', 'I')
29
- VirtualAlloc = Win32API.new('kernel32', 'VirtualAlloc', 'LLLL', 'P')
30
- VirtualAllocEx = Win32API.new('kernel32', 'VirtualAllocEx', 'LLLLL', 'P')
31
- VirtualFree = Win32API.new('kernel32', 'VirtualFree', 'LLL', 'I')
32
- VirtualFreeEx = Win32API.new('kernel32', 'VirtualFreeEx', 'LLLL', 'I')
33
- VirtualLock = Win32API.new('kernel32', 'VirtualLock', 'PL', 'I')
34
- VirtualProtect = Win32API.new('kernel32', 'VirtualProtect', 'PLLP', 'I')
35
- VirtualProtectEx = Win32API.new('kernel32', 'VirtualProtectEx', 'LPLLP', 'I')
36
- VirtualQuery = Win32API.new('kernel32', 'VirtualQuery', 'LPL', 'L')
37
- VirtualQueryEx = Win32API.new('kernel32', 'VirtualQueryEx', 'LLPL', 'L')
38
- VirtualUnlock = Win32API.new('kernel32', 'VirtualUnlock', 'PL', 'I')
39
- ZeroMemory = Win32API.new('kernel32', 'RtlZeroMemory', 'PL', 'I')
40
-
41
- def GlobalAlloc(flags, bytes)
42
- GlobalAlloc.call(flags, bytes)
43
- end
44
-
45
- def GlobalFlags(handle)
46
- GlobalFlags.call(handle)
47
- end
48
-
49
- def GlobalFree(handle)
50
- GlobalFree.call(handle)
51
- end
52
-
53
- def GlobalHandle(handle)
54
- GlobalHandle.call(handle)
55
- end
56
-
57
- def GlobalLock(handle)
58
- GlobalLock.call(handle)
59
- end
60
-
61
- def GlobalMemoryStatus(buf)
62
- GlobalMemoryStatus.call(buf)
63
- end
64
-
65
- def GlobalMemoryStatusEx(buf)
66
- GlobalMemoryStatusEx.call(buf)
67
- end
68
-
69
- def GlobalReAlloc(handle, bytes, flags)
70
- GlobalReAlloc.call(handle, bytes, flags)
71
- end
72
-
73
- def GlobalSize(handle)
74
- GlobalSize.call(handle)
75
- end
76
-
77
- def GlobalUnlock(handle)
78
- GlobalUnlock.call(handle)
79
- end
80
-
81
- def VirtualAlloc(address, size, alloc_type, protect)
82
- VirtualAlloc.call(address, size, alloc_type, protect)
83
- end
84
-
85
- def VirtualAllocEx(handle, address, size, alloc_type, protect)
86
- VirtualAllocEx.call(handle, address, size, alloc_type, protect)
87
- end
88
-
89
- def VirtualFree(address, size, free_type)
90
- VirtualFree.call(address, size, free_type) != 0
91
- end
92
-
93
- def VirtualFreeEx(handle, address, size, free_type)
94
- VirtualFreeEx.call(handle, address, size, free_type) != 0
95
- end
96
-
97
- def VirtualLock(address, size)
98
- VirtualLock.call(address, size) != 0
99
- end
100
-
101
- def VirtualProtect(address, size, new_protect, old_protect)
102
- VirtualProtect.call(address, size, new_protect, old_protect) != 0
103
- end
104
-
105
- def VirtualProtectEx(handle, address, size, new_protect, old_protect)
106
- VirtualProtectEx.call(handle, address, size, new_protect, old_protect) != 0
107
- end
108
-
109
- def VirtualQuery(address, buffer, length)
110
- VirtualQuery.call(address, buffer, length)
111
- end
112
-
113
- def VirtualQueryEx(handle, address, buffer, length)
114
- VirtualQueryEx.call(handle, address, buffer, length)
115
- end
116
-
117
- def VirtualUnlock(address, size)
118
- VirtualUnlock.call(address, size) != 0
119
- end
120
-
121
- def ZeroMemory(dest, length)
122
- ZeroMemory.call(dest, length)
123
- end
25
+ API.new('GlobalAlloc', 'II', 'I')
26
+ API.new('GlobalFlags', 'I', 'I')
27
+ API.new('GlobalFree', 'I', 'I')
28
+ API.new('GlobalHandle', 'P', 'I')
29
+ API.new('GlobalLock', 'L', 'L')
30
+ API.new('GlobalMemoryStatus', 'P', 'V')
31
+ API.new('GlobalMemoryStatusEx', 'P', 'V')
32
+ API.new('GlobalReAlloc', 'III', 'I')
33
+ API.new('GlobalSize', 'I', 'I')
34
+ API.new('GlobalUnlock', 'I', 'I')
35
+ API.new('VirtualAlloc', 'LLLL', 'P')
36
+ API.new('VirtualAllocEx', 'LLLLL', 'P')
37
+ API.new('VirtualFree', 'LLL', 'B')
38
+ API.new('VirtualFreeEx', 'LLLL', 'B')
39
+ API.new('VirtualLock', 'PL', 'B')
40
+ API.new('VirtualProtect', 'PLLP', 'B')
41
+ API.new('VirtualProtectEx', 'LPLLP', 'B')
42
+ API.new('VirtualQuery', 'LPL', 'L')
43
+ API.new('VirtualQueryEx', 'LLPL', 'L')
44
+ API.new('VirtualUnlock', 'PL', 'B')
45
+ API.new('RtlZeroMemory', 'PL', 'L')
124
46
  end
125
47
  end
@@ -1,22 +1,27 @@
1
- require 'Win32API'
1
+ require 'windows/api'
2
+ include Windows
2
3
 
3
4
  module Windows
4
5
  module MSVCRT
5
6
  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', 'L')
13
- Swab = Win32API.new('msvcrt', '_swab', 'PPI', 'V')
7
+ API.auto_constant = false
8
+ API.auto_method = false
9
+ API.auto_unicode = false
10
+
11
+ Memcpy = API.new('memcpy', 'PLL', 'P', 'msvcrt')
12
+ Memccpy = API.new('_memccpy', 'PPIL', 'P', 'msvcrt')
13
+ Memchr = API.new('memchr', 'PIL', 'P', 'msvcrt')
14
+ Memcmp = API.new('memcmp', 'PPL', 'I', 'msvcrt')
15
+ Memicmp = API.new('_memicmp', 'PPL', 'I', 'msvcrt')
16
+ Memmove = API.new('memmove', 'PPL', 'P', 'msvcrt')
17
+ Memset = API.new('memset', 'PLL', 'L', 'msvcrt')
18
+ Swab = API.new('_swab', 'PPI', 'V', 'msvcrt')
19
+
20
+ MemcpyPLL = API.new('memcpy', 'PLL', 'P', 'msvcrt')
21
+ MemcpyLPL = API.new('memcpy', 'LPL', 'P', 'msvcrt')
22
+ MemcpyLLL = API.new('memcpy', 'LLL', 'P', 'msvcrt')
23
+ MemcpyPPL = API.new('memcpy', 'PPL', 'P', 'msvcrt')
14
24
 
15
- MemcpyPLL = Win32API.new('msvcrt', 'memcpy', 'PLL', 'P')
16
- MemcpyLPL = Win32API.new('msvcrt', 'memcpy', 'LPL', 'P')
17
- MemcpyLLL = Win32API.new('msvcrt', 'memcpy', 'LLL', 'P')
18
- MemcpyPPL = Win32API.new('msvcrt', 'memcpy', 'PPL', 'P')
19
-
20
25
  # Wrapper for the memcpy() function. Both the +dest+ and +src+ can
21
26
  # be either a string or a memory address. If +size+ is omitted, it
22
27
  # defaults to the length of +src+.
@@ -66,4 +71,4 @@ module Windows
66
71
  end
67
72
  end
68
73
  end
69
- end
74
+ end
@@ -1,8 +1,13 @@
1
- require 'Win32API'
1
+ require 'windows/api'
2
+ include Windows
2
3
 
3
4
  module Windows
4
5
  module MSVCRT
5
6
  module File
7
+ API.auto_method = false
8
+ API.auto_constant = false
9
+ API.auto_unicode = false
10
+
6
11
  S_IFMT = 0170000 # file type mask
7
12
  S_IFDIR = 0040000 # directory
8
13
  S_IFCHR = 0020000 # character special
@@ -12,10 +17,28 @@ module Windows
12
17
  S_IWRITE = 0000200 # write permission, owner
13
18
  S_IEXEC = 0000100 # execute/search permission, owner
14
19
 
15
- Stat = Win32API.new('msvcrt', '_stat', 'PP', 'I')
16
- Wstat = Win32API.new('msvcrt', '_wstat', 'PP', 'I')
17
- Stat64 = Win32API.new('msvcrt', '_stat64', 'PP', 'I')
18
- Wstat64 = Win32API.new('msvcrt', '_wstat64', 'PP', 'I')
20
+ Mktemp = API.new('_mktemp', 'P', 'P', 'msvcrt')
21
+ Stat = API.new('_stat', 'PP', 'I', 'msvcrt')
22
+ Stat64 = API.new('_stat64', 'PP', 'I', 'msvcrt')
23
+ Wmktemp = API.new('_wmktemp', 'P', 'P', 'msvcrt')
24
+ Wstat = API.new('_wstat', 'PP', 'I', 'msvcrt')
25
+ Wstat64 = API.new('_wstat64', 'PP', 'I', 'msvcrt')
26
+
27
+ # VC++ 8.0 or later
28
+ begin
29
+ Mktemp_s = API.new('_mktemp_s', 'PL', 'L', 'msvcrt')
30
+ Wmktemp_s = API.new('_wmktemp_s', 'PL', 'L', 'msvcrt')
31
+ rescue RuntimeError
32
+ # Ignore - you must check for it via 'defined?'
33
+ end
34
+
35
+ def mktemp(template)
36
+ Mktemp.call(template)
37
+ end
38
+
39
+ def mktemp_s(template, size)
40
+ Mktemp_s.call(template, size)
41
+ end
19
42
 
20
43
  def stat(path, buffer)
21
44
  Stat.call(path, buffer)
@@ -24,7 +47,15 @@ module Windows
24
47
  def stat64(path, buffer)
25
48
  Stat64.call(path, buffer)
26
49
  end
27
-
50
+
51
+ def wmktemp(template)
52
+ Wmktemp.call(template)
53
+ end
54
+
55
+ def wmktemp_s(template, size)
56
+ Wmktemp_s.call(template, size)
57
+ end
58
+
28
59
  def wstat(path, buffer)
29
60
  Wstat.call(path, buffer)
30
61
  end
@@ -34,4 +65,4 @@ module Windows
34
65
  end
35
66
  end
36
67
  end
37
- end
68
+ end