From dcde65b232008f9e4c975ee15a5c379ed868e9d2 Mon Sep 17 00:00:00 2001 From: lysShub Date: Fri, 5 Jul 2024 17:13:28 +0800 Subject: [PATCH] fix memmod checkptr fail Signed-off-by: lysShub --- driver/memmod/memmod_windows.go | 2 +- driver/memmod/syscall_windows.go | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) 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 (