ffi

package
v0.0.0-...-2efa699 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const WinDivertBatchMax = 0xFF /* 255 */
View Source
const WinDivertMTUMax = 40 + 0xFFFF
View Source
const WinDivertParamQueueLengthDefault = 4096
View Source
const WinDivertParamQueueLengthMax = 16384
View Source
const WinDivertParamQueueLengthMin = 32
View Source
const WinDivertParamQueueSizeDefault = 4194304 /* 4MB */
View Source
const WinDivertParamQueueSizeMax = 33554432 /* 32MB */
View Source
const WinDivertParamQueueSizeMin = 65535 /* 64KB */
View Source
const WinDivertParamQueueTimeDefault = 2000 /* 2s */
View Source
const WinDivertParamQueueTimeMax = 16000 /* 16s */
View Source
const WinDivertParamQueueTimeMin = 100 /* 100ms */
View Source
const WinDivertPriorityDefault = Priority(0)
View Source
const WinDivertPriorityHighest = Priority(30000)
View Source
const WinDivertPriorityLowest = Priority(-WinDivertPriorityHighest)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChecksumFlag

type ChecksumFlag int64
const (
	All      ChecksumFlag = 0x00
	NoIP     ChecksumFlag = 0x01
	NoICMP   ChecksumFlag = 0x02
	NoICMPv6 ChecksumFlag = 0x04
	NoTCP    ChecksumFlag = 0x08
	NoUDP    ChecksumFlag = 0x10
)

func (ChecksumFlag) String

func (i ChecksumFlag) String() string

type Direction

type Direction int
const (
	Outbound Direction = 1
	Inbound  Direction = 0
)

func (Direction) String

func (i Direction) String() string

type Event

type Event int

WINDIVERT_EVENT https://reqrypt.org/windivert-doc.html#divert_events

const (
	NetworkPacket Event = iota
	FlowEstablished
	FlowDeleted
	SocketBind
	SocketConnect
	SocketListen
	SocketAccept
	SocketClose
	ReflectOpen
	ReflectClose
)

func (Event) String

func (i Event) String() string

type Filter

type Filter string

func (*Filter) String

func (f *Filter) String() string

String returns the string representation of the filter, with trailing zeroes trimmed

type Flag

type Flag uint8
const (
	None        Flag = 0x00
	Sniff       Flag = 0x01
	Drop        Flag = 0x02
	ReceiveOnly Flag = 0x04
	SendOnly    Flag = 0x08
	NoInstall   Flag = 0x10
	Fragments   Flag = 0x20
)

func (Flag) String

func (flags Flag) String() string

type Layer

type Layer int

WINDIVERT_LAYER https://reqrypt.org/windivert-doc.html#divert_layers

const (
	// Network packets to/from the local machine.
	Network Layer = iota
	// Network packets passing through the local machine.
	NetworkForward
	// Network flow established/deleted events.
	Flow
	// Socket operation events.
	Socket
	// Reflect WinDivert handle events.
	Reflect
)

func (Layer) String

func (i Layer) String() string

type LibraryReference

