aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--conn/default.go1
-rw-r--r--conn/mark_default.go1
-rw-r--r--conn/mark_unix.go1
-rw-r--r--device/queueconstants_default.go1
-rw-r--r--device/queueconstants_ios.go1
-rw-r--r--device/race_disabled_test.go3
-rw-r--r--device/race_enabled_test.go3
-rw-r--r--device/sticky_default.go1
-rw-r--r--ipc/uapi_bsd.go1
-rw-r--r--ipc/uapi_unix.go1
-rw-r--r--main.go1
-rw-r--r--rwcancel/rwcancel.go1
-rw-r--r--tun/operateonfd.go1
-rw-r--r--tun/wintun/memmod/memmod_windows.go24
-rw-r--r--tun/wintun/memmod/syscall_windows.go17
15 files changed, 47 insertions, 11 deletions
diff --git a/conn/default.go b/conn/default.go
index 161454a..97bf08c 100644
--- a/conn/default.go
+++ b/conn/default.go
@@ -1,3 +1,4 @@
+//go:build !linux && !windows
// +build !linux,!windows
/* SPDX-License-Identifier: MIT
diff --git a/conn/mark_default.go b/conn/mark_default.go
index c315f4b..91cf6a8 100644
--- a/conn/mark_default.go
+++ b/conn/mark_default.go
@@ -1,3 +1,4 @@
+//go:build !linux && !openbsd && !freebsd
// +build !linux,!openbsd,!freebsd
/* SPDX-License-Identifier: MIT
diff --git a/conn/mark_unix.go b/conn/mark_unix.go
index 18eb581..faa4245 100644
--- a/conn/mark_unix.go
+++ b/conn/mark_unix.go
@@ -1,3 +1,4 @@
+//go:build linux || openbsd || freebsd
// +build linux openbsd freebsd
/* SPDX-License-Identifier: MIT
diff --git a/device/queueconstants_default.go b/device/queueconstants_default.go
index d5c6927..fa2c055 100644
--- a/device/queueconstants_default.go
+++ b/device/queueconstants_default.go
@@ -1,3 +1,4 @@
+//go:build !android && !ios && !windows
// +build !android,!ios,!windows
/* SPDX-License-Identifier: MIT
diff --git a/device/queueconstants_ios.go b/device/queueconstants_ios.go
index 36c8704..21a0e26 100644
--- a/device/queueconstants_ios.go
+++ b/device/queueconstants_ios.go
@@ -1,3 +1,4 @@
+//go:build ios
// +build ios
/* SPDX-License-Identifier: MIT
diff --git a/device/race_disabled_test.go b/device/race_disabled_test.go
index 65fac7e..6552f22 100644
--- a/device/race_disabled_test.go
+++ b/device/race_disabled_test.go
@@ -1,4 +1,5 @@
-//+build !race
+//go:build !race
+// +build !race
/* SPDX-License-Identifier: MIT
*
diff --git a/device/race_enabled_test.go b/device/race_enabled_test.go
index f8ccac3..1abba5a 100644
--- a/device/race_enabled_test.go
+++ b/device/race_enabled_test.go
@@ -1,4 +1,5 @@
-//+build race
+//go:build race
+// +build race
/* SPDX-License-Identifier: MIT
*
diff --git a/device/sticky_default.go b/device/sticky_default.go
index 1cc52f6..fa39ac0 100644
--- a/device/sticky_default.go
+++ b/device/sticky_default.go
@@ -1,3 +1,4 @@
+//go:build !linux
// +build !linux
package device
diff --git a/ipc/uapi_bsd.go b/ipc/uapi_bsd.go
index 5beee9e..062f5d7 100644
--- a/ipc/uapi_bsd.go
+++ b/ipc/uapi_bsd.go
@@ -1,3 +1,4 @@
+//go:build darwin || freebsd || openbsd
// +build darwin freebsd openbsd
/* SPDX-License-Identifier: MIT
diff --git a/ipc/uapi_unix.go b/ipc/uapi_unix.go
index 544651b..48f6846 100644
--- a/ipc/uapi_unix.go
+++ b/ipc/uapi_unix.go
@@ -1,3 +1,4 @@
+//go:build linux || darwin || freebsd || openbsd
// +build linux darwin freebsd openbsd
/* SPDX-License-Identifier: MIT
diff --git a/main.go b/main.go
index 639d644..d7181b8 100644
--- a/main.go
+++ b/main.go
@@ -1,3 +1,4 @@
+//go:build !windows
// +build !windows
/* SPDX-License-Identifier: MIT
diff --git a/rwcancel/rwcancel.go b/rwcancel/rwcancel.go
index 5dff446..7013b16 100644
--- a/rwcancel/rwcancel.go
+++ b/rwcancel/rwcancel.go
@@ -1,3 +1,4 @@
+//go:build !windows
// +build !windows
/* SPDX-License-Identifier: MIT
diff --git a/tun/operateonfd.go b/tun/operateonfd.go
index a9dcaef..aab7116 100644
--- a/tun/operateonfd.go
+++ b/tun/operateonfd.go
@@ -1,3 +1,4 @@
+//go:build !windows
// +build !windows
/* SPDX-License-Identifier: MIT
diff --git a/tun/wintun/memmod/memmod_windows.go b/tun/wintun/memmod/memmod_windows.go
index 6eb022d..075c03a 100644
--- a/tun/wintun/memmod/memmod_windows.go
+++ b/tun/wintun/memmod/memmod_windows.go
@@ -159,6 +159,16 @@ func (module *Module) finalizeSection(sectionData *sectionFinalizeData) error {
return nil
}
+var rtlAddFunctionTable = windows.NewLazySystemDLL("ntdll.dll").NewProc("RtlAddFunctionTable")
+
+func (module *Module) registerExceptionHandlers() {
+ directory := module.headerDirectory(IMAGE_DIRECTORY_ENTRY_EXCEPTION)
+ if directory.Size == 0 || directory.VirtualAddress == 0 {
+ return
+ }
+ rtlAddFunctionTable.Call(module.codeBase+uintptr(directory.VirtualAddress), uintptr(directory.Size)/unsafe.Sizeof(IMAGE_RUNTIME_FUNCTION_ENTRY{}), module.codeBase)
+}
+
func (module *Module) finalizeSections() error {
sections := module.headers.Sections()
imageOffset := module.headers.OptionalHeader.imageOffset()
@@ -166,6 +176,7 @@ func (module *Module) finalizeSections() error {
sectionData.address = uintptr(sections[0].PhysicalAddress()) | imageOffset
sectionData.alignedAddress = alignDown(sectionData.address, uintptr(module.headers.OptionalHeader.SectionAlignment))
sectionData.size = module.realSectionSize(&sections[0])
+ sections[0].SetVirtualSize(uint32(sectionData.size))
sectionData.characteristics = sections[0].Characteristics
// Loop through all sections and change access flags.
@@ -173,6 +184,7 @@ func (module *Module) finalizeSections() error {
sectionAddress := uintptr(sections[i].PhysicalAddress()) | imageOffset
alignedAddress := alignDown(sectionAddress, uintptr(module.headers.OptionalHeader.SectionAlignment))
sectionSize := module.realSectionSize(&sections[i])
+ sections[i].SetVirtualSize(uint32(sectionSize))
// Combine access flags of all sections that share a page.
// TODO: We currently share flags of a trailing large section with the page of a first small section. This should be optimized.
if sectionData.alignedAddress == alignedAddress || sectionData.address+sectionData.size > alignedAddress {
@@ -491,15 +503,6 @@ func LoadLibrary(data []byte) (module *Module, err error) {
return
}
- // Disable protected delayed load for now. TODO: We should support this properly at some point.
- if IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG < module.headers.OptionalHeader.NumberOfRvaAndSizes {
- directory := module.headerDirectory(IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG)
- if directory.Size != 0 && directory.VirtualAddress != 0 {
- loadConfig := (*IMAGE_LOAD_CONFIG_DIRECTORY)(a2p(module.codeBase + uintptr(directory.VirtualAddress)))
- loadConfig.GuardFlags &^= IMAGE_GUARD_PROTECT_DELAYLOAD_IAT
- }
- }
-
// Mark memory pages depending on section headers and release sections that are marked as "discardable".
err = module.finalizeSections()
if err != nil {
@@ -507,6 +510,9 @@ func LoadLibrary(data []byte) (module *Module, err error) {
return
}
+ // Register exception tables, if they exist.
+ module.registerExceptionHandlers()
+
// TLS callbacks are executed BEFORE the main loading.
module.executeTLS()
diff --git a/tun/wintun/memmod/syscall_windows.go b/tun/wintun/memmod/syscall_windows.go
index 6d2d18e..a111f92 100644
--- a/tun/wintun/memmod/syscall_windows.go
+++ b/tun/wintun/memmod/syscall_windows.go
@@ -332,6 +332,17 @@ func (imgimpdesc *IMAGE_IMPORT_DESCRIPTOR) OriginalFirstThunk() uint32 {
return imgimpdesc.characteristicsOrOriginalFirstThunk
}
+type IMAGE_DELAYLOAD_DESCRIPTOR struct {
+ Attributes uint32
+ DllNameRVA uint32
+ ModuleHandleRVA uint32
+ ImportAddressTableRVA uint32
+ ImportNameTableRVA uint32
+ BoundImportAddressTableRVA uint32
+ UnloadInformationTableRVA uint32
+ TimeDateStamp uint32
+}
+
type IMAGE_LOAD_CONFIG_CODE_INTEGRITY struct {
Flags uint16
Catalog uint16
@@ -359,6 +370,12 @@ const (
IMAGE_GUARD_CF_FUNCTION_TABLE_SIZE_SHIFT = 28
)
+type IMAGE_RUNTIME_FUNCTION_ENTRY struct {
+ BeginAddress uint32
+ EndAddress uint32
+ UnwindInfoAddress uint32
+}
+
const (
DLL_PROCESS_ATTACH = 1
DLL_THREAD_ATTACH = 2