Files
psycep ce5ca7f159 module: rename to github.com/mandiant/gopacket
Fixes #6. The module was declared as `module gopacket` in go.mod,
which is not a canonical import path. External projects could not
`go get github.com/mandiant/gopacket` to use any of the 24
protocol packages as a library; the only workaround was to clone
the repo and add a `replace` directive to their own go.mod.

This commit:
- Sets `module github.com/mandiant/gopacket` in go.mod.
- Rewrites 434 import statements across 157 files from the bare
  `gopacket/...` prefix to `github.com/mandiant/gopacket/...`.

Pure mechanical change, no behavior difference. Makes the README's
library story (pkg/ directory, 24 reusable packages) actually
usable from external code.
2026-04-22 10:27:18 -05:00

105 lines
2.9 KiB
Go

// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package relay
import (
"fmt"
"log"
"github.com/mandiant/gopacket/internal/build"
)
// RelayPipeTransport implements dcerpc.Transport over a raw SMB2 relay pipe.
// Uses SMB2 WRITE + READ for pipe communication (more compatible than IOCTL).
type RelayPipeTransport struct {
client *SMBRelayClient
fileID [16]byte
writeBuf []byte
readBuf []byte
readOff int
}
// NewRelayPipeTransport creates a transport adapter for the given pipe.
func NewRelayPipeTransport(client *SMBRelayClient, fileID [16]byte) *RelayPipeTransport {
return &RelayPipeTransport{
client: client,
fileID: fileID,
}
}
// Write buffers data for the next send operation.
func (t *RelayPipeTransport) Write(b []byte) (int, error) {
t.writeBuf = append(t.writeBuf, b...)
if build.Debug {
log.Printf("[D] RelayPipe: buffered %d bytes (total: %d)", len(b), len(t.writeBuf))
}
return len(b), nil
}
// Read sends buffered write data via SMB2 WRITE, then reads response via SMB2 READ.
func (t *RelayPipeTransport) Read(b []byte) (int, error) {
// If we have buffered write data, send it via SMB2 WRITE first
if len(t.writeBuf) > 0 {
if build.Debug {
log.Printf("[D] RelayPipe: writing %d bytes to pipe", len(t.writeBuf))
}
if err := t.client.WritePipe(t.fileID, t.writeBuf); err != nil {
t.writeBuf = nil
return 0, fmt.Errorf("write pipe failed: %v", err)
}
t.writeBuf = nil
// Read response via SMB2 READ
if build.Debug {
log.Printf("[D] RelayPipe: reading response from pipe")
}
data, err := t.client.ReadPipe(t.fileID, 65536)
if err != nil {
return 0, fmt.Errorf("read pipe failed: %v", err)
}
t.readBuf = data
t.readOff = 0
}
// Return data from the read buffer
if t.readOff < len(t.readBuf) {
n := copy(b, t.readBuf[t.readOff:])
t.readOff += n
if build.Debug {
log.Printf("[D] RelayPipe: read returned %d bytes", n)
}
return n, nil
}
// No buffered data - need to read more from the pipe (overflow)
if build.Debug {
log.Printf("[D] RelayPipe: reading overflow via SMB2 READ")
}
data, err := t.client.ReadPipe(t.fileID, 65536)
if err != nil {
return 0, err
}
t.readBuf = data
t.readOff = 0
n := copy(b, t.readBuf)
t.readOff += n
return n, nil
}
// Close closes the pipe handle.
func (t *RelayPipeTransport) Close() error {
return t.client.ClosePipe(t.fileID)
}