github.com/iDigitalFlame/xmt@v0.5.4/tools/errors.py (about) 1 #!/usr/bin/python3 2 # Copyright (C) 2020 - 2023 iDigitalFlame 3 # 4 # This program is free software: you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published by 6 # the Free Software Foundation, either version 3 of the License, or 7 # any later version. 8 # 9 # This program is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with this program. If not, see <https://www.gnu.org/licenses/>. 16 # 17 18 from sys import argv 19 20 21 class ErrorValue(object): 22 __slots__ = ("pkg", "text", "ident") 23 24 def __init__(self, text, pkg=None, ident=None): 25 self.pkg = pkg 26 self.text = text 27 self.ident = ident 28 29 def __str__(self): 30 if not isinstance(self.ident, str): 31 return self.text 32 if not isinstance(self.pkg, str): 33 return f"{self.text} ({self.ident})" 34 return f"{self.text} ({self.pkg}.{self.ident})" 35 36 37 ERRORS = [None] * 0xFF 38 39 40 def find_error(v): 41 if isinstance(v, int): 42 if v < 0 or v > 0xFF: 43 return None 44 return ERRORS[v] 45 try: 46 n = int(v, base=0) 47 if n < 0 or n > 0xFF: 48 return None 49 return ERRORS[n] 50 except ValueError: 51 pass 52 return None 53 54 55 def add(index, text, pkg=None, ident=None): 56 ERRORS[index] = ErrorValue(text, pkg, ident) 57 58 59 add(0x00, "invalid/unknown error") 60 add(0x01, "unspecified error") 61 add(0x10, "empty or invalid Guardian name", "man") 62 add(0x11, "no paths found", "man", "ErrNoEndpoints") 63 add(0x12, "invalid path/name", "man") 64 add(0x13, "invalid link type", "man") 65 add(0x14, "update without a Service status handle", "device/winapi/svc") 66 add(0x15, "unexpected key size", "device/winapi/registry") 67 add(0x16, "unexpected key type", "device/winapi/registry") 68 add(0x17, "invalid env value", "device/winapi") 69 add(0x18, "cannot load DLL function", "device/winapi") 70 add(0x19, "base is not a valid DOS header", "device/winapi") 71 add(0x1A, "offset base is not a valid NT header", "device/winapi") 72 add(0x1B, "header does not represent a DLL", "device/winapi") 73 add(0x1C, "header has an invalid first entry point", "device/winapi") 74 add(0x1D, "cannot find data section", "device/winapi") 75 add(0x1E, "invalid address value", "device") 76 add(0x1F, "quit", "device", "ErrQuit") 77 add(0x20, "only supported on Windows devices", "device", "ErrNoWindows") 78 add(0x21, "only supported on *nix devices", "device", "ErrNoNix") 79 add(0x22, "cannot dump self", "device") 80 add(0x23, "buffer limit reached", "data", "ErrLimit") 81 add(0x24, "invalid buffer type", "data", "ErrInvalidType") 82 add(0x25, "invalid index", "data", "ErrInvalidIndex") 83 add(0x26, "buffer is too large", "data", "ErrTooLarge") 84 add(0x27, "invalid whence", "data") 85 add(0x28, "block size must be a power of two between 16 and 128", "data/crypto") 86 add(0x29, "block size must equal IV size", "data/crypto") 87 add(0x2A, "malformed Tag", "com", "ErrMalformedTag") 88 add(0x2B, "tags list is too large", "com", "ErrTagsTooLarge") 89 add(0x2C, "packet ID does not match the supplied ID", "com") 90 add(0x2D, "invalid or missing TLS certificates", "com", "ErrInvalidTLSConfig") 91 add(0x2E, "invalid permissions", "com/pipe") 92 add(0x2F, "invalid permissions size", "com/pipe") 93 add(0x30, "empty host field", "com/wc2") 94 add(0x31, "invalid port specified", "com/wc2") 95 add(0x32, "invalid HTTP response", "com/wc2") 96 add(0x33, "body is not writable", "com/wc2") 97 add(0x34, "could not get underlying net.Conn", "com/wc2") 98 add(0x35, "not a file", "com/wc2") 99 add(0x36, "not a directory", "com/wc2") 100 add(0x37, "stdout already set", "cmd") 101 add(0x38, "stderr already set", "cmd") 102 add(0x39, "stdin already set", "cmd") 103 add(0x3A, "process has not started", "cmd", "ErrNotStarted") 104 add(0x3B, "process arguments are empty", "cmd", "ErrEmptyCommand") 105 add(0x3C, "process still running", "cmd", "ErrStillRunning") 106 add(0x3D, "process already started", "cmd", "ErrAlreadyStarted") 107 add(0x3E, "could not find a suitable process", "cmd/filter", "ErrNoProcessFound") 108 add(0x3F, "empty or nil Host", "c2", "ErrNoHost") 109 add(0x40, "other side did not come up", "c2", "ErrNoConn") 110 add(0x41, "empty or nil Profile", "c2/cfg", "ErrInvalidProfile") 111 add(0x42, "first Packet is invalid", "c2") 112 add(0x43, "empty or invalid pipe name", "c2") 113 add(0x45, "unexpected OK value", "c2") 114 add(0x46, "empty or nil Packet", "c2", "ErrMalformedPacket") 115 add(0x47, "not a Listener", "c2/cfg", "ErrNotAListener") 116 add(0x48, "not a Connector", "c2/cfg", "ErrNotAConnector") 117 add(0x49, "unable to listen", "c2") 118 add(0x4A, "empty Listener name", "c2") 119 add(0x4B, "listener already exists", "c2") 120 add(0x4C, "send buffer is full", "c2", "ErrFullBuffer") 121 add( 122 0x4D, 123 "frag/multi total is zero on a frag/multi packet", 124 "c2", 125 "ErrInvalidPacketCount", 126 ) 127 add(0x4E, "must be a client session", "c2") 128 add(0x4F, "migration in progress", "c2") 129 add(0x50, "cannot marshal Profile", "c2") 130 add(0x51, "cannot marshal Proxy data", "c2") 131 add(0x52, "packet ID does not match the supplied ID", "c2") 132 add(0x53, "proxy support disabled", "c2") 133 add(0x54, "cannot marshal Proxy Profile", "c2") 134 add(0x55, "only a single Proxy per session can be active", "c2") 135 add(0x56, "frag/multi count is larger than 0xFFFF", "c2", "ErrTooManyPackets") 136 add(0x57, "received Packet that does not match our own device ID", "c2") 137 add(0x58, "no Job created for client Session", "c2", "ErrNoTask") 138 add(0x59, "empty or nil Job", "c2") 139 add(0x5A, "cannot assign a Job ID", "c2") 140 add(0x5B, "job already registered", "c2") 141 add(0x5C, "empty or nil Tasklet", "c2") 142 add(0x5D, "setting is invalid", "c2/cfg", "ErrInvalidSetting") 143 add(0x5E, "cannot add multiple transforms", "c2/cfg", "ErrMultipleTransforms") 144 add(0x5F, "cannot add multiple connections", "c2/cfg", "ErrMultipleConnections") 145 add(0x60, "binary source not available", "c2/cfg") 146 add(0x61, 'missing "type" string', "c2/cfg") 147 add(0x62, "key not found", "c2/cfg") 148 add(0x63, "mapping ID is invalid", "c2/task") 149 add(0x64, "mapping ID is already exists", "c2/task") 150 add(0x65, "empty host field", "c2/task") 151 add(0x66, "invalid port specified", "c2/task") 152 add(0x67, "invalid HTTP response", "c2/task") 153 add(0x68, "invalid operation", "c2/task") 154 add(0x69, "invalid Packet", "c2/task") 155 add(0x6A, "empty or nil Tasklet", "c2/task") 156 add(0x6B, "script is empty", "c2/task") 157 add(0x6C, "empty key name", "c2/task") 158 add(0x6D, "empty value name", "c2/task") 159 add(0x6E, "arguments cannot be nil or empty", "c2/wrapper") 160 add(0xFE, "invalid Task mapping", "c2") 161 add(0x6F, "cannot find function", "device/winapi") 162 add(0x6F, "function is a forward", "device/winapi") 163 add(0x70, "invalid StartHour value", "c2") 164 add(0x71, "invalid StartMin value", "c2") 165 add(0x72, "invalid EndHour value", "c2") 166 add(0x73, "invalid EndMin value", "c2") 167 add(0x74, "invalid hex string length", "data") 168 add(0x75, "invalid non-colon character", "data") 169 add(0x76, "invalid non-hex byte", "data") 170 add(0x77, "cannot parse curve PublicKey", "data") 171 add(0x78, "cannot multiply PrivateKey with PublicKey", "data") 172 add(0x79, "non-trusted server PublicKey", "c2") 173 174 175 if __name__ == "__main__": 176 if len(argv) == 2: 177 print(find_error(argv[1])) 178 else: 179 print(f"{argv[0]} <error_code>")