mongowire

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

from https://raw.githubusercontent.com/ma6174/mgosniff/cf913f17c2f681392231629e4c29d90b990a6d2d/utils.go

https://github.com/ma6174/mgosniff/blob/master/parser.go

Index

Constants

View Source
const (
	OpReply       = OpCode(1)
	OpMessage     = OpCode(1000)
	OpUpdate      = OpCode(2001)
	OpInsert      = OpCode(2002)
	Reserved      = OpCode(2003)
	OpQuery       = OpCode(2004)
	OpGetMore     = OpCode(2005)
	OpDelete      = OpCode(2006)
	OpKillCursors = OpCode(2007)
	OpCompressed  = OpCode(2012)
	OpMsg         = OpCode(2013)
)

The full set of known request op codes: http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#request-opcodes

View Source
const HeaderLen = 16

Variables

This section is empty.

Functions

func MustReadInt32

func MustReadInt32(r io.Reader) (n int32)

func MustReadInt64

func MustReadInt64(r io.Reader) (n int64)

func MustReadUInt32

func MustReadUInt32(r io.Reader) (n uint32)

func MustReadUInt8

func MustReadUInt8(r io.Reader) (n uint8)

func ReadBytes

func ReadBytes(r io.Reader, n int) []byte

func ReadCString

func ReadCString(r io.Reader) string

func ReadDocument

func ReadDocument(r io.Reader) (m bson.D)

func ReadDocuments

func ReadDocuments(r io.Reader) (ms []bson.D)

func ReadInt32

func ReadInt32(r io.Reader) (n int32, err error)

func ReadInt64

func ReadInt64(r io.Reader) *int64

func ReadOne

func ReadOne(r io.Reader) []byte

func ToJson

func ToJson(v interface{}, l int) string

Types

type CountingReader

type CountingReader struct {
	BytesRead int
	// contains filtered or unexported fields
}

func (*CountingReader) Read

func (r *CountingReader) Read(p []byte) (n int, err error)

type Crc32c

type Crc32c struct {
	// contains filtered or unexported fields
}

func (*Crc32c) CheckCrc

func (c *Crc32c) CheckCrc(crc uint32) bool

func (*Crc32c) GetCrc

func (c *Crc32c) GetCrc() uint32

func (*Crc32c) Init

func (c *Crc32c) Init()

func (*Crc32c) String

func (c *Crc32c) String() string

func (*Crc32c) UpdateCrc

func (c *Crc32c) UpdateCrc(msg []byte)

func (*Crc32c) Write

func (c *Crc32c) Write(msg []byte) (int, error)

type MSGSection

type MSGSection interface {
	MSGSection()
}

type MSGSection_Body

type MSGSection_Body struct {
	Document bson.D
}

func (MSGSection_Body) MSGSection

func (MSGSection_Body) MSGSection()

type MSGSection_DocumentSequence

type MSGSection_DocumentSequence struct {
	Size               int32
	SequenceIdentifier string
	Documents          []bson.D
}

func (MSGSection_DocumentSequence) MSGSection

func (MSGSection_DocumentSequence) MSGSection()

type MessageHeader

type MessageHeader struct {
	// MessageLength is the total message size, including this header
	MessageLength int32
	// RequestID is the identifier for this miessage
	RequestID int32
	// ResponseTo is the RequestID of the message being responded to. used in DB responses
	ResponseTo int32
	// OpCode is the request type, see consts above.
	OpCode OpCode
}

MessageHeader is the mongo MessageHeader

func ReadHeader

func ReadHeader(r io.Reader) (*MessageHeader, error)

func (*MessageHeader) FromWire

func (m *MessageHeader) FromWire(b []byte)

FromWire reads the wirebytes into this object

func (*MessageHeader) String

func (m *MessageHeader) String() string

String returns a string representation of the message header. Useful for debugging.

func (MessageHeader) ToWire

func (m MessageHeader) ToWire() ([]byte, error)

ToWire converts the MessageHeader to the wire protocol

func (*MessageHeader) WriteTo

func (m *MessageHeader) WriteTo(w io.Writer) error

type OP_COMPRESSED

type OP_COMPRESSED struct {
	Header            MessageHeader
	OriginalOpcode    OpCode
	UncompressedSize  int32
	CompressorID      wiremessage.CompressorID
	CompressedMessage []byte
}

func (*OP_COMPRESSED) FromWire

func (o *OP_COMPRESSED) FromWire(r io.Reader) error

func (*OP_COMPRESSED) GetHeader

func (m *OP_COMPRESSED) GetHeader() MessageHeader

func (*OP_COMPRESSED) ToWire

func (o *OP_COMPRESSED) ToWire() ([]byte, error)

func (*OP_COMPRESSED) WriteTo

func (o *OP_COMPRESSED) WriteTo(w io.Writer) error

type OP_GETMORE

type OP_GETMORE struct {
	Header             MessageHeader
	Flags              int32
	FullCollectionName string
	NumberToReturn     int32
	CursorID           int64
}

