win32-process 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +226 -221
- data/MANIFEST +9 -9
- data/README +76 -76
- data/Rakefile +58 -58
- data/examples/example_create.rb +35 -35
- data/examples/example_kill.rb +34 -34
- data/lib/win32/process.rb +894 -881
- data/lib/win32/process/constants.rb +105 -105
- data/lib/win32/process/functions.rb +72 -66
- data/lib/win32/process/helper.rb +13 -13
- data/lib/win32/process/structs.rb +114 -103
- data/test/test_win32_process.rb +319 -319
- data/test/test_win32_process_kill.rb +144 -144
- data/win32-process.gemspec +27 -27
- metadata +2 -2
@@ -1,105 +1,105 @@
|
|
1
|
-
module Process::Constants
|
2
|
-
private
|
3
|
-
|
4
|
-
# Priority constants
|
5
|
-
|
6
|
-
ABOVE_NORMAL_PRIORITY_CLASS = 0x0008000
|
7
|
-
BELOW_NORMAL_PRIORITY_CLASS = 0x0004000
|
8
|
-
HIGH_PRIORITY_CLASS = 0x0000080
|
9
|
-
IDLE_PRIORITY_CLASS = 0x0000040
|
10
|
-
NORMAL_PRIORITY_CLASS = 0x0000020
|
11
|
-
REALTIME_PRIORITY_CLASS = 0x0000010
|
12
|
-
|
13
|
-
# Error constants
|
14
|
-
|
15
|
-
INVALID_HANDLE_VALUE = 0xffffffff
|
16
|
-
ERROR_ACCESS_DENIED = 0x00000005
|
17
|
-
|
18
|
-
# Process Access Rights
|
19
|
-
|
20
|
-
PROCESS_TERMINATE = 0x00000001
|
21
|
-
PROCESS_SET_INFORMATION = 0x00000200
|
22
|
-
PROCESS_QUERY_INFORMATION = 0x00000400
|
23
|
-
PROCESS_ALL_ACCESS = 0x001F0FFF
|
24
|
-
PROCESS_VM_READ = 0x00000010
|
25
|
-
|
26
|
-
# Process wait time for Process.kill
|
27
|
-
|
28
|
-
INFINITE = 0xFFFFFFFF
|
29
|
-
|
30
|
-
# Process creation flags
|
31
|
-
|
32
|
-
CREATE_BREAKAWAY_FROM_JOB = 0x01000000
|
33
|
-
CREATE_DEFAULT_ERROR_MODE = 0x04000000
|
34
|
-
CREATE_NEW_CONSOLE = 0x00000010
|
35
|
-
CREATE_NEW_PROCESS_GROUP = 0x00000200
|
36
|
-
CREATE_NO_WINDOW = 0x08000000
|
37
|
-
CREATE_PROTECTED_PROCESS = 0x00040000
|
38
|
-
CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x02000000
|
39
|
-
CREATE_SEPARATE_WOW_VDM = 0x00000800
|
40
|
-
CREATE_SHARED_WOW_VDM = 0x00001000
|
41
|
-
CREATE_SUSPENDED = 0x00000004
|
42
|
-
CREATE_UNICODE_ENVIRONMENT = 0x00000400
|
43
|
-
DEBUG_ONLY_THIS_PROCESS = 0x00000002
|
44
|
-
DEBUG_PROCESS = 0x00000001
|
45
|
-
DETACHED_PROCESS = 0x00000008
|
46
|
-
INHERIT_PARENT_AFFINITY = 0x00010000
|
47
|
-
|
48
|
-
STARTF_USESHOWWINDOW = 0x00000001
|
49
|
-
STARTF_USESIZE = 0x00000002
|
50
|
-
STARTF_USEPOSITION = 0x00000004
|
51
|
-
STARTF_USECOUNTCHARS = 0x00000008
|
52
|
-
STARTF_USEFILLATTRIBUTE = 0x00000010
|
53
|
-
STARTF_RUNFULLSCREEN = 0x00000020
|
54
|
-
STARTF_FORCEONFEEDBACK = 0x00000040
|
55
|
-
STARTF_FORCEOFFFEEDBACK = 0x00000080
|
56
|
-
STARTF_USESTDHANDLES = 0x00000100
|
57
|
-
STARTF_USEHOTKEY = 0x00000200
|
58
|
-
STARTF_TITLEISLINKNAME = 0x00000800
|
59
|
-
STARTF_TITLEISAPPID = 0x00001000
|
60
|
-
STARTF_PREVENTPINNING = 0x00002000
|
61
|
-
|
62
|
-
LOGON_WITH_PROFILE = 0x00000001
|
63
|
-
LOGON_NETCREDENTIALS_ONLY = 0x00000002
|
64
|
-
|
65
|
-
SHUTDOWN_NORETRY = 0x00000001
|
66
|
-
|
67
|
-
# Security
|
68
|
-
|
69
|
-
TokenUser = 1
|
70
|
-
TOKEN_QUERY = 0x00000008
|
71
|
-
|
72
|
-
# Define these for Windows. They are not actually used but are defined
|
73
|
-
# for interface compatibility.
|
74
|
-
|
75
|
-
PRIO_PROCESS = 0
|
76
|
-
PRIO_PGRP = 1
|
77
|
-
PRIO_USER = 2
|
78
|
-
|
79
|
-
# Define these for Windows
|
80
|
-
|
81
|
-
RLIMIT_CPU = 0 # PerProcessUserTimeLimit
|
82
|
-
RLIMIT_FSIZE = 1 # Hard coded at 4TB - 64K (assumes NTFS)
|
83
|
-
RLIMIT_AS = 5 # ProcessMemoryLimit
|
84
|
-
RLIMIT_RSS = 5 # ProcessMemoryLimit
|
85
|
-
RLIMIT_VMEM = 5 # ProcessMemoryLimit
|
86
|
-
|
87
|
-
# Job constants
|
88
|
-
|
89
|
-
JOB_OBJECT_SET_ATTRIBUTES = 0x00000002
|
90
|
-
JOB_OBJECT_QUERY = 0x00000004
|
91
|
-
JOB_OBJECT_LIMIT_PROCESS_TIME = 0x00000002
|
92
|
-
JOB_OBJECT_LIMIT_PROCESS_MEMORY = 0x00000100
|
93
|
-
JobObjectExtendedLimitInformation = 9
|
94
|
-
|
95
|
-
# Console Events
|
96
|
-
|
97
|
-
CTRL_C_EVENT = 0
|
98
|
-
CTRL_BREAK_EVENT = 1
|
99
|
-
|
100
|
-
# Miscellaneous
|
101
|
-
|
102
|
-
HANDLE_FLAG_INHERIT = 0x00000001
|
103
|
-
SEM_FAILCRITICALERRORS = 0x00000001
|
104
|
-
SEM_NOGPFAULTERRORBOX = 0x00000002
|
105
|
-
end
|
1
|
+
module Process::Constants
|
2
|
+
private
|
3
|
+
|
4
|
+
# Priority constants
|
5
|
+
|
6
|
+
ABOVE_NORMAL_PRIORITY_CLASS = 0x0008000
|
7
|
+
BELOW_NORMAL_PRIORITY_CLASS = 0x0004000
|
8
|
+
HIGH_PRIORITY_CLASS = 0x0000080
|
9
|
+
IDLE_PRIORITY_CLASS = 0x0000040
|
10
|
+
NORMAL_PRIORITY_CLASS = 0x0000020
|
11
|
+
REALTIME_PRIORITY_CLASS = 0x0000010
|
12
|
+
|
13
|
+
# Error constants
|
14
|
+
|
15
|
+
INVALID_HANDLE_VALUE = 0xffffffff
|
16
|
+
ERROR_ACCESS_DENIED = 0x00000005
|
17
|
+
|
18
|
+
# Process Access Rights
|
19
|
+
|
20
|
+
PROCESS_TERMINATE = 0x00000001
|
21
|
+
PROCESS_SET_INFORMATION = 0x00000200
|
22
|
+
PROCESS_QUERY_INFORMATION = 0x00000400
|
23
|
+
PROCESS_ALL_ACCESS = 0x001F0FFF
|
24
|
+
PROCESS_VM_READ = 0x00000010
|
25
|
+
|
26
|
+
# Process wait time for Process.kill
|
27
|
+
|
28
|
+
INFINITE = 0xFFFFFFFF
|
29
|
+
|
30
|
+
# Process creation flags
|
31
|
+
|
32
|
+
CREATE_BREAKAWAY_FROM_JOB = 0x01000000
|
33
|
+
CREATE_DEFAULT_ERROR_MODE = 0x04000000
|
34
|
+
CREATE_NEW_CONSOLE = 0x00000010
|
35
|
+
CREATE_NEW_PROCESS_GROUP = 0x00000200
|
36
|
+
CREATE_NO_WINDOW = 0x08000000
|
37
|
+
CREATE_PROTECTED_PROCESS = 0x00040000
|
38
|
+
CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x02000000
|
39
|
+
CREATE_SEPARATE_WOW_VDM = 0x00000800
|
40
|
+
CREATE_SHARED_WOW_VDM = 0x00001000
|
41
|
+
CREATE_SUSPENDED = 0x00000004
|
42
|
+
CREATE_UNICODE_ENVIRONMENT = 0x00000400
|
43
|
+
DEBUG_ONLY_THIS_PROCESS = 0x00000002
|
44
|
+
DEBUG_PROCESS = 0x00000001
|
45
|
+
DETACHED_PROCESS = 0x00000008
|
46
|
+
INHERIT_PARENT_AFFINITY = 0x00010000
|
47
|
+
|
48
|
+
STARTF_USESHOWWINDOW = 0x00000001
|
49
|
+
STARTF_USESIZE = 0x00000002
|
50
|
+
STARTF_USEPOSITION = 0x00000004
|
51
|
+
STARTF_USECOUNTCHARS = 0x00000008
|
52
|
+
STARTF_USEFILLATTRIBUTE = 0x00000010
|
53
|
+
STARTF_RUNFULLSCREEN = 0x00000020
|
54
|
+
STARTF_FORCEONFEEDBACK = 0x00000040
|
55
|
+
STARTF_FORCEOFFFEEDBACK = 0x00000080
|
56
|
+
STARTF_USESTDHANDLES = 0x00000100
|
57
|
+
STARTF_USEHOTKEY = 0x00000200
|
58
|
+
STARTF_TITLEISLINKNAME = 0x00000800
|
59
|
+
STARTF_TITLEISAPPID = 0x00001000
|
60
|
+
STARTF_PREVENTPINNING = 0x00002000
|
61
|
+
|
62
|
+
LOGON_WITH_PROFILE = 0x00000001
|
63
|
+
LOGON_NETCREDENTIALS_ONLY = 0x00000002
|
64
|
+
|
65
|
+
SHUTDOWN_NORETRY = 0x00000001
|
66
|
+
|
67
|
+
# Security
|
68
|
+
|
69
|
+
TokenUser = 1
|
70
|
+
TOKEN_QUERY = 0x00000008
|
71
|
+
|
72
|
+
# Define these for Windows. They are not actually used but are defined
|
73
|
+
# for interface compatibility.
|
74
|
+
|
75
|
+
PRIO_PROCESS = 0
|
76
|
+
PRIO_PGRP = 1
|
77
|
+
PRIO_USER = 2
|
78
|
+
|
79
|
+
# Define these for Windows
|
80
|
+
|
81
|
+
RLIMIT_CPU = 0 # PerProcessUserTimeLimit
|
82
|
+
RLIMIT_FSIZE = 1 # Hard coded at 4TB - 64K (assumes NTFS)
|
83
|
+
RLIMIT_AS = 5 # ProcessMemoryLimit
|
84
|
+
RLIMIT_RSS = 5 # ProcessMemoryLimit
|
85
|
+
RLIMIT_VMEM = 5 # ProcessMemoryLimit
|
86
|
+
|
87
|
+
# Job constants
|
88
|
+
|
89
|
+
JOB_OBJECT_SET_ATTRIBUTES = 0x00000002
|
90
|
+
JOB_OBJECT_QUERY = 0x00000004
|
91
|
+
JOB_OBJECT_LIMIT_PROCESS_TIME = 0x00000002
|
92
|
+
JOB_OBJECT_LIMIT_PROCESS_MEMORY = 0x00000100
|
93
|
+
JobObjectExtendedLimitInformation = 9
|
94
|
+
|
95
|
+
# Console Events
|
96
|
+
|
97
|
+
CTRL_C_EVENT = 0
|
98
|
+
CTRL_BREAK_EVENT = 1
|
99
|
+
|
100
|
+
# Miscellaneous
|
101
|
+
|
102
|
+
HANDLE_FLAG_INHERIT = 0x00000001
|
103
|
+
SEM_FAILCRITICALERRORS = 0x00000001
|
104
|
+
SEM_NOGPFAULTERRORBOX = 0x00000002
|
105
|
+
end
|
@@ -1,66 +1,72 @@
|
|
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
|
-
ffi_lib :kernel32
|
20
|
-
|
21
|
-
attach_pfunc :CloseHandle, [:ulong], :bool
|
22
|
-
attach_pfunc :GenerateConsoleCtrlEvent, [:ulong, :ulong], :bool
|
23
|
-
attach_pfunc :GetCurrentProcess, [], :ulong
|
24
|
-
attach_pfunc :GetModuleHandle, :GetModuleHandleA, [:string], :ulong
|
25
|
-
attach_pfunc :GetProcessAffinityMask, [:ulong, :pointer, :pointer], :bool
|
26
|
-
attach_pfunc :GetPriorityClass, [:ulong], :ulong
|
27
|
-
attach_pfunc :GetProcAddress, [:ulong, :string], :ulong
|
28
|
-
attach_pfunc :
|
29
|
-
attach_pfunc :
|
30
|
-
attach_pfunc :
|
31
|
-
attach_pfunc :
|
32
|
-
attach_pfunc :
|
33
|
-
attach_pfunc :
|
34
|
-
attach_pfunc :
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
attach_pfunc :
|
48
|
-
attach_pfunc :
|
49
|
-
attach_pfunc :
|
50
|
-
attach_pfunc :
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
attach_pfunc :
|
56
|
-
attach_pfunc :
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
attach_pfunc :get_osfhandle, :_get_osfhandle, [:int], :ulong
|
66
|
-
|
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
|
+
ffi_lib :kernel32
|
20
|
+
|
21
|
+
attach_pfunc :CloseHandle, [:ulong], :bool
|
22
|
+
attach_pfunc :GenerateConsoleCtrlEvent, [:ulong, :ulong], :bool
|
23
|
+
attach_pfunc :GetCurrentProcess, [], :ulong
|
24
|
+
attach_pfunc :GetModuleHandle, :GetModuleHandleA, [:string], :ulong
|
25
|
+
attach_pfunc :GetProcessAffinityMask, [:ulong, :pointer, :pointer], :bool
|
26
|
+
attach_pfunc :GetPriorityClass, [:ulong], :ulong
|
27
|
+
attach_pfunc :GetProcAddress, [:ulong, :string], :ulong
|
28
|
+
attach_pfunc :GetVersionExA, [:pointer], :bool
|
29
|
+
attach_pfunc :IsProcessInJob, [:ulong, :pointer, :pointer], :void
|
30
|
+
attach_pfunc :OpenProcess, [:ulong, :bool, :ulong], :ulong
|
31
|
+
attach_pfunc :SetHandleInformation, [:ulong, :ulong, :ulong], :bool
|
32
|
+
attach_pfunc :SetErrorMode, [:uint], :uint
|
33
|
+
attach_pfunc :SetPriorityClass, [:ulong, :ulong], :bool
|
34
|
+
attach_pfunc :TerminateProcess, [:ulong, :uint], :bool
|
35
|
+
attach_pfunc :WaitForSingleObject, [:ulong, :ulong], :ulong
|
36
|
+
|
37
|
+
attach_pfunc :CreateRemoteThread,
|
38
|
+
[:ulong, :pointer, :size_t, :ulong, :pointer, :ulong, :pointer], :ulong
|
39
|
+
|
40
|
+
attach_pfunc :GetVolumeInformationA,
|
41
|
+
[:string, :pointer, :ulong, :pointer, :pointer, :pointer, :pointer, :ulong], :bool
|
42
|
+
|
43
|
+
attach_pfunc :CreateProcessW,
|
44
|
+
[:buffer_in, :buffer_in, :pointer, :pointer, :bool,
|
45
|
+
:ulong, :buffer_in, :buffer_in, :pointer, :pointer], :bool
|
46
|
+
|
47
|
+
attach_pfunc :AssignProcessToJobObject, [:ulong, :ulong], :bool
|
48
|
+
attach_pfunc :CreateJobObjectA, [:pointer, :string], :ulong
|
49
|
+
attach_pfunc :OpenJobObjectA, [:ulong, :bool, :string], :ulong
|
50
|
+
attach_pfunc :QueryInformationJobObject, [:ulong, :int, :pointer, :ulong, :pointer], :bool
|
51
|
+
attach_pfunc :SetInformationJobObject, [:ulong, :int, :pointer, :ulong], :bool
|
52
|
+
|
53
|
+
ffi_lib :advapi32
|
54
|
+
|
55
|
+
attach_pfunc :ConvertSidToStringSidA, [:buffer_in, :pointer], :bool
|
56
|
+
attach_pfunc :GetTokenInformation, [:ulong, :int, :pointer, :ulong, :pointer], :bool
|
57
|
+
attach_pfunc :OpenProcessToken, [:ulong, :ulong, :pointer], :bool
|
58
|
+
|
59
|
+
attach_pfunc :CreateProcessWithLogonW,
|
60
|
+
[:buffer_in, :buffer_in, :buffer_in, :ulong, :buffer_in, :buffer_in,
|
61
|
+
:ulong, :buffer_in, :buffer_in, :pointer, :pointer], :bool
|
62
|
+
|
63
|
+
ffi_lib FFI::Library::LIBC
|
64
|
+
|
65
|
+
attach_pfunc :get_osfhandle, :_get_osfhandle, [:int], :ulong
|
66
|
+
|
67
|
+
begin
|
68
|
+
attach_pfunc :get_errno, :_get_errno, [:pointer], :int
|
69
|
+
rescue FFI::NotFoundError
|
70
|
+
# Do nothing, Windows XP or earlier.
|
71
|
+
end
|
72
|
+
end
|
data/lib/win32/process/helper.rb
CHANGED
@@ -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
|
13
|
-
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
|
+
end
|
@@ -1,103 +1,114 @@
|
|
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
|
-
private
|
12
|
-
|
13
|
-
# sizeof(LARGE_INTEGER) == 8
|
14
|
-
class LARGE_INTEGER < FFI::Union
|
15
|
-
layout(:QuadPart, :long_long)
|
16
|
-
end
|
17
|
-
|
18
|
-
# sizeof(IO_COUNTERS) == 48
|
19
|
-
class IO_COUNTERS < FFI::Struct
|
20
|
-
layout(
|
21
|
-
:ReadOperationCount, :ulong_long,
|
22
|
-
:WriteOperationCount, :ulong_long,
|
23
|
-
:OtherOperationCount, :ulong_long,
|
24
|
-
:ReadTransferCount, :ulong_long,
|
25
|
-
:WriteTransferCount, :ulong_long,
|
26
|
-
:OtherTransferCount, :ulong_long
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
class JOBJECT_BASIC_LIMIT_INFORMATION < FFI::Struct
|
31
|
-
layout(
|
32
|
-
:PerProcessUserTimeLimit, LARGE_INTEGER,
|
33
|
-
:PerJobUserTimeLimit, LARGE_INTEGER,
|
34
|
-
:LimitFlags, :ulong,
|
35
|
-
:MinimumWorkingSetSize, :size_t,
|
36
|
-
:MaximumWorkingSetSize, :size_t,
|
37
|
-
:ActiveProcessLimit, :ulong,
|
38
|
-
:Affinity, :pointer,
|
39
|
-
:PriorityClass, :ulong,
|
40
|
-
:SchedulingClass, :ulong
|
41
|
-
)
|
42
|
-
end
|
43
|
-
|
44
|
-
class JOBJECT_EXTENDED_LIMIT_INFORMATION < FFI::Struct
|
45
|
-
layout(
|
46
|
-
:BasicLimitInformation, JOBJECT_BASIC_LIMIT_INFORMATION,
|
47
|
-
:IoInfo, IO_COUNTERS,
|
48
|
-
:ProcessMemoryLimit, :size_t,
|
49
|
-
:JobMemoryLimit, :size_t,
|
50
|
-
:PeakProcessMemoryUsed, :size_t,
|
51
|
-
:PeakJobMemoryUsed, :size_t
|
52
|
-
)
|
53
|
-
end
|
54
|
-
|
55
|
-
class SECURITY_ATTRIBUTES < FFI::Struct
|
56
|
-
layout(
|
57
|
-
:nLength, :ulong,
|
58
|
-
:lpSecurityDescriptor, :pointer,
|
59
|
-
:bInheritHandle, :bool
|
60
|
-
)
|
61
|
-
end
|
62
|
-
|
63
|
-
# sizeof(STARTUPINFO) == 68
|
64
|
-
class STARTUPINFO < FFI::Struct
|
65
|
-
layout(
|
66
|
-
:cb, :ulong,
|
67
|
-
:lpReserved, :string,
|
68
|
-
:lpDesktop, :string,
|
69
|
-
:lpTitle, :string,
|
70
|
-
:dwX, :ulong,
|
71
|
-
:dwY, :ulong,
|
72
|
-
:dwXSize, :ulong,
|
73
|
-
:dwYSize, :ulong,
|
74
|
-
:dwXCountChars, :ulong,
|
75
|
-
:dwYCountChars, :ulong,
|
76
|
-
:dwFillAttribute, :ulong,
|
77
|
-
:dwFlags, :ulong,
|
78
|
-
:wShowWindow, :short,
|
79
|
-
:cbReserved2, :short,
|
80
|
-
:lpReserved2, :pointer,
|
81
|
-
:hStdInput, :ulong,
|
82
|
-
:hStdOutput, :ulong,
|
83
|
-
:hStdError, :ulong
|
84
|
-
)
|
85
|
-
end
|
86
|
-
|
87
|
-
class PROCESS_INFORMATION < FFI::Struct
|
88
|
-
layout(
|
89
|
-
:hProcess, :ulong,
|
90
|
-
:hThread, :ulong,
|
91
|
-
:dwProcessId, :ulong,
|
92
|
-
:dwThreadId, :ulong
|
93
|
-
)
|
94
|
-
end
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
+
private
|
12
|
+
|
13
|
+
# sizeof(LARGE_INTEGER) == 8
|
14
|
+
class LARGE_INTEGER < FFI::Union
|
15
|
+
layout(:QuadPart, :long_long)
|
16
|
+
end
|
17
|
+
|
18
|
+
# sizeof(IO_COUNTERS) == 48
|
19
|
+
class IO_COUNTERS < FFI::Struct
|
20
|
+
layout(
|
21
|
+
:ReadOperationCount, :ulong_long,
|
22
|
+
:WriteOperationCount, :ulong_long,
|
23
|
+
:OtherOperationCount, :ulong_long,
|
24
|
+
:ReadTransferCount, :ulong_long,
|
25
|
+
:WriteTransferCount, :ulong_long,
|
26
|
+
:OtherTransferCount, :ulong_long
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
class JOBJECT_BASIC_LIMIT_INFORMATION < FFI::Struct
|
31
|
+
layout(
|
32
|
+
:PerProcessUserTimeLimit, LARGE_INTEGER,
|
33
|
+
:PerJobUserTimeLimit, LARGE_INTEGER,
|
34
|
+
:LimitFlags, :ulong,
|
35
|
+
:MinimumWorkingSetSize, :size_t,
|
36
|
+
:MaximumWorkingSetSize, :size_t,
|
37
|
+
:ActiveProcessLimit, :ulong,
|
38
|
+
:Affinity, :pointer,
|
39
|
+
:PriorityClass, :ulong,
|
40
|
+
:SchedulingClass, :ulong
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
class JOBJECT_EXTENDED_LIMIT_INFORMATION < FFI::Struct
|
45
|
+
layout(
|
46
|
+
:BasicLimitInformation, JOBJECT_BASIC_LIMIT_INFORMATION,
|
47
|
+
:IoInfo, IO_COUNTERS,
|
48
|
+
:ProcessMemoryLimit, :size_t,
|
49
|
+
:JobMemoryLimit, :size_t,
|
50
|
+
:PeakProcessMemoryUsed, :size_t,
|
51
|
+
:PeakJobMemoryUsed, :size_t
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
class SECURITY_ATTRIBUTES < FFI::Struct
|
56
|
+
layout(
|
57
|
+
:nLength, :ulong,
|
58
|
+
:lpSecurityDescriptor, :pointer,
|
59
|
+
:bInheritHandle, :bool
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
# sizeof(STARTUPINFO) == 68
|
64
|
+
class STARTUPINFO < FFI::Struct
|
65
|
+
layout(
|
66
|
+
:cb, :ulong,
|
67
|
+
:lpReserved, :string,
|
68
|
+
:lpDesktop, :string,
|
69
|
+
:lpTitle, :string,
|
70
|
+
:dwX, :ulong,
|
71
|
+
:dwY, :ulong,
|
72
|
+
:dwXSize, :ulong,
|
73
|
+
:dwYSize, :ulong,
|
74
|
+
:dwXCountChars, :ulong,
|
75
|
+
:dwYCountChars, :ulong,
|
76
|
+
:dwFillAttribute, :ulong,
|
77
|
+
:dwFlags, :ulong,
|
78
|
+
:wShowWindow, :short,
|
79
|
+
:cbReserved2, :short,
|
80
|
+
:lpReserved2, :pointer,
|
81
|
+
:hStdInput, :ulong,
|
82
|
+
:hStdOutput, :ulong,
|
83
|
+
:hStdError, :ulong
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
class PROCESS_INFORMATION < FFI::Struct
|
88
|
+
layout(
|
89
|
+
:hProcess, :ulong,
|
90
|
+
:hThread, :ulong,
|
91
|
+
:dwProcessId, :ulong,
|
92
|
+
:dwThreadId, :ulong
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
class OSVERSIONINFO < FFI::Struct
|
97
|
+
layout(
|
98
|
+
:dwOSVersionInfoSize, :ulong,
|
99
|
+
:dwMajorVersion, :ulong,
|
100
|
+
:dwMinorVersion, :ulong,
|
101
|
+
:dwBuildNumber, :ulong,
|
102
|
+
:dwPlatformId, :ulong,
|
103
|
+
:szCSDVersion, [:char, 128]
|
104
|
+
)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Used by Process.create
|
108
|
+
ProcessInfo = Struct.new("ProcessInfo",
|
109
|
+
:process_handle,
|
110
|
+
:thread_handle,
|
111
|
+
:process_id,
|
112
|
+
:thread_id
|
113
|
+
)
|
114
|
+
end
|