Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: permission denied #48

Closed
dgofman opened this issue Jun 6, 2021 · 3 comments
Closed

panic: permission denied #48

dgofman opened this issue Jun 6, 2021 · 3 comments

Comments

@dgofman
Copy link

dgofman commented Jun 6, 2021

I have implemented monkey_arm64.go jmpToFunctionValue. Now trying to compile and execute my code on a Mac M1.
I am getting an exception when making a call to syscall.Mprotect (syscall.PROT_WRITE). Do you know how to fix this problem?

func mprotectCrossPage(addr uintptr, length int, prot int) {
	pageSize := syscall.Getpagesize()
	for p := pageStart(addr); p < addr+uintptr(length); p += uintptr(pageSize) {
		page := rawMemoryAccess(p, pageSize)

	        err := syscall.Mprotect(page, prot) //syscall.PROT_READ|syscall.PROT_WRITE|syscall.PROT_EXEC

		if err != nil {
			panic(err)
		}
	}
}
func jmpToFunctionValue(to uintptr) []byte {
	/*return []byte{
		0x48, 0xBA,
		byte(to),
		byte(to >> 8),
		byte(to >> 16),
		byte(to >> 24),
		byte(to >> 32),
		byte(to >> 40),
		byte(to >> 48),
		byte(to >> 56), // movabs rdx,to
		0xFF, 0x22,     // jmp QWORD PTR [rdx]
	}*/
	raw := []uint32{
		uint32((((to) & 0xffff) << 5) | 0xD2800000),       // MOVZ X0, <bytes 0,1>
		uint32((((to >> 16) & 0xffff) << 5) | 0xF2A00000), // MOVK X0, <bytes 2,4>, LSL 16
		uint32((((to >> 32) & 0xffff) << 5) | 0xF2C00000), // MOVK X0, <bytes 4,5>, LSL 32
		uint32((((to >> 48) & 0xffff) << 5) | 0xF2E00000), // MOVK X0, <bytes 6,7>, LSL 48
		0xD63F0000, // BLR X0
	}

	// Get the slice header
	header := *(*reflect.SliceHeader)(unsafe.Pointer(&raw))

	header.Len *= 4 // 4 bytes in uint32
	header.Cap *= 4 // 4 bytes in uint32

	// Convert slice header to an []byte
	data := *(*[]byte)(unsafe.Pointer(&header))
	return data
}
@dgofman
Copy link
Author

dgofman commented Jun 6, 2021

@agiledragon
Copy link
Owner

Please refer to this issue that has been closed, #10.

@agiledragon
Copy link
Owner

Arm64 is fully supported in the v2.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants