mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-12-04 13:13:25 +01:00
82128c47d9
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
37 lines
822 B
Go
37 lines
822 B
Go
// +build amd64 arm64
|
|
|
|
/* SPDX-License-Identifier: MIT
|
|
*
|
|
* Copyright (C) 2020 WireGuard LLC. All Rights Reserved.
|
|
*/
|
|
|
|
package memmod
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
func (opthdr *IMAGE_OPTIONAL_HEADER) imageOffset() uintptr {
|
|
return uintptr(opthdr.ImageBase & 0xffffffff00000000)
|
|
}
|
|
|
|
func (module *Module) check4GBBoundaries(alignedImageSize uintptr) (err error) {
|
|
for (module.codeBase >> 32) < ((module.codeBase + alignedImageSize) >> 32) {
|
|
node := &addressList{
|
|
next: module.blockedMemory,
|
|
address: module.codeBase,
|
|
}
|
|
module.blockedMemory = node
|
|
module.codeBase, err = windows.VirtualAlloc(0,
|
|
alignedImageSize,
|
|
windows.MEM_RESERVE|windows.MEM_COMMIT,
|
|
windows.PAGE_READWRITE)
|
|
if err != nil {
|
|
return fmt.Errorf("Error allocating memory block: %w", err)
|
|
}
|
|
}
|
|
return
|
|
}
|