Skip to content

Instantly share code, notes, and snippets.

@ii64
Last active January 30, 2023 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ii64/a61d02a3c996e82b7af407c99b506ade to your computer and use it in GitHub Desktop.
Save ii64/a61d02a3c996e82b7af407c99b506ade to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
"syscall"
"unsafe"
)
func main() {
b := []byte{
0xb8, 0xeb, 0xaf, 0x0c, 0x00,
0xc3,
}
bfp := unsafe.Pointer(&b[0])
println(bfp)
pgSz := os.Getpagesize()
pgStart := pgSz * (int(uintptr(bfp)) / pgSz)
println(pgStart, pgSz)
if _, _, err := syscall.Syscall(syscall.SYS_MPROTECT, uintptr(pgStart), uintptr(os.Getpagesize()), syscall.PROT_READ|syscall.PROT_WRITE|syscall.PROT_EXEC); err != 0 {
panic(err)
}
// fp := b.Load("test", rt.Frame{})
fp := &bfp
f := *(*func() uint)(unsafe.Pointer(&fp))
fmt.Printf("%+#v\n", f)
v := f()
fmt.Printf("%X", v)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment