forked from Netpas/win
-
Notifications
You must be signed in to change notification settings - Fork 0
/
psapi.go
248 lines (221 loc) · 7.34 KB
/
psapi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// This file was automatically generated by https://github.com/kbinani/win/blob/generator/internal/cmd/gen/gen.go
// go run internal/cmd/gen/gen.go
// +build windows
package win
import (
"syscall"
"unsafe"
)
var (
// Library
libpsapi uintptr
// Functions
emptyWorkingSet uintptr
enumDeviceDrivers uintptr
enumPageFiles uintptr
enumProcessModules uintptr
enumProcessModulesEx uintptr
enumProcesses uintptr
getDeviceDriverBaseName uintptr
getDeviceDriverFileName uintptr
getMappedFileName uintptr
getModuleBaseName uintptr
getModuleFileNameEx uintptr
getModuleInformation uintptr
getPerformanceInfo uintptr
getProcessImageFileName uintptr
getProcessMemoryInfo uintptr
getWsChanges uintptr
getWsChangesEx uintptr
initializeProcessForWsWatch uintptr
queryWorkingSet uintptr
queryWorkingSetEx uintptr
)
func init() {
// Library
libpsapi = doLoadLibrary("psapi.dll")
// Functions
emptyWorkingSet = doGetProcAddress(libpsapi, "EmptyWorkingSet")
enumDeviceDrivers = doGetProcAddress(libpsapi, "EnumDeviceDrivers")
enumPageFiles = doGetProcAddress(libpsapi, "EnumPageFilesW")
enumProcessModules = doGetProcAddress(libpsapi, "EnumProcessModules")
enumProcessModulesEx = doGetProcAddress(libpsapi, "EnumProcessModulesEx")
enumProcesses = doGetProcAddress(libpsapi, "EnumProcesses")
getDeviceDriverBaseName = doGetProcAddress(libpsapi, "GetDeviceDriverBaseNameW")
getDeviceDriverFileName = doGetProcAddress(libpsapi, "GetDeviceDriverFileNameW")
getMappedFileName = doGetProcAddress(libpsapi, "GetMappedFileNameW")
getModuleBaseName = doGetProcAddress(libpsapi, "GetModuleBaseNameW")
getModuleFileNameEx = doGetProcAddress(libpsapi, "GetModuleFileNameExW")
getModuleInformation = doGetProcAddress(libpsapi, "GetModuleInformation")
getPerformanceInfo = doGetProcAddress(libpsapi, "GetPerformanceInfo")
getProcessImageFileName = doGetProcAddress(libpsapi, "GetProcessImageFileNameW")
getProcessMemoryInfo = doGetProcAddress(libpsapi, "GetProcessMemoryInfo")
getWsChanges = doGetProcAddress(libpsapi, "GetWsChanges")
getWsChangesEx = doGetProcAddress(libpsapi, "GetWsChangesEx")
initializeProcessForWsWatch = doGetProcAddress(libpsapi, "InitializeProcessForWsWatch")
queryWorkingSet = doGetProcAddress(libpsapi, "QueryWorkingSet")
queryWorkingSetEx = doGetProcAddress(libpsapi, "QueryWorkingSetEx")
}
func EmptyWorkingSet(hProcess HANDLE) bool {
ret1 := syscall3(emptyWorkingSet, 1,
uintptr(hProcess),
0,
0)
return ret1 != 0
}
func EnumDeviceDrivers(lpImageBase *LPVOID, cb DWORD, lpcbNeeded *uint32) bool {
ret1 := syscall3(enumDeviceDrivers, 3,
uintptr(unsafe.Pointer(lpImageBase)),
uintptr(cb),
uintptr(unsafe.Pointer(lpcbNeeded)))
return ret1 != 0
}
func EnumPageFiles(pCallBackRoutine PENUM_PAGE_FILE_CALLBACK, pContext LPVOID) bool {
pCallBackRoutineCallback := syscall.NewCallback(func(pContextRawArg LPVOID, pPageFileInfoRawArg PENUM_PAGE_FILE_INFORMATION, lpFilenameRawArg /*const*/ *uint16) uintptr {
lpFilename := stringFromUnicode16(lpFilenameRawArg)
ret := pCallBackRoutine(pContextRawArg, pPageFileInfoRawArg, lpFilename)
return uintptr(ret)
})
ret1 := syscall3(enumPageFiles, 2,
pCallBackRoutineCallback,
uintptr(unsafe.Pointer(pContext)),
0)
return ret1 != 0
}
func EnumProcessModules(hProcess HANDLE, lphModule *HMODULE, cb DWORD, lpcbNeeded *uint32) bool {
ret1 := syscall6(enumProcessModules, 4,
uintptr(hProcess),
uintptr(unsafe.Pointer(lphModule)),
uintptr(cb),
uintptr(unsafe.Pointer(lpcbNeeded)),
0,
0)
return ret1 != 0
}
func EnumProcessModulesEx(hProcess HANDLE, lphModule *HMODULE, cb DWORD, lpcbNeeded *uint32, dwFilterFlag DWORD) bool {
ret1 := syscall6(enumProcessModulesEx, 5,
uintptr(hProcess),
uintptr(unsafe.Pointer(lphModule)),
uintptr(cb),
uintptr(unsafe.Pointer(lpcbNeeded)),
uintptr(dwFilterFlag),
0)
return ret1 != 0
}
func EnumProcesses(lpidProcess *uint32, cb DWORD, cbNeeded *uint32) bool {
ret1 := syscall3(enumProcesses, 3,
uintptr(unsafe.Pointer(lpidProcess)),
uintptr(cb),
uintptr(unsafe.Pointer(cbNeeded)))
return ret1 != 0
}
func GetDeviceDriverBaseName(imageBase LPVOID, lpBaseName LPWSTR, nSize DWORD) DWORD {
ret1 := syscall3(getDeviceDriverBaseName, 3,
uintptr(unsafe.Pointer(imageBase)),
uintptr(unsafe.Pointer(lpBaseName)),
uintptr(nSize))
return DWORD(ret1)
}
func GetDeviceDriverFileName(imageBase LPVOID, lpFilename LPWSTR, nSize DWORD) DWORD {
ret1 := syscall3(getDeviceDriverFileName, 3,
uintptr(unsafe.Pointer(imageBase)),
uintptr(unsafe.Pointer(lpFilename)),
uintptr(nSize))
return DWORD(ret1)
}
func GetMappedFileName(hProcess HANDLE, lpv LPVOID, lpFilename LPWSTR, nSize DWORD) DWORD {
ret1 := syscall6(getMappedFileName, 4,
uintptr(hProcess),
uintptr(unsafe.Pointer(lpv)),
uintptr(unsafe.Pointer(lpFilename)),
uintptr(nSize),
0,
0)
return DWORD(ret1)
}
func GetModuleBaseName(hProcess HANDLE, hModule HMODULE, lpBaseName LPWSTR, nSize DWORD) DWORD {
ret1 := syscall6(getModuleBaseName, 4,
uintptr(hProcess),
uintptr(hModule),
uintptr(unsafe.Pointer(lpBaseName)),
uintptr(nSize),
0,
0)
return DWORD(ret1)
}
func GetModuleFileNameEx(hProcess HANDLE, hModule HMODULE, lpFilename LPWSTR, nSize DWORD) DWORD {
ret1 := syscall6(getModuleFileNameEx, 4,
uintptr(hProcess),
uintptr(hModule),
uintptr(unsafe.Pointer(lpFilename)),
uintptr(nSize),
0,
0)
return DWORD(ret1)
}
func GetModuleInformation(hProcess HANDLE, hModule HMODULE, lpmodinfo *MODULEINFO, cb DWORD) bool {
ret1 := syscall6(getModuleInformation, 4,
uintptr(hProcess),
uintptr(hModule),
uintptr(unsafe.Pointer(lpmodinfo)),
uintptr(cb),
0,
0)
return ret1 != 0
}
func GetPerformanceInfo(pPerformanceInformation PPERFORMACE_INFORMATION, cb DWORD) bool {
ret1 := syscall3(getPerformanceInfo, 2,
uintptr(unsafe.Pointer(pPerformanceInformation)),
uintptr(cb),
0)
return ret1 != 0
}
func GetProcessImageFileName(hProcess HANDLE, lpImageFileName LPWSTR, nSize DWORD) DWORD {
ret1 := syscall3(getProcessImageFileName, 3,
uintptr(hProcess),
uintptr(unsafe.Pointer(lpImageFileName)),
uintptr(nSize))
return DWORD(ret1)
}
func GetProcessMemoryInfo(process HANDLE, ppsmemCounters PPROCESS_MEMORY_COUNTERS, cb DWORD) bool {
ret1 := syscall3(getProcessMemoryInfo, 3,
uintptr(process),
uintptr(unsafe.Pointer(ppsmemCounters)),
uintptr(cb))
return ret1 != 0
}
func GetWsChanges(hProcess HANDLE, lpWatchInfo PPSAPI_WS_WATCH_INFORMATION, cb DWORD) bool {
ret1 := syscall3(getWsChanges, 3,
uintptr(hProcess),
uintptr(unsafe.Pointer(lpWatchInfo)),
uintptr(cb))
return ret1 != 0
}
func GetWsChangesEx(hProcess HANDLE, lpWatchInfoEx PPSAPI_WS_WATCH_INFORMATION_EX, cb DWORD) bool {
ret1 := syscall3(getWsChangesEx, 3,
uintptr(hProcess),
uintptr(unsafe.Pointer(lpWatchInfoEx)),
uintptr(cb))
return ret1 != 0
}
func InitializeProcessForWsWatch(hProcess HANDLE) bool {
ret1 := syscall3(initializeProcessForWsWatch, 1,
uintptr(hProcess),
0,
0)
return ret1 != 0
}
func QueryWorkingSet(hProcess HANDLE, pv uintptr, cb DWORD) bool {
ret1 := syscall3(queryWorkingSet, 3,
uintptr(hProcess),
pv,
uintptr(cb))
return ret1 != 0
}
func QueryWorkingSetEx(hProcess HANDLE, pv uintptr, cb DWORD) bool {
ret1 := syscall3(queryWorkingSetEx, 3,
uintptr(hProcess),
pv,
uintptr(cb))
return ret1 != 0
}