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.
31 lines
627 B
31 lines
627 B
package monkey |
|
|
|
import ( |
|
"reflect" |
|
"syscall" |
|
"unsafe" |
|
) |
|
|
|
func rawMemoryAccess(p uintptr, length int) []byte { |
|
return *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{ |
|
Data: p, |
|
Len: length, |
|
Cap: length, |
|
})) |
|
} |
|
|
|
func pageStart(ptr uintptr) uintptr { |
|
return ptr & ^(uintptr(syscall.Getpagesize() - 1)) |
|
} |
|
|
|
// from is a pointer to the actual function |
|
// to is a pointer to a go funcvalue |
|
func replaceFunction(from, to uintptr) (original []byte) { |
|
jumpData := jmpToFunctionValue(to) |
|
f := rawMemoryAccess(from, len(jumpData)) |
|
original = make([]byte, len(f)) |
|
copy(original, f) |
|
|
|
copyToLocation(from, jumpData) |
|
return |
|
}
|
|
|