gpt4 book ai didi

Go 系统调用 EnumProcessModules

转载 作者:数据小太阳 更新时间:2023-10-29 03:27:55 26 4
gpt4 key购买 nike

我正在尝试调用 ;EnumProcessModules;使用给定句柄的 Go

var (
psapi = syscall.NewLazyDLL("Psapi.dll")
procEnumProcessModules = psapi.NewProc("EnumProcessModules")
)

func EnumProcessModules(handle uintptr) {
log.Println(handle)
modules := make([]interface{}, 2049)
var needed int
procEnumProcessModules.Call(
handle,
uintptr(unsafe.Pointer(&modules)),
uintptr(2048),
uintptr(unsafe.Pointer(&needed)),
)
log.Println(needed)
for i := 0; i < needed; i++ {
log.Println(modules[i])
}
}

一切似乎都正常......所需的设置但是当我尝试访问模块变量时我收到以下错误:

unexpected fault address 0x12d0000
fatal error: fault
[signal 0xc0000005 code=0x0 addr=0x12d0000 pc=0x455b56]

模块数组应该是什么样的?

最佳答案

是的,您必须引用第一个元素。

var n uint32
var needed uint32

// How many I need?
ret, _, _ := procEnumProcessModules.Call(
uintptr(handle),
0,
uintptr(n),
uintptr(unsafe.Pointer(&needed)))

if int(ret) == 1 && needed > 0 {

procHandles := make([]syscall.Handle, needed)
procHandlesPtr := unsafe.Pointer(&procHandles[0])

n = needed
ret2, _, _ := procEnumProcessModules.Call(
uintptr(n),
uintptr(procHandlesPtr),
uintptr(n),
uintptr(unsafe.Pointer(&needed))))

if int(ret2) == 1 {
for i:= 0; i < needed / 4; i++ {
fmt.Println(procHandles[i])
}
}

关于Go 系统调用 EnumProcessModules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34374582/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com