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

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

@ -3,84 +3,84 @@
package disk package disk
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/power-devops/perfstat" "github.com/power-devops/perfstat"
"github.com/shirou/gopsutil/v3/internal/common" "github.com/shirou/gopsutil/v3/internal/common"
) )
var FSType map[int]string var FSType map[int]string
func init() { func init() {
FSType = map[int]string{0: "jfs2", 1: "namefs", 2: "nfs", 3: "jfs", 5: "cdrom", 6: "proc", 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", 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", 33: "veritas-fs", 34: "udfs", 35: "nfs4", 36: "nfs4-pseudo", 37: "smbfs", 38: "mcr-pseudofs",
39: "ahafs", 40: "sterm-nfs", 41: "asmfs" } 39: "ahafs", 40: "sterm-nfs", 41: "asmfs"}
} }
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
f, err := perfstat.FileSystemStat() f, err := perfstat.FileSystemStat()
if err != nil { if err != nil {
return nil, err return nil, err
} }
ret := make([]PartitionStat, len(f)) ret := make([]PartitionStat, len(f))
for _, fs := range f { for _, fs := range f {
fstyp, exists := FSType[fs.FSType] fstyp, exists := FSType[fs.FSType]
if ! exists { if !exists {
fstyp = "unknown" fstyp = "unknown"
} }
info := PartitionStat{ info := PartitionStat{
Device: fs.Device, Device: fs.Device,
Mountpoint: fs.MountPoint, Mountpoint: fs.MountPoint,
Fstype: fstyp, Fstype: fstyp,
} }
ret = append(ret,info) ret = append(ret, info)
} }
return ret, err return ret, err
} }
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) { 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) { func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
f, err := perfstat.FileSystemStat() f, err := perfstat.FileSystemStat()
if err != nil { if err != nil {
return nil, err return nil, err
} }
blocksize := uint64(512) blocksize := uint64(512)
for _, fs := range f { for _, fs := range f {
if path == fs.MountPoint { if path == fs.MountPoint {
fstyp, exists := FSType[fs.FSType] fstyp, exists := FSType[fs.FSType]
if ! exists { if !exists {
fstyp = "unknown" fstyp = "unknown"
} }
info := UsageStat{ info := UsageStat{
Path: path, Path: path,
Fstype: fstyp, Fstype: fstyp,
Total: uint64(fs.TotalBlocks) * blocksize, Total: uint64(fs.TotalBlocks) * blocksize,
Free: uint64(fs.FreeBlocks) * blocksize, Free: uint64(fs.FreeBlocks) * blocksize,
Used: uint64(fs.TotalBlocks - fs.FreeBlocks) * blocksize, Used: uint64(fs.TotalBlocks-fs.FreeBlocks) * blocksize,
InodesTotal: uint64(fs.TotalInodes), InodesTotal: uint64(fs.TotalInodes),
InodesFree: uint64(fs.FreeInodes), InodesFree: uint64(fs.FreeInodes),
InodesUsed: uint64(fs.TotalInodes - fs.FreeInodes), InodesUsed: uint64(fs.TotalInodes - fs.FreeInodes),
} }
info.UsedPercent = (float64(info.Used) / float64(info.Total)) * 100.0 info.UsedPercent = (float64(info.Used) / float64(info.Total)) * 100.0
info.InodesUsedPercent = (float64(info.InodesUsed) / float64(info.InodesTotal)) * 100.0 info.InodesUsedPercent = (float64(info.InodesUsed) / float64(info.InodesTotal)) * 100.0
return &info, nil return &info, nil
} }
} }
return nil, fmt.Errorf("mountpoint %s not found", path) return nil, fmt.Errorf("mountpoint %s not found", path)
} }
func SerialNumberWithContext(ctx context.Context, name string) (string, error) { func SerialNumberWithContext(ctx context.Context, name string) (string, error) {
return "", common.ErrNotImplementedError return "", common.ErrNotImplementedError
} }
func LabelWithContext(ctx context.Context, name string) (string, error) { 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 // A blacklist of read-only virtual filesystems. Writable filesystems are of
// operational concern and must not be included in this list. // operational concern and must not be included in this list.
fsTypeBlacklist = map[string]struct{}{ fsTypeBlacklist = map[string]struct{}{
"ctfs": struct{}{}, "ctfs": {},
"dev": struct{}{}, "dev": {},
"fd": struct{}{}, "fd": {},
"lofs": struct{}{}, "lofs": {},
"lxproc": struct{}{}, "lxproc": {},
"mntfs": struct{}{}, "mntfs": {},
"objfs": struct{}{}, "objfs": {},
"proc": struct{}{}, "proc": {},
} }
) )

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save