gonfapi

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2021 License: LGPL-2.1 Imports: 9 Imported by: 0

README

gonfapi

gonfapi

Documentation

Overview

gonfapi Package sort provides primitives for sorting slices and user-defined collections.

Index

Constants

View Source
const (
	TCP_PACKET_BUF_SIZE int32 = 8192
	UDP_PACKET_BUF_SIZE int32 = 2 * 65536
)

C enum and #define is 4Bytes

View Source
const (
	MAX_ADDRESS_LENGTH    = 28
	MAX_IP_ADDRESS_LENGTH = 16
	AF_INET               = 2
	AF_INET6              = 23
	IPPROTO_UDP           = 17
	IPPROTO_TCP           = 6
)

Variables

This section is empty.

Functions

func PtrToBytes

func PtrToBytes(b *byte, len int) (data []byte)

指针转到数组切片

Types

type DIRECTION

type DIRECTION int32
const (
	D_IN   DIRECTION = 1
	D_OUT  DIRECTION = 2
	D_BOTH DIRECTION = 3
)

type DataCode

type DataCode int32
const (
	TCP_CONNECTED DataCode = iota
	TCP_CLOSED
	TCP_RECEIVE
	TCP_SEND
	TCP_CAN_RECEIVE
	TCP_CAN_SEND
	TCP_REQ_SUSPEND
	TCP_REQ_RESUME
	//UDP
	UDP_CREATED
	UDP_CLOSED
	UDP_RECEIVE
	UDP_SEND
	UDP_CAN_RECEIVE
	UDP_CAN_SEND
	UDP_REQ_SUSPEND
	UDP_REQ_RESUME
	//REQ RULE
	REQ_ADD_HEAD_RULE
	REQ_ADD_TAIL_RULE
	REQ_DELETE_RULES
	//CONNECT
	TCP_CONNECT_REQUEST
	UDP_CONNECT_REQUEST
	//other
	TCP_DISABLE_USER_MODE_FILTERING
	UDP_DISABLE_USER_MODE_FILTERING

	REQ_SET_TCP_OPT
	REQ_IS_PROXY

	TCP_REINJECT
	TCP_REMOVE_CLOSED
	TCP_DEFERRED_DISCONNECT

	IP_RECEIVE
	IP_SEND
	TCP_RECEIVE_PUSH
)

type EventHandler

type EventHandler interface {
	ThreadStart() uintptr
	ThreadEnd() uintptr
	TcpConnectRequest(id uint64, pConnInfo *NF_TCP_CONN_INFO) uintptr
	TcpConnected(id uint64, pConnInfo *NF_TCP_CONN_INFO) uintptr
	TcpClosed(id uint64, pConnInfo *NF_TCP_CONN_INFO) uintptr
	TcpReceive(id uint64, buf *byte, len int32) uintptr
	TcpSend(id uint64, buf *byte, len int32) uintptr
	TcpCanReceive(id uint64) uintptr
	TcpCanSend(id uint64) uintptr
	UdpCreated(id uint64, pConnInfo *NF_UDP_CONN_INFO) uintptr
	UdpConnectRequest(id uint64, pConnInfo *NF_UDP_CONN_REQUEST) uintptr
	UdpClosed(id uint64, pConnInfo *NF_UDP_CONN_INFO) uintptr
	UdpReceive(id uint64, remoteAddress *SockaddrInx, buf *byte, len int32, options *NF_UDP_OPTIONS) uintptr
	UdpSend(id uint64, remoteAddress *SockaddrInx, buf *byte, len int32, options *NF_UDP_OPTIONS) uintptr
	UdpCanReceive(id uint64) uintptr
	UdpCanSend(id uint64) uintptr
}

事件回调接口 所有返回值为0

type FILTERING_FLAG

