github.com/iDigitalFlame/xmt@v0.5.4/device/v_no_implant.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 device
    21  
    22  import (
    23  	"net"
    24  
    25  	"github.com/iDigitalFlame/xmt/util"
    26  	"github.com/iDigitalFlame/xmt/util/xerr"
    27  )
    28  
    29  // State returns a string representation of the Login's Status type.
    30  func (l Login) State() string {
    31  	switch l.Status {
    32  	case 0:
    33  		return "Active"
    34  	case 1:
    35  		return "Connected"
    36  	case 2:
    37  		return "ConnectedQuery"
    38  	case 3:
    39  		return "Shadow"
    40  	case 4:
    41  		return "Disconnected"
    42  	case 5:
    43  		return "Idle"
    44  	case 6:
    45  		return "Listen"
    46  	case 7:
    47  		return "Reset"
    48  	case 8:
    49  		return "Down"
    50  	case 9:
    51  		return "Init"
    52  	}
    53  	return "Unknown"
    54  }
    55  
    56  // String returns a string representation of the OSType.
    57  func (o OSType) String() string {
    58  	switch o {
    59  	case Windows:
    60  		return "Windows"
    61  	case Linux:
    62  		return "Linux"
    63  	case Unix:
    64  		return "Unix/BSD"
    65  	case Mac:
    66  		return "MacOS"
    67  	case IOS:
    68  		return "iOS"
    69  	case Android:
    70  		return "Android"
    71  	case Plan9:
    72  		return "Plan9"
    73  	case Unsupported:
    74  		return "Unsupported"
    75  	}
    76  	return "Unknown"
    77  }
    78  func (d device) String() string {
    79  	b := builders.Get().(*util.Builder)
    80  	b.Grow(30)
    81  	b.WriteString(d.Name + "(" + d.Mac.String() + "): [")
    82  	for i := range d.Address {
    83  		if i > 0 {
    84  			b.WriteByte(' ')
    85  		}
    86  		b.WriteString(d.Address[i].String())
    87  	}
    88  	b.WriteByte(']')
    89  	r := b.Output()
    90  	builders.Put(b)
    91  	return r
    92  }
    93  
    94  // String returns a simple string representation of the Machine instance.
    95  func (m Machine) String() string {
    96  	var e string
    97  	if m.IsElevated() {
    98  		e = "*"
    99  	}
   100  	return "[" + m.ID.String() + "] " + m.Hostname + " (" + m.Version + ") " + e + m.User
   101  }
   102  
   103  // MarshalJSON implements the json.Marshaler interface.
   104  func (a Address) MarshalJSON() ([]byte, error) {
   105  	return []byte(`"` + a.String() + `"`), nil
   106  }
   107  
   108  // UnmarshalJSON implements the json.Unmarshaler interface.
   109  func (a *Address) UnmarshalJSON(b []byte) error {
   110  	if len(b) < 1 || b[len(b)-1] != '"' || b[0] != '"' {
   111  		return xerr.Sub("invalid address value", 0x1E)
   112  	}
   113  	if i := net.ParseIP(string(b[1 : len(b)-2])); i != nil {
   114  		a.Set(i)
   115  	}
   116  	return nil
   117  }