-
Notifications
You must be signed in to change notification settings - Fork 9
/
divert_dll_32.go
58 lines (48 loc) · 1.48 KB
/
divert_dll_32.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//go:build windows && !divert_cgo && !divert_embedded && (386 || arm)
// +build windows
// +build !divert_cgo
// +build !divert_embedded
// +build 386 arm
package divert
import (
"runtime"
"sync"
"unsafe"
"golang.org/x/sys/windows"
)
func open(filter string, layer Layer, priority int16, flags uint64) (h *Handle, err error) {
if priority < PriorityLowest || priority > PriorityHighest {
return nil, errPriority
}
filterPtr, err := windows.BytePtrFromString(filter)
if err != nil {
return nil, err
}
runtime.LockOSThread()
// 386: Shadow panics on Windows 32-bit system, as `flags` is `uint64` while `uintptr` is `uint32` for 32-bit system.
hd, _, err := winDivertOpen.Call(uintptr(unsafe.Pointer(filterPtr)), uintptr(layer), uintptr(priority), uintptr(flags), 0)
runtime.UnlockOSThread()
if windows.Handle(hd) == windows.InvalidHandle {
return nil, Error(err.(windows.Errno))
}
rEvent, _ := windows.CreateEvent(nil, 0, 0, nil)
wEvent, _ := windows.CreateEvent(nil, 0, 0, nil)
return &Handle{
Mutex: sync.Mutex{},
Handle: windows.Handle(hd),
rOverlapped: windows.Overlapped{
HEvent: rEvent,
},
wOverlapped: windows.Overlapped{
HEvent: wEvent,
},
}, nil
}
// CalcChecksums is ...
func CalcChecksums(buffer []byte, address *Address, flags uint64) bool {
re, _, err := winDivertCalcChecksums.Call(uintptr(unsafe.Pointer(&buffer[0])), uintptr(len(buffer)), uintptr(unsafe.Pointer(address)), uintptr(flags), 0)
if err != nil {
return false
}
return re != 0
}