type FILTERING_FLAG uint32
const (
	NF_ALLOW                       FILTERING_FLAG = 0   // Allow the activity without filtering transmitted packets
	NF_BLOCK                       FILTERING_FLAG = 1   // Block the activity
	NF_FILTER                      FILTERING_FLAG = 2   // Filter the transmitted packets
	NF_SUSPENDED                   FILTERING_FLAG = 4   // Suspend receives from server and sends from client
	NF_OFFLINE                     FILTERING_FLAG = 8   // Emulate establishing a TCP connection with remote server
	NF_INDICATE_CONNECT_REQUESTS   FILTERING_FLAG = 16  // Indicate outgoing connect requests to API
	NF_DISABLE_REDIRECT_PROTECTION FILTERING_FLAG = 32  // Disable blocking indicating connect requests for outgoing connections of local proxies
	NF_PEND_CONNECT_REQUEST        FILTERING_FLAG = 64  // Pend outgoing connect request to complete it later using nf_complete(TCP|UDP)ConnectRequest
	NF_FILTER_AS_IP_PACKETS        FILTERING_FLAG = 128 // Indicate the traffic as IP packets via ipSend/ipReceive
	NF_READONLY                    FILTERING_FLAG = 256 // Don't block the IP packets and indicate them to ipSend/ipReceive only for monitoring
	NF_CONTROL_FLOW                FILTERING_FLAG = 512
)

type INT16

type INT16 = basetype.INT16

type INT32

type INT32 = basetype.INT32

type IpAddress

type IpAddress [16]byte

IP Addres

|0000|0000|0000|0000|

|ipv4|

|------ ipv6 -------|

func (*IpAddress) GetIP

func (s *IpAddress) GetIP(v4 bool) (ip net.IP)

func (*IpAddress) SetIP

func (s *IpAddress) SetIP(v4 bool, ip net.IP)

type NFApi

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

func NewLoad

func NewLoad(dll string) (*NFApi, error)

func (*NFApi) Load

func (a *NFApi) Load(dll string) error

读取DLL

func (NFApi) NfAddBindingRule

func (a NFApi) NfAddBindingRule(prule *NF_BINDING_RULE, toHead bool) (NF_STATUS, error)

func (NFApi) NfAddFlowCtl

func (a NFApi) NfAddFlowCtl(pData *NF_FLOWCTL_DATA, pFcHandle *uint32) (NF_STATUS, error)

func (NFApi) NfAddRule

func (a NFApi) NfAddRule(rule *NF_RULE, ToHead bool) (NF_STATUS, error)

添加规则

func (NFApi) NfAddRuleEx

func (a NFApi) NfAddRuleEx(rule *NF_RULE_EX, ToHead bool) (NF_STATUS, error)

添加扩展规则

func (NFApi) NfAdjustProcessPriviledges

func (a NFApi) NfAdjustProcessPriviledges()

运行当前进程查看所有进行名称

func (NFApi) NfCompleteTCPConnectRequest

func (a NFApi) NfCompleteTCPConnectRequest(id uint64, pConnInfo *NF_TCP_CONN_INFO) (NF_STATUS, error)

完成TCP请求

func (NFApi) NfCompleteUDPConnectRequest

func (a NFApi) NfCompleteUDPConnectRequest(id uint64, pConnInfo *NF_UDP_CONN_INFO) (NF_STATUS, error)

完成UDP请求

func (NFApi) NfDeleteBindingRules

func (a NFApi) NfDeleteBindingRules() (NF_STATUS, error)

func (NFApi) NfDeleteFlowCtl

func (a NFApi) NfDeleteFlowCtl(fcHandle uint32) (NF_STATUS, error)

func (NFApi) NfDeleteRules

func (a NFApi) NfDeleteRules() (NF_STATUS, error)

删除规则

func (NFApi) NfFree

func (a NFApi) NfFree()

释放

func (NFApi) NfGetConnCount

func (a NFApi) NfGetConnCount() (uint32, error)

Debug routine

func (NFApi) NfGetDriverType

func (a NFApi) NfGetDriverType() (uint32, error)

func (NFApi) NfGetFlowCtlStat

func (a NFApi) NfGetFlowCtlStat(fcHandle uint32, pData *NF_FLOWCTL_STAT) (NF_STATUS, error)

func (NFApi) NfGetProcessNameFromKernel

func (a NFApi) NfGetProcessNameFromKernel(processId uint32) (string, bool, error)

获取进程名称(内核)

func (NFApi) NfGetProcessNameW

