github.com/eh-steve/goloader@v0.0.0-20240111193454-90ff3cfdae39/mprotect/mprotect_windows.go (about) 1 //go:build windows 2 // +build windows 3 4 package mprotect 5 6 import ( 7 "syscall" 8 "unsafe" 9 ) 10 11 var pageSize = syscall.Getpagesize() 12 13 func GetPage(p uintptr) []byte { 14 return (*(*[0xFFFFFF]byte)(unsafe.Pointer(p & ^uintptr(pageSize-1))))[:pageSize] 15 } 16 17 func RawMemoryAccess(b uintptr) []byte { 18 return (*(*[0xFF]byte)(unsafe.Pointer(b)))[:] 19 } 20 21 func MprotectMakeWritable(page []byte) error { 22 return VirtualProtect(uintptr(unsafe.Pointer(&page[0])), uintptr(len(page)), syscall.PAGE_READWRITE) 23 } 24 25 func MprotectMakeExecutable(page []byte) error { 26 return VirtualProtect(uintptr(unsafe.Pointer(&page[0])), uintptr(len(page)), syscall.PAGE_EXECUTE_READ) 27 } 28 29 func MprotectMakeReadOnly(page []byte) error { 30 return VirtualProtect(uintptr(unsafe.Pointer(&page[0])), uintptr(len(page)), syscall.PAGE_READONLY) 31 }