win32-process 0.8.3 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,91 +1,91 @@
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
- unless instance_methods.include?(:attach_pfunc)
11
- # Wrapper method for attach_function + private
12
- def attach_pfunc(*args)
13
- attach_function(*args)
14
- private args[0]
15
- end
16
- end
17
- end
18
-
19
- extend FFI::Library
20
-
21
- typedef :ulong, :dword
22
- typedef :uintptr_t, :handle
23
- typedef :uintptr_t, :hwnd
24
- typedef :uintptr_t, :hmodule
25
-
26
- ffi_lib :kernel32
27
-
28
- attach_pfunc :CloseHandle, [:handle], :bool
29
- attach_pfunc :CreateToolhelp32Snapshot, [:dword, :dword], :handle
30
- attach_pfunc :GenerateConsoleCtrlEvent, [:dword, :dword], :bool
31
- attach_pfunc :GetCurrentProcess, [], :handle
32
- attach_pfunc :GetModuleHandle, :GetModuleHandleA, [:string], :hmodule
33
- attach_pfunc :GetProcessAffinityMask, [:handle, :pointer, :pointer], :bool
34
- attach_pfunc :GetPriorityClass, [:handle], :dword
35
- attach_pfunc :GetProcAddress, [:hmodule, :string], :pointer
36
- attach_pfunc :GetVersionExA, [:pointer], :bool
37
- attach_pfunc :Heap32ListFirst, [:handle, :pointer], :bool
38
- attach_pfunc :Heap32ListNext, [:handle, :pointer], :bool
39
- attach_pfunc :Heap32First, [:pointer, :dword, :uintptr_t], :bool
40
- attach_pfunc :Heap32Next, [:pointer], :bool
41
- attach_pfunc :Module32First, [:handle, :pointer], :bool
42
- attach_pfunc :Module32Next, [:handle, :pointer], :bool
43
- attach_pfunc :IsProcessInJob, [:handle, :pointer, :pointer], :bool # 2nd arg optional
44
- attach_pfunc :OpenProcess, [:dword, :int, :dword], :handle
45
- attach_pfunc :Process32First, [:handle, :pointer], :bool
46
- attach_pfunc :Process32Next, [:handle, :pointer], :bool
47
- attach_pfunc :SetHandleInformation, [:handle, :dword, :dword], :bool
48
- attach_pfunc :SetErrorMode, [:uint], :uint
49
- attach_pfunc :SetPriorityClass, [:handle, :dword], :bool
50
- attach_pfunc :TerminateProcess, [:handle, :uint], :bool
51
- attach_pfunc :Thread32First, [:handle, :pointer], :bool
52
- attach_pfunc :Thread32Next, [:handle, :pointer], :bool
53
- attach_pfunc :WaitForSingleObject, [:handle, :dword], :dword
54
-
55
- attach_pfunc :CreateRemoteThread,
56
- [:handle, :pointer, :size_t, :pointer, :pointer, :dword, :pointer], :handle
57
-
58
- attach_pfunc :GetVolumeInformationA,
59
- [:string, :pointer, :dword, :pointer, :pointer, :pointer, :pointer, :dword], :bool
60
-
61
- attach_pfunc :CreateProcessW,
62
- [:buffer_in, :buffer_inout, :pointer, :pointer, :int,
63
- :dword, :buffer_in, :buffer_in, :pointer, :pointer], :bool
64
-
65
- attach_pfunc :AssignProcessToJobObject, [:handle, :handle], :bool
66
- attach_pfunc :CreateJobObjectA, [:pointer, :string], :handle
67
- attach_pfunc :OpenJobObjectA, [:dword, :int, :string], :handle
68
- attach_pfunc :QueryInformationJobObject, [:handle, :int, :pointer, :dword, :pointer], :bool
69
- attach_pfunc :SetInformationJobObject, [:handle, :int, :pointer, :dword], :bool
70
- attach_pfunc :GetExitCodeProcess, [:handle, :pointer], :bool
71
-
72
- ffi_lib :advapi32
73
-
74
- attach_pfunc :ConvertSidToStringSidA, [:buffer_in, :pointer], :bool
75
- attach_pfunc :GetTokenInformation, [:handle, :int, :pointer, :dword, :pointer], :bool
76
- attach_pfunc :OpenProcessToken, [:handle, :dword, :pointer], :bool
77
-
78
- attach_pfunc :CreateProcessWithLogonW,
79
- [:buffer_in, :buffer_in, :buffer_in, :dword, :buffer_in, :buffer_inout,
80
- :dword, :buffer_in, :buffer_in, :pointer, :pointer], :bool
81
-
82
- ffi_lib FFI::Library::LIBC
83
-
84
- attach_pfunc :get_osfhandle, :_get_osfhandle, [:int], :intptr_t
85
-
86
- begin
87
- attach_pfunc :get_errno, :_get_errno, [:pointer], :int
88
- rescue FFI::NotFoundError
89
- # Do nothing, Windows XP or earlier.
90
- end
91
- 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
+ unless instance_methods.include?(:attach_pfunc)
11
+ # Wrapper method for attach_function + private
12
+ def attach_pfunc(*args)
13
+ attach_function(*args)
14
+ private args[0]
15
+ end
16
+ end
17
+ end
18
+
19
+ extend FFI::Library
20
+
21
+ typedef :ulong, :dword
22
+ typedef :uintptr_t, :handle
23
+ typedef :uintptr_t, :hwnd
24
+ typedef :uintptr_t, :hmodule
25
+
26
+ ffi_lib :kernel32
27
+
28
+ attach_pfunc :CloseHandle, [:handle], :bool
29
+ attach_pfunc :CreateToolhelp32Snapshot, [:dword, :dword], :handle
30
+ attach_pfunc :GenerateConsoleCtrlEvent, [:dword, :dword], :bool
31
+ attach_pfunc :GetCurrentProcess, [], :handle
32
+ attach_pfunc :GetModuleHandle, :GetModuleHandleA, [:string], :hmodule
33
+ attach_pfunc :GetProcessAffinityMask, [:handle, :pointer, :pointer], :bool
34
+ attach_pfunc :GetPriorityClass, [:handle], :dword
35
+ attach_pfunc :GetProcAddress, [:hmodule, :string], :pointer
36
+ attach_pfunc :GetVersionExA, [:pointer], :bool
37
+ attach_pfunc :Heap32ListFirst, [:handle, :pointer], :bool
38
+ attach_pfunc :Heap32ListNext, [:handle, :pointer], :bool
39
+ attach_pfunc :Heap32First, [:pointer, :dword, :uintptr_t], :bool
40
+ attach_pfunc :Heap32Next, [:pointer], :bool
41
+ attach_pfunc :Module32First, [:handle, :pointer], :bool
42
+ attach_pfunc :Module32Next, [:handle, :pointer], :bool
43
+ attach_pfunc :IsProcessInJob, [:handle, :pointer, :pointer], :bool # 2nd arg optional
44
+ attach_pfunc :OpenProcess, [:dword, :int, :dword], :handle
45
+ attach_pfunc :Process32First, [:handle, :pointer], :bool
46
+ attach_pfunc :Process32Next, [:handle, :pointer], :bool
47
+ attach_pfunc :SetHandleInformation, [:handle, :dword, :dword], :bool
48
+ attach_pfunc :SetErrorMode, [:uint], :uint
49
+ attach_pfunc :SetPriorityClass, [:handle, :dword], :bool
50
+ attach_pfunc :TerminateProcess, [:handle, :uint], :bool
51
+ attach_pfunc :Thread32First, [:handle, :pointer], :bool
52
+ attach_pfunc :Thread32Next, [:handle, :pointer], :bool
53
+ attach_pfunc :WaitForSingleObject, [:handle, :dword], :dword
54
+
55
+ attach_pfunc :CreateRemoteThread,
56
+ [:handle, :pointer, :size_t, :pointer, :pointer, :dword, :pointer], :handle
57
+
58
+ attach_pfunc :GetVolumeInformationA,
59
+ [:string, :pointer, :dword, :pointer, :pointer, :pointer, :pointer, :dword], :bool
60
+
61
+ attach_pfunc :CreateProcessW,
62
+ [:buffer_in, :buffer_inout, :pointer, :pointer, :int,
63
+ :dword, :buffer_in, :buffer_in, :pointer, :pointer], :bool
64
+
65
+ attach_pfunc :AssignProcessToJobObject, [:handle, :handle], :bool
66
+ attach_pfunc :CreateJobObjectA, [:pointer, :string], :handle
67
+ attach_pfunc :OpenJobObjectA, [:dword, :int, :string], :handle
68
+ attach_pfunc :QueryInformationJobObject, [:handle, :int, :pointer, :dword, :pointer], :bool
69
+ attach_pfunc :SetInformationJobObject, [:handle, :int, :pointer, :dword], :bool
70
+ attach_pfunc :GetExitCodeProcess, [:handle, :pointer], :bool
71
+
72
+ ffi_lib :advapi32
73
+
74
+ attach_pfunc :ConvertSidToStringSidA, [:buffer_in, :pointer], :bool
75
+ attach_pfunc :GetTokenInformation, [:handle, :int, :pointer, :dword, :pointer], :bool
76
+ attach_pfunc :OpenProcessToken, [:handle, :dword, :pointer], :bool
77
+
78
+ attach_pfunc :CreateProcessWithLogonW,
79
+ [:buffer_in, :buffer_in, :buffer_in, :dword, :buffer_in, :buffer_inout,
80
+ :dword, :buffer_in, :buffer_in, :pointer, :pointer], :bool
81
+
82
+ ffi_lib FFI::Library::LIBC
83
+
84
+ attach_pfunc :get_osfhandle, :_get_osfhandle, [:int], :intptr_t
85
+
86
+ begin
87
+ attach_pfunc :get_errno, :_get_errno, [:pointer], :int
88
+ rescue FFI::NotFoundError
89
+ # Do nothing, Windows XP or earlier.
90
+ end
91
+ 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