github.com/iDigitalFlame/xmt@v0.5.4/com/v_no_impant.go (about) 1 //go:build !implant 2 // +build !implant 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 com 21 22 import "github.com/iDigitalFlame/xmt/util" 23 24 // String returns a character representation of this Flag. 25 func (f Flag) String() string { 26 var ( 27 b [27]byte 28 n int 29 ) 30 if f&FlagFrag != 0 { 31 b[n] = 'F' 32 n++ 33 } 34 if f&FlagMulti != 0 { 35 b[n] = 'M' 36 n++ 37 } 38 if f&FlagProxy != 0 { 39 b[n] = 'P' 40 n++ 41 } 42 if f&FlagError != 0 { 43 b[n] = 'E' 44 n++ 45 } 46 if f&FlagChannel != 0 { 47 b[n] = 'C' 48 n++ 49 } 50 if f&FlagChannelEnd != 0 { 51 b[n] = 'K' 52 n++ 53 } 54 if f&FlagOneshot != 0 { 55 b[n] = 'O' 56 n++ 57 } 58 if f&FlagMultiDevice != 0 { 59 b[n] = 'X' 60 n++ 61 } 62 if f&FlagCrypt != 0 { 63 b[n] = 'Z' 64 n++ 65 } 66 if n == 0 { 67 n += copy(b[:], "V"+util.Uitoa16(uint64(f))) 68 } 69 switch { 70 case f&FlagMulti != 0 && f.Len() > 0: 71 n += copy(b[n:], "["+util.Uitoa(uint64(f.Len()))+"]") 72 case f&FlagFrag != 0 && f&FlagMulti == 0: 73 if f.Len() == 0 { 74 n += copy(b[n:], "["+util.Uitoa16(uint64(f.Group()))+"]") 75 } else { 76 n += copy(b[n:], "["+util.Uitoa16(uint64(f.Group()))+":"+util.Uitoa(uint64(f.Position())+1)+"/"+util.Uitoa(uint64(f.Len()))+"]") 77 } 78 } 79 return string(b[:n]) 80 } 81 func byteHexStr(b byte) string { 82 if b < 16 { 83 return util.HexTable[b&0x0F : (b&0x0F)+1] 84 } 85 return util.HexTable[b>>4:(b>>4)+1] + util.HexTable[b&0x0F:(b&0x0F)+1] 86 } 87 88 // String returns a string descriptor of the Packet struct. 89 func (p Packet) String() string { 90 switch { 91 case p.Empty() && p.Flags == 0 && p.Job == 0 && p.ID == 0: 92 return "NoP" 93 case p.Empty() && p.Flags == 0 && p.Job == 0: 94 return "0x" + byteHexStr(p.ID) 95 case p.Empty() && p.Flags == 0 && p.ID == 0: 96 return "<invalid>NoP/" + util.Uitoa(uint64(p.Job)) 97 case p.Empty() && p.Flags == 0: 98 return "0x" + byteHexStr(p.ID) + "/" + util.Uitoa(uint64(p.Job)) 99 case p.Empty() && p.Job == 0 && p.ID == 0: 100 return p.Flags.String() 101 case p.Empty() && p.Job == 0: 102 return "0x" + byteHexStr(p.ID) + " " + p.Flags.String() 103 case p.Empty() && p.ID == 0: 104 return "NoP/" + util.Uitoa(uint64(p.Job)) + " " + p.Flags.String() 105 case p.Empty(): 106 return "0x" + byteHexStr(p.ID) + "/" + util.Uitoa(uint64(p.Job)) + " " + p.Flags.String() 107 case p.Flags == 0 && p.Job == 0 && p.ID == 0: 108 return "<invalid>NoP: " + util.Uitoa(uint64(p.Size())) + "B" 109 case p.Flags == 0 && p.Job == 0: 110 return "0x" + byteHexStr(p.ID) + ": " + util.Uitoa(uint64(p.Size())) + "B" 111 case p.Flags == 0 && p.ID == 0: 112 return "<invalid>NoP/" + util.Uitoa(uint64(p.Job)) + ": " + util.Uitoa(uint64(p.Size())) + "B" 113 case p.Flags == 0: 114 return "0x" + byteHexStr(p.ID) + "/" + util.Uitoa(uint64(p.Job)) + ": " + util.Uitoa(uint64(p.Size())) + "B" 115 case p.Job == 0 && p.ID == 0: 116 return p.Flags.String() + ": " + util.Uitoa(uint64(p.Size())) + "B" 117 case p.Job == 0: 118 return "0x" + byteHexStr(p.ID) + " " + p.Flags.String() + ": " + util.Uitoa(uint64(p.Size())) + "B" 119 case p.ID == 0: 120 return "<invalid>NoP/" + util.Uitoa(uint64(p.Job)) + " " + p.Flags.String() + ": " + util.Uitoa(uint64(p.Size())) + "B" 121 } 122 return "0x" + byteHexStr(p.ID) + "/" + util.Uitoa(uint64(p.Job)) + " " + p.Flags.String() + ": " + util.Uitoa(uint64(p.Size())) + "B" 123 } 124 func (i *ipListener) String() string { 125 return "IP:" + util.Uitoa(uint64(i.proto)) + "/" + i.Addr().String() 126 } 127 func (t *tcpListener) String() string { 128 return "TCP/" + t.Addr().String() 129 } 130 func (l *udpListener) String() string { 131 return "UDP/" + l.sock.LocalAddr().String() 132 }