2021-10-11 22:53:36 +02:00
|
|
|
//go:build (windows && amd64) || (windows && arm64)
|
2020-12-23 17:49:36 +01:00
|
|
|
// +build windows,amd64 windows,arm64
|
2020-11-06 05:24:50 +01:00
|
|
|
|
|
|
|
/* SPDX-License-Identifier: MIT
|
|
|
|
*
|
2021-01-28 17:52:15 +01:00
|
|
|
* Copyright (C) 2017-2021 WireGuard LLC. All Rights Reserved.
|
2020-11-06 05:24:50 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
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 {
|
2020-11-07 21:56:32 +01:00
|
|
|
return fmt.Errorf("Error allocating memory block: %w", err)
|
2020-11-06 05:24:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|