header

package
v1.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SMB_HEADER_SIZE = 32
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Header struct {
	// Protocol (4 bytes): This field MUST contain the 4-byte literal string '\xFF', 'S', 'M', 'B',
	// with the letters represented by their respective ASCII values in the order shown. In the earliest
	// available SMB documentation, this field is defined as a one byte message type (0xFF) followed by
	// a three byte server type identifier.
	Protocol [4]byte
	// Command (1 byte): A one-byte command code. Defined SMB command codes are listed in section 2.2.2.1.
	Command codes.CommandCode
	// Status (4 bytes): A 32-bit field used to communicate error messages from the server to the client.
	Status types.ULONG
	// Flags (1 byte): An 8-bit field of 1-bit flags describing various features in effect for the message.
	Flags flags.Flags
	// Flags2 (2 bytes): A 16-bit field of 1-bit flags that represent various features in effect for the message.
	// Unspecified bits are reserved and MUST be zero.
	Flags2 flags2.Flags2
	// PID (2 bytes): A 32-bit field that represents the process identifier (PID).
	PIDHigh types.USHORT
	// SecurityFeatures (8 bytes): This 8-byte field has three possible interpretations.
	SecurityFeatures securityfeatures.SecurityFeatures
	// Reserved (2 bytes): This field is reserved and SHOULD be set to 0x0000.
	Reserved types.USHORT
	// TID (2 bytes): A tree identifier (TID).
	TID types.USHORT
	// PIDLow (2 bytes): A 32-bit field that represents the process identifier (PID).
	PIDLow types.USHORT
	// UID (2 bytes): A user identifier (UID).
	UID types.USHORT
	// MID (2 bytes): A multiplex identifier (MID).
	MID types.USHORT
}

Header represents the header structure for SMB packets Source: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-cifs/69a29f73-de0c-45a6-a1aa-8ceeea42217f

func NewHeader

func NewHeader() *Header

NewHeader creates a new SMB Header with default values and initializes the SecurityFeatures field with a Reserved security features object.

Returns:

  • *Header: A pointer to the newly created SMB Header

func NewHeaderWithSecurityFeaturesConnectionLess

func NewHeaderWithSecurityFeaturesConnectionLess() *Header

NewHeaderWithSecurityFeaturesConnectionLess creates a new SMB Header with default values and initializes the SecurityFeatures field with a ConnectionlessTransport security features object.

Returns:

  • *Header: A pointer to the newly created SMB Header

func NewHeaderWithSecurityFeaturesSecuritySignature

func NewHeaderWithSecurityFeaturesSecuritySignature() *Header

NewHeaderWithSecurityFeaturesSecuritySignature creates a new SMB Header with default values and initializes the SecurityFeatures field with a SecuritySignature security features object.

Returns:

  • *Header: A pointer to the newly created SMB Header

func (*Header) GetMID

func (h *Header) GetMID() types.USHORT

GetMID returns the multiplex identifier (MID) value

Returns:

  • types.USHORT: The multiplex identifier (MID) value

func (*Header) GetPID

func (h *Header) GetPID() types.ULONG

GetPID returns the full 32-bit process identifier (PID) value combining PIDHigh and PIDLow

Returns:

  • types.ULONG: The full 32-bit process identifier (PID) value

func (*Header) GetTID

func (h *Header) GetTID() types.USHORT

GetTID returns the tree identifier (TID) value

Returns:

  • types.USHORT: The tree identifier (TID) value

func (*Header) GetUID

func (h *Header) GetUID() types.USHORT

GetUID returns the user identifier (UID) value

Returns:

  • types.USHORT: The user identifier (UID) value

func (*Header) IsRequest

func (h *Header) IsRequest() bool

IsRequest returns true if the header is a request, false otherwise.

Returns:

  • bool: True if the header is a request, false otherwise

func (*Header) IsResponse

func (h *Header) IsResponse() bool

IsResponse returns true if the header is a response, false otherwise.

Returns:

  • bool: True if the header is a response, false otherwise

func (*Header) Marshal

func (h *Header) Marshal() ([]byte, error)

Marshal serializes the SMB Header structure into a byte slice. It converts all header fields into their binary representation using little-endian byte order. The resulting byte slice will be exactly 32 bytes (SMB_HEADER_SIZE) long, containing all header fields in the order specified by the SMB protocol.

Returns:

  • []byte: The serialized header as a byte slice
  • error: Any error encountered during serialization, or nil if successful

func (*Header) SetFlags

func (h *Header) SetFlags(value uint8)

SetFlags sets the flags field in the SMB Header. The flags field is an 8-bit field of 1-bit flags describing various features in effect for the message.

Parameters:

  • flags: The byte value to set as flags

func (*Header) SetFlags2

func (h *Header) SetFlags2(value uint16)

SetFlags2 sets the flags2 field in the SMB Header. The flags2 field is a 16-bit field of 1-bit flags that represent various features in effect for the message.

Parameters:

  • flags2: The uint16 value to set as flags2

func (*Header) SetMID

func (h *Header) SetMID(mid types.USHORT)

SetMID sets the multiplex identifier (MID) value

Parameters:

  • mid: The new multiplex identifier (MID) value

func (*Header) SetPID

func (h *Header) SetPID(pid types.ULONG)

SetPID sets both PIDHigh and PIDLow from a 32-bit process identifier (PID)

Parameters:

  • pid: The new 32-bit process identifier (PID) value

func (*Header) SetTID

func (h *Header) SetTID(tid types.USHORT)

SetTID sets the tree identifier (TID) value

Parameters:

  • tid: The new tree identifier (TID) value

func (*Header) SetUID

func (h *Header) SetUID(uid types.USHORT)

SetUID sets the user identifier (UID) value

Parameters:

  • uid: The new user identifier (UID) value

func (*Header) Unmarshal

func (h *Header) Unmarshal(data []byte) (int, error)

Unmarshal deserializes a byte slice into the SMB Header structure. It reads the binary representation of the header fields from the input byte slice using little-endian byte order. This method determines the appropriate security features type based on the header flags and unmarshals accordingly.

Parameters:

  • data: The byte slice containing the serialized SMB header

Returns:

  • int: The number of bytes read from the input byte slice
  • error: Any error encountered during deserialization, or nil if successful

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL