Skip to content

Commit

Permalink
fix memmod checkptr fail
Browse files Browse the repository at this point in the history
Signed-off-by: lysShub <[email protected]>
  • Loading branch information
lysShub committed Jul 5, 2024
1 parent dcc0eb7 commit dcde65b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion driver/memmod/memmod_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 8 additions & 4 deletions driver/memmod/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit dcde65b

Please sign in to comment.