func (a NFApi) NfGetProcessNameW(processId uint32) (string, bool, error)

获取进程名称

func (NFApi) NfGetTCPConnInfo

func (a NFApi) NfGetTCPConnInfo(id uint64, pConnInfo *NF_TCP_CONN_INFO) (NF_STATUS, error)

获取TCP链接信息

func (NFApi) NfGetTCPStat

func (a NFApi) NfGetTCPStat(id uint64, pData *NF_FLOWCTL_STAT) (NF_STATUS, error)

func (NFApi) NfGetUDPConnInfo

func (a NFApi) NfGetUDPConnInfo(id uint64, pConnInfo *NF_UDP_CONN_INFO) (NF_STATUS, error)

获取UDP链接信息

func (NFApi) NfGetUDPStat

func (a NFApi) NfGetUDPStat(id uint64, pData *NF_FLOWCTL_STAT) (NF_STATUS, error)

func (NFApi) NfInit

func (a NFApi) NfInit(driverName string, Ev *NF_EventHandler) (NF_STATUS, error)

初始化

func (NFApi) NfIpPostReceive

func (a NFApi) NfIpPostReceive(buf []byte, option *NF_IP_PACKET_OPTIONS) (NF_STATUS, error)

接收UDP数据

func (NFApi) NfIpPostSend

func (a NFApi) NfIpPostSend(buf []byte, option *NF_IP_PACKET_OPTIONS) (NF_STATUS, error)

发送IP数据

func (NFApi) NfModifyFlowCtl

func (a NFApi) NfModifyFlowCtl(fcHandle uint32, pData *NF_FLOWCTL_DATA) (NF_STATUS, error)

func (NFApi) NfRegisterDriver

func (a NFApi) NfRegisterDriver(driverName string) (NF_STATUS, error)

注册驱动

func (NFApi) NfRegisterDriverEx

func (a NFApi) NfRegisterDriverEx(driverName string, path string) (NF_STATUS, error)

从其他位置注册驱动

func (NFApi) NfSetOptions

func (a NFApi) NfSetOptions(nThreads uint16, flag uint16)

设置NFAPI选项

func (NFApi) NfSetRules

func (a NFApi) NfSetRules(rule []NF_RULE) (NF_STATUS, error)

设置规则

func (NFApi) NfSetRulesEx

func (a NFApi) NfSetRulesEx(rule []NF_RULE_EX) (NF_STATUS, error)

设置扩展规则

func (NFApi) NfSetTCPFlowCtl

func (a NFApi) NfSetTCPFlowCtl(id uint64, fcHandle uint32) (NF_STATUS, error)

func (NFApi) NfSetTCPTimeout

func (a NFApi) NfSetTCPTimeout(id uint32) (NF_STATUS, error)

tcp超时

func (NFApi) NfSetUDPFlowCtl

func (a NFApi) NfSetUDPFlowCtl(id uint64, fcHandle uint32) (NF_STATUS, error)

func (NFApi) NfTcpClose

func (a NFApi) NfTcpClose(id uint64) (NF_STATUS, error)

tcp关闭

func (NFApi) NfTcpDisableFiltering

func (a NFApi) NfTcpDisableFiltering(id uint64) (NF_STATUS, error)

禁用TCP过滤

func (NFApi) NfTcpIsProxy

func (a NFApi) NfTcpIsProxy(processId uint32) (bool, error)

进程TCP是否代理

func (NFApi) NfTcpPostReceive

func (a NFApi) NfTcpPostReceive(id uint64, bufer []byte) (NF_STATUS, error)

TCP数据接受

func (NFApi) NfTcpPostSend

func (a NFApi) NfTcpPostSend(id uint64, bufer []byte) (NF_STATUS, error)

TCP数据发送

func (NFApi) NfTcpSetConnectionState

func (a NFApi) NfTcpSetConnectionState(id uint64, suspended bool) (NF_STATUS, error)

设置TCP链接状态

func (NFApi) NfTcpSetSockOpt

func (a NFApi) NfTcpSetSockOpt(id uint64, optname int32, optval []byte) (NF_STATUS, error)

设置TCP链接参数

func (NFApi) NfUdpDisableFiltering