func (*OP_GETMORE) FromWire

func (m *OP_GETMORE) FromWire(r io.Reader)

func (*OP_GETMORE) GetHeader

func (m *OP_GETMORE) GetHeader() MessageHeader

type OP_KILL_CURSORS

type OP_KILL_CURSORS struct {
	Header            MessageHeader
	ZERO              int32
	NumberOfCursorIDs int32
	CursorIDs         []int64
}

func (*OP_KILL_CURSORS) FromWire

func (m *OP_KILL_CURSORS) FromWire(r io.Reader)

func (*OP_KILL_CURSORS) GetHeader

func (m *OP_KILL_CURSORS) GetHeader() MessageHeader

type OP_MSG

type OP_MSG struct {
	Header   MessageHeader
	Flags    OP_MSG_Flags
	Sections []MSGSection
	Checksum uint32
}

func (*OP_MSG) FromWire

func (o *OP_MSG) FromWire(r io.Reader, crc *Crc32c, msgLen int) error

func (*OP_MSG) GetHeader

func (m *OP_MSG) GetHeader() MessageHeader

func (*OP_MSG) ToWire

func (o *OP_MSG) ToWire() ([]byte, error)

func (*OP_MSG) WriteTo

func (o *OP_MSG) WriteTo(w io.Writer) error

type OP_MSG_Flags

type OP_MSG_Flags int32

func (OP_MSG_Flags) ChecksumPresent

func (f OP_MSG_Flags) ChecksumPresent() bool

func (OP_MSG_Flags) MoreToCome

func (f OP_MSG_Flags) MoreToCome() bool

type OP_QUERY

type OP_QUERY struct {
	Header             MessageHeader
	Flags              OP_QUERY_Flags
	FullCollectionName string
	NumberToSkip       int32
	NumberToReturn     int32

	Query                bson.D
	ReturnFieldsSelector bson.D
}

func (*OP_QUERY) FromWire

func (m *OP_QUERY) FromWire(r io.Reader)

func (*OP_QUERY) GetHeader

func (m *OP_QUERY) GetHeader() MessageHeader

type OP_QUERY_Flags

type OP_QUERY_Flags int32

func (OP_QUERY_Flags) AwaitData

func (f OP_QUERY_Flags) AwaitData() bool

func (OP_QUERY_Flags) Exhaust

func (f OP_QUERY_Flags) Exhaust() bool

func (OP_QUERY_Flags) NoCursorTimeout

func (f OP_QUERY_Flags) NoCursorTimeout() bool

func (OP_QUERY_Flags) OplogReplay

func (f OP_QUERY_Flags) OplogReplay() bool

func (OP_QUERY_Flags) Partial

func (f OP_QUERY_Flags) Partial() bool

func (OP_QUERY_Flags) SlaveOk

func (f OP_QUERY_Flags) SlaveOk() bool

func (OP_QUERY_Flags) TailableCursor

func (f OP_QUERY_Flags) TailableCursor() bool

type OP_REPLY

type OP_REPLY struct {
	Header         MessageHeader
	Flags          int32
	CursorID       int64
	StartingFrom   int32
	NumberReturned int32
	Documents      []bson.D // interface?
}

func (*OP_REPLY) GetHeader

func (m *OP_REPLY) GetHeader() MessageHeader

func (*OP_REPLY) ToWire

func (o *OP_REPLY) ToWire() ([]byte, error)

func (*OP_REPLY) WriteTo

func (o *OP_REPLY) WriteTo(w io.Writer) error

type OpCode

type OpCode int32

OpCode allow identifying the type of operation:

http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#request-opcodes

func (OpCode) HasResponse

func (c OpCode) HasResponse() bool

HasResponse tells us if the operation will have a response from the server.

func (OpCode) IsMutation

func (c OpCode) IsMutation() bool

IsMutation tells us if the operation will mutate data. These operations can be followed up by a getLastErr operation.

func (OpCode) String

func (c OpCode) String() string

String returns a human readable representation of the OpCode.

type Request

type Request struct {
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(c io.Reader) (*Request, error)

func NewRequestWithHeader

func NewRequestWithHeader(h MessageHeader, c io.Reader) *Request

func (*Request) GetHeader

func (req *Request) GetHeader() *MessageHeader

func (*Request) GetOpCompressed

func (req *Request) GetOpCompressed() *OP_COMPRESSED

func (*Request) GetOpKillCursors

func (req *Request) GetOpKillCursors() *OP_KILL_CURSORS

func (*Request) GetOpMore

func (req *Request) GetOpMore() *OP_GETMORE

func (*Request) GetOpMsg

func (req *Request) GetOpMsg() *OP_MSG

func (*Request) GetOpQuery

func (req *Request) GetOpQuery() *OP_QUERY

type WireSerializer

type WireSerializer interface {
	GetHeader() MessageHeader
	//ToWire() []byte
	WriteTo(io.Writer) error
}

Jump to

Keyboard shortcuts

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