diff --git a/driver/memmod/memmod_windows.go b/driver/memmod/memmod_windows.go index 7b54282aa..90472c63d 100644 --- a/driver/memmod/memmod_windows.go +++ b/driver/memmod/memmod_windows.go @@ -690,7 +690,7 @@ func alignUp(value, alignment uintptr) uintptr { } func a2p(addr uintptr) unsafe.Pointer { - return unsafe.Pointer(addr) + return unsafe.Add(unsafe.Pointer(nil), addr) } func memcpy(dst, src, size uintptr) { diff --git a/driver/memmod/syscall_windows.go b/driver/memmod/syscall_windows.go index cdc6ef678..67236a14c 100644 --- a/driver/memmod/syscall_windows.go +++ b/driver/memmod/syscall_windows.go @@ -117,10 +117,14 @@ type IMAGE_NT_HEADERS struct { } func (ntheader *IMAGE_NT_HEADERS) Sections() []IMAGE_SECTION_HEADER { - return (*[0xffff]IMAGE_SECTION_HEADER)(unsafe.Pointer( - (uintptr)(unsafe.Pointer(ntheader)) + - unsafe.Offsetof(ntheader.OptionalHeader) + - uintptr(ntheader.FileHeader.SizeOfOptionalHeader)))[:ntheader.FileHeader.NumberOfSections] + ptr := unsafe.Pointer(ntheader) + ptr = unsafe.Add(ptr, unsafe.Offsetof(ntheader.OptionalHeader)) + ptr = unsafe.Add(ptr, ntheader.FileHeader.SizeOfOptionalHeader) + + return unsafe.Slice( + (*IMAGE_SECTION_HEADER)(ptr), + ntheader.FileHeader.NumberOfSections, + ) } const (