mirror of https://github.com/shirou/gopsutil
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.0 KiB
Go
80 lines
2.0 KiB
Go
3 years ago
|
//go:build (windows && amd64) || (windows && arm64)
|
||
|
// +build windows,amd64 windows,arm64
|
||
9 years ago
|
|
||
|
package process
|
||
|
|
||
5 years ago
|
import (
|
||
|
"syscall"
|
||
|
"unsafe"
|
||
5 years ago
|
|
||
3 years ago
|
"github.com/shirou/gopsutil/v3/internal/common"
|
||
4 years ago
|
"golang.org/x/sys/windows"
|
||
5 years ago
|
)
|
||
|
|
||
9 years ago
|
type PROCESS_MEMORY_COUNTERS struct {
|
||
|
CB uint32
|
||
|
PageFaultCount uint32
|
||
|
PeakWorkingSetSize uint64
|
||
|
WorkingSetSize uint64
|
||
|
QuotaPeakPagedPoolUsage uint64
|
||
|
QuotaPagedPoolUsage uint64
|
||
|
QuotaPeakNonPagedPoolUsage uint64
|
||
|
QuotaNonPagedPoolUsage uint64
|
||
|
PagefileUsage uint64
|
||
|
PeakPagefileUsage uint64
|
||
|
}
|
||
5 years ago
|
|
||
4 years ago
|
func queryPebAddress(procHandle syscall.Handle, is32BitProcess bool) (uint64, error) {
|
||
5 years ago
|
if is32BitProcess {
|
||
3 years ago
|
// we are on a 64-bit process reading an external 32-bit process
|
||
5 years ago
|
var wow64 uint
|
||
|
|
||
|
ret, _, _ := common.ProcNtQueryInformationProcess.Call(
|
||
|
uintptr(procHandle),
|
||
|
uintptr(common.ProcessWow64Information),
|
||
|
uintptr(unsafe.Pointer(&wow64)),
|
||
|
uintptr(unsafe.Sizeof(wow64)),
|
||
|
uintptr(0),
|
||
|
)
|
||
4 years ago
|
if status := windows.NTStatus(ret); status == windows.STATUS_SUCCESS {
|
||
|
return uint64(wow64), nil
|
||
|
} else {
|
||
|
return 0, windows.NTStatus(ret)
|
||
5 years ago
|
}
|
||
|
} else {
|
||
3 years ago
|
// we are on a 64-bit process reading an external 64-bit process
|
||
5 years ago
|
var info processBasicInformation64
|
||
5 years ago
|
|
||
|
ret, _, _ := common.ProcNtQueryInformationProcess.Call(
|
||
|
uintptr(procHandle),
|
||
|
uintptr(common.ProcessBasicInformation),
|
||
|
uintptr(unsafe.Pointer(&info)),
|
||
|
uintptr(unsafe.Sizeof(info)),
|
||
|
uintptr(0),
|
||
|
)
|
||
4 years ago
|
if status := windows.NTStatus(ret); status == windows.STATUS_SUCCESS {
|
||
|
return info.PebBaseAddress, nil
|
||
|
} else {
|
||
|
return 0, windows.NTStatus(ret)
|
||
5 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func readProcessMemory(procHandle syscall.Handle, _ bool, address uint64, size uint) []byte {
|
||
|
var read uint
|
||
|
|
||
|
buffer := make([]byte, size)
|
||
|
|
||
|
ret, _, _ := common.ProcNtReadVirtualMemory.Call(
|
||
|
uintptr(procHandle),
|
||
|
uintptr(address),
|
||
|
uintptr(unsafe.Pointer(&buffer[0])),
|
||
|
uintptr(size),
|
||
|
uintptr(unsafe.Pointer(&read)),
|
||
|
)
|
||
|
if int(ret) >= 0 && read > 0 {
|
||
|
return buffer[:read]
|
||
|
}
|
||
|
return nil
|
||
|
}
|