github.com/iDigitalFlame/xmt@v0.5.4/cmd/filter/filter_nix.go (about) 1 //go:build !windows 2 // +build !windows 3 4 // Copyright (C) 2020 - 2023 iDigitalFlame 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program. If not, see <https://www.gnu.org/licenses/>. 18 // 19 20 package filter 21 22 import "github.com/iDigitalFlame/xmt/util/xerr" 23 24 // Select will attempt to find a process with the specified Filter options. 25 // If a suitable process is found, the Process ID will be returned. 26 // 27 // An'ErrNoProcessFound' error will be returned if no processes that match the 28 // Filter are found. 29 // 30 // This function returns 'ErrNoWindows' on non-Windows devices if a PID is not set. 31 func (f Filter) Select() (uint32, error) { 32 if f.PID > 0 { 33 return f.PID, nil 34 } 35 return 0, xerr.Sub("only supported on Windows devices", 0x20) 36 } 37 38 // Token will attempt to find a process with the specified Filter options. 39 // If a suitable process is found, the Process Token Handle will be returned. 40 // The first argument is the access rights requested, expressed as an uint32. 41 // 42 // An'ErrNoProcessFound' error will be returned if no processes that match the 43 // Filter are found. 44 // 45 // This function returns 'ErrNoWindows' on non-Windows devices. 46 func (Filter) Token(_ uint32) (uintptr, error) { 47 return 0, xerr.Sub("only supported on Windows devices", 0x20) 48 } 49 50 // Thread will attempt to find a process with the specified Filter options. 51 // If a suitable process is found, a handle to the first Thread in the Process 52 // will be returned. The first argument is the access rights requested, expressed 53 // as an uint32. 54 // 55 // An 'ErrNoProcessFound' error will be returned if no processes that match the 56 // Filter are found. 57 // 58 // This function returns 'ErrNoWindows' on non-Windows devices. 59 func (Filter) Thread(_ uint32) (uintptr, error) { 60 return 0, xerr.Sub("only supported on Windows devices", 0x20) 61 } 62 63 // Handle will attempt to find a process with the specified Filter options. 64 // If a suitable process is found, the Process Handle will be returned. 65 // The first argument is the access rights requested, expressed as an uint32. 66 // 67 // An'ErrNoProcessFound' error will be returned if no processes that match the 68 // Filter are found. 69 // 70 // This function returns 'ErrNoWindows' on non-Windows devices. 71 func (Filter) Handle(_ uint32) (uintptr, error) { 72 return 0, xerr.Sub("only supported on Windows devices", 0x20) 73 } 74 75 // SelectFunc will attempt to find a process with the specified Filter options. 76 // If a suitable process is found, the Process ID will be returned. 77 // 78 // This function allows for a filtering function to be passed along that will be 79 // supplied with the ProcessID, if the process is elevated, the process name 80 // and process handle. The function supplied should return true if the process 81 // passes the filter. The function argument may be nil. 82 // 83 // An'ErrNoProcessFound' error will be returned if no processes that match the 84 // Filter are found. 85 // 86 // This function returns 'ErrNoWindows' on non-Windows devices if a PID is not set. 87 func (f Filter) SelectFunc(_ filter) (uint32, error) { 88 if f.PID > 0 { 89 return f.PID, nil 90 } 91 return 0, xerr.Sub("only supported on Windows devices", 0x20) 92 } 93 94 // TokenFunc will attempt to find a process with the specified Filter options. 95 // If a suitable process is found, the Process Token Handle will be returned. 96 // The first argument is the access rights requested, expressed as an uint32. 97 // 98 // This function allows for a filtering function to be passed along that will be 99 // supplied with the ProcessID, if the process is elevated, the process name 100 // and process handle. The function supplied should return true if the process 101 // passes the filter. The function argument may be nil. 102 // 103 // An'ErrNoProcessFound' error will be returned if no processes that match the 104 // Filter are found. 105 // 106 // This function returns 'ErrNoWindows' on non-Windows devices. 107 func (Filter) TokenFunc(_ uint32, _ filter) (uintptr, error) { 108 return 0, xerr.Sub("only supported on Windows devices", 0x20) 109 } 110 111 // HandleFunc will attempt to find a process with the specified Filter options. 112 // If a suitable process is found, the Process Handle will be returned. 113 // 114 // This function allows for a filtering function to be passed along that will be 115 // supplied with the ProcessID, if the process is elevated, the process name 116 // and process handle. The function supplied should return true if the process 117 // passes the filter. The function argument may be nil. 118 // 119 // An'ErrNoProcessFound' error will be returned if no processes that match the 120 // Filter are found. 121 // 122 // This function returns 'ErrNoWindows' on non-Windows devices. 123 func (Filter) HandleFunc(_ uint32, _ filter) (uintptr, error) { 124 return 0, xerr.Sub("only supported on Windows devices", 0x20) 125 } 126 127 // ThreadFunc will attempt to find a process with the specified Filter options. 128 // If a suitable process is found, a handle to the first Thread in the Process 129 // will be returned. The first argument is the access rights requested, expressed 130 // as an uint32. 131 // 132 // This function allows for a filtering function to be passed along that will be 133 // supplied with the ProcessID, if the process is elevated, the process name 134 // and process handle. The function supplied should return true if the process 135 // passes the filter. The function argument may be nil. 136 // 137 // An'ErrNoProcessFound' error will be returned if no processes that match the 138 // Filter are found. 139 // 140 // This function returns 'ErrNoWindows' on non-Windows devices. 141 func (Filter) ThreadFunc(_ uint32, _ filter) (uintptr, error) { 142 return 0, xerr.Sub("only supported on Windows devices", 0x20) 143 }