Last active
January 30, 2023 08:33
-
-
Save ii64/a61d02a3c996e82b7af407c99b506ade to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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