func (a NFApi) NfUdpDisableFiltering(id uint64) (NF_STATUS, error)

禁用UDP过滤

func (NFApi) NfUdpPostReceive

func (a NFApi) NfUdpPostReceive(id uint64, remoteAddress []byte, buf []byte, option *NF_UDP_OPTIONS) (NF_STATUS, error)

接收UDP数据

func (NFApi) NfUdpPostSend

func (a NFApi) NfUdpPostSend(id uint64, remoteAddress []byte, buf []byte, option *NF_UDP_OPTIONS) (NF_STATUS, error)

发送UDP数据

func (NFApi) NfUdpSetConnectionState

func (a NFApi) NfUdpSetConnectionState(id uint64, suspended bool) (NF_STATUS, error)

设置UDP链接状态

func (NFApi) NfUnRegisterDriver

func (a NFApi) NfUnRegisterDriver(driverName string) (NF_STATUS, error)

卸载驱动服务(需要重启或手动停止服务才可以重新注册)

type NF_BINDING_RULE

type NF_BINDING_RULE struct {
	Protocol           INT32
	ProcessId          UINT32
	ProcessName        [260]UINT16
	LocalPort          UINT16
	IpFamily           UINT16
	LocalIpAddress     IpAddress
	LocalIpAddressMask IpAddress
	NewLocalIpAddress  IpAddress
	NewLocalPort       UINT16
	FilteringFlag      UINT32
}

type NF_BUFFERS

type NF_BUFFERS struct {
	InBuf, InBufLen, OutBuf, OutBufLen uint64
}

type NF_DATA

type NF_DATA struct {
	Code       INT32
	ID         UINT64
	BufferSize UINT32
	Buffer     byte
}

type NF_EventHandler

type NF_EventHandler struct {
	ThreadStart       uintptr
	ThreadEnd         uintptr
	TcpConnectRequest uintptr
	TcpConnected      uintptr
	TcpClosed         uintptr
	TcpReceive        uintptr
	TcpSend           uintptr
	TcpCanReceive     uintptr
	TcpCanSend        uintptr
	UdpCreated        uintptr
	UdpConnectRequest uintptr
	UdpClosed         uintptr
	UdpReceive        uintptr
	UdpSend           uintptr
	UdpCanReceive     uintptr
	UdpCanSend        uintptr
}

NF_EventHandler 传递到dll的结构体 所有字段皆为回调参数指针

func (*NF_EventHandler) Build

func (eh *NF_EventHandler) Build(e EventHandler)

赋值EventHandler的指针

type NF_FLOWCTL_DATA

type NF_FLOWCTL_DATA struct {
	InLimit, OutLimit UINT64
}

type NF_FLOWCTL_MODIFY_DATA

type NF_FLOWCTL_MODIFY_DATA struct {
	FcHandle uint32
	Data     NF_FLOWCTL_DATA
}

type NF_FLOWCTL_SET_DATA

type NF_FLOWCTL_SET_DATA struct {
	EndpointId UINT64
	FcHandle   UINT32
}

type NF_FLOWCTL_STAT

type NF_FLOWCTL_STAT struct {
	InBytes, OutBytes UINT64
}

type NF_IP_FLAG

type NF_IP_FLAG uint32

IP

const (
	NFIF_NONE NF_IP_FLAG = iota
	NFIF_READONLY
)

type NF_IP_PACKET_OPTIONS

type NF_IP_PACKET_OPTIONS struct {
	IpFamily          UINT16
	IpHeaderSize      UINT32
	CompartmentId     UINT32
	InterfaceIndex    UINT32
	SubInterfaceIndex UINT32
	Flags             UINT32
}

* * IP options *

type NF_PORT_RANGE

type NF_PORT_RANGE struct {
	ValueLow  UINT16
	ValueHigh UINT16
}

NF_PORT_RANGE

type NF_READ_RESULT

type NF_READ_RESULT struct {
	Length uint64
}

type NF_RULE

type NF_RULE struct {
	Protocol            INT32
	ProcessId           UINT32
	Direction           uint8
	LocalPort           UINT16
	RemotePort          UINT16
	IpFamily            INT16
	LocalIpAddress      IpAddress
	LocalIpAddressMask  IpAddress
	RemoteIpAddress     IpAddress
	RemoteIpAddressMask IpAddress
	FilteringFlag       UINT32
}

