Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcc2827f

Browse files
committed
Use ModuleEntry32 and Module32First from golang.org/x/sys/windows
Now that they are available upstream (seehttps://golang.org/cl/369174)use the type and function from golang.org/x/sys/windows instead ofduplicating them in this package.
1 parentb99b715 commitcc2827f

File tree

3 files changed

+8
-32
lines changed

3 files changed

+8
-32
lines changed

‎go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/tklauser/ps
22

33
go1.13
44

5-
requiregolang.org/x/sysv0.0.0-20211102061401-a2f17f7b995c
5+
requiregolang.org/x/sysv0.0.0-20211204120058-94396e421777

‎go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
golang.org/x/sysv0.0.0-20211102061401-a2f17f7b995c h1:QOfDMdrf/UwlVR0UBq2Mpr58UzNtvgJRXA4BgPfFACs=
2-
golang.org/x/sysv0.0.0-20211102061401-a2f17f7b995c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1+
golang.org/x/sysv0.0.0-20211204120058-94396e421777 h1:QAkhGVjOxMa+n4mlsAWeAU+BMZmimQAaNiMu+iUi94E=
2+
golang.org/x/sysv0.0.0-20211204120058-94396e421777/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

‎process_windows.go

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package ps
66

77
import (
88
"fmt"
9-
"syscall"
109
"time"
1110
"unsafe"
1211

@@ -71,42 +70,19 @@ func getCreationTime(pid uint32) time.Time {
7170
returntime.Unix(0,creationTime.Nanoseconds())
7271
}
7372

74-
const_MAX_MODULE_NAME32=255
75-
76-
typemoduleEntry32struct {
77-
Sizeuint32
78-
ModuleIDuint32
79-
ProcessIDuint32
80-
GlblcntUsageuint32
81-
ProccntUsageuint32
82-
ModBaseAddruintptr
83-
ModBaseSizeuint32
84-
ModuleHandle windows.Handle
85-
Module [_MAX_MODULE_NAME32+1]uint16
86-
ExePath [windows.MAX_PATH]uint16
87-
}
88-
89-
constsizeofModuleEntry32=uint32(unsafe.Sizeof(moduleEntry32{}))
90-
91-
// Windows API functions
92-
var (
93-
modkernel32=windows.NewLazySystemDLL("kernel32.dll")
94-
procModule32First=modkernel32.NewProc("Module32FirstW")
95-
)
96-
9773
funcgetExecutablePath(piduint32)string {
9874
handle,err:=windows.CreateToolhelp32Snapshot(windows.TH32CS_SNAPMODULE,pid)
9975
iferr!=nil {
10076
return""
10177
}
10278
deferwindows.CloseHandle(handle)
10379

104-
entry:=moduleEntry32{
105-
Size:sizeofModuleEntry32,
80+
entry:=windows.ModuleEntry32{
81+
Size:uint32(windows.SizeofModuleEntry32),
10682
}
10783

108-
r0,_,_:=syscall.Syscall(procModule32First.Addr(),2,uintptr(handle),uintptr(unsafe.Pointer(&entry)),0)
109-
ifr0==0 {
84+
err=windows.Module32First(handle,&entry)
85+
iferr!=nil {
11086
return""
11187
}
11288
returnwindows.UTF16ToString(entry.ExePath[:])
@@ -117,8 +93,8 @@ func newWindowsProcess(pe32 *windows.ProcessEntry32) Process {
11793
pid:int(pe32.ProcessID),
11894
ppid:int(pe32.ParentProcessID),
11995
command:windows.UTF16ToString(pe32.ExeFile[:]),
120-
creationTime:getCreationTime(pe32.ProcessID),
12196
executablePath:getExecutablePath(pe32.ProcessID),
97+
creationTime:getCreationTime(pe32.ProcessID),
12298
}
12399
}
124100

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp