forked from KnicKnic/go-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ntdll.go
45 lines (36 loc) · 1.08 KB
/
ntdll.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package ntdll
import (
"syscall"
"unsafe"
"github.com/KnicKnic/go-windows/pkg/kernel32"
"golang.org/x/sys/windows"
)
// Do the interface allocations only once for common
var (
modntdll = windows.NewLazySystemDLL("ntdll.dll")
procmemcpy = modntdll.NewProc("memcpy")
)
func Memcpy(dest uintptr, src uintptr, size uint64) (ptr uintptr) {
r0, _, _ := syscall.Syscall(procmemcpy.Addr(), 3, uintptr(dest), uintptr(src), uintptr(size))
ptr = uintptr(r0)
return
}
func MemcpyDestC(dest uintptr, src []byte, size uint64) {
if size != 0 {
_, _, _ = syscall.Syscall(procmemcpy.Addr(), 3, uintptr(dest), uintptr(unsafe.Pointer(&src[0])), uintptr(size))
}
}
func MemcpySrcC(dest []byte, src uintptr, size uint64) {
if size != 0 {
_, _, _ = syscall.Syscall(procmemcpy.Addr(), 3, uintptr(unsafe.Pointer(&dest[0])), uintptr(src), uintptr(size))
}
}
func MemcpyLocalAlloc(data []byte) (ptr uintptr, err error) {
size := uint64(len(data))
ptr, err = kernel32.LocalAlloc(size)
if err != nil {
return
}
MemcpyDestC(ptr, data, uint64(size))
return
}