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