win32-process 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,121 +1,121 @@
1
- require 'ffi'
2
-
3
- module Process::Constants
4
- include FFI::Library
5
-
6
- private
7
-
8
- # Priority constants
9
-
10
- ABOVE_NORMAL_PRIORITY_CLASS = 0x0008000
11
- BELOW_NORMAL_PRIORITY_CLASS = 0x0004000
12
- HIGH_PRIORITY_CLASS = 0x0000080
13
- IDLE_PRIORITY_CLASS = 0x0000040
14
- NORMAL_PRIORITY_CLASS = 0x0000020
15
- REALTIME_PRIORITY_CLASS = 0x0000010
16
-
17
- # Error constants
18
-
19
- INVALID_HANDLE_VALUE = FFI::Pointer.new(-1).address
20
- ERROR_ACCESS_DENIED = 0x00000005
21
-
22
- # Process Access Rights
23
-
24
- PROCESS_TERMINATE = 0x00000001
25
- PROCESS_SET_INFORMATION = 0x00000200
26
- PROCESS_QUERY_INFORMATION = 0x00000400
27
- PROCESS_ALL_ACCESS = 0x001F0FFF
28
- PROCESS_VM_READ = 0x00000010
29
-
30
- # Process wait time for Process.kill
31
-
32
- INFINITE = 0xFFFFFFFF
33
-
34
- # Process creation flags
35
-
36
- CREATE_BREAKAWAY_FROM_JOB = 0x01000000
37
- CREATE_DEFAULT_ERROR_MODE = 0x04000000
38
- CREATE_NEW_CONSOLE = 0x00000010
39
- CREATE_NEW_PROCESS_GROUP = 0x00000200
40
- CREATE_NO_WINDOW = 0x08000000
41
- CREATE_PROTECTED_PROCESS = 0x00040000
42
- CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x02000000
43
- CREATE_SEPARATE_WOW_VDM = 0x00000800
44
- CREATE_SHARED_WOW_VDM = 0x00001000
45
- CREATE_SUSPENDED = 0x00000004
46
- CREATE_UNICODE_ENVIRONMENT = 0x00000400
47
- DEBUG_ONLY_THIS_PROCESS = 0x00000002
48
- DEBUG_PROCESS = 0x00000001
49
- DETACHED_PROCESS = 0x00000008
50
- INHERIT_PARENT_AFFINITY = 0x00010000
51
-
52
- STARTF_USESHOWWINDOW = 0x00000001
53
- STARTF_USESIZE = 0x00000002
54
- STARTF_USEPOSITION = 0x00000004
55
- STARTF_USECOUNTCHARS = 0x00000008
56
- STARTF_USEFILLATTRIBUTE = 0x00000010
57
- STARTF_RUNFULLSCREEN = 0x00000020
58
- STARTF_FORCEONFEEDBACK = 0x00000040
59
- STARTF_FORCEOFFFEEDBACK = 0x00000080
60
- STARTF_USESTDHANDLES = 0x00000100
61
- STARTF_USEHOTKEY = 0x00000200
62
- STARTF_TITLEISLINKNAME = 0x00000800
63
- STARTF_TITLEISAPPID = 0x00001000
64
- STARTF_PREVENTPINNING = 0x00002000
65
-
66
- LOGON_WITH_PROFILE = 0x00000001
67
- LOGON_NETCREDENTIALS_ONLY = 0x00000002
68
-
69
- SHUTDOWN_NORETRY = 0x00000001
70
-
71
- # Security
72
-
73
- TokenUser = 1
74
- TOKEN_QUERY = 0x00000008
75
-
76
- # Define these for Windows. They are not actually used but are defined
77
- # for interface compatibility.
78
-
79
- PRIO_PROCESS = 0
80
- PRIO_PGRP = 1
81
- PRIO_USER = 2
82
-
83
- # Define these for Windows
84
-
85
- RLIMIT_CPU = 0 # PerProcessUserTimeLimit
86
- RLIMIT_FSIZE = 1 # Hard coded at 4TB - 64K (assumes NTFS)
87
- RLIMIT_AS = 5 # ProcessMemoryLimit
88
- RLIMIT_RSS = 5 # ProcessMemoryLimit
89
- RLIMIT_VMEM = 5 # ProcessMemoryLimit
90
-
91
- # Job constants
92
-
93
- JOB_OBJECT_SET_ATTRIBUTES = 0x00000002
94
- JOB_OBJECT_QUERY = 0x00000004
95
- JOB_OBJECT_LIMIT_PROCESS_TIME = 0x00000002
96
- JOB_OBJECT_LIMIT_PROCESS_MEMORY = 0x00000100
97
- JobObjectExtendedLimitInformation = 9
98
-
99
- # Console Events
100
-
101
- CTRL_C_EVENT = 0
102
- CTRL_BREAK_EVENT = 1
103
-
104
- # Miscellaneous
105
-
106
- HANDLE_FLAG_INHERIT = 0x00000001
107
- SEM_FAILCRITICALERRORS = 0x00000001
108
- SEM_NOGPFAULTERRORBOX = 0x00000002
109
-
110
- # GetExitCodeProcess
111
-
112
- STILL_ACTIVE = 259
113
-
114
- # Snapshot constants
115
-
116
- TH32CS_SNAPHEAPLIST = 0x00000001
117
- TH32CS_SNAPPROCESS = 0x00000002
118
- TH32CS_SNAPTHREAD = 0x00000004
119
- TH32CS_SNAPMODULE = 0x00000008
120
- ERROR_NO_MORE_FILES = 0x00000018
121
- end
1
+ require 'ffi'
2
+
3
+ module Process::Constants
4
+ include FFI::Library
5
+
6
+ private
7
+
8
+ # Priority constants
9
+
10
+ ABOVE_NORMAL_PRIORITY_CLASS = 0x0008000
11
+ BELOW_NORMAL_PRIORITY_CLASS = 0x0004000
12
+ HIGH_PRIORITY_CLASS = 0x0000080
13
+ IDLE_PRIORITY_CLASS = 0x0000040
14
+ NORMAL_PRIORITY_CLASS = 0x0000020
15
+ REALTIME_PRIORITY_CLASS = 0x0000010
16
+
17
+ # Error constants
18
+
19
+ INVALID_HANDLE_VALUE = FFI::Pointer.new(-1).address
20
+ ERROR_ACCESS_DENIED = 0x00000005
21
+
22
+ # Process Access Rights
23
+
24
+ PROCESS_TERMINATE = 0x00000001
25
+ PROCESS_SET_INFORMATION = 0x00000200
26
+ PROCESS_QUERY_INFORMATION = 0x00000400
27
+ PROCESS_ALL_ACCESS = 0x001F0FFF
28
+ PROCESS_VM_READ = 0x00000010
29
+
30
+ # Process wait time for Process.kill
31
+
32
+ INFINITE = 0xFFFFFFFF
33
+
34
+ # Process creation flags
35
+
36
+ CREATE_BREAKAWAY_FROM_JOB = 0x01000000
37
+ CREATE_DEFAULT_ERROR_MODE = 0x04000000
38
+ CREATE_NEW_CONSOLE = 0x00000010
39
+ CREATE_NEW_PROCESS_GROUP = 0x00000200
40
+ CREATE_NO_WINDOW = 0x08000000
41
+ CREATE_PROTECTED_PROCESS = 0x00040000
42
+ CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x02000000
43
+ CREATE_SEPARATE_WOW_VDM = 0x00000800
44
+ CREATE_SHARED_WOW_VDM = 0x00001000
45
+ CREATE_SUSPENDED = 0x00000004
46
+ CREATE_UNICODE_ENVIRONMENT = 0x00000400
47
+ DEBUG_ONLY_THIS_PROCESS = 0x00000002
48
+ DEBUG_PROCESS = 0x00000001
49
+ DETACHED_PROCESS = 0x00000008
50
+ INHERIT_PARENT_AFFINITY = 0x00010000
51
+
52
+ STARTF_USESHOWWINDOW = 0x00000001
53
+ STARTF_USESIZE = 0x00000002
54
+ STARTF_USEPOSITION = 0x00000004
55
+ STARTF_USECOUNTCHARS = 0x00000008
56
+ STARTF_USEFILLATTRIBUTE = 0x00000010
57
+ STARTF_RUNFULLSCREEN = 0x00000020
58
+ STARTF_FORCEONFEEDBACK = 0x00000040
59
+ STARTF_FORCEOFFFEEDBACK = 0x00000080
60
+ STARTF_USESTDHANDLES = 0x00000100
61
+ STARTF_USEHOTKEY = 0x00000200
62
+ STARTF_TITLEISLINKNAME = 0x00000800
63
+ STARTF_TITLEISAPPID = 0x00001000
64
+ STARTF_PREVENTPINNING = 0x00002000
65
+
66
+ LOGON_WITH_PROFILE = 0x00000001
67
+ LOGON_NETCREDENTIALS_ONLY = 0x00000002
68
+
69
+ SHUTDOWN_NORETRY = 0x00000001
70
+
71
+ # Security
72
+
73
+ TokenUser = 1
74
+ TOKEN_QUERY = 0x00000008
75
+
76
+ # Define these for Windows. They are not actually used but are defined
77
+ # for interface compatibility.
78
+
79
+ PRIO_PROCESS = 0
80
+ PRIO_PGRP = 1
81
+ PRIO_USER = 2
82
+
83
+ # Define these for Windows
84
+
85
+ RLIMIT_CPU = 0 # PerProcessUserTimeLimit
86
+ RLIMIT_FSIZE = 1 # Hard coded at 4TB - 64K (assumes NTFS)
87
+ RLIMIT_AS = 5 # ProcessMemoryLimit
88
+ RLIMIT_RSS = 5 # ProcessMemoryLimit
89
+ RLIMIT_VMEM = 5 # ProcessMemoryLimit
90
+
91
+ # Job constants
92
+
93
+ JOB_OBJECT_SET_ATTRIBUTES = 0x00000002
94
+ JOB_OBJECT_QUERY = 0x00000004
95
+ JOB_OBJECT_LIMIT_PROCESS_TIME = 0x00000002
96
+ JOB_OBJECT_LIMIT_PROCESS_MEMORY = 0x00000100
97
+ JobObjectExtendedLimitInformation = 9
98
+
99
+ # Console Events
100
+
101
+ CTRL_C_EVENT = 0
102
+ CTRL_BREAK_EVENT = 1
103
+
104
+ # Miscellaneous
105
+
106
+ HANDLE_FLAG_INHERIT = 0x00000001
107
+ SEM_FAILCRITICALERRORS = 0x00000001
108
+ SEM_NOGPFAULTERRORBOX = 0x00000002
109
+
110
+ # GetExitCodeProcess
111
+
112
+ STILL_ACTIVE = 259
113
+
114
+ # Snapshot constants
115
+
116
+ TH32CS_SNAPHEAPLIST = 0x00000001
117
+ TH32CS_SNAPPROCESS = 0x00000002
118
+ TH32CS_SNAPTHREAD = 0x00000004
119
+ TH32CS_SNAPMODULE = 0x00000008
120
+ ERROR_NO_MORE_FILES = 0x00000018
121
+ end
@@ -1,89 +1,89 @@
1
- if RUBY_PLATFORM == 'java'
2
- require 'rubygems'
3
- gem 'ffi'
4
- end
5
-
6
- require 'ffi'
7
-
8
- module Process::Functions
9
- module FFI::Library
10
- # Wrapper method for attach_function + private
11
- def attach_pfunc(*args)
12
- attach_function(*args)
13
- private args[0]
14
- end
15
- end
16
-
17
- extend FFI::Library
18
-
19
- typedef :ulong, :dword
20
- typedef :uintptr_t, :handle
21
- typedef :uintptr_t, :hwnd
22
- typedef :uintptr_t, :hmodule
23
-
24
- ffi_lib :kernel32
25
-
26
- attach_pfunc :CloseHandle, [:handle], :bool
27
- attach_pfunc :CreateToolhelp32Snapshot, [:dword, :dword], :handle
28
- attach_pfunc :GenerateConsoleCtrlEvent, [:dword, :dword], :bool
29
- attach_pfunc :GetCurrentProcess, [], :handle
30
- attach_pfunc :GetModuleHandle, :GetModuleHandleA, [:string], :hmodule
31
- attach_pfunc :GetProcessAffinityMask, [:handle, :pointer, :pointer], :bool
32
- attach_pfunc :GetPriorityClass, [:handle], :dword
33
- attach_pfunc :GetProcAddress, [:hmodule, :string], :pointer
34
- attach_pfunc :GetVersionExA, [:pointer], :bool
35
- attach_pfunc :Heap32ListFirst, [:handle, :pointer], :bool
36
- attach_pfunc :Heap32ListNext, [:handle, :pointer], :bool
37
- attach_pfunc :Heap32First, [:pointer, :dword, :uintptr_t], :bool
38
- attach_pfunc :Heap32Next, [:pointer], :bool
39
- attach_pfunc :Module32First, [:handle, :pointer], :bool
40
- attach_pfunc :Module32Next, [:handle, :pointer], :bool
41
- attach_pfunc :IsProcessInJob, [:handle, :pointer, :pointer], :bool # 2nd arg optional
42
- attach_pfunc :OpenProcess, [:dword, :bool, :dword], :handle
43
- attach_pfunc :Process32First, [:handle, :pointer], :bool
44
- attach_pfunc :Process32Next, [:handle, :pointer], :bool
45
- attach_pfunc :SetHandleInformation, [:handle, :dword, :dword], :bool
46
- attach_pfunc :SetErrorMode, [:uint], :uint
47
- attach_pfunc :SetPriorityClass, [:handle, :dword], :bool
48
- attach_pfunc :TerminateProcess, [:handle, :uint], :bool
49
- attach_pfunc :Thread32First, [:handle, :pointer], :bool
50
- attach_pfunc :Thread32Next, [:handle, :pointer], :bool
51
- attach_pfunc :WaitForSingleObject, [:handle, :dword], :dword
52
-
53
- attach_pfunc :CreateRemoteThread,
54
- [:handle, :pointer, :size_t, :pointer, :pointer, :dword, :pointer], :handle
55
-
56
- attach_pfunc :GetVolumeInformationA,
57
- [:string, :pointer, :dword, :pointer, :pointer, :pointer, :pointer, :dword], :bool
58
-
59
- attach_pfunc :CreateProcessW,
60
- [:buffer_in, :buffer_in, :pointer, :pointer, :bool,
61
- :dword, :buffer_in, :buffer_in, :pointer, :pointer], :bool
62
-
63
- attach_pfunc :AssignProcessToJobObject, [:handle, :handle], :bool
64
- attach_pfunc :CreateJobObjectA, [:pointer, :string], :handle
65
- attach_pfunc :OpenJobObjectA, [:dword, :bool, :string], :handle
66
- attach_pfunc :QueryInformationJobObject, [:handle, :int, :pointer, :dword, :pointer], :bool
67
- attach_pfunc :SetInformationJobObject, [:handle, :int, :pointer, :dword], :bool
68
- attach_pfunc :GetExitCodeProcess, [:handle, :pointer], :bool
69
-
70
- ffi_lib :advapi32
71
-
72
- attach_pfunc :ConvertSidToStringSidA, [:buffer_in, :pointer], :bool
73
- attach_pfunc :GetTokenInformation, [:handle, :int, :pointer, :dword, :pointer], :bool
74
- attach_pfunc :OpenProcessToken, [:handle, :dword, :pointer], :bool
75
-
76
- attach_pfunc :CreateProcessWithLogonW,
77
- [:buffer_in, :buffer_in, :buffer_in, :dword, :buffer_in, :buffer_in,
78
- :dword, :buffer_in, :buffer_in, :pointer, :pointer], :bool
79
-
80
- ffi_lib FFI::Library::LIBC
81
-
82
- attach_pfunc :get_osfhandle, :_get_osfhandle, [:int], :intptr_t
83
-
84
- begin
85
- attach_pfunc :get_errno, :_get_errno, [:pointer], :int
86
- rescue FFI::NotFoundError
87
- # Do nothing, Windows XP or earlier.
88
- end
89
- end
1
+ if RUBY_PLATFORM == 'java'
2
+ require 'rubygems'
3
+ gem 'ffi'
4
+ end
5
+
6
+ require 'ffi'
7
+
8
+ module Process::Functions
9
+ module FFI::Library
10
+ # Wrapper method for attach_function + private
11
+ def attach_pfunc(*args)
12
+ attach_function(*args)
13
+ private args[0]
14
+ end
15
+ end
16
+
17
+ extend FFI::Library
18
+
19
+ typedef :ulong, :dword
20
+ typedef :uintptr_t, :handle
21
+ typedef :uintptr_t, :hwnd
22
+ typedef :uintptr_t, :hmodule
23
+
24
+ ffi_lib :kernel32
25
+
26
+ attach_pfunc :CloseHandle, [:handle], :bool
27
+ attach_pfunc :CreateToolhelp32Snapshot, [:dword, :dword], :handle
28
+ attach_pfunc :GenerateConsoleCtrlEvent, [:dword, :dword], :bool
29
+ attach_pfunc :GetCurrentProcess, [], :handle
30
+ attach_pfunc :GetModuleHandle, :GetModuleHandleA, [:string], :hmodule
31
+ attach_pfunc :GetProcessAffinityMask, [:handle, :pointer, :pointer], :bool
32
+ attach_pfunc :GetPriorityClass, [:handle], :dword
33
+ attach_pfunc :GetProcAddress, [:hmodule, :string], :pointer
34
+ attach_pfunc :GetVersionExA, [:pointer], :bool
35
+ attach_pfunc :Heap32ListFirst, [:handle, :pointer], :bool
36
+ attach_pfunc :Heap32ListNext, [:handle, :pointer], :bool
37
+ attach_pfunc :Heap32First, [:pointer, :dword, :uintptr_t], :bool
38
+ attach_pfunc :Heap32Next, [:pointer], :bool
39
+ attach_pfunc :Module32First, [:handle, :pointer], :bool
40
+ attach_pfunc :Module32Next, [:handle, :pointer], :bool
41
+ attach_pfunc :IsProcessInJob, [:handle, :pointer, :pointer], :bool # 2nd arg optional
42
+ attach_pfunc :OpenProcess, [:dword, :int, :dword], :handle
43
+ attach_pfunc :Process32First, [:handle, :pointer], :bool
44
+ attach_pfunc :Process32Next, [:handle, :pointer], :bool
45
+ attach_pfunc :SetHandleInformation, [:handle, :dword, :dword], :bool
46
+ attach_pfunc :SetErrorMode, [:uint], :uint
47
+ attach_pfunc :SetPriorityClass, [:handle, :dword], :bool
48
+ attach_pfunc :TerminateProcess, [:handle, :uint], :bool
49
+ attach_pfunc :Thread32First, [:handle, :pointer], :bool
50
+ attach_pfunc :Thread32Next, [:handle, :pointer], :bool
51
+ attach_pfunc :WaitForSingleObject, [:handle, :dword], :dword
52
+
53
+ attach_pfunc :CreateRemoteThread,
54
+ [:handle, :pointer, :size_t, :pointer, :pointer, :dword, :pointer], :handle
55
+
56
+ attach_pfunc :GetVolumeInformationA,
57
+ [:string, :pointer, :dword, :pointer, :pointer, :pointer, :pointer, :dword], :bool
58
+
59
+ attach_pfunc :CreateProcessW,
60
+ [:buffer_in, :buffer_inout, :pointer, :pointer, :int,
61
+ :dword, :buffer_in, :buffer_in, :pointer, :pointer], :bool
62
+
63
+ attach_pfunc :AssignProcessToJobObject, [:handle, :handle], :bool
64
+ attach_pfunc :CreateJobObjectA, [:pointer, :string], :handle
65
+ attach_pfunc :OpenJobObjectA, [:dword, :int, :string], :handle
66
+ attach_pfunc :QueryInformationJobObject, [:handle, :int, :pointer, :dword, :pointer], :bool
67
+ attach_pfunc :SetInformationJobObject, [:handle, :int, :pointer, :dword], :bool
68
+ attach_pfunc :GetExitCodeProcess, [:handle, :pointer], :bool
69
+
70
+ ffi_lib :advapi32
71
+
72
+ attach_pfunc :ConvertSidToStringSidA, [:buffer_in, :pointer], :bool
73
+ attach_pfunc :GetTokenInformation, [:handle, :int, :pointer, :dword, :pointer], :bool
74
+ attach_pfunc :OpenProcessToken, [:handle, :dword, :pointer], :bool
75
+
76
+ attach_pfunc :CreateProcessWithLogonW,
77
+ [:buffer_in, :buffer_in, :buffer_in, :dword, :buffer_in, :buffer_in,
78
+ :dword, :buffer_in, :buffer_in, :pointer, :pointer], :bool
79
+
80
+ ffi_lib FFI::Library::LIBC
81
+
82
+ attach_pfunc :get_osfhandle, :_get_osfhandle, [:int], :intptr_t
83
+
84
+ begin
85
+ attach_pfunc :get_errno, :_get_errno, [:pointer], :int
86
+ rescue FFI::NotFoundError
87
+ # Do nothing, Windows XP or earlier.
88
+ end
89
+ end
@@ -1,13 +1,13 @@
1
- class String
2
- # Convert a regular string to a wide character string. This does not
3
- # modify the receiver.
4
- def to_wide_string
5
- (self + 0.chr).encode('UTF-16LE')
6
- end
7
-
8
- # Convert a regular string to a wide character string. This modifies
9
- # the receiver.
10
- def to_wide_string!
11
- replace((self + 0.chr).encode('UTF-16LE'))
12
- end
1
+ class String
2
+ # Convert a regular string to a wide character string. This does not
3
+ # modify the receiver.
4
+ def to_wide_string
5
+ (self + 0.chr).encode('UTF-16LE')
6
+ end
7
+
8
+ # Convert a regular string to a wide character string. This modifies
9
+ # the receiver.
10
+ def to_wide_string!
11
+ replace((self + 0.chr).encode('UTF-16LE'))
12
+ end
13
13
  end