type LibraryReference struct {

	// WinDivertOpen opens a WinDivert handle.
	WinDivertOpen *syscall.LazyProc `func:"WinDivertOpen"`

	// WinDivertRecv receives (reads) a packet from a WinDivert handle.
	WinDivertRecv *syscall.LazyProc `func:"WinDivertRecv"`

	// WinDivertRecvEx receives (reads) a packet from a WinDivert handle.
	WinDivertRecvEx *syscall.LazyProc `func:"WinDivertRecvEx"`

	// WinDivertSend sends (writes/injects) a packet to a WinDivert handle.
	WinDivertSend *syscall.LazyProc `func:"WinDivertSend"`

	// WinDivertSendEx sends (writes/injects) a packet to a WinDivert handle.
	WinDivertSendEx *syscall.LazyProc `func:"WinDivertSendEx"`

	// WinDivertShutdown shuts down a WinDivert handle.
	WinDivertShutdown *syscall.LazyProc `func:"WinDivertShutdown"`

	// WinDivertClose closes a WinDivert handle.
	WinDivertClose *syscall.LazyProc `func:"WinDivertClose"`

	// WinDivertSetParam sets a WinDivert handle parameter.
	WinDivertSetParam *syscall.LazyProc `func:"WinDivertSetParam"`

	// WinDivertGetParam gets a WinDivert handle parameter.
	WinDivertGetParam *syscall.LazyProc `func:"WinDivertGetParam"`

	WinDivertHelperParsePacket       *syscall.LazyProc `func:"WinDivertHelperParsePacket"`
	WinDivertHelperHashPacket        *syscall.LazyProc `func:"WinDivertHelperHashPacket"`
	WinDivertHelperParseIPv4Address  *syscall.LazyProc `func:"WinDivertHelperParseIPv4Address"`
	WinDivertHelperParseIPv6Address  *syscall.LazyProc `func:"WinDivertHelperParseIPv6Address"`
	WinDivertHelperFormatIPv4Address *syscall.LazyProc `func:"WinDivertHelperFormatIPv4Address"`
	WinDivertHelperFormatIPv6Address *syscall.LazyProc `func:"WinDivertHelperFormatIPv6Address"`
	WinDivertHelperCalcChecksums     *syscall.LazyProc `func:"WinDivertHelperCalcChecksums"`
	WinDivertHelperDecrementTTL      *syscall.LazyProc `func:"WinDivertHelperDecrementTTL"`
	WinDivertHelperCompileFilter     *syscall.LazyProc `func:"WinDivertHelperCompileFilter"`
	WinDivertHelperEvalFilter        *syscall.LazyProc `func:"WinDivertHelperEvalFilter"`
	WinDivertHelperFormatFilter      *syscall.LazyProc `func:"WinDivertHelperFormatFilter"`
	WinDivertHelperNtohs             *syscall.LazyProc `func:"WinDivertHelperNtohs"`
	WinDivertHelperNtohl             *syscall.LazyProc `func:"WinDivertHelperNtohl"`
	WinDivertHelperNtohll            *syscall.LazyProc `func:"WinDivertHelperNtohll"`
	WinDivertHelperNtohIPv6Address   *syscall.LazyProc `func:"WinDivertHelperNtohIPv6Address"`
	WinDivertHelperHtons             *syscall.LazyProc `func:"WinDivertHelperHtons"`
	WinDivertHelperHtonl             *syscall.LazyProc `func:"WinDivertHelperHtonl"`
	WinDivertHelperHtonll            *syscall.LazyProc `func:"WinDivertHelperHtonll"`
	WinDivertHelperHtonIPv6Address   *syscall.LazyProc `func:"WinDivertHelperHtonIPv6Address"`
	// contains filtered or unexported fields
}

LibraryReference contains functions to a memory copy of WinDivert.dll.

func NewDLLReference

func NewDLLReference(dllPath string) (ret *LibraryReference, err error)

NewDLLReference loads the WinDivert DLL into the program and makes all function pointers available.

func (*LibraryReference) CalcChecksums

func (l *LibraryReference) CalcChecksums(packet *Packet, flags ChecksumFlag)

(Re)calculates the checksum for any IPv4/ICMP/ICMPv6/TCP/UDP checksum present in the given packet. Individual checksum calculations may be disabled via the appropriate flag. Typically this function should be invoked on a modified packet before it is injected with WinDivertSend(). By default this function will calculate each checksum from scratch, even if the existing checksum is correct. This may be inefficient for some applications. For better performance, incremental checksum calculations should be used instead (not provided by this API). If pAddr is non-NULL, this function sets the corresponding *Checksum flag (see WINDIVERT_ADDRESS). Normally, pAddr should point to the address passed to WinDivertSend() for packet injection. https://reqrypt.org/windivert-doc.html#divert_helper_calc_checksums

func (*LibraryReference) Close

func (l *LibraryReference) Close(handle uintptr) error

Close closes the handle See https://reqrypt.org/windivert-doc.html#divert_close

func (*LibraryReference) CompileFilter

func (l *LibraryReference) CompileFilter(filter Filter, layer Layer) (object Filter, errorPosition uint, err error)

https://reqrypt.org/windivert-doc.html#divert_helper_compile_filter

func (*LibraryReference) DecrementTTL

func (l *LibraryReference) DecrementTTL(packet *Packet) (bool, error)

Decrements the ip.TTL or ipv6.HopHimit field by 1, and returns TRUE only if the result is non-zero. This is useful for applications where packet loops may be a problem. For IPv4, this function will preserve the validity of the IPv4 checksum. That is, if the packet had a valid checksum before the operation, the resulting checksum will also be valid after the operation. This function updates the checksum field incrementally. https://reqrypt.org/windivert-doc.html#divert_helper_dec_ttl

