github.com/wfusion/gofusion@v1.1.14/common/utils/gomonkey/modify_binary_windows.go (about) 1 package gomonkey 2 3 import ( 4 "syscall" 5 "unsafe" 6 ) 7 8 func modifyBinary(target uintptr, bytes []byte) { 9 function := entryAddress(target, len(bytes)) 10 11 proc := syscall.NewLazyDLL("kernel32.dll").NewProc("VirtualProtect") 12 const PROT_READ_WRITE = 0x40 13 var old uint32 14 result, _, _ := proc.Call(target, uintptr(len(bytes)), uintptr(PROT_READ_WRITE), uintptr(unsafe.Pointer(&old))) 15 if result == 0 { 16 panic(result) 17 } 18 copy(function, bytes) 19 20 var ignore uint32 21 result, _, _ = proc.Call(target, uintptr(len(bytes)), uintptr(old), uintptr(unsafe.Pointer(&ignore))) 22 if result == 0 { 23 panic(result) 24 } 25 }