@@ -1,218 +1,218 @@
1
- if RUBY_PLATFORM == 'java'
2
- require 'rubygems'
3
- gem 'ffi'
4
- end
5
-
6
- require 'ffi'
7
-
8
- module Process::Structs
9
- extend FFI::Library
10
-
11
- typedef :ulong, :dword
12
- typedef :uintptr_t, :handle
13
- typedef :short, :word
14
-
15
- private
16
-
17
- # sizeof(LARGE_INTEGER) == 8
18
- class LARGE_INTEGER < FFI::Union
19
- layout(:QuadPart, :long_long)
20
- end
21
-
22
- # sizeof(IO_COUNTERS) == 48
23
- class IO_COUNTERS < FFI::Struct
24
- layout(
25
- :ReadOperationCount, :ulong_long,
26
- :WriteOperationCount, :ulong_long,
27
- :OtherOperationCount, :ulong_long,
28
- :ReadTransferCount, :ulong_long,
29
- :WriteTransferCount, :ulong_long,
30
- :OtherTransferCount, :ulong_long
31
- )
32
- end
33
-
34
- class JOBJECT_BASIC_LIMIT_INFORMATION < FFI::Struct
35
- layout(
36
- :PerProcessUserTimeLimit, LARGE_INTEGER,
37
- :PerJobUserTimeLimit, LARGE_INTEGER,
38
- :LimitFlags, :dword,
39
- :MinimumWorkingSetSize, :size_t,
40
- :MaximumWorkingSetSize, :size_t,
41
- :ActiveProcessLimit, :dword,
42
- :Affinity, :pointer,
43
- :PriorityClass, :dword,
44
- :SchedulingClass, :dword
45
- )
46
- end
47
-
48
- class JOBJECT_EXTENDED_LIMIT_INFORMATION < FFI::Struct
49
- layout(
50
- :BasicLimitInformation, JOBJECT_BASIC_LIMIT_INFORMATION,
51
- :IoInfo, IO_COUNTERS,
52
- :ProcessMemoryLimit, :size_t,
53
- :JobMemoryLimit, :size_t,
54
- :PeakProcessMemoryUsed, :size_t,
55
- :PeakJobMemoryUsed, :size_t
56
- )
57
- end
58
-
59
- class SECURITY_ATTRIBUTES < FFI::Struct
60
- layout(
61
- :nLength, :dword,
62
- :lpSecurityDescriptor, :pointer,
63
- :bInheritHandle, :bool
64
- )
65
- end
66
-
67
- # sizeof(STARTUPINFO) == 68
68
- class STARTUPINFO < FFI::Struct
69
- layout(
70
- :cb, :ulong,
71
- :lpReserved, :string,
72
- :lpDesktop, :string,
73
- :lpTitle, :string,
74
- :dwX, :dword,
75
- :dwY, :dword,
76
- :dwXSize, :dword,
77
- :dwYSize, :dword,
78
- :dwXCountChars, :dword,
79
- :dwYCountChars, :dword,
80
- :dwFillAttribute, :dword,
81
- :dwFlags, :dword,
82
- :wShowWindow, :word,
83
- :cbReserved2, :word,
84
- :lpReserved2, :pointer,
85
- :hStdInput, :handle,
86
- :hStdOutput, :handle,
87
- :hStdError, :handle
88
- )
89
- end
90
-
91
- class PROCESS_INFORMATION < FFI::Struct
92
- layout(
93
- :hProcess, :handle,
94
- :hThread, :handle,
95
- :dwProcessId, :ulong,
96
- :dwThreadId, :ulong
97
- )
98
- end
99
-
100
- class OSVERSIONINFO < FFI::Struct
101
- layout(
102
- :dwOSVersionInfoSize, :dword,
103
- :dwMajorVersion, :dword,
104
- :dwMinorVersion, :dword,
105
- :dwBuildNumber, :dword,
106
- :dwPlatformId, :dword,
107
- :szCSDVersion, [:char, 128]
108
- )
109
- end
110
-
111
- class THREADENTRY32 < FFI::Struct
112
- layout(
113
- :dwSize, :dword,
114
- :cntUsage, :dword,
115
- :th32ThreadID, :dword,
116
- :th32OwnerProcessID, :dword,
117
- :tpBasePri, :long,
118
- :tpDeltaPri, :long,
119
- :dwFlags, :dword
120
- )
121
- end
122
-
123
- class HEAPLIST32 < FFI::Struct
124
- layout(
125
- :dwSize, :size_t,
126
- :th32ProcessID, :dword,
127
- :th32HeapID, :uintptr_t,
128
- :dwFlags, :dword
129
- )
130
- end
131
-
132
- class HEAPENTRY32 < FFI::Struct
133
- layout(
134
- :dwSize, :size_t,
135
- :hHandle, :handle,
136
- :dwAddress, :uintptr_t,
137
- :dwBlockSize, :size_t,
138
- :dwFlags, :dword,
139
- :dwLockCount, :dword,
140
- :dwResvd, :dword,
141
- :th32ProcessID, :dword,
142
- :th32HeapID, :uintptr_t
143
- )
144
- end
145
-
146
- class MODULEENTRY32 < FFI::Struct
147
- layout(
148
- :dwSize, :dword,
149
- :th32ModuleID, :dword,
150
- :th32ProcessID, :dword,
151
- :GlblcntUsage, :dword,
152
- :ProccntUsage, :dword,
153
- :modBaseAddr, :pointer,
154
- :modBaseSize, :dword,
155
- :hModule, :handle,
156
- :szModule, [:char, 256],
157
- :szExePath, [:char, 260]
158
- )
159
- end
160
-
161
- class PROCESSENTRY32 < FFI::Struct
162
- layout(
163
- :dwSize, :dword,
164
- :cntUsage, :dword,
165
- :th32ProcessID, :dword,
166
- :th32DefaultHeapID, :uintptr_t,
167
- :th32ModuleID, :dword,
168
- :cntThreads, :dword,
169
- :th32ParentProcessID, :dword,
170
- :pcPriClassBase, :long,
171
- :dwFlags, :dword,
172
- :szExeFile, [:char, 260]
173
- )
174
- end
175
-
176
- # Used by Process.create
177
-
178
- ProcessInfo = Struct.new("ProcessInfo",
179
- :process_handle,
180
- :thread_handle,
181
- :process_id,
182
- :thread_id
183
- )
184
-
185
- # Used by Process.snapshot
186
-
187
- ThreadSnapInfo = Struct.new("ThreadSnapInfo",
188
- :thread_id,
189
- :process_id,
190
- :base_priority
191
- )
192
-
193
- HeapSnapInfo = Struct.new("HeapSnapInfo",
194
- :address,
195
- :block_size,
196
- :flags,
197
- :process_id,
198
- :heap_id
199
- )
200
-
201
- ModuleSnapInfo = Struct.new("ModuleSnapInfo",
202
- :process_id,
203
- :address,
204
- :module_size,
205
- :handle,
206
- :name,
207
- :path
208
- )
209
-
210
- ProcessSnapInfo = Struct.new("ProcessSnapInfo",
211
- :process_id,
212
- :threads,
213
- :parent_process_id,
214
- :priority,
215
- :flags,
216
- :path
217
- )
218
- end
1
+ if RUBY_PLATFORM == 'java'
2
+ require 'rubygems'
3
+ gem 'ffi'
4
+ end
5
+
6
+ require 'ffi'
7
+
8
+ module Process::Structs
9
+ extend FFI::Library
10
+
11
+ typedef :ulong, :dword
12
+ typedef :uintptr_t, :handle
13
+ typedef :short, :word
14
+
15
+ private
16
+
17
+ # sizeof(LARGE_INTEGER) == 8
18
+ class LARGE_INTEGER < FFI::Union
19
+ layout(:QuadPart, :long_long)
20
+ end
21
+
22
+ # sizeof(IO_COUNTERS) == 48
23
+ class IO_COUNTERS < FFI::Struct
24
+ layout(
25
+ :ReadOperationCount, :ulong_long,
26
+ :WriteOperationCount, :ulong_long,
27
+ :OtherOperationCount, :ulong_long,
28
+ :ReadTransferCount, :ulong_long,
29
+ :WriteTransferCount, :ulong_long,
30
+ :OtherTransferCount, :ulong_long
31
+ )
32
+ end
33
+
34
+ class JOBJECT_BASIC_LIMIT_INFORMATION < FFI::Struct
35
+ layout(
36
+ :PerProcessUserTimeLimit, LARGE_INTEGER,
37
+ :PerJobUserTimeLimit, LARGE_INTEGER,
38
+ :LimitFlags, :dword,
39
+ :MinimumWorkingSetSize, :size_t,
40
+ :MaximumWorkingSetSize, :size_t,
41
+ :ActiveProcessLimit, :dword,
42
+ :Affinity, :pointer,
43
+ :PriorityClass, :dword,
44
+ :SchedulingClass, :dword
45
+ )
46
+ end
47
+
48
+ class JOBJECT_EXTENDED_LIMIT_INFORMATION < FFI::Struct
49
+ layout(
50
+ :BasicLimitInformation, JOBJECT_BASIC_LIMIT_INFORMATION,
51
+ :IoInfo, IO_COUNTERS,
52
+ :ProcessMemoryLimit, :size_t,
53
+ :JobMemoryLimit, :size_t,
54
+ :PeakProcessMemoryUsed, :size_t,
55
+ :PeakJobMemoryUsed, :size_t
56
+ )
57
+ end
58
+
59
+ class SECURITY_ATTRIBUTES < FFI::Struct
60
+ layout(
61
+ :nLength, :dword,
62
+ :lpSecurityDescriptor, :pointer,
63
+ :bInheritHandle, :int
64
+ )
65
+ end
66
+
67
+ # sizeof(STARTUPINFO) == 68
68
+ class STARTUPINFO < FFI::Struct
69
+ layout(
70
+ :cb, :ulong,
71
+ :lpReserved, :string,
72
+ :lpDesktop, :string,
73
+ :lpTitle, :string,
74
+ :dwX, :dword,
75
+ :dwY, :dword,
76
+ :dwXSize, :dword,
77
+ :dwYSize, :dword,
78
+ :dwXCountChars, :dword,
79
+ :dwYCountChars, :dword,
80
+ :dwFillAttribute, :dword,
81
+ :dwFlags, :dword,
82
+ :wShowWindow, :word,
83
+ :cbReserved2, :word,
84
+ :lpReserved2, :pointer,
85
+ :hStdInput, :handle,
86
+ :hStdOutput, :handle,
87
+ :hStdError, :handle
88
+ )
89
+ end
90
+
91
+ class PROCESS_INFORMATION < FFI::Struct
92
+ layout(
93
+ :hProcess, :handle,
94
+ :hThread, :handle,
95
+ :dwProcessId, :ulong,
96
+ :dwThreadId, :ulong
97
+ )
98
+ end
99
+
100
+ class OSVERSIONINFO < FFI::Struct
101
+ layout(
102
+ :dwOSVersionInfoSize, :dword,
103
+ :dwMajorVersion, :dword,
104
+ :dwMinorVersion, :dword,
105
+ :dwBuildNumber, :dword,
106
+ :dwPlatformId, :dword,
107
+ :szCSDVersion, [:char, 128]
108
+ )
109
+ end
110
+
111
+ class THREADENTRY32 < FFI::Struct
112
+ layout(
113
+ :dwSize, :dword,
114
+ :cntUsage, :dword,
115
+ :th32ThreadID, :dword,
116
+ :th32OwnerProcessID, :dword,
117
+ :tpBasePri, :long,
118
+ :tpDeltaPri, :long,
119
+ :dwFlags, :dword
120
+ )
121
+ end
122
+
123
+ class HEAPLIST32 < FFI::Struct
124
+ layout(
125
+ :dwSize, :size_t,
126
+ :th32ProcessID, :dword,
127
+ :th32HeapID, :uintptr_t,
128
+ :dwFlags, :dword
129
+ )
130
+ end
131
+
132
+ class HEAPENTRY32 < FFI::Struct
133
+ layout(
134
+ :dwSize, :size_t,
135
+ :hHandle, :handle,
136
+ :dwAddress, :uintptr_t,
137
+ :dwBlockSize, :size_t,
138
+ :dwFlags, :dword,
139
+ :dwLockCount, :dword,
140
+ :dwResvd, :dword,
141
+ :th32ProcessID, :dword,
142
+ :th32HeapID, :uintptr_t
143
+ )
144
+ end
145
+
146
+ class MODULEENTRY32 < FFI::Struct
147
+ layout(
148
+ :dwSize, :dword,
149
+ :th32ModuleID, :dword,
150
+ :th32ProcessID, :dword,
151
+ :GlblcntUsage, :dword,
152
+ :ProccntUsage, :dword,
153
+ :modBaseAddr, :pointer,
154
+ :modBaseSize, :dword,
155
+ :hModule, :handle,
156
+ :szModule, [:char, 256],
157
+ :szExePath, [:char, 260]
158
+ )
159
+ end
160
+
161
+ class PROCESSENTRY32 < FFI::Struct
162
+ layout(
163
+ :dwSize, :dword,
164
+ :cntUsage, :dword,
165
+ :th32ProcessID, :dword,
166
+ :th32DefaultHeapID, :uintptr_t,
167
+ :th32ModuleID, :dword,
168
+ :cntThreads, :dword,
169
+ :th32ParentProcessID, :dword,
170
+ :pcPriClassBase, :long,
171
+ :dwFlags, :dword,
172
+ :szExeFile, [:char, 260]
173
+ )
174
+ end
175
+
176
+ # Used by Process.create
177
+
178
+ ProcessInfo = Struct.new("ProcessInfo",
179
+ :process_handle,
180
+ :thread_handle,
181
+ :process_id,
182
+ :thread_id
183
+ )
184
+
185
+ # Used by Process.snapshot
186
+
187
+ ThreadSnapInfo = Struct.new("ThreadSnapInfo",
188
+ :thread_id,
189
+ :process_id,
190
+ :base_priority
191
+ )
192
+
193
+ HeapSnapInfo = Struct.new("HeapSnapInfo",
194
+ :address,
195
+ :block_size,
196
+ :flags,
197
+ :process_id,
198
+ :heap_id
199
+ )
200
+
201
+ ModuleSnapInfo = Struct.new("ModuleSnapInfo",
202
+ :process_id,
203
+ :address,
204
+ :module_size,
205
+ :handle,
206
+ :name,
207
+ :path
208
+ )
209
+
210
+ ProcessSnapInfo = Struct.new("ProcessSnapInfo",
211
+ :process_id,
212
+ :threads,
213
+ :parent_process_id,
214
+ :priority,
215
+ :flags,
216
+ :path
217
+ )
218
+ end