@bun-win32/psapi 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # bun-psapi
2
+
3
+ Zero-dependency, zero-overhead Win32 PSAPI bindings for [Bun](https://bun.sh) on Windows.
4
+
5
+ ## Overview
6
+
7
+ `bun-psapi` exposes the `psapi.dll` exports using Bun's FFI. It provides a single class, `Psapi`, which lazily binds native symbols on first use. You can optionally preload a subset or all symbols up-front via `Preload()`.
8
+
9
+ ## Features
10
+
11
+ - [Bun](https://bun.sh)-first ergonomics on Windows 10/11.
12
+ - Direct FFI to `psapi.dll` (process enumeration, module info, memory stats, working sets, device drivers, and more).
13
+ - In-source docs in `structs/Psapi.ts` with links to Microsoft Docs.
14
+ - Lazy binding on first call; optional eager preload (`Psapi.Preload()`).
15
+ - No wrapper overhead; calls map 1:1 to native APIs.
16
+ - Strongly-typed Win32 aliases (see `types/Psapi.ts`).
17
+
18
+ ## Requirements
19
+
20
+ - [Bun](https://bun.sh) runtime
21
+ - Windows 10 or later
22
+
23
+ ## Installation
24
+
25
+ ```sh
26
+ bun add bun-psapi
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ ```ts
32
+ import Psapi from 'bun-psapi';
33
+
34
+ // Optionally bind a subset up-front
35
+ Psapi.Preload(['EnumProcesses', 'GetModuleBaseNameW']);
36
+
37
+ // Enumerate all process IDs
38
+ const idBuffer = Buffer.alloc(4096);
39
+ const sizeNeeded = Buffer.alloc(4);
40
+
41
+ Psapi.EnumProcesses(idBuffer.ptr, idBuffer.byteLength, sizeNeeded.ptr);
42
+
43
+ const count = sizeNeeded.readUInt32LE(0) / 4;
44
+ console.log('Processes: %d', count);
45
+ ```
46
+
47
+ ## Examples
48
+
49
+ Run the included example to see the library in action:
50
+
51
+ ```sh
52
+ bun run example # Process enumeration + performance info
53
+ ```
54
+
55
+ ## Notes
56
+
57
+ - Either rely on lazy binding or call `Psapi.Preload()`.
58
+ - Windows only. Bun runtime required.
package/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ import './runtime/extensions';
2
+
3
+ import Psapi from './structs/Psapi';
4
+
5
+ export * from './types/Psapi';
6
+ export default Psapi;
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "author": "Stev Peifer <stev@bell.net>",
3
+ "bugs": {
4
+ "url": "https://github.com/obscuritysrl/bun-psapi/issues"
5
+ },
6
+ "description": "Zero-dependency, zero-overhead Win32 PSAPI bindings for Bun (FFI) on Windows.",
7
+ "devDependencies": {
8
+ "@types/bun": "latest"
9
+ },
10
+ "exports": {
11
+ ".": "./index.ts"
12
+ },
13
+ "license": "MIT",
14
+ "module": "index.ts",
15
+ "name": "@bun-win32/psapi",
16
+ "peerDependencies": {
17
+ "typescript": "^5"
18
+ },
19
+ "private": false,
20
+ "homepage": "https://github.com/obscuritysrl/bun-psapi#readme",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git://github.com/obscuritysrl/bun-psapi.git"
24
+ },
25
+ "type": "module",
26
+ "version": "2.0.0",
27
+ "main": "./index.ts",
28
+ "keywords": [
29
+ "bun",
30
+ "ffi",
31
+ "win32",
32
+ "windows",
33
+ "psapi",
34
+ "bindings",
35
+ "typescript",
36
+ "dll"
37
+ ],
38
+ "files": [
39
+ "index.ts",
40
+ "runtime/*.ts",
41
+ "structs/*.ts",
42
+ "types/*.ts",
43
+ "README.md"
44
+ ],
45
+ "sideEffects": false,
46
+ "engines": {
47
+ "bun": ">=1.1.0"
48
+ },
49
+ "scripts": {
50
+ "example": "bun ./example/psapi.ts"
51
+ }
52
+ }
@@ -0,0 +1,210 @@
1
+ import { type Pointer, ptr } from 'bun:ffi';
2
+
3
+ declare global {
4
+ /**
5
+ * Adds a native pointer property to all ArrayBuffer, Buffer, DataView, and TypedArray types.
6
+ *
7
+ * The `ptr` property returns a native pointer usable with Bun FFI.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const arr = new Uint8Array([1, 2, 3]);
12
+ * nativeFunction(arr.ptr, arr.length);
13
+ * ```
14
+ */
15
+ interface ArrayBuffer {
16
+ /**
17
+ * Native pointer to ArrayBuffer memory for Bun FFI.
18
+ * @example
19
+ * ```ts
20
+ * const buf = new ArrayBuffer(8);
21
+ * nativeFunction(buf.ptr, buf.byteLength);
22
+ * ```
23
+ */
24
+ readonly ptr: Pointer;
25
+ }
26
+ interface BigInt64Array {
27
+ /**
28
+ * Native pointer to BigInt64Array memory for Bun FFI.
29
+ * @example
30
+ * ```ts
31
+ * const arr = new BigInt64Array([1n, 2n]);
32
+ * nativeFunction(arr.ptr, arr.length);
33
+ * ```
34
+ */
35
+ readonly ptr: Pointer;
36
+ }
37
+ interface BigUint64Array {
38
+ /**
39
+ * Native pointer to BigUint64Array memory for Bun FFI.
40
+ * @example
41
+ * ```ts
42
+ * const arr = new BigUint64Array([1n, 2n]);
43
+ * nativeFunction(arr.ptr, arr.length);
44
+ * ```
45
+ */
46
+ readonly ptr: Pointer;
47
+ }
48
+ interface Buffer {
49
+ /**
50
+ * Native pointer to Buffer memory for Bun FFI.
51
+ * @example
52
+ * ```ts
53
+ * const buf = Buffer.from([1, 2, 3]);
54
+ * nativeFunction(buf.ptr, buf.length);
55
+ * ```
56
+ */
57
+ readonly ptr: Pointer;
58
+ }
59
+ interface DataView {
60
+ /**
61
+ * Native pointer to DataView memory for Bun FFI.
62
+ * @example
63
+ * ```ts
64
+ * const view = new DataView(new ArrayBuffer(4));
65
+ * nativeFunction(view.ptr, view.byteLength);
66
+ * ```
67
+ */
68
+ readonly ptr: Pointer;
69
+ }
70
+ interface Float32Array {
71
+ /**
72
+ * Native pointer to Float32Array memory for Bun FFI.
73
+ * @example
74
+ * ```ts
75
+ * const arr = new Float32Array([1, 2, 3]);
76
+ * nativeFunction(arr.ptr, arr.length);
77
+ * ```
78
+ */
79
+ readonly ptr: Pointer;
80
+ }
81
+ interface Float64Array {
82
+ /**
83
+ * Native pointer to Float64Array memory for Bun FFI.
84
+ * @example
85
+ * ```ts
86
+ * const arr = new Float64Array([1, 2, 3]);
87
+ * nativeFunction(arr.ptr, arr.length);
88
+ * ```
89
+ */
90
+ readonly ptr: Pointer;
91
+ }
92
+ interface Int16Array {
93
+ /**
94
+ * Native pointer to Int16Array memory for Bun FFI.
95
+ * @example
96
+ * ```ts
97
+ * const arr = new Int16Array([1, 2, 3]);
98
+ * nativeFunction(arr.ptr, arr.length);
99
+ * ```
100
+ */
101
+ readonly ptr: Pointer;
102
+ }
103
+ interface Int32Array {
104
+ /**
105
+ * Native pointer to Int32Array memory for Bun FFI.
106
+ * @example
107
+ * ```ts
108
+ * const arr = new Int32Array([1, 2, 3]);
109
+ * nativeFunction(arr.ptr, arr.length);
110
+ * ```
111
+ */
112
+ readonly ptr: Pointer;
113
+ }
114
+ interface Int8Array {
115
+ /**
116
+ * Native pointer to Int8Array memory for Bun FFI.
117
+ * @example
118
+ * ```ts
119
+ * const arr = new Int8Array([1, 2, 3]);
120
+ * nativeFunction(arr.ptr, arr.length);
121
+ * ```
122
+ */
123
+ readonly ptr: Pointer;
124
+ }
125
+ interface SharedArrayBuffer {
126
+ /**
127
+ * Native pointer to SharedArrayBuffer memory for Bun FFI.
128
+ * @example
129
+ * ```ts
130
+ * const buf = new SharedArrayBuffer(8);
131
+ * nativeFunction(buf.ptr, buf.byteLength);
132
+ * ```
133
+ */
134
+ readonly ptr: Pointer;
135
+ }
136
+ interface Uint16Array {
137
+ /**
138
+ * Native pointer to Uint16Array memory for Bun FFI.
139
+ * @example
140
+ * ```ts
141
+ * const arr = new Uint16Array([1, 2, 3]);
142
+ * nativeFunction(arr.ptr, arr.length);
143
+ * ```
144
+ */
145
+ readonly ptr: Pointer;
146
+ }
147
+ interface Uint32Array {
148
+ /**
149
+ * Native pointer to Uint32Array memory for Bun FFI.
150
+ * @example
151
+ * ```ts
152
+ * const arr = new Uint32Array([1, 2, 3]);
153
+ * nativeFunction(arr.ptr, arr.length);
154
+ * ```
155
+ */
156
+ readonly ptr: Pointer;
157
+ }
158
+ interface Uint8Array {
159
+ /**
160
+ * Native pointer to Uint8Array memory for Bun FFI.
161
+ * @example
162
+ * ```ts
163
+ * const arr = new Uint8Array([1, 2, 3]);
164
+ * nativeFunction(arr.ptr, arr.length);
165
+ * ```
166
+ */
167
+ readonly ptr: Pointer;
168
+ }
169
+ interface Uint8ClampedArray {
170
+ /**
171
+ * Native pointer to Uint8ClampedArray memory for Bun FFI.
172
+ * @example
173
+ * ```ts
174
+ * const arr = new Uint8ClampedArray([1, 2, 3]);
175
+ * nativeFunction(arr.ptr, arr.length);
176
+ * ```
177
+ */
178
+ readonly ptr: Pointer;
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Installs the `ptr` property on all supported binary view prototypes.
184
+ *
185
+ * The property is non-enumerable and non-configurable. The getter calls `ptr(this)`.
186
+ */
187
+ const constructors = [ArrayBuffer, BigInt64Array, BigUint64Array, Buffer, DataView, Float32Array, Float64Array, Int16Array, Int32Array, Int8Array, SharedArrayBuffer, Uint16Array, Uint32Array, Uint8Array, Uint8ClampedArray] as const;
188
+
189
+ constructors.forEach(
190
+ ({ prototype }) =>
191
+ !Object.getOwnPropertyDescriptor(prototype, 'ptr') &&
192
+ Object.defineProperty(prototype, 'ptr', {
193
+ configurable: false,
194
+ enumerable: false,
195
+ /**
196
+ * Returns a native pointer to the underlying memory.
197
+ * @returns Native pointer for Bun FFI.
198
+ * @example
199
+ * ```ts
200
+ * const arr = new Uint8Array([1, 2, 3]);
201
+ * nativeFunction(arr.ptr, arr.length);
202
+ * ```
203
+ */
204
+ get(this): Pointer {
205
+ return ptr(this);
206
+ },
207
+ })
208
+ );
209
+
210
+ export {};
@@ -0,0 +1,276 @@
1
+ import { type FFIFunction, FFIType, dlopen } from 'bun:ffi';
2
+
3
+ import type {
4
+ BOOL,
5
+ DWORD,
6
+ HANDLE,
7
+ HMODULE,
8
+ LPDWORD,
9
+ LPHMODULE,
10
+ LPMODULEINFO,
11
+ LPSTR,
12
+ LPVOID,
13
+ LPWSTR,
14
+ PDWORD,
15
+ PENUM_PAGE_FILE_CALLBACKA,
16
+ PENUM_PAGE_FILE_CALLBACKW,
17
+ PPERFORMANCE_INFORMATION,
18
+ PPROCESS_MEMORY_COUNTERS,
19
+ PPSAPI_WS_WATCH_INFORMATION,
20
+ PPSAPI_WS_WATCH_INFORMATION_EX,
21
+ PVOID,
22
+ } from '../types/Psapi';
23
+
24
+ /**
25
+ * Thin, lazy-loaded FFI bindings for `psapi.dll`.
26
+ *
27
+ * Each static method corresponds one-to-one with a Win32 export declared in `Symbols`.
28
+ * The first call to a method binds the underlying native symbol via `bun:ffi` and
29
+ * memoizes it on the class for subsequent calls. For bulk, up-front binding, use `Preload`.
30
+ *
31
+ * Symbols are defined with explicit `FFIType` signatures and kept alphabetized.
32
+ * You normally do not access `Symbols` directly; call the static methods or preload
33
+ * a subset for hot paths.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * import Psapi from './structs/Psapi';
38
+ *
39
+ * // Lazy: bind on first call
40
+ * const result = Psapi.EnumProcesses(buffer.ptr, buffer.byteLength, sizeNeeded.ptr);
41
+ *
42
+ * // Or preload a subset to avoid per-symbol lazy binding cost
43
+ * Psapi.Preload(['EnumProcesses', 'GetModuleBaseNameW']);
44
+ * ```
45
+ */
46
+ class Psapi {
47
+ /**
48
+ * Lazily binds a single `psapi.dll` export and memoizes it on the class.
49
+ *
50
+ * If the symbol has already been bound (property is non-configurable), this is a no-op.
51
+ * Subsequent calls go directly through the memoized native function.
52
+ *
53
+ * @param method Exact export name from `Symbols`.
54
+ * @returns The bound native function, typed to the corresponding static method.
55
+ * @example
56
+ * ```ts
57
+ * // Internal usage: public wrappers call Load on first invocation
58
+ * // return Psapi.Load('EnumProcesses')();
59
+ * ```
60
+ */
61
+ private static Load<T extends keyof typeof Psapi.Symbols>(method: T): (typeof Psapi)[T] {
62
+ const skip = Object.getOwnPropertyDescriptor(Psapi, method)?.configurable === false;
63
+
64
+ if (skip) {
65
+ return Psapi[method];
66
+ }
67
+
68
+ const library = dlopen('psapi.dll', { [method]: Psapi.Symbols[method] });
69
+
70
+ const propertyDescriptor = { configurable: false, value: library.symbols[method] };
71
+ Object.defineProperty(Psapi, method, propertyDescriptor);
72
+
73
+ return Psapi[method];
74
+ }
75
+
76
+ /**
77
+ * Eagerly binds one or more `psapi.dll` exports in a single `dlopen` call.
78
+ *
79
+ * When called with no arguments, every symbol in `Symbols` is bound.
80
+ * Already-bound symbols are skipped.
81
+ *
82
+ * @param methods Optional list of export names to preload. Defaults to all symbols.
83
+ * @example
84
+ * ```ts
85
+ * // Preload specific hot-path symbols
86
+ * Psapi.Preload(['EnumProcessModules', 'GetModuleBaseNameW', 'GetModuleFileNameExW']);
87
+ *
88
+ * // Or preload everything
89
+ * Psapi.Preload();
90
+ * ```
91
+ */
92
+ public static Preload(methods?: (keyof typeof Psapi.Symbols)[]): void {
93
+ methods ??= Object.keys(Psapi.Symbols) as (keyof typeof Psapi.Symbols)[];
94
+
95
+ const symbols = Object.fromEntries(
96
+ methods
97
+ .filter((method) => Object.getOwnPropertyDescriptor(Psapi, method)?.configurable !== false)
98
+ .map((method) => [method, Psapi.Symbols[method]])
99
+ );
100
+
101
+ const library = dlopen('psapi.dll', symbols);
102
+
103
+ const propertyDescriptorMap = Object.fromEntries(
104
+ Object.entries(library.symbols).map(([key, value]) => [key, { configurable: false, value }])
105
+ );
106
+
107
+ Object.defineProperties(Psapi, propertyDescriptorMap);
108
+ }
109
+
110
+ private static readonly Symbols = {
111
+ EmptyWorkingSet: { args: [FFIType.u64], returns: FFIType.i32 },
112
+ EnumDeviceDrivers: { args: [FFIType.ptr, FFIType.u32, FFIType.ptr], returns: FFIType.i32 },
113
+ EnumPageFilesA: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
114
+ EnumPageFilesW: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
115
+ EnumProcessModules: { args: [FFIType.u64, FFIType.ptr, FFIType.u32, FFIType.ptr], returns: FFIType.i32 },
116
+ EnumProcessModulesEx: { args: [FFIType.u64, FFIType.ptr, FFIType.u32, FFIType.ptr, FFIType.u32], returns: FFIType.i32 },
117
+ EnumProcesses: { args: [FFIType.ptr, FFIType.u32, FFIType.ptr], returns: FFIType.i32 },
118
+ GetDeviceDriverBaseNameA: { args: [FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.u32 },
119
+ GetDeviceDriverBaseNameW: { args: [FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.u32 },
120
+ GetDeviceDriverFileNameA: { args: [FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.u32 },
121
+ GetDeviceDriverFileNameW: { args: [FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.u32 },
122
+ GetMappedFileNameA: { args: [FFIType.u64, FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.u32 },
123
+ GetMappedFileNameW: { args: [FFIType.u64, FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.u32 },
124
+ GetModuleBaseNameA: { args: [FFIType.u64, FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.u32 },
125
+ GetModuleBaseNameW: { args: [FFIType.u64, FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.u32 },
126
+ GetModuleFileNameExA: { args: [FFIType.u64, FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.u32 },
127
+ GetModuleFileNameExW: { args: [FFIType.u64, FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.u32 },
128
+ GetModuleInformation: { args: [FFIType.u64, FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.i32 },
129
+ GetPerformanceInfo: { args: [FFIType.ptr, FFIType.u32], returns: FFIType.i32 },
130
+ GetProcessImageFileNameA: { args: [FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.u32 },
131
+ GetProcessImageFileNameW: { args: [FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.u32 },
132
+ GetProcessMemoryInfo: { args: [FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.i32 },
133
+ GetWsChanges: { args: [FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.i32 },
134
+ GetWsChangesEx: { args: [FFIType.u64, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
135
+ InitializeProcessForWsWatch: { args: [FFIType.u64], returns: FFIType.i32 },
136
+ QueryWorkingSet: { args: [FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.i32 },
137
+ QueryWorkingSetEx: { args: [FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.i32 },
138
+ } as const satisfies Record<string, FFIFunction>;
139
+
140
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-emptyworkingset
141
+ public static EmptyWorkingSet(hProcess: HANDLE): BOOL {
142
+ return Psapi.Load('EmptyWorkingSet')(hProcess);
143
+ }
144
+
145
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-enumdevicedrivers
146
+ public static EnumDeviceDrivers(lpImageBase: LPVOID, cb: DWORD, lpcbNeeded: LPDWORD): BOOL {
147
+ return Psapi.Load('EnumDeviceDrivers')(lpImageBase, cb, lpcbNeeded);
148
+ }
149
+
150
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-enumpagefilesa
151
+ public static EnumPageFilesA(pCallBackRoutine: PENUM_PAGE_FILE_CALLBACKA, pContext: LPVOID): BOOL {
152
+ return Psapi.Load('EnumPageFilesA')(pCallBackRoutine, pContext);
153
+ }
154
+
155
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-enumpagefilesw
156
+ public static EnumPageFilesW(pCallBackRoutine: PENUM_PAGE_FILE_CALLBACKW, pContext: LPVOID): BOOL {
157
+ return Psapi.Load('EnumPageFilesW')(pCallBackRoutine, pContext);
158
+ }
159
+
160
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-enumprocessmodules
161
+ public static EnumProcessModules(hProcess: HANDLE, lphModule: LPHMODULE, cb: DWORD, lpcbNeeded: LPDWORD): BOOL {
162
+ return Psapi.Load('EnumProcessModules')(hProcess, lphModule, cb, lpcbNeeded);
163
+ }
164
+
165
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-enumprocessmodulesex
166
+ public static EnumProcessModulesEx(hProcess: HANDLE, lphModule: LPHMODULE, cb: DWORD, lpcbNeeded: LPDWORD, dwFilterFlag: DWORD): BOOL {
167
+ return Psapi.Load('EnumProcessModulesEx')(hProcess, lphModule, cb, lpcbNeeded, dwFilterFlag);
168
+ }
169
+
170
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-enumprocesses
171
+ public static EnumProcesses(lpidProcess: LPDWORD, cb: DWORD, lpcbNeeded: LPDWORD): BOOL {
172
+ return Psapi.Load('EnumProcesses')(lpidProcess, cb, lpcbNeeded);
173
+ }
174
+
175
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getdevicedriverbasenamea
176
+ public static GetDeviceDriverBaseNameA(ImageBase: bigint, lpBaseName: LPSTR, nSize: DWORD): DWORD {
177
+ return Psapi.Load('GetDeviceDriverBaseNameA')(ImageBase, lpBaseName, nSize);
178
+ }
179
+
180
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getdevicedriverbasenamew
181
+ public static GetDeviceDriverBaseNameW(ImageBase: bigint, lpBaseName: LPWSTR, nSize: DWORD): DWORD {
182
+ return Psapi.Load('GetDeviceDriverBaseNameW')(ImageBase, lpBaseName, nSize);
183
+ }
184
+
185
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getdevicedriverfilenamea
186
+ public static GetDeviceDriverFileNameA(ImageBase: bigint, lpFilename: LPSTR, nSize: DWORD): DWORD {
187
+ return Psapi.Load('GetDeviceDriverFileNameA')(ImageBase, lpFilename, nSize);
188
+ }
189
+
190
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getdevicedriverfilenamew
191
+ public static GetDeviceDriverFileNameW(ImageBase: bigint, lpFilename: LPWSTR, nSize: DWORD): DWORD {
192
+ return Psapi.Load('GetDeviceDriverFileNameW')(ImageBase, lpFilename, nSize);
193
+ }
194
+
195
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getmappedfilenamea
196
+ public static GetMappedFileNameA(hProcess: HANDLE, lpv: bigint, lpFilename: LPSTR, nSize: DWORD): DWORD {
197
+ return Psapi.Load('GetMappedFileNameA')(hProcess, lpv, lpFilename, nSize);
198
+ }
199
+
200
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getmappedfilenamew
201
+ public static GetMappedFileNameW(hProcess: HANDLE, lpv: bigint, lpFilename: LPWSTR, nSize: DWORD): DWORD {
202
+ return Psapi.Load('GetMappedFileNameW')(hProcess, lpv, lpFilename, nSize);
203
+ }
204
+
205
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getmodulebasenamea
206
+ public static GetModuleBaseNameA(hProcess: HANDLE, hModule: HMODULE, lpBaseName: LPSTR, nSize: DWORD): DWORD {
207
+ return Psapi.Load('GetModuleBaseNameA')(hProcess, hModule, lpBaseName, nSize);
208
+ }
209
+
210
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getmodulebasenamew
211
+ public static GetModuleBaseNameW(hProcess: HANDLE, hModule: HMODULE, lpBaseName: LPWSTR, nSize: DWORD): DWORD {
212
+ return Psapi.Load('GetModuleBaseNameW')(hProcess, hModule, lpBaseName, nSize);
213
+ }
214
+
215
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getmodulefilenameexa
216
+ public static GetModuleFileNameExA(hProcess: HANDLE, hModule: HMODULE, lpFilename: LPSTR, nSize: DWORD): DWORD {
217
+ return Psapi.Load('GetModuleFileNameExA')(hProcess, hModule, lpFilename, nSize);
218
+ }
219
+
220
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getmodulefilenameexw
221
+ public static GetModuleFileNameExW(hProcess: HANDLE, hModule: HMODULE, lpFilename: LPWSTR, nSize: DWORD): DWORD {
222
+ return Psapi.Load('GetModuleFileNameExW')(hProcess, hModule, lpFilename, nSize);
223
+ }
224
+
225
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getmoduleinformation
226
+ public static GetModuleInformation(hProcess: HANDLE, hModule: HMODULE, lpmodinfo: LPMODULEINFO, cb: DWORD): BOOL {
227
+ return Psapi.Load('GetModuleInformation')(hProcess, hModule, lpmodinfo, cb);
228
+ }
229
+
230
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getperformanceinfo
231
+ public static GetPerformanceInfo(pPerformanceInformation: PPERFORMANCE_INFORMATION, cb: DWORD): BOOL {
232
+ return Psapi.Load('GetPerformanceInfo')(pPerformanceInformation, cb);
233
+ }
234
+
235
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getprocessimagefilenamea
236
+ public static GetProcessImageFileNameA(hProcess: HANDLE, lpImageFileName: LPSTR, nSize: DWORD): DWORD {
237
+ return Psapi.Load('GetProcessImageFileNameA')(hProcess, lpImageFileName, nSize);
238
+ }
239
+
240
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getprocessimagefilenamew
241
+ public static GetProcessImageFileNameW(hProcess: HANDLE, lpImageFileName: LPWSTR, nSize: DWORD): DWORD {
242
+ return Psapi.Load('GetProcessImageFileNameW')(hProcess, lpImageFileName, nSize);
243
+ }
244
+
245
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getprocessmemoryinfo
246
+ public static GetProcessMemoryInfo(Process: HANDLE, ppsmemCounters: PPROCESS_MEMORY_COUNTERS, cb: DWORD): BOOL {
247
+ return Psapi.Load('GetProcessMemoryInfo')(Process, ppsmemCounters, cb);
248
+ }
249
+
250
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getwschanges
251
+ public static GetWsChanges(hProcess: HANDLE, lpWatchInfo: PPSAPI_WS_WATCH_INFORMATION, cb: DWORD): BOOL {
252
+ return Psapi.Load('GetWsChanges')(hProcess, lpWatchInfo, cb);
253
+ }
254
+
255
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-getwschangesex
256
+ public static GetWsChangesEx(hProcess: HANDLE, lpWatchInfoEx: PPSAPI_WS_WATCH_INFORMATION_EX, cb: PDWORD): BOOL {
257
+ return Psapi.Load('GetWsChangesEx')(hProcess, lpWatchInfoEx, cb);
258
+ }
259
+
260
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-initializeprocessforwswatch
261
+ public static InitializeProcessForWsWatch(hProcess: HANDLE): BOOL {
262
+ return Psapi.Load('InitializeProcessForWsWatch')(hProcess);
263
+ }
264
+
265
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-queryworkingset
266
+ public static QueryWorkingSet(hProcess: HANDLE, pv: PVOID, cb: DWORD): BOOL {
267
+ return Psapi.Load('QueryWorkingSet')(hProcess, pv, cb);
268
+ }
269
+
270
+ // https://learn.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-queryworkingsetex
271
+ public static QueryWorkingSetEx(hProcess: HANDLE, pv: PVOID, cb: DWORD): BOOL {
272
+ return Psapi.Load('QueryWorkingSetEx')(hProcess, pv, cb);
273
+ }
274
+ }
275
+
276
+ export default Psapi;
package/types/Psapi.ts ADDED
@@ -0,0 +1,29 @@
1
+ import type { Pointer } from 'bun:ffi';
2
+
3
+ export enum ListModulesFilterFlag {
4
+ LIST_MODULES_32BIT = 0x01,
5
+ LIST_MODULES_64BIT = 0x02,
6
+ LIST_MODULES_ALL = 0x03,
7
+ LIST_MODULES_DEFAULT = 0x00,
8
+ }
9
+
10
+ export type BOOL = number;
11
+ export type DWORD = number;
12
+ export type HANDLE = bigint;
13
+ export type HMODULE = bigint;
14
+ export type LPCSTR = Pointer;
15
+ export type LPCWSTR = Pointer;
16
+ export type LPDWORD = Pointer;
17
+ export type LPHMODULE = Pointer;
18
+ export type LPMODULEINFO = Pointer;
19
+ export type LPSTR = Pointer;
20
+ export type LPVOID = Pointer;
21
+ export type LPWSTR = Pointer;
22
+ export type PDWORD = Pointer;
23
+ export type PENUM_PAGE_FILE_CALLBACKA = Pointer;
24
+ export type PENUM_PAGE_FILE_CALLBACKW = Pointer;
25
+ export type PPERFORMANCE_INFORMATION = Pointer;
26
+ export type PPROCESS_MEMORY_COUNTERS = Pointer;
27
+ export type PPSAPI_WS_WATCH_INFORMATION = Pointer;
28
+ export type PPSAPI_WS_WATCH_INFORMATION_EX = Pointer;
29
+ export type PVOID = Pointer;