func (*LibraryReference) EvalFilter

func (l *LibraryReference) EvalFilter(packet *Packet, filter Filter) (bool, error)

Evaluates the given packet against the given packet filter string. This function returns TRUE if the packet matches, and returns FALSE otherwise. This function also returns FALSE if an error occurs, in which case GetLastError() can be used to get the reason for the error. Otherwise, if no error occurred, GetLastError() will return 0. Note that this function is relatively slow since the packet filter string will be (re)compiled for each call. This overhead can be minimized by pre-compiling the filter string into the object representation using the WinDivertHelperCompileFilter() function. https://reqrypt.org/windivert-doc.html#divert_helper_eval_filter

func (*LibraryReference) FormatFilter

func (l *LibraryReference) FormatFilter(filter Filter, layer Layer) (object Filter, err error)

https://reqrypt.org/windivert-doc.html#divert_helper_format_filter

func (*LibraryReference) GetParam

func (l *LibraryReference) GetParam(handle uintptr, param Param) (value uint64, err error)

func (*LibraryReference) Open

func (l *LibraryReference) Open(filter Filter, layer Layer, priority Priority, flag Flag) (handle uintptr, err error)

Open opens a new WinDivert handle.

func (*LibraryReference) Recv

func (l *LibraryReference) Recv(handle uintptr, receiveBufferSize uint) (*Packet, error)

Recv diverts a packet from the network stack https://reqrypt.org/windivert-doc.html#divert_recv

func (*LibraryReference) Send

func (l *LibraryReference) Send(handle uintptr, packet *Packet) (uint, error)

Send injects the packet on the network stack https://reqrypt.org/windivert-doc.html#divert_send

func (*LibraryReference) SetParam

func (l *LibraryReference) SetParam(handle uintptr, param Param, value uint64) (err error)

func (*LibraryReference) Shutdown

func (l *LibraryReference) Shutdown(handle uintptr, how Shutdown) error

type Packet

type Packet struct {
	Address *WinDivertAddress
	Length  uint
	Content []byte
}

Wrapped packet

func (*Packet) Decode

func (p *Packet) Decode(options gopacket.DecodeOptions) gopacket.Packet

func (*Packet) IPVersion

func (p *Packet) IPVersion() uint8

type Param

type Param int

WINDIVERT_PARAM

const (
	QueueLength  Param = 0
	QueueTime    Param = 1
	QueueSize    Param = 2
	VersionMajor Param = 3
	VersionMinor Param = 4
)

func (Param) String

func (i Param) String() string

type Priority

type Priority int16

Priority of the handles Multiple handles should not have the same priority.

type Shutdown

type Shutdown int64

WINDIVERT_SHUTDOWN

const (
	Recv Shutdown = 0x1
	Send Shutdown = 0x2
	Both Shutdown = 0x3
)

func (Shutdown) String

func (i Shutdown) String() string

type WinDivertAddress

type WinDivertAddress struct {
	// A timestamp indicating when event occurred.
	Timestamp int64
	// contains filtered or unexported fields
}

WINDIVERT_ADDRESS https://reqrypt.org/windivert-doc.html#divert_address

func (*WinDivertAddress) Direction

func (a *WinDivertAddress) Direction() Direction

Direction returns the direction of the packet

func (*WinDivertAddress) Event

func (a *WinDivertAddress) Event() Event

The captured event (WINDIVERT_EVENT_*).

func (*WinDivertAddress) Flow

func (*WinDivertAddress) IPChecksumValid

func (a *WinDivertAddress) IPChecksumValid() bool

Set to 1 if the IPv4 checksum is valid, 0 otherwise.

func (*WinDivertAddress) IPv6

func (a *WinDivertAddress) IPv6() bool

Set to 1 for IPv6 packets/events, 0 otherwise.

func (*WinDivertAddress) Impostor

func (a *WinDivertAddress) Impostor() bool

Set to 1 for impostor packets, 0 otherwise.

func (*WinDivertAddress) Layer

func (a *WinDivertAddress) Layer() Layer

The handle's layer (WINDIVERT_LAYER_*).

func (*WinDivertAddress) Loopback

func (a *WinDivertAddress) Loopback() bool

Set to 1 for loopback packets, 0 otherwise.

