github.com/Rookout/GoSDK@v0.1.48/pkg/services/safe_hook_installer/bytes_writer.go (about) 1 //go:build !(darwin && arm64) && !windows 2 // +build !darwin !arm64 3 // +build !windows 4 5 package safe_hook_installer 6 7 import ( 8 "syscall" 9 "unsafe" 10 11 "github.com/Rookout/GoSDK/pkg/rookoutErrors" 12 "github.com/Rookout/GoSDK/pkg/services/protector" 13 ) 14 15 func (h *HookWriter) AddWritePermission() rookoutErrors.RookoutError { 16 currentMemoryProtection, err := protector.GetMemoryProtection(uint64(h.hookPageAlignedStart), uint64(h.hookPageAlignedEnd-h.hookPageAlignedStart)) 17 if err != nil { 18 return err 19 } 20 h.originalMemoryProtection = currentMemoryProtection 21 22 return protector.ChangeMemoryProtection(h.hookPageAlignedStart, h.hookPageAlignedEnd, currentMemoryProtection|syscall.PROT_WRITE) 23 } 24 25 func (h *HookWriter) RestorePermissions() rookoutErrors.RookoutError { 26 return protector.ChangeMemoryProtection(h.hookPageAlignedStart, h.hookPageAlignedEnd, h.originalMemoryProtection) 27 } 28 29 func (h *HookWriter) write() int { 30 for i, b := range h.Hook { 31 *(*uint8)(unsafe.Pointer(h.HookAddr + uintptr(i))) = b 32 } 33 return 0 34 }