Skip to content

Commit e0d9718

Browse files
author
redanthrax
committed
Merge remote-tracking branch 'upstream/main' into FreeBSD
2 parents 042a304 + 438814e commit e0d9718

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

providers/windows/boottime_windows.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,13 @@
1818
package windows
1919

2020
import (
21-
"fmt"
2221
"time"
2322

24-
windows "github.com/elastic/go-windows"
23+
"golang.org/x/sys/windows"
2524
)
2625

2726
func BootTime() (time.Time, error) {
28-
msSinceBoot, err := windows.GetTickCount64()
29-
if err != nil {
30-
return time.Time{}, fmt.Errorf("failed to get boot time: %w", err)
31-
}
32-
33-
bootTime := time.Now().Add(-1 * time.Duration(msSinceBoot) * time.Millisecond)
27+
bootTime := time.Now().Add(-1 * windows.DurationSinceBoot())
3428

3529
// According to GetTickCount64, the resolution of the value is limited to
3630
// the resolution of the system timer, which is typically in the range of

providers/windows/process_windows.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ func (p *process) init() error {
125125
var args []string
126126
var cwd string
127127
var ppid int
128-
pbi, err := getProcessBasicInformation(handle)
128+
pbi, err := getProcessBasicInformation(syswin.Handle(handle))
129129
if err == nil {
130130
ppid = int(pbi.InheritedFromUniqueProcessID)
131-
userProcParams, err := getUserProcessParams(handle, pbi)
131+
userProcParams, err := getUserProcessParams(syswin.Handle(handle), pbi)
132132
if err == nil {
133133
if argsW, err := readProcessUnicodeString(handle, &userProcParams.CommandLine); err == nil {
134134
args, err = splitCommandline(argsW)
@@ -159,15 +159,16 @@ func (p *process) init() error {
159159
return nil
160160
}
161161

162-
func getProcessBasicInformation(handle syscall.Handle) (pbi windows.ProcessBasicInformationStruct, err error) {
163-
actualSize, err := windows.NtQueryInformationProcess(handle, windows.ProcessBasicInformation, unsafe.Pointer(&pbi), uint32(windows.SizeOfProcessBasicInformationStruct))
162+
func getProcessBasicInformation(handle syswin.Handle) (pbi windows.ProcessBasicInformationStruct, err error) {
163+
var actualSize uint32
164+
err = syswin.NtQueryInformationProcess(handle, syswin.ProcessBasicInformation, unsafe.Pointer(&pbi), uint32(windows.SizeOfProcessBasicInformationStruct), &actualSize)
164165
if actualSize < uint32(windows.SizeOfProcessBasicInformationStruct) {
165166
return pbi, errors.New("bad size for PROCESS_BASIC_INFORMATION")
166167
}
167168
return pbi, err
168169
}
169170

170-
func getUserProcessParams(handle syscall.Handle, pbi windows.ProcessBasicInformationStruct) (params windows.RtlUserProcessParameters, err error) {
171+
func getUserProcessParams(handle syswin.Handle, pbi windows.ProcessBasicInformationStruct) (params windows.RtlUserProcessParameters, err error) {
171172
const is32bitProc = unsafe.Sizeof(uintptr(0)) == 4
172173

173174
// Offset of params field within PEB structure.
@@ -180,7 +181,8 @@ func getUserProcessParams(handle syscall.Handle, pbi windows.ProcessBasicInforma
180181
// Read the PEB from the target process memory
181182
pebSize := paramsOffset + 8
182183
peb := make([]byte, pebSize)
183-
nRead, err := windows.ReadProcessMemory(handle, pbi.PebBaseAddress, peb)
184+
var nRead uintptr
185+
err = syswin.ReadProcessMemory(handle, pbi.PebBaseAddress, &peb[0], uintptr(pebSize), &nRead)
184186
if err != nil {
185187
return params, err
186188
}
@@ -193,7 +195,7 @@ func getUserProcessParams(handle syscall.Handle, pbi windows.ProcessBasicInforma
193195

194196
// Read the RTL_USER_PROCESS_PARAMETERS from the target process memory
195197
paramsBuf := make([]byte, windows.SizeOfRtlUserProcessParameters)
196-
nRead, err = windows.ReadProcessMemory(handle, paramsAddr, paramsBuf)
198+
err = syswin.ReadProcessMemory(handle, paramsAddr, &paramsBuf[0], uintptr(windows.SizeOfRtlUserProcessParameters), &nRead)
197199
if err != nil {
198200
return params, err
199201
}

0 commit comments

Comments
 (0)