[英]Go syscall EnumProcessModules
Im trying to call ;EnumProcessModules; 我试图调用; EnumProcessModules; using Go of a given handle
使用给定句柄的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])
}
}
Everything seems to work... needed is set but the moment I try to access modules variable I get the following error: 一切似乎正常工作……需要的已设置,但是当我尝试访问模块变量时,出现以下错误:
unexpected fault address 0x12d0000
fatal error: fault
[signal 0xc0000005 code=0x0 addr=0x12d0000 pc=0x455b56]
How should the modules array look like? 模块数组应该是什么样子?
Yes, you must reference the first element. 是的,您必须引用第一个元素。
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])
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.