func (*WinDivertAddress) Network

func (*WinDivertAddress) Reflect

func (*WinDivertAddress) Sniffed

func (a *WinDivertAddress) Sniffed() bool

Set to 1 if the event was sniffed (i.e., not blocked), 0 otherwise.

func (*WinDivertAddress) Socket

func (*WinDivertAddress) TCPChecksumValid

func (a *WinDivertAddress) TCPChecksumValid() bool

Set to 1 if the TCP checksum is valid, 0 otherwise.

func (*WinDivertAddress) UDPChecksumValid

func (a *WinDivertAddress) UDPChecksumValid() bool

Set to 1 if the UDP checksum is valid, 0 otherwise.

type WinDivertDataFlow

type WinDivertDataFlow addressInternalUnion

WINDIVERT_DATA_FLOW

func (*WinDivertDataFlow) Endpoint

func (d *WinDivertDataFlow) Endpoint() uint64

The endpoint ID of the flow.

func (*WinDivertDataFlow) LocalAddr

func (d *WinDivertDataFlow) LocalAddr() netip.Addr

func (*WinDivertDataFlow) LocalPort

func (d *WinDivertDataFlow) LocalPort() uint16

func (*WinDivertDataFlow) ParentEndpoint

func (d *WinDivertDataFlow) ParentEndpoint() uint64

The parent endpoint ID of the flow.

func (*WinDivertDataFlow) ProcessId

func (d *WinDivertDataFlow) ProcessId() uint32

The ID of the process associated with the flow.

func (*WinDivertDataFlow) Protocol

func (d *WinDivertDataFlow) Protocol() uint8

func (*WinDivertDataFlow) RemoteAddr

func (d *WinDivertDataFlow) RemoteAddr() netip.Addr

func (*WinDivertDataFlow) RemotePort

func (d *WinDivertDataFlow) RemotePort() uint16

type WinDivertDataNetwork

type WinDivertDataNetwork addressInternalUnion

WINDIVERT_DATA_NETWORK

func (*WinDivertDataNetwork) IfIdx

func (d *WinDivertDataNetwork) IfIdx() uint32

The interface index on which the packet arrived (for inbound packets), or is to be sent (for outbound packets).

func (*WinDivertDataNetwork) SubIfIdx

func (d *WinDivertDataNetwork) SubIfIdx() uint32

The sub-interface index for IfIdx.

type WinDivertDataReflect

type WinDivertDataReflect addressInternalUnion

WINDIVERT_DATA_REFLECT

func (*WinDivertDataReflect) Flags

func (d *WinDivertDataReflect) Flags() Flag

func (*WinDivertDataReflect) Layer

func (d *WinDivertDataReflect) Layer() Layer

func (*WinDivertDataReflect) Priority

func (d *WinDivertDataReflect) Priority() int16

func (*WinDivertDataReflect) ProcessId

func (d *WinDivertDataReflect) ProcessId() uint32

The ID of the process that opened the handle.

func (*WinDivertDataReflect) Timestamp

func (d *WinDivertDataReflect) Timestamp() int64

A timestamp indicating when the handle was opened.

type WinDivertDataSocket

type WinDivertDataSocket addressInternalUnion

WINDIVERT_DATA_SOCKET

func (*WinDivertDataSocket) Endpoint

func (d *WinDivertDataSocket) Endpoint() uint64

The endpoint ID of the socket operation.

func (*WinDivertDataSocket) LocalAddr

func (d *WinDivertDataSocket) LocalAddr() netip.Addr

func (*WinDivertDataSocket) LocalPort

func (d *WinDivertDataSocket) LocalPort() uint16

func (*WinDivertDataSocket) ParentEndpoint

func (d *WinDivertDataSocket) ParentEndpoint() uint64

The parent endpoint ID of the socket operation.

func (*WinDivertDataSocket) ProcessId

func (d *WinDivertDataSocket) ProcessId() uint32

The ID of the process associated with the socket operation.

func (*WinDivertDataSocket) Protocol

func (d *WinDivertDataSocket) Protocol() uint8

func (*WinDivertDataSocket) RemoteAddr

func (d *WinDivertDataSocket) RemoteAddr() netip.Addr

func (*WinDivertDataSocket) RemotePort

func (d *WinDivertDataSocket) RemotePort() uint16

Jump to

Keyboard shortcuts

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