You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
606 B
26 lines
606 B
//+build !windows |
|
|
|
package monkey |
|
|
|
import ( |
|
"syscall" |
|
) |
|
|
|
// this function is super unsafe |
|
// aww yeah |
|
// It copies a slice to a raw memory location, disabling all memory protection before doing so. |
|
func copyToLocation(location uintptr, data []byte) { |
|
f := rawMemoryAccess(location, len(data)) |
|
|
|
page := rawMemoryAccess(pageStart(location), syscall.Getpagesize()) |
|
err := syscall.Mprotect(page, syscall.PROT_READ|syscall.PROT_WRITE|syscall.PROT_EXEC) |
|
if err != nil { |
|
panic(err) |
|
} |
|
copy(f, data[:]) |
|
|
|
err = syscall.Mprotect(page, syscall.PROT_READ|syscall.PROT_EXEC) |
|
if err != nil { |
|
panic(err) |
|
} |
|
}
|
|
|