pull/1208/head
mmorel-35 3 years ago
parent 04c870cb3d
commit eb5f6203d8

@ -36,9 +36,9 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
}
ct := &TimesStat{
CPU: "cpu-total",
Idle: float64(c.IdlePct),
User: float64(c.UserPct),
System: float64(c.KernPct),
Idle: float64(c.IdlePct),
User: float64(c.UserPct),
System: float64(c.KernPct),
Iowait: float64(c.WaitPct),
}
ret = append(ret, *ct)
@ -56,11 +56,11 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
return nil, err
}
info := InfoStat{
CPU: 0,
Mhz: float64(c.ProcessorHz / 1000000),
CPU: 0,
Mhz: float64(c.ProcessorHz / 1000000),
Cores: int32(c.NCpusCfg),
}
result := []InfoStat{info};
}
result := []InfoStat{info}
return result, nil
}
@ -71,4 +71,3 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
}
return c.NCpusCfg, nil
}

@ -7,8 +7,8 @@ import (
"fmt"
"unsafe"
"github.com/yusufpapurcu/wmi"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/yusufpapurcu/wmi"
"golang.org/x/sys/windows"
)

@ -3,84 +3,84 @@
package disk
import (
"context"
"fmt"
"context"
"fmt"
"github.com/power-devops/perfstat"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/power-devops/perfstat"
"github.com/shirou/gopsutil/v3/internal/common"
)
var FSType map[int]string
func init() {
FSType = map[int]string{0: "jfs2", 1: "namefs", 2: "nfs", 3: "jfs", 5: "cdrom", 6: "proc",
16: "special-fs", 17: "cache-fs", 18: "nfs3", 19: "automount-fs", 20: "pool-fs", 32: "vxfs",
33: "veritas-fs", 34: "udfs", 35: "nfs4", 36: "nfs4-pseudo", 37: "smbfs", 38: "mcr-pseudofs",
39: "ahafs", 40: "sterm-nfs", 41: "asmfs" }
FSType = map[int]string{0: "jfs2", 1: "namefs", 2: "nfs", 3: "jfs", 5: "cdrom", 6: "proc",
16: "special-fs", 17: "cache-fs", 18: "nfs3", 19: "automount-fs", 20: "pool-fs", 32: "vxfs",
33: "veritas-fs", 34: "udfs", 35: "nfs4", 36: "nfs4-pseudo", 37: "smbfs", 38: "mcr-pseudofs",
39: "ahafs", 40: "sterm-nfs", 41: "asmfs"}
}
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
f, err := perfstat.FileSystemStat()
if err != nil {
return nil, err
}
ret := make([]PartitionStat, len(f))
f, err := perfstat.FileSystemStat()
if err != nil {
return nil, err
}
ret := make([]PartitionStat, len(f))
for _, fs := range f {
fstyp, exists := FSType[fs.FSType]
if ! exists {
fstyp = "unknown"
}
info := PartitionStat{
Device: fs.Device,
Mountpoint: fs.MountPoint,
Fstype: fstyp,
}
ret = append(ret,info)
}
for _, fs := range f {
fstyp, exists := FSType[fs.FSType]
if !exists {
fstyp = "unknown"
}
info := PartitionStat{
Device: fs.Device,
Mountpoint: fs.MountPoint,
Fstype: fstyp,
}
ret = append(ret, info)
}
return ret, err
return ret, err
}
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
return nil, common.ErrNotImplementedError
return nil, common.ErrNotImplementedError
}
func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
f, err := perfstat.FileSystemStat()
if err != nil {
return nil, err
}
f, err := perfstat.FileSystemStat()
if err != nil {
return nil, err
}
blocksize := uint64(512)
for _, fs := range f {
if path == fs.MountPoint {
fstyp, exists := FSType[fs.FSType]
if ! exists {
fstyp = "unknown"
}
info := UsageStat{
Path: path,
Fstype: fstyp,
Total: uint64(fs.TotalBlocks) * blocksize,
Free: uint64(fs.FreeBlocks) * blocksize,
Used: uint64(fs.TotalBlocks - fs.FreeBlocks) * blocksize,
InodesTotal: uint64(fs.TotalInodes),
InodesFree: uint64(fs.FreeInodes),
InodesUsed: uint64(fs.TotalInodes - fs.FreeInodes),
}
info.UsedPercent = (float64(info.Used) / float64(info.Total)) * 100.0
info.InodesUsedPercent = (float64(info.InodesUsed) / float64(info.InodesTotal)) * 100.0
return &info, nil
}
}
return nil, fmt.Errorf("mountpoint %s not found", path)
blocksize := uint64(512)
for _, fs := range f {
if path == fs.MountPoint {
fstyp, exists := FSType[fs.FSType]
if !exists {
fstyp = "unknown"
}
info := UsageStat{
Path: path,
Fstype: fstyp,
Total: uint64(fs.TotalBlocks) * blocksize,
Free: uint64(fs.FreeBlocks) * blocksize,
Used: uint64(fs.TotalBlocks-fs.FreeBlocks) * blocksize,
InodesTotal: uint64(fs.TotalInodes),
InodesFree: uint64(fs.FreeInodes),
InodesUsed: uint64(fs.TotalInodes - fs.FreeInodes),
}
info.UsedPercent = (float64(info.Used) / float64(info.Total)) * 100.0
info.InodesUsedPercent = (float64(info.InodesUsed) / float64(info.InodesTotal)) * 100.0
return &info, nil
}
}
return nil, fmt.Errorf("mountpoint %s not found", path)
}
func SerialNumberWithContext(ctx context.Context, name string) (string, error) {
return "", common.ErrNotImplementedError
return "", common.ErrNotImplementedError
}
func LabelWithContext(ctx context.Context, name string) (string, error) {
return "", common.ErrNotImplementedError
return "", common.ErrNotImplementedError
}

