Create first test integration for new windows kext
This commit is contained in:
21
firewall/interception/kexttest/main.go
Normal file
21
firewall/interception/kexttest/main.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/Safing/portmaster/firewall/interception/windowskext"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
kext, err := windowskext.New("./WinDivert.dll")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
vR, err := kext.RecvVerdictRequest()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("verdictRequest: %+v", vR)
|
||||||
|
}
|
||||||
@@ -205,8 +205,8 @@ func (wd *WinDivert) GetParam(param uintptr) (uint64, error) {
|
|||||||
var value uint64
|
var value uint64
|
||||||
|
|
||||||
r1, _, lastErr := wd.getParam.Call(
|
r1, _, lastErr := wd.getParam.Call(
|
||||||
wd.handle, // __in HANDLE handle
|
wd.handle, // __in HANDLE handle
|
||||||
param, // __in WINDIVERT_PARAM param
|
param, // __in WINDIVERT_PARAM param
|
||||||
uintptr(unsafe.Pointer(&value)), // __out UINT64 *pValue
|
uintptr(unsafe.Pointer(&value)), // __out UINT64 *pValue
|
||||||
)
|
)
|
||||||
if r1 == rvFalse {
|
if r1 == rvFalse {
|
||||||
@@ -220,7 +220,7 @@ func (wd *WinDivert) HelperCalcChecksums(packetData []byte, address *WinDivertAd
|
|||||||
byteSliceToPtr(packetData), // __inout PVOID pPacket
|
byteSliceToPtr(packetData), // __inout PVOID pPacket
|
||||||
uintptr(len(packetData)), // __in UINT packetLen
|
uintptr(len(packetData)), // __in UINT packetLen
|
||||||
uintptr(unsafe.Pointer(address)), // __in_opt PWINDIVERT_ADDRESS pAddr
|
uintptr(unsafe.Pointer(address)), // __in_opt PWINDIVERT_ADDRESS pAddr
|
||||||
flags, // __in UINT64 flags
|
flags, // __in UINT64 flags
|
||||||
)
|
)
|
||||||
if r1 == rvFalse {
|
if r1 == rvFalse {
|
||||||
return lastErr
|
return lastErr
|
||||||
|
|||||||
62
firewall/interception/windowskext/kext.go
Normal file
62
firewall/interception/windowskext/kext.go
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package windowskext
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
|
||||||
|
"github.com/tevino/abool"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WinKext struct {
|
||||||
|
dll *windows.DLL
|
||||||
|
|
||||||
|
recvVerdictRequest *windows.Proc
|
||||||
|
|
||||||
|
valid *abool.AtomicBool
|
||||||
|
}
|
||||||
|
|
||||||
|
type VerdictRequest struct {
|
||||||
|
ID uint32
|
||||||
|
ProcessID uint32
|
||||||
|
Direction bool
|
||||||
|
IPv6 bool
|
||||||
|
SrcIP [4]uint32
|
||||||
|
DstIP [4]uint32
|
||||||
|
SrcPort uint16
|
||||||
|
DstPort uint16
|
||||||
|
Protocol uint8
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(dllLocation string) (*WinKext, error) {
|
||||||
|
|
||||||
|
new := &WinKext{}
|
||||||
|
var err error
|
||||||
|
|
||||||
|
// load dll
|
||||||
|
new.dll, err = windows.LoadDLL(dllLocation)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// load functions
|
||||||
|
new.recvVerdictRequest, err = new.dll.FindProc("PortmasterRecvVerdictRequest")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not find proc PortmasterRecvVerdictRequest: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return new, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kext *WinKext) RecvVerdictRequest() (*VerdictRequest, error) {
|
||||||
|
new := &VerdictRequest{}
|
||||||
|
|
||||||
|
rc, _, lastErr := kext.recvVerdictRequest.Call(
|
||||||
|
uintptr(unsafe.Pointer(new)),
|
||||||
|
)
|
||||||
|
if rc != 0 {
|
||||||
|
return nil, lastErr
|
||||||
|
}
|
||||||
|
return new, nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user