NF_RULE

type NF_RULE_EX

type NF_RULE_EX struct {
	NF_RULE

	LocalPortRange      NF_PORT_RANGE
	RemotePortRange     NF_PORT_RANGE
	RedirectTo          SockaddrInx
	LocalProxyProcessId UINT32
	// contains filtered or unexported fields
}

NF_RULE_EX

func (*NF_RULE_EX) GetProcessName

func (n *NF_RULE_EX) GetProcessName() string

func (*NF_RULE_EX) SetProcessName

func (n *NF_RULE_EX) SetProcessName(s string)

type NF_STATUS

type NF_STATUS int32
const (
	NF_STATUS_SUCCESS             NF_STATUS = 0
	NF_STATUS_FAIL                NF_STATUS = -1
	NF_STATUS_INVALID_ENDPOINT_ID NF_STATUS = -2
	NF_STATUS_NOT_INITIALIZED     NF_STATUS = -3
	NF_STATUS_IO_ERROR            NF_STATUS = -4
	NF_STATUS_REBOOT_REQUIRED     NF_STATUS = -5
)

type NF_TCP_CONN_INFO

type NF_TCP_CONN_INFO struct {
	FilteringFlag UINT32
	ProcessId     UINT32
	Direction     uint8
	IpFamily      UINT16
	LocalAddress  SockaddrInx
	RemoteAddress SockaddrInx
}

* * TCP connection properties UNALIGNED *

type NF_UDP_CONN_INFO

type NF_UDP_CONN_INFO struct {
	ProcessId    UINT32
	IpFamily     UINT16
	LocalAddress SockaddrInx
}

* * UDP endpoint properties UNALIGNED *

type NF_UDP_CONN_REQUEST

type NF_UDP_CONN_REQUEST struct {
	FilteringFlag UINT32
	ProcessId     UINT32
	IpFamily      UINT16
	LocalAddress  SockaddrInx
	RemoteAddress SockaddrInx
}

* * UDP TDI_CONNECT request properties UNALIGNED *

type NF_UDP_OPTIONS

type NF_UDP_OPTIONS struct {
	Flags         UINT32
	OptionsLength INT32
	Options       [2048]byte //Options of variable size
}

* * UDP options UNALIGNED *

func (NF_UDP_OPTIONS) GetBytes added in v0.0.2

func (op NF_UDP_OPTIONS) GetBytes() (data []byte)

type SockaddrInx

type SockaddrInx struct {
	Family      UINT16   //AF_INT or AF_INT6. LittleEndian
	Port        UINT16   //Port. BigEndian
	Data1       [4]byte  //ipv4 Adder,ipv6 is zero. BigEndian
	Data2       [16]byte //ipv6 Adder,ipv4 is zero. BigEndian
	IPV6ScopeId UINT32   //ipv6 scope id
}

sockaddr_in4/6

func PtrToAddress

func PtrToAddress(b *byte) *SockaddrInx

指针转到SockaddrInx

func (*SockaddrInx) GetIP

func (s *SockaddrInx) GetIP() (v4 bool, ip net.IP)

func (*SockaddrInx) GetPort

func (s *SockaddrInx) GetPort() uint16

func (*SockaddrInx) IsIpv6

func (s *SockaddrInx) IsIpv6() bool

func (*SockaddrInx) SetIP

func (s *SockaddrInx) SetIP(v4 bool, ip net.IP)

func (*SockaddrInx) SetPort

func (s *SockaddrInx) SetPort(p uint16)

func (*SockaddrInx) String

func (s *SockaddrInx) String() string

func (*SockaddrInx) ToBytes

func (s *SockaddrInx) ToBytes() (data []byte)

type UINT16

type UINT16 = basetype.UINT16

type UINT32

type UINT32 = basetype.UINT32

type UINT64

type UINT64 = basetype.UINT64

Directories

Path Synopsis
Applicable to unaligned structures
Applicable to unaligned structures

Jump to

Keyboard shortcuts

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