@ -27,14 +27,14 @@ var (
// A blacklist of read-only virtual filesystems. Writable filesystems are of
// operational concern and must not be included in this list.
fsTypeBlacklist = map[string]struct{}{
"ctfs": struct{}{},
"dev": struct{}{},
"fd": struct{}{},
"lofs": struct{}{},
"lxproc": struct{}{},
"mntfs": struct{}{},
"objfs": struct{}{},
"proc": struct{}{},
"ctfs": {},
"dev": {},
"fd": {},
"lofs": {},
"lxproc": {},
"mntfs": {},
"objfs": {},
"proc": {},
}
)

@ -6,19 +6,19 @@
package host
const (
sizeofPtr = 0x8
sizeofShort = 0x2
sizeofInt = 0x4
sizeofLong = 0x8
sizeofLongLong = 0x8
sizeOfUtmpx = 0xc5
sizeofPtr = 0x8
sizeofShort = 0x2
sizeofInt = 0x4
sizeofLong = 0x8
sizeofLongLong = 0x8
sizeOfUtmpx = 0xc5
)
type (
_C_short int16
_C_int int32
_C_long int64
_C_long_long int64
_C_short int16
_C_int int32
_C_long int64
_C_long_long int64
)
type Utmp struct {

@ -13,9 +13,9 @@ import (
"time"
"unsafe"
"github.com/yusufpapurcu/wmi"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/shirou/gopsutil/v3/process"
"github.com/yusufpapurcu/wmi"
"golang.org/x/sys/windows"
)

@ -11,61 +11,60 @@ package load
import "C"
import (
"context"
"unsafe"
"context"
"unsafe"
"github.com/power-devops/perfstat"
"github.com/power-devops/perfstat"
)
func Avg() (*AvgStat, error) {
return AvgWithContext(context.Background())
return AvgWithContext(context.Background())
}
func AvgWithContext(ctx context.Context) (*AvgStat, error) {
c, err := perfstat.CpuTotalStat()
if err != nil {
return nil, err
}
ret := &AvgStat{
Load1: float64(c.LoadAvg1),
Load5: float64(c.LoadAvg5),
Load15: float64(c.LoadAvg15),
}
c, err := perfstat.CpuTotalStat()
if err != nil {
return nil, err
}
ret := &AvgStat{
Load1: float64(c.LoadAvg1),
Load5: float64(c.LoadAvg5),
Load15: float64(c.LoadAvg15),
}
return ret, nil
return ret, nil
}
// Misc returns miscellaneous host-wide statistics.
// darwin use ps command to get process running/blocked count.
// Almost same as Darwin implementation, but state is different.
func Misc() (*MiscStat, error) {
return MiscWithContext(context.Background())
return MiscWithContext(context.Background())
}
func MiscWithContext(ctx context.Context) (*MiscStat, error) {
info := C.struct_procentry64{}
cpid := C.pid_t(0)
info := C.struct_procentry64{}
cpid := C.pid_t(0)
ret := MiscStat{}
for {
// getprocs first argument is a void*
num, err := C.getprocs64(unsafe.Pointer(&info), C.sizeof_struct_procentry64, nil, 0, &cpid, 1)
if err != nil {
return nil, err
}
ret := MiscStat{}
for {
// getprocs first argument is a void*
num, err := C.getprocs64(unsafe.Pointer(&info), C.sizeof_struct_procentry64, nil, 0, &cpid, 1)
if err != nil {
return nil, err
}
ret.ProcsTotal++
switch info.pi_state {
case C.SACTIVE:
ret.ProcsRunning++
case C.SSTOP:
ret.ProcsBlocked++
}
ret.ProcsTotal++
switch info.pi_state {
case C.SACTIVE:
ret.ProcsRunning++
case C.SSTOP:
ret.ProcsBlocked++
}
if num == 0 {
break
}
if num == 0 {
break
}
return &ret, nil
}
return &ret, nil
}

@ -91,7 +91,7 @@ type SwapMemoryStat struct {
// Linux specific numbers
// https://www.kernel.org/doc/Documentation/cgroup-v2.txt
PgMajFault uint64 `json:"pgMajFault"`
PgMajFault uint64 `json:"pgMajFault"`
}
func (m VirtualMemoryStat) String() string {

@ -3,56 +3,56 @@
package mem
import (
"context"
"context"
"github.com/power-devops/perfstat"
"github.com/power-devops/perfstat"
)
func VirtualMemory() (*VirtualMemoryStat, error) {
return VirtualMemoryWithContext(context.Background())
return VirtualMemoryWithContext(context.Background())
}
func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
m, err := perfstat.MemoryTotalStat()
if err != nil {
return nil, err
}
pagesize := uint64(4096)
ret := VirtualMemoryStat{
Total: uint64(m.RealTotal) * pagesize,
Available: uint64(m.RealAvailable) * pagesize,
Free: uint64(m.RealFree) * pagesize,
Used: uint64(m.RealInUse) * pagesize,
UsedPercent: 100 * float64(m.RealInUse) / float64(m.RealTotal),
Active: uint64(m.VirtualActive) * pagesize,
SwapTotal: uint64(m.PgSpTotal) * pagesize,
SwapFree: uint64(m.PgSpFree) * pagesize,
}
return &ret, nil
m, err := perfstat.MemoryTotalStat()
if err != nil {
return nil, err
}
pagesize := uint64(4096)
ret := VirtualMemoryStat{
Total: uint64(m.RealTotal) * pagesize,
Available: uint64(m.RealAvailable) * pagesize,
Free: uint64(m.RealFree) * pagesize,
Used: uint64(m.RealInUse) * pagesize,
UsedPercent: 100 * float64(m.RealInUse) / float64(m.RealTotal),
Active: uint64(m.VirtualActive) * pagesize,
SwapTotal: uint64(m.PgSpTotal) * pagesize,
SwapFree: uint64(m.PgSpFree) * pagesize,
}
return &ret, nil
}
func SwapMemory() (*SwapMemoryStat, error) {
return SwapMemoryWithContext(context.Background())
return SwapMemoryWithContext(context.Background())
}
func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
m, err := perfstat.MemoryTotalStat()
if err != nil {
return nil, err
}
pagesize := uint64(4096)
swapUsed := uint64(m.PgSpTotal - m.PgSpFree - m.PgSpRsvd) * pagesize
swapTotal := uint64(m.PgSpTotal) * pagesize
ret := SwapMemoryStat{
Total: swapTotal,
Free: uint64(m.PgSpFree) * pagesize,
Used: swapUsed,
UsedPercent: float64(100 * swapUsed) / float64(swapTotal),
Sin: uint64(m.PgSpIn),
Sout: uint64(m.PgSpOut),
PgIn: uint64(m.PageIn),
PgOut: uint64(m.PageOut),
PgFault: uint64(m.PageFaults),
}
return &ret, nil
m, err := perfstat.MemoryTotalStat()
if err != nil {
return nil, err
}
pagesize := uint64(4096)
swapUsed := uint64(m.PgSpTotal-m.PgSpFree-m.PgSpRsvd) * pagesize
swapTotal := uint64(m.PgSpTotal) * pagesize
ret := SwapMemoryStat{
Total: swapTotal,
Free: uint64(m.PgSpFree) * pagesize,
Used: swapUsed,
UsedPercent: float64(100*swapUsed) / float64(swapTotal),
Sin: uint64(m.PgSpIn),
Sout: uint64(m.PgSpOut),
PgIn: uint64(m.PageIn),
PgOut: uint64(m.PageOut),
PgFault: uint64(m.PageFaults),
}
return &ret, nil
}

@ -21,10 +21,10 @@ func TestIOCountersByFileParsing(t *testing.T) {
assert.Nil(t, err, "Temporary file creation failed: ", err)
cases := [4][2]string{
[2]string{"eth0: ", "eth1: "},
[2]string{"eth0:0: ", "eth1:0: "},
[2]string{"eth0:", "eth1:"},
[2]string{"eth0:0:", "eth1:0:"},
{"eth0: ", "eth1: "},
{"eth0:0: ", "eth1:0: "},
{"eth0:", "eth1:"},
{"eth0:0:", "eth1:0:"},
}
for _, testCase := range cases {
err = tmpfile.Truncate(0)

@ -333,7 +333,6 @@ func ConntrackStatsWithContext(ctx context.Context, percpu bool) ([]ConntrackSta
return nil, common.ErrNotImplementedError
}
// NetProtoCounters returns network statistics for the entire system
// If protocols is empty then all protocols are returned, otherwise
// just the protocols in the list are returned.

@ -6,196 +6,196 @@
package process
const (
CTLKern = 1
KernProc = 14
KernProcPID = 1
KernProcProc = 8
KernProcPathname = 12
KernProcArgs = 7
CTLKern = 1
KernProc = 14
KernProcPID = 1
KernProcProc = 8
KernProcPathname = 12
KernProcArgs = 7
)
const (
sizeofPtr = 0x8
sizeofShort = 0x2
sizeofInt = 0x4
sizeofLong = 0x8
sizeofLongLong = 0x8
sizeofPtr = 0x8
sizeofShort = 0x2
sizeofInt = 0x4
sizeofLong = 0x8
sizeofLongLong = 0x8
)
const (
sizeOfKinfoVmentry = 0x488
sizeOfKinfoProc = 0x440
sizeOfKinfoVmentry = 0x488
sizeOfKinfoProc = 0x440
)
const (
SIDL = 1
SRUN = 2
SSLEEP = 3
SSTOP = 4
SZOMB = 5
SWAIT = 6
SLOCK = 7
SIDL = 1
SRUN = 2
SSLEEP = 3
SSTOP = 4
SZOMB = 5
SWAIT = 6
SLOCK = 7
)
type (
_C_short int16
_C_int int32
_C_long int64
_C_long_long int64
_C_short int16
_C_int int32
_C_long int64
_C_long_long int64
)
type Timespec struct {
Sec int64
Nsec int64
Sec int64
Nsec int64
}
type Timeval struct {
Sec int64
Usec int64
Sec int64
Usec int64
}
type Rusage struct {
Utime Timeval
Stime Timeval
Maxrss int64
Ixrss int64
Idrss int64
Isrss int64
Minflt int64
Majflt int64
Nswap int64
Inblock int64
Oublock int64
Msgsnd int64
Msgrcv int64
Nsignals int64
Nvcsw int64
Nivcsw int64
Utime Timeval
Stime Timeval
Maxrss int64
Ixrss int64
Idrss int64
Isrss int64
Minflt int64
Majflt int64
Nswap int64
Inblock int64
Oublock int64
Msgsnd int64
Msgrcv int64
Nsignals int64
Nvcsw int64
Nivcsw int64
}
type Rlimit struct {
Cur int64
Max int64
Cur int64
Max int64
}
type KinfoProc struct {
Structsize int32
Layout int32
Args *int64 /* pargs */
Paddr *int64 /* proc */
Addr *int64 /* user */
Tracep *int64 /* vnode */
Textvp *int64 /* vnode */
Fd *int64 /* filedesc */
Vmspace *int64 /* vmspace */
Wchan *byte
Pid int32
Ppid int32
Pgid int32
Tpgid int32
Sid int32
Tsid int32
Jobc int16
Spare_short1 int16
Tdev_freebsd11 uint32
Siglist [16]byte /* sigset */
Sigmask [16]byte /* sigset */
Sigignore [16]byte /* sigset */
Sigcatch [16]byte /* sigset */
Uid uint32
Ruid uint32
Svuid uint32
Rgid uint32
Svgid uint32
Ngroups int16
Spare_short2 int16
Groups [16]uint32
Size uint64
Rssize int64
Swrss int64
Tsize int64
Dsize int64
Ssize int64
Xstat uint16
Acflag uint16
Pctcpu uint32
Estcpu uint32
Slptime uint32
Swtime uint32
Cow uint32
Runtime uint64
Start Timeval
Childtime Timeval
Flag int64
Kiflag int64
Traceflag int32
Stat uint8
Nice int8
Lock uint8
Rqindex uint8
Oncpu_old uint8
Lastcpu_old uint8
Tdname [17]uint8
Wmesg [9]uint8
Login [18]uint8
Lockname [9]uint8
Comm [20]int8
Emul [17]uint8
Loginclass [18]uint8
Moretdname [4]uint8
Sparestrings [46]uint8
Spareints [2]int32
Tdev uint64
Oncpu int32
Lastcpu int32
Tracer int32
Flag2 int32
Fibnum int32
Cr_flags uint32
Jid int32
Numthreads int32
Tid int32
Pri Priority
Rusage Rusage
Rusage_ch Rusage
Pcb *int64 /* pcb */
Kstack *byte
Udata *byte
Tdaddr *int64 /* thread */
Spareptrs [6]*byte
Sparelongs [12]int64
Sflag int64
Tdflags int64
Structsize int32
Layout int32
Args *int64 /* pargs */
Paddr *int64 /* proc */
Addr *int64 /* user */
Tracep *int64 /* vnode */
Textvp *int64 /* vnode */
Fd *int64 /* filedesc */
Vmspace *int64 /* vmspace */
Wchan *byte
Pid int32
Ppid int32
Pgid int32
Tpgid int32
Sid int32
Tsid int32
Jobc int16
Spare_short1 int16
Tdev_freebsd11 uint32
Siglist [16]byte /* sigset */
Sigmask [16]byte /* sigset */
Sigignore [16]byte /* sigset */
Sigcatch [16]byte /* sigset */
Uid uint32
Ruid uint32
Svuid uint32
Rgid uint32
Svgid uint32
Ngroups int16
Spare_short2 int16
Groups [16]uint32
Size uint64
Rssize int64
Swrss int64
Tsize int64
Dsize int64
Ssize int64
Xstat uint16
Acflag uint16
Pctcpu uint32
Estcpu uint32
Slptime uint32
Swtime uint32
Cow uint32
Runtime uint64
Start Timeval
Childtime Timeval
Flag int64
Kiflag int64
Traceflag int32
Stat uint8
Nice int8
Lock uint8
Rqindex uint8
Oncpu_old uint8
Lastcpu_old uint8
Tdname [17]uint8
Wmesg [9]uint8
Login [18]uint8
Lockname [9]uint8
Comm [20]int8
Emul [17]uint8
Loginclass [18]uint8
Moretdname [4]uint8
Sparestrings [46]uint8
Spareints [2]int32
Tdev uint64
Oncpu int32
Lastcpu int32
Tracer int32
Flag2 int32
Fibnum int32
Cr_flags uint32
Jid int32
Numthreads int32
Tid int32
Pri Priority
Rusage Rusage
Rusage_ch Rusage
Pcb *int64 /* pcb */
Kstack *byte
Udata *byte
Tdaddr *int64 /* thread */
Spareptrs [6]*byte
Sparelongs [12]int64
Sflag int64
Tdflags int64
}
type Priority struct {
Class uint8
Level uint8
Native uint8
User uint8
Class uint8
Level uint8
Native uint8
User uint8
}
type KinfoVmentry struct {
Structsize int32
Type int32
Start uint64
End uint64
Offset uint64
Vn_fileid uint64
Vn_fsid_freebsd11 uint32
Flags int32
Resident int32
Private_resident int32
Protection int32
Ref_count int32
Shadow_count int32
Vn_type int32
Vn_size uint64
Vn_rdev_freebsd11 uint32
Vn_mode uint16
Status uint16
Vn_fsid uint64
Vn_rdev uint64
X_kve_ispare [8]int32
Path [1024]uint8
Structsize int32
Type int32
Start uint64
End uint64
Offset uint64
Vn_fileid uint64
Vn_fsid_freebsd11 uint32
Flags int32
Resident int32
Private_resident int32
Protection int32
Ref_count int32
Shadow_count int32
Vn_type int32
Vn_size uint64
Vn_rdev_freebsd11 uint32
Vn_mode uint16
Status uint16
Vn_fsid uint64
Vn_rdev uint64
X_kve_ispare [8]int32
Path [1024]uint8
}

@ -106,75 +106,75 @@ type processBasicInformation64 struct {
}
type processEnvironmentBlock32 struct {
Reserved1 [2]uint8
BeingDebugged uint8
Reserved2 uint8
Reserved3 [2]uint32
Ldr uint32
Reserved1 [2]uint8
BeingDebugged uint8
Reserved2 uint8
Reserved3 [2]uint32
Ldr uint32
ProcessParameters uint32
// More fields which we don't use so far
}
type processEnvironmentBlock64 struct {
Reserved1 [2]uint8
BeingDebugged uint8
Reserved2 uint8
_ [4]uint8 // padding, since we are 64 bit, the next pointer is 64 bit aligned (when compiling for 32 bit, this is not the case without manual padding)
Reserved3 [2]uint64
Ldr uint64
Reserved1 [2]uint8
BeingDebugged uint8
Reserved2 uint8
_ [4]uint8 // padding, since we are 64 bit, the next pointer is 64 bit aligned (when compiling for 32 bit, this is not the case without manual padding)
Reserved3 [2]uint64
Ldr uint64
ProcessParameters uint64
// More fields which we don't use so far
}
type rtlUserProcessParameters32 struct {
Reserved1 [16]uint8
ConsoleHandle uint32
ConsoleFlags uint32
StdInputHandle uint32
StdOutputHandle uint32
StdErrorHandle uint32
Reserved1 [16]uint8
ConsoleHandle uint32
ConsoleFlags uint32
StdInputHandle uint32
StdOutputHandle uint32
StdErrorHandle uint32
CurrentDirectoryPathNameLength uint16
_ uint16 // Max Length
CurrentDirectoryPathAddress uint32
CurrentDirectoryHandle uint32
DllPathNameLength uint16
_ uint16 // Max Length
DllPathAddress uint32
ImagePathNameLength uint16
_ uint16 // Max Length
ImagePathAddress uint32
CommandLineLength uint16
_ uint16 // Max Length
CommandLineAddress uint32
EnvironmentAddress uint32
_ uint16 // Max Length
CurrentDirectoryPathAddress uint32
CurrentDirectoryHandle uint32
DllPathNameLength uint16
_ uint16 // Max Length
DllPathAddress uint32
ImagePathNameLength uint16
_ uint16 // Max Length
ImagePathAddress uint32
CommandLineLength uint16
_ uint16 // Max Length
CommandLineAddress uint32
EnvironmentAddress uint32
// More fields which we don't use so far
}
type rtlUserProcessParameters64 struct {
Reserved1 [16]uint8
ConsoleHandle uint64
ConsoleFlags uint64
StdInputHandle uint64
StdOutputHandle uint64
StdErrorHandle uint64
Reserved1 [16]uint8
ConsoleHandle uint64
ConsoleFlags uint64
StdInputHandle uint64
StdOutputHandle uint64
StdErrorHandle uint64
CurrentDirectoryPathNameLength uint16
_ uint16 // Max Length
_ uint32 // Padding
CurrentDirectoryPathAddress uint64
CurrentDirectoryHandle uint64
DllPathNameLength uint16
_ uint16 // Max Length
_ uint32 // Padding
DllPathAddress uint64
ImagePathNameLength uint16
_ uint16 // Max Length
_ uint32 // Padding
ImagePathAddress uint64
CommandLineLength uint16
_ uint16 // Max Length
_ uint32 // Padding
CommandLineAddress uint64
EnvironmentAddress uint64
_ uint16 // Max Length
_ uint32 // Padding
CurrentDirectoryPathAddress uint64
CurrentDirectoryHandle uint64
DllPathNameLength uint16
_ uint16 // Max Length
_ uint32 // Padding
DllPathAddress uint64
ImagePathNameLength uint16
_ uint16 // Max Length
_ uint32 // Padding
ImagePathAddress uint64
CommandLineLength uint16
_ uint16 // Max Length
_ uint32 // Padding
CommandLineAddress uint64
EnvironmentAddress uint64
// More fields which we don't use so far
}
@ -946,7 +946,6 @@ func getProcessCPUTimes(pid int32) (SYSTEM_TIMES, error) {
return times, err
}
func getUserProcessParams32(handle windows.Handle) (rtlUserProcessParameters32, error) {
pebAddress, err := queryPebAddress(syscall.Handle(handle), true)
if err != nil {
@ -1068,14 +1067,14 @@ func getProcessEnvironmentVariables(pid int32, ctx context.Context) ([]string, e
is32BitProcess: procIs32Bits,
offset: processParameterBlockAddress,
})
envvarScanner.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error){
envvarScanner.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error) {
if atEOF && len(data) == 0 {
return 0, nil, nil
}
// Check for UTF-16 zero character
for i := 0; i < len(data) - 1; i+=2 {
for i := 0; i < len(data)-1; i += 2 {
if data[i] == 0 && data[i+1] == 0 {
return i+2, data[0:i], nil
return i + 2, data[0:i], nil
}
}
if atEOF {
@ -1105,9 +1104,9 @@ func getProcessEnvironmentVariables(pid int32, ctx context.Context) ([]string, e
}
type processReader struct {
processHandle windows.Handle
processHandle windows.Handle
is32BitProcess bool
offset uint64
offset uint64
}
func (p *processReader) Read(buf []byte) (int, error) {

Loading…
Cancel
Save