win32-mmap 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,41 +1,41 @@
1
- require 'ffi'
2
-
3
- module Windows
4
- module Constants
5
- include FFI::Library
6
-
7
- private
8
-
9
- GENERIC_READ = 0x80000000
10
- GENERIC_WRITE = 0x40000000
11
- OPEN_ALWAYS = 4
12
-
13
- WAIT_OBJECT_0 = 0
14
-
15
- INVALID_HANDLE_VALUE = FFI::Pointer.new(-1).address
16
-
17
- PAGE_NOACCESS = 0x01
18
- PAGE_READONLY = 0x02
19
- PAGE_READWRITE = 0x04
20
- PAGE_WRITECOPY = 0x08
21
- PAGE_EXECUTE = 0x10
22
- PAGE_EXECUTE_READ = 0x20
23
- PAGE_EXECUTE_READWRITE = 0x40
24
- PAGE_EXECUTE_WRITECOPY = 0x80
25
- PAGE_GUARD = 0x100
26
- PAGE_NOCACHE = 0x200
27
- PAGE_WRITECOMBINE = 0x400
28
-
29
- SEC_FILE = 0x800000
30
- SEC_IMAGE = 0x1000000
31
- SEC_VLM = 0x2000000
32
- SEC_RESERVE = 0x4000000
33
- SEC_COMMIT = 0x8000000
34
- SEC_NOCACHE = 0x10000000
35
-
36
- FILE_MAP_COPY = 0x0001
37
- FILE_MAP_WRITE = 0x0002
38
- FILE_MAP_READ = 0x0004
39
- FILE_MAP_ALL_ACCESS = 983071
40
- end
41
- end
1
+ require 'ffi'
2
+
3
+ module Windows
4
+ module Constants
5
+ include FFI::Library
6
+
7
+ private
8
+
9
+ GENERIC_READ = 0x80000000
10
+ GENERIC_WRITE = 0x40000000
11
+ OPEN_ALWAYS = 4
12
+
13
+ WAIT_OBJECT_0 = 0
14
+
15
+ INVALID_HANDLE_VALUE = FFI::Pointer.new(-1).address
16
+
17
+ PAGE_NOACCESS = 0x01
18
+ PAGE_READONLY = 0x02
19
+ PAGE_READWRITE = 0x04
20
+ PAGE_WRITECOPY = 0x08
21
+ PAGE_EXECUTE = 0x10
22
+ PAGE_EXECUTE_READ = 0x20
23
+ PAGE_EXECUTE_READWRITE = 0x40
24
+ PAGE_EXECUTE_WRITECOPY = 0x80
25
+ PAGE_GUARD = 0x100
26
+ PAGE_NOCACHE = 0x200
27
+ PAGE_WRITECOMBINE = 0x400
28
+
29
+ SEC_FILE = 0x800000
30
+ SEC_IMAGE = 0x1000000
31
+ SEC_VLM = 0x2000000
32
+ SEC_RESERVE = 0x4000000
33
+ SEC_COMMIT = 0x8000000
34
+ SEC_NOCACHE = 0x10000000
35
+
36
+ FILE_MAP_COPY = 0x0001
37
+ FILE_MAP_WRITE = 0x0002
38
+ FILE_MAP_READ = 0x0004
39
+ FILE_MAP_ALL_ACCESS = 983071
40
+ end
41
+ end
@@ -1,50 +1,50 @@
1
- require 'ffi'
2
-
3
- module Windows
4
- module Functions
5
- module FFI::Library
6
- def attach_pfunc(*args)
7
- attach_function(*args)
8
- private args[0]
9
- end
10
- end
11
-
12
- extend FFI::Library
13
-
14
- ffi_lib :kernel32
15
-
16
- typedef :ulong, :dword
17
- typedef :uintptr_t, :handle
18
- typedef :pointer, :ptr
19
- typedef :string, :str
20
-
21
- attach_pfunc :CloseHandle, [:handle], :bool
22
-
23
- attach_pfunc :CreateFile, :CreateFileA,
24
- [:str, :dword, :dword, :pointer, :dword, :dword, :handle],
25
- :handle
26
-
27
- attach_pfunc :CreateFileMapping, :CreateFileMappingA,
28
- [:handle, :pointer, :dword, :dword, :dword, :str],
29
- :handle
30
-
31
- attach_pfunc :CreateSemaphore, :CreateSemaphoreA,
32
- [:pointer, :long, :long, :str],
33
- :handle
34
-
35
- attach_pfunc :FlushViewOfFile, [:uintptr_t, :size_t], :bool
36
-
37
- attach_pfunc :MapViewOfFileEx,
38
- [:handle, :dword, :dword, :dword, :size_t, :uintptr_t],
39
- :uintptr_t
40
-
41
- attach_pfunc :OpenFileMapping, :OpenFileMappingA,
42
- [:dword, :bool, :str],
43
- :handle
44
-
45
- attach_pfunc :ReleaseSemaphore, [:handle, :long, :pointer], :bool
46
- attach_pfunc :UnmapViewOfFile, [:uintptr_t], :bool
47
- attach_pfunc :WaitForSingleObject, [:handle, :dword], :dword
48
- attach_pfunc :VirtualQuery, [:uintptr_t, :pointer, :size_t], :size_t
49
- end
50
- end
1
+ require 'ffi'
2
+
3
+ module Windows
4
+ module Functions
5
+ module FFI::Library
6
+ def attach_pfunc(*args)
7
+ attach_function(*args)
8
+ private args[0]
9
+ end
10
+ end
11
+
12
+ extend FFI::Library
13
+
14
+ ffi_lib :kernel32
15
+
16
+ typedef :ulong, :dword
17
+ typedef :uintptr_t, :handle
18
+ typedef :pointer, :ptr
19
+ typedef :string, :str
20
+
21
+ attach_pfunc :CloseHandle, [:handle], :bool
22
+
23
+ attach_pfunc :CreateFile, :CreateFileA,
24
+ [:str, :dword, :dword, :pointer, :dword, :dword, :handle],
25
+ :handle
26
+
27
+ attach_pfunc :CreateFileMapping, :CreateFileMappingA,
28
+ [:handle, :pointer, :dword, :dword, :dword, :str],
29
+ :handle
30
+
31
+ attach_pfunc :CreateSemaphore, :CreateSemaphoreA,
32
+ [:pointer, :long, :long, :str],
33
+ :handle
34
+
35
+ attach_pfunc :FlushViewOfFile, [:uintptr_t, :size_t], :bool
36
+
37
+ attach_pfunc :MapViewOfFileEx,
38
+ [:handle, :dword, :dword, :dword, :size_t, :uintptr_t],
39
+ :uintptr_t
40
+
41
+ attach_pfunc :OpenFileMapping, :OpenFileMappingA,
42
+ [:dword, :bool, :str],
43
+ :handle
44
+
45
+ attach_pfunc :ReleaseSemaphore, [:handle, :long, :pointer], :bool
46
+ attach_pfunc :UnmapViewOfFile, [:uintptr_t], :bool
47
+ attach_pfunc :WaitForSingleObject, [:handle, :dword], :dword
48
+ attach_pfunc :VirtualQuery, [:uintptr_t, :pointer, :size_t], :size_t
49
+ end
50
+ end
@@ -1,28 +1,28 @@
1
- require 'ffi'
2
-
3
- module Windows
4
- module Structs
5
- extend FFI::Library
6
- typedef :ulong, :dword
7
-
8
- class SECURITY_ATTRIBUTES < FFI::Struct
9
- layout(
10
- :nLength, :dword,
11
- :lpSecurityDescriptor, :pointer,
12
- :bInheritHandle, :bool
13
- )
14
- end
15
-
16
- class MEMORY_BASIC_INFORMATION < FFI::Struct
17
- layout(
18
- :BaseAddress, :pointer,
19
- :AllocationBase, :pointer,
20
- :AllocationProtect, :ulong,
21
- :RegionSize, :size_t,
22
- :State, :ulong,
23
- :Protect, :dword,
24
- :Type, :dword
25
- )
26
- end
27
- end
28
- end
1
+ require 'ffi'
2
+
3
+ module Windows
4
+ module Structs
5
+ extend FFI::Library
6
+ typedef :ulong, :dword
7
+
8
+ class SECURITY_ATTRIBUTES < FFI::Struct
9
+ layout(
10
+ :nLength, :dword,
11
+ :lpSecurityDescriptor, :pointer,
12
+ :bInheritHandle, :bool
13
+ )
14
+ end
15
+
16
+ class MEMORY_BASIC_INFORMATION < FFI::Struct
17
+ layout(
18
+ :BaseAddress, :pointer,
19
+ :AllocationBase, :pointer,
20
+ :AllocationProtect, :ulong,
21
+ :RegionSize, :size_t,
22
+ :State, :ulong,
23
+ :Protect, :dword,
24
+ :Type, :dword
25
+ )
26
+ end
27
+ end
28
+ end
@@ -1,113 +1,113 @@
1
- #####################################################################
2
- # test_win32_mmap.rb
3
- #
4
- # Test suite for the win32-mmap package. This should be run via the
5
- # 'rake test' task.
6
- #####################################################################
7
- require 'test-unit'
8
- require 'win32/mmap'
9
- include Win32
10
-
11
- class TC_Win32_Mmap < Test::Unit::TestCase
12
- def setup
13
- @mmap = MMap.new(:name => 'test', :size => 100)
14
- end
15
-
16
- test "version is set to expected value" do
17
- assert_equal('0.4.1', MMap::VERSION)
18
- end
19
-
20
- test "dynamic variable names and string values work as expected" do
21
- assert_nothing_raised{ @mmap.foo = 'test' }
22
- assert_nothing_raised{ @mmap.bar = 'alpha123' }
23
- assert_equal('test', @mmap.foo)
24
- assert_equal('alpha123', @mmap.bar)
25
- end
26
-
27
- test "dynamic variable names and integer values work as expected" do
28
- assert_nothing_raised{ @mmap.bar = 7 }
29
- assert_nothing_raised{ @mmap.zero = 0 }
30
- assert_equal(7, @mmap.bar)
31
- assert_equal(0, @mmap.zero)
32
- end
33
-
34
- test "dynamic variable names and hash values work as expected" do
35
- assert_nothing_raised{ @mmap.ahash = {'foo' => 0} }
36
- assert_nothing_raised{ @mmap.bhash = {'foo' => 0, 'bar' => 'hello'} }
37
- assert_equal({'foo' => 0}, @mmap.ahash)
38
- assert_equal({'foo' => 0, 'bar' => 'hello'}, @mmap.bhash)
39
- end
40
-
41
- test "dynamic variable names and array values work as expected" do
42
- assert_nothing_raised{ @mmap.aarray = [1, 'x', 3] }
43
- assert_nothing_raised{ @mmap.barray = [{1 => 2}, [1,2,3], 'foo'] }
44
- assert_equal([1, 'x', 3], @mmap.aarray)
45
- assert_equal([{1=>2}, [1,2,3], 'foo'], @mmap.barray)
46
- end
47
-
48
- test "primitive write/read of file" do
49
- input = "Greetings, astute reader"
50
- assert_nothing_raised{ @mmap.write_string(input) }
51
- assert_equal(input, @mmap.read_string(input.length))
52
- end
53
-
54
- test "passing an invalid option raises an argument error" do
55
- assert_raises(ArgumentError){ MMap.new(:foo => 1) }
56
- end
57
-
58
- test "address method basic functionality" do
59
- assert_respond_to(@mmap, :address)
60
- assert_kind_of(Fixnum, @mmap.address)
61
- end
62
-
63
- test "base_address method basic functionality" do
64
- assert_respond_to(@mmap, :base_address)
65
- assert_respond_to(@mmap, :base_address=)
66
- assert_kind_of(Fixnum, @mmap.base_address)
67
- end
68
-
69
- test "name accessor basic functionality" do
70
- assert_respond_to(@mmap, :name)
71
- assert_respond_to(@mmap, :name=)
72
- assert_equal('test', @mmap.name)
73
- end
74
-
75
- test "inherit accessor basic functionality" do
76
- assert_respond_to(@mmap, :inherit?)
77
- assert_respond_to(@mmap, :inherit=)
78
- assert_equal(false, @mmap.inherit?)
79
- end
80
-
81
- test "size accessor basic functionality" do
82
- assert_respond_to(@mmap, :size)
83
- assert_respond_to(@mmap, :size=)
84
- assert_equal(100, @mmap.size)
85
- end
86
-
87
- test "file accessor basic functionality" do
88
- assert_respond_to(@mmap, :file)
89
- assert_respond_to(@mmap, :file=)
90
- assert_nil(@mmap.file)
91
- end
92
-
93
- test "access accessor basic functionality" do
94
- assert_respond_to(@mmap, :access)
95
- assert_respond_to(@mmap, :access=)
96
- end
97
-
98
- test "autolock accessor basic functionality" do
99
- assert_respond_to(@mmap, :autolock?)
100
- assert_respond_to(@mmap, :autolock=)
101
- assert_equal(true, @mmap.autolock?)
102
- end
103
-
104
- test "protection accessor basic functionality" do
105
- assert_respond_to(@mmap, :protection)
106
- assert_respond_to(@mmap, :protection=)
107
- assert_equal(4, @mmap.protection)
108
- end
109
-
110
- def teardown
111
- @mmap.close
112
- end
113
- end
1
+ #####################################################################
2
+ # test_win32_mmap.rb
3
+ #
4
+ # Test suite for the win32-mmap package. This should be run via the
5
+ # 'rake test' task.
6
+ #####################################################################
7
+ require 'test-unit'
8
+ require 'win32/mmap'
9
+ include Win32
10
+
11
+ class TC_Win32_Mmap < Test::Unit::TestCase
12
+ def setup
13
+ @mmap = MMap.new(:name => 'test', :size => 100)
14
+ end
15
+
16
+ test "version is set to expected value" do
17
+ assert_equal('0.4.2', MMap::VERSION)
18
+ end
19
+
20
+ test "dynamic variable names and string values work as expected" do
21
+ assert_nothing_raised{ @mmap.foo = 'test' }
22
+ assert_nothing_raised{ @mmap.bar = 'alpha123' }
23
+ assert_equal('test', @mmap.foo)
24
+ assert_equal('alpha123', @mmap.bar)
25
+ end
26
+
27
+ test "dynamic variable names and integer values work as expected" do
28
+ assert_nothing_raised{ @mmap.bar = 7 }
29
+ assert_nothing_raised{ @mmap.zero = 0 }
30
+ assert_equal(7, @mmap.bar)
31
+ assert_equal(0, @mmap.zero)
32
+ end
33
+
34
+ test "dynamic variable names and hash values work as expected" do
35
+ assert_nothing_raised{ @mmap.ahash = {'foo' => 0} }
36
+ assert_nothing_raised{ @mmap.bhash = {'foo' => 0, 'bar' => 'hello'} }
37
+ assert_equal({'foo' => 0}, @mmap.ahash)
38
+ assert_equal({'foo' => 0, 'bar' => 'hello'}, @mmap.bhash)
39
+ end
40
+
41
+ test "dynamic variable names and array values work as expected" do
42
+ assert_nothing_raised{ @mmap.aarray = [1, 'x', 3] }
43
+ assert_nothing_raised{ @mmap.barray = [{1 => 2}, [1,2,3], 'foo'] }
44
+ assert_equal([1, 'x', 3], @mmap.aarray)
45
+ assert_equal([{1=>2}, [1,2,3], 'foo'], @mmap.barray)
46
+ end
47
+
48
+ test "primitive write/read of file" do
49
+ input = "Greetings, astute reader"
50
+ assert_nothing_raised{ @mmap.write_string(input) }
51
+ assert_equal(input, @mmap.read_string(input.length))
52
+ end
53
+
54
+ test "passing an invalid option raises an argument error" do
55
+ assert_raises(ArgumentError){ MMap.new(:foo => 1) }
56
+ end
57
+
58
+ test "address method basic functionality" do
59
+ assert_respond_to(@mmap, :address)
60
+ assert_kind_of(Fixnum, @mmap.address)
61
+ end
62
+
63
+ test "base_address method basic functionality" do
64
+ assert_respond_to(@mmap, :base_address)
65
+ assert_respond_to(@mmap, :base_address=)
66
+ assert_kind_of(Fixnum, @mmap.base_address)
67
+ end
68
+
69
+ test "name accessor basic functionality" do
70
+ assert_respond_to(@mmap, :name)
71
+ assert_respond_to(@mmap, :name=)
72
+ assert_equal('test', @mmap.name)
73
+ end
74
+
75
+ test "inherit accessor basic functionality" do
76
+ assert_respond_to(@mmap, :inherit?)
77
+ assert_respond_to(@mmap, :inherit=)
78
+ assert_equal(false, @mmap.inherit?)
79
+ end
80
+
81
+ test "size accessor basic functionality" do
82
+ assert_respond_to(@mmap, :size)
83
+ assert_respond_to(@mmap, :size=)
84
+ assert_equal(100, @mmap.size)
85
+ end
86
+
87
+ test "file accessor basic functionality" do
88
+ assert_respond_to(@mmap, :file)
89
+ assert_respond_to(@mmap, :file=)
90
+ assert_nil(@mmap.file)
91
+ end
92
+
93
+ test "access accessor basic functionality" do
94
+ assert_respond_to(@mmap, :access)
95
+ assert_respond_to(@mmap, :access=)
96
+ end
97
+
98
+ test "autolock accessor basic functionality" do
99
+ assert_respond_to(@mmap, :autolock?)
100
+ assert_respond_to(@mmap, :autolock=)
101
+ assert_equal(true, @mmap.autolock?)
102
+ end
103
+
104
+ test "protection accessor basic functionality" do
105
+ assert_respond_to(@mmap, :protection)
106
+ assert_respond_to(@mmap, :protection=)
107
+ assert_equal(4, @mmap.protection)
108
+ end
109
+
110
+ def teardown
111
+ @mmap.close
112
+ end
113
+ end