@bun-win32/wevtapi 1.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/AI.md ADDED
@@ -0,0 +1,71 @@
1
+ # AI Guide for @bun-win32/wevtapi
2
+
3
+ How to use this package, not what the Win32 API does.
4
+
5
+ ## Usage
6
+
7
+ ```ts
8
+ import Wevtapi, { SomeFlag } from '@bun-win32/wevtapi';
9
+
10
+ // Methods bind lazily on first call
11
+ const result = Wevtapi.SomeFunctionW(arg1, arg2);
12
+
13
+ // Preload: array, single string, or no args (all symbols)
14
+ Wevtapi.Preload(['SomeFunctionW', 'AnotherFunction']);
15
+ Wevtapi.Preload('SomeFunctionW');
16
+ Wevtapi.Preload();
17
+ ```
18
+
19
+ ## Where To Look
20
+
21
+ | Need | Read |
22
+ | --------------------------------- | -------------------- |
23
+ | Find a method or its MS Docs link | `structs/Wevtapi.ts` |
24
+ | Find types, enums, constants | `types/Wevtapi.ts` |
25
+ | Quick examples | `README.md` |
26
+
27
+ `index.ts` re-exports the class and all types - import from `@bun-win32/wevtapi` directly.
28
+
29
+ ## Calling Convention
30
+
31
+ All documented `wevtapi.dll` exports are bound. Each method maps 1:1 to its DLL export. Names, parameter names, and order match Microsoft Docs.
32
+
33
+ ### Strings
34
+
35
+ `W` methods take UTF-16LE NUL-terminated buffers. `A` methods take ANSI strings.
36
+
37
+ ```ts
38
+ const wide = Buffer.from('Hello\0', 'utf16le'); // LPCWSTR
39
+ Wevtapi.SomeFunctionW(wide.ptr);
40
+
41
+ // Reading a wide string back from a buffer:
42
+ const text = new TextDecoder('utf-16').decode(buf).replace(/\0.*$/, '');
43
+ ```
44
+
45
+ ### Return types
46
+
47
+ - `HANDLE`, `HWND`, etc. -> `bigint`
48
+ - `DWORD`, `UINT`, `BOOL`, `INT`, `LONG` -> `number`
49
+ - `LPVOID`, `LPWSTR`, etc. -> `Pointer`
50
+ - Win32 `BOOL` is `number` (0 or non-zero), **not** JS `boolean`. Do not compare with `=== true`.
51
+
52
+ ### Pointers, handles, out-parameters
53
+
54
+ - **Pointer** params (`LP*`, `P*`, `Pointer`): pass `buffer.ptr` from a caller-allocated `Buffer`.
55
+ - **Handle** params (`HANDLE`, `HWND`, etc.): pass a `bigint` value.
56
+ - **Out-parameters**: allocate a `Buffer`, pass `.ptr`, read the result after the call.
57
+
58
+ ```ts
59
+ const out = Buffer.alloc(4);
60
+ Wevtapi.SomeFunction(out.ptr);
61
+ const value = out.readUInt32LE(0);
62
+ ```
63
+
64
+ ### Nullability
65
+
66
+ - `| NULL` in a signature -> pass `null` (optional pointer).
67
+ - `| 0n` in a signature -> pass `0n` (optional handle).
68
+
69
+ ## Errors and Cleanup
70
+
71
+ Return values are raw. If the Win32 function uses last-error semantics, read via `GetLastError()`. Resource cleanup is your responsibility - same as raw Win32.
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # @bun-win32/wevtapi
2
+
3
+ Zero-dependency, zero-overhead Win32 Wevtapi bindings for [Bun](https://bun.sh) on Windows.
4
+
5
+ ## Overview
6
+
7
+ `@bun-win32/wevtapi` exposes the `wevtapi.dll` exports using [Bun](https://bun.sh)'s FFI. It provides a single class, `Wevtapi`, which lazily binds native symbols on first use. You can optionally preload a subset or all symbols up-front via `Preload()`.
8
+
9
+ The bindings are strongly typed for a smooth DX in TypeScript.
10
+
11
+ ## Features
12
+
13
+ - [Bun](https://bun.sh)-first ergonomics on Windows 10/11.
14
+ - Direct FFI to `wevtapi.dll` (Windows Event Log queries, rendering, subscriptions, channel configuration, and publisher metadata).
15
+ - In-source docs in `structs/Wevtapi.ts` with links to Microsoft Learn.
16
+ - Lazy binding on first call; optional eager preload (`Wevtapi.Preload()`).
17
+ - No wrapper overhead; calls map 1:1 to native APIs.
18
+ - Strongly-typed Win32 aliases, enums, and constants (see `types/Wevtapi.ts`).
19
+
20
+ ## Requirements
21
+
22
+ - [Bun](https://bun.sh) runtime
23
+ - Windows 10 or later
24
+
25
+ ## Installation
26
+
27
+ ```sh
28
+ bun add @bun-win32/wevtapi
29
+ ```
30
+
31
+ ## Quick Start
32
+
33
+ ```ts
34
+ import Wevtapi, { EvtQueryFlags } from '@bun-win32/wevtapi';
35
+
36
+ const channelPath = Buffer.from('System\0', 'utf16le');
37
+ const query = Buffer.from('*\0', 'utf16le');
38
+ const resultSet = Wevtapi.EvtQuery(0n, channelPath.ptr, query.ptr, EvtQueryFlags.EvtQueryChannelPath);
39
+
40
+ if (resultSet === 0n) {
41
+ throw new Error('EvtQuery failed');
42
+ }
43
+
44
+ Wevtapi.EvtClose(resultSet);
45
+ ```
46
+
47
+ > [!NOTE]
48
+ > AI agents: see `AI.md` for the package binding contract and source-navigation guidance. It explains how to use the package without scanning the entire implementation.
49
+
50
+ ## Examples
51
+
52
+ Run the included examples:
53
+
54
+ ```sh
55
+ bun run example:event-tail
56
+ bun run example:channel-report
57
+ ```
58
+
59
+ ## Notes
60
+
61
+ - Either rely on lazy binding or call `Wevtapi.Preload()`.
62
+ - Windows only. Bun runtime required.
package/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ import Wevtapi from './structs/Wevtapi';
2
+
3
+ export * from './types/Wevtapi';
4
+ export default Wevtapi;
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "author": "Stev Peifer <stev@bell.net>",
3
+ "bugs": {
4
+ "url": "https://github.com/ObscuritySRL/bun-win32/issues"
5
+ },
6
+ "dependencies": {
7
+ "@bun-win32/core": "1.1.2"
8
+ },
9
+ "description": "Zero-dependency, zero-overhead Win32 WEVTAPI bindings for Bun (FFI) on Windows.",
10
+ "devDependencies": {
11
+ "@bun-win32/kernel32": "1.0.21",
12
+ "@types/bun": "latest"
13
+ },
14
+ "exports": {
15
+ ".": "./index.ts"
16
+ },
17
+ "license": "MIT",
18
+ "module": "index.ts",
19
+ "name": "@bun-win32/wevtapi",
20
+ "peerDependencies": {
21
+ "typescript": "^5"
22
+ },
23
+ "private": false,
24
+ "homepage": "https://github.com/ObscuritySRL/bun-win32#readme",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git://github.com/ObscuritySRL/bun-win32.git",
28
+ "directory": "packages/wevtapi"
29
+ },
30
+ "type": "module",
31
+ "version": "1.0.0",
32
+ "main": "./index.ts",
33
+ "keywords": [
34
+ "bun",
35
+ "ffi",
36
+ "win32",
37
+ "windows",
38
+ "wevtapi",
39
+ "windows-event-log",
40
+ "event-log",
41
+ "subscriptions",
42
+ "bindings",
43
+ "typescript",
44
+ "dll"
45
+ ],
46
+ "files": [
47
+ "AI.md",
48
+ "README.md",
49
+ "index.ts",
50
+ "structs/*.ts",
51
+ "types/*.ts"
52
+ ],
53
+ "sideEffects": false,
54
+ "engines": {
55
+ "bun": ">=1.1.0"
56
+ },
57
+ "scripts": {
58
+ "example:channel-report": "bun ./example/channel-report.ts",
59
+ "example:event-tail": "bun ./example/event-tail.ts"
60
+ }
61
+ }
@@ -0,0 +1,319 @@
1
+ import { type FFIFunction, FFIType } from 'bun:ffi';
2
+
3
+ import { Win32 } from '@bun-win32/core';
4
+
5
+ import type {
6
+ BOOL,
7
+ DWORD,
8
+ EVT_HANDLE,
9
+ EVT_OBJECT_ARRAY_PROPERTY_HANDLE,
10
+ EVT_SUBSCRIBE_CALLBACK,
11
+ EvtChannelConfigPropertyId,
12
+ EvtEventMetadataPropertyId,
13
+ EvtEventPropertyId,
14
+ EvtExportLogFlags,
15
+ EvtFormatMessageFlags,
16
+ EvtLoginClass,
17
+ EvtLogPropertyId,
18
+ EvtOpenLogFlags,
19
+ EvtPublisherMetadataPropertyId,
20
+ EvtQueryFlags,
21
+ EvtQueryPropertyId,
22
+ EvtRenderContextFlags,
23
+ EvtRenderFlags,
24
+ EvtSeekFlags,
25
+ EvtSubscribeFlags,
26
+ HANDLE,
27
+ LCID,
28
+ LONGLONG,
29
+ LPCWSTR,
30
+ LPWSTR,
31
+ NULL,
32
+ PDWORD,
33
+ PEVT_HANDLE,
34
+ PEVT_RPC_LOGIN,
35
+ PEVT_VARIANT,
36
+ PLPCWSTR,
37
+ PVOID,
38
+ } from '../types/Wevtapi';
39
+
40
+ /**
41
+ * Thin, lazy-loaded FFI bindings for `wevtapi.dll`.
42
+ *
43
+ * Each static method corresponds one-to-one with a Win32 export declared in `Symbols`.
44
+ * The first call to a method binds the underlying native symbol via `bun:ffi` and
45
+ * memoizes it on the class for subsequent calls. For bulk, up-front binding, use `Preload`.
46
+ *
47
+ * Symbols are defined with explicit `FFIType` signatures and kept alphabetized.
48
+ * You normally do not access `Symbols` directly; call the static methods or preload
49
+ * a subset for hot paths.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * import Wevtapi from './structs/Wevtapi';
54
+ *
55
+ * const channelPath = Buffer.from('System\0', 'utf16le');
56
+ * const query = Buffer.from('*\0', 'utf16le');
57
+ * const queryHandle = Wevtapi.EvtQuery(0n, channelPath.ptr, query.ptr, 0x0000_0001);
58
+ * ```
59
+ */
60
+ class Wevtapi extends Win32 {
61
+ protected static override name = 'wevtapi.dll';
62
+
63
+ /** @inheritdoc */
64
+ protected static override readonly Symbols = {
65
+ EvtArchiveExportedLog: { args: [FFIType.u64, FFIType.ptr, FFIType.u32, FFIType.u32], returns: FFIType.i32 },
66
+ EvtCancel: { args: [FFIType.u64], returns: FFIType.i32 },
67
+ EvtClearLog: { args: [FFIType.u64, FFIType.ptr, FFIType.ptr, FFIType.u32], returns: FFIType.i32 },
68
+ EvtClose: { args: [FFIType.u64], returns: FFIType.i32 },
69
+ EvtCreateBookmark: { args: [FFIType.ptr], returns: FFIType.u64 },
70
+ EvtCreateRenderContext: { args: [FFIType.u32, FFIType.ptr, FFIType.u32], returns: FFIType.u64 },
71
+ EvtExportLog: { args: [FFIType.u64, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.u32], returns: FFIType.i32 },
72
+ EvtFormatMessage: { args: [FFIType.u64, FFIType.u64, FFIType.u32, FFIType.u32, FFIType.ptr, FFIType.u32, FFIType.u32, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
73
+ EvtGetChannelConfigProperty: { args: [FFIType.u64, FFIType.u32, FFIType.u32, FFIType.u32, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
74
+ EvtGetEventInfo: { args: [FFIType.u64, FFIType.u32, FFIType.u32, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
75
+ EvtGetEventMetadataProperty: { args: [FFIType.u64, FFIType.u32, FFIType.u32, FFIType.u32, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
76
+ EvtGetExtendedStatus: { args: [FFIType.u32, FFIType.ptr, FFIType.ptr], returns: FFIType.u32 },
77
+ EvtGetLogInfo: { args: [FFIType.u64, FFIType.u32, FFIType.u32, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
78
+ EvtGetObjectArrayProperty: { args: [FFIType.u64, FFIType.u32, FFIType.u32, FFIType.u32, FFIType.u32, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
79
+ EvtGetObjectArraySize: { args: [FFIType.u64, FFIType.ptr], returns: FFIType.i32 },
80
+ EvtGetPublisherMetadataProperty: { args: [FFIType.u64, FFIType.u32, FFIType.u32, FFIType.u32, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
81
+ EvtGetQueryInfo: { args: [FFIType.u64, FFIType.u32, FFIType.u32, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
82
+ EvtNext: { args: [FFIType.u64, FFIType.u32, FFIType.ptr, FFIType.u32, FFIType.u32, FFIType.ptr], returns: FFIType.i32 },
83
+ EvtNextChannelPath: { args: [FFIType.u64, FFIType.u32, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
84
+ EvtNextEventMetadata: { args: [FFIType.u64, FFIType.u32], returns: FFIType.u64 },
85
+ EvtNextPublisherId: { args: [FFIType.u64, FFIType.u32, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
86
+ EvtOpenChannelConfig: { args: [FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.u64 },
87
+ EvtOpenChannelEnum: { args: [FFIType.u64, FFIType.u32], returns: FFIType.u64 },
88
+ EvtOpenEventMetadataEnum: { args: [FFIType.u64, FFIType.u32], returns: FFIType.u64 },
89
+ EvtOpenLog: { args: [FFIType.u64, FFIType.ptr, FFIType.u32], returns: FFIType.u64 },
90
+ EvtOpenPublisherEnum: { args: [FFIType.u64, FFIType.u32], returns: FFIType.u64 },
91
+ EvtOpenPublisherMetadata: { args: [FFIType.u64, FFIType.ptr, FFIType.ptr, FFIType.u32, FFIType.u32], returns: FFIType.u64 },
92
+ EvtOpenSession: { args: [FFIType.u32, FFIType.ptr, FFIType.u32, FFIType.u32], returns: FFIType.u64 },
93
+ EvtQuery: { args: [FFIType.u64, FFIType.ptr, FFIType.ptr, FFIType.u32], returns: FFIType.u64 },
94
+ EvtRender: { args: [FFIType.u64, FFIType.u64, FFIType.u32, FFIType.u32, FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
95
+ EvtSaveChannelConfig: { args: [FFIType.u64, FFIType.u32], returns: FFIType.i32 },
96
+ EvtSeek: { args: [FFIType.u64, FFIType.i64, FFIType.u64, FFIType.u32, FFIType.u32], returns: FFIType.i32 },
97
+ EvtSetChannelConfigProperty: { args: [FFIType.u64, FFIType.u32, FFIType.u32, FFIType.ptr], returns: FFIType.i32 },
98
+ EvtSubscribe: { args: [FFIType.u64, FFIType.u64, FFIType.ptr, FFIType.ptr, FFIType.u64, FFIType.ptr, FFIType.ptr, FFIType.u32], returns: FFIType.u64 },
99
+ EvtUpdateBookmark: { args: [FFIType.u64, FFIType.u64], returns: FFIType.i32 },
100
+ } as const satisfies Record<string, FFIFunction>;
101
+
102
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtarchiveexportedlog
103
+ public static EvtArchiveExportedLog(Session: EVT_HANDLE | 0n, LogFilePath: LPCWSTR, Locale: LCID, Flags: DWORD): BOOL {
104
+ return Wevtapi.Load('EvtArchiveExportedLog')(Session, LogFilePath, Locale, Flags);
105
+ }
106
+
107
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtcancel
108
+ public static EvtCancel(Object: EVT_HANDLE | 0n): BOOL {
109
+ return Wevtapi.Load('EvtCancel')(Object);
110
+ }
111
+
112
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtclearlog
113
+ public static EvtClearLog(Session: EVT_HANDLE | 0n, ChannelPath: LPCWSTR, TargetFilePath: LPCWSTR | NULL, Flags: DWORD): BOOL {
114
+ return Wevtapi.Load('EvtClearLog')(Session, ChannelPath, TargetFilePath, Flags);
115
+ }
116
+
117
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtclose
118
+ public static EvtClose(Object: EVT_HANDLE): BOOL {
119
+ return Wevtapi.Load('EvtClose')(Object);
120
+ }
121
+
122
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtcreatebookmark
123
+ public static EvtCreateBookmark(BookmarkXml: LPCWSTR | NULL): EVT_HANDLE {
124
+ return Wevtapi.Load('EvtCreateBookmark')(BookmarkXml);
125
+ }
126
+
127
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtcreaterendercontext
128
+ public static EvtCreateRenderContext(ValuePathsCount: DWORD, ValuePaths: PLPCWSTR | NULL, Flags: EvtRenderContextFlags): EVT_HANDLE {
129
+ return Wevtapi.Load('EvtCreateRenderContext')(ValuePathsCount, ValuePaths, Flags);
130
+ }
131
+
132
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtexportlog
133
+ public static EvtExportLog(Session: EVT_HANDLE | 0n, Path: LPCWSTR | NULL, Query: LPCWSTR | NULL, TargetFilePath: LPCWSTR, Flags: EvtExportLogFlags): BOOL {
134
+ return Wevtapi.Load('EvtExportLog')(Session, Path, Query, TargetFilePath, Flags);
135
+ }
136
+
137
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtformatmessage
138
+ public static EvtFormatMessage(
139
+ PublisherMetadata: EVT_HANDLE | 0n,
140
+ Event: EVT_HANDLE | 0n,
141
+ MessageId: DWORD,
142
+ ValueCount: DWORD,
143
+ Values: PEVT_VARIANT | NULL,
144
+ Flags: EvtFormatMessageFlags,
145
+ BufferSize: DWORD,
146
+ Buffer: LPWSTR | NULL,
147
+ BufferUsed: PDWORD,
148
+ ): BOOL {
149
+ return Wevtapi.Load('EvtFormatMessage')(PublisherMetadata, Event, MessageId, ValueCount, Values, Flags, BufferSize, Buffer, BufferUsed);
150
+ }
151
+
152
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtgetchannelconfigproperty
153
+ public static EvtGetChannelConfigProperty(ChannelConfig: EVT_HANDLE, PropertyId: EvtChannelConfigPropertyId, Flags: DWORD, PropertyValueBufferSize: DWORD, PropertyValueBuffer: PEVT_VARIANT | NULL, PropertyValueBufferUsed: PDWORD): BOOL {
154
+ return Wevtapi.Load('EvtGetChannelConfigProperty')(ChannelConfig, PropertyId, Flags, PropertyValueBufferSize, PropertyValueBuffer, PropertyValueBufferUsed);
155
+ }
156
+
157
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtgeteventinfo
158
+ public static EvtGetEventInfo(Event: EVT_HANDLE, PropertyId: EvtEventPropertyId, PropertyValueBufferSize: DWORD, PropertyValueBuffer: PEVT_VARIANT | NULL, PropertyValueBufferUsed: PDWORD): BOOL {
159
+ return Wevtapi.Load('EvtGetEventInfo')(Event, PropertyId, PropertyValueBufferSize, PropertyValueBuffer, PropertyValueBufferUsed);
160
+ }
161
+
162
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtgeteventmetadataproperty
163
+ public static EvtGetEventMetadataProperty(
164
+ EventMetadata: EVT_HANDLE,
165
+ PropertyId: EvtEventMetadataPropertyId,
166
+ Flags: DWORD,
167
+ EventMetadataPropertyBufferSize: DWORD,
168
+ EventMetadataPropertyBuffer: PEVT_VARIANT | NULL,
169
+ EventMetadataPropertyBufferUsed: PDWORD,
170
+ ): BOOL {
171
+ return Wevtapi.Load('EvtGetEventMetadataProperty')(EventMetadata, PropertyId, Flags, EventMetadataPropertyBufferSize, EventMetadataPropertyBuffer, EventMetadataPropertyBufferUsed);
172
+ }
173
+
174
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtgetextendedstatus
175
+ public static EvtGetExtendedStatus(BufferSize: DWORD, Buffer: LPWSTR | NULL, BufferUsed: PDWORD): DWORD {
176
+ return Wevtapi.Load('EvtGetExtendedStatus')(BufferSize, Buffer, BufferUsed);
177
+ }
178
+
179
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtgetloginfo
180
+ public static EvtGetLogInfo(Log: EVT_HANDLE, PropertyId: EvtLogPropertyId, PropertyValueBufferSize: DWORD, PropertyValueBuffer: PEVT_VARIANT | NULL, PropertyValueBufferUsed: PDWORD): BOOL {
181
+ return Wevtapi.Load('EvtGetLogInfo')(Log, PropertyId, PropertyValueBufferSize, PropertyValueBuffer, PropertyValueBufferUsed);
182
+ }
183
+
184
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtgetobjectarrayproperty
185
+ public static EvtGetObjectArrayProperty(
186
+ ObjectArray: EVT_OBJECT_ARRAY_PROPERTY_HANDLE,
187
+ PropertyId: DWORD,
188
+ ArrayIndex: DWORD,
189
+ Flags: DWORD,
190
+ PropertyValueBufferSize: DWORD,
191
+ PropertyValueBuffer: PEVT_VARIANT | NULL,
192
+ PropertyValueBufferUsed: PDWORD,
193
+ ): BOOL {
194
+ return Wevtapi.Load('EvtGetObjectArrayProperty')(ObjectArray, PropertyId, ArrayIndex, Flags, PropertyValueBufferSize, PropertyValueBuffer, PropertyValueBufferUsed);
195
+ }
196
+
197
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtgetobjectarraysize
198
+ public static EvtGetObjectArraySize(ObjectArray: EVT_OBJECT_ARRAY_PROPERTY_HANDLE, ObjectArraySize: PDWORD): BOOL {
199
+ return Wevtapi.Load('EvtGetObjectArraySize')(ObjectArray, ObjectArraySize);
200
+ }
201
+
202
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtgetpublishermetadataproperty
203
+ public static EvtGetPublisherMetadataProperty(
204
+ PublisherMetadata: EVT_HANDLE,
205
+ PropertyId: EvtPublisherMetadataPropertyId,
206
+ Flags: DWORD,
207
+ PublisherMetadataPropertyBufferSize: DWORD,
208
+ PublisherMetadataPropertyBuffer: PEVT_VARIANT | NULL,
209
+ PublisherMetadataPropertyBufferUsed: PDWORD,
210
+ ): BOOL {
211
+ return Wevtapi.Load('EvtGetPublisherMetadataProperty')(PublisherMetadata, PropertyId, Flags, PublisherMetadataPropertyBufferSize, PublisherMetadataPropertyBuffer, PublisherMetadataPropertyBufferUsed);
212
+ }
213
+
214
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtgetqueryinfo
215
+ public static EvtGetQueryInfo(QueryOrSubscription: EVT_HANDLE, PropertyId: EvtQueryPropertyId, PropertyValueBufferSize: DWORD, PropertyValueBuffer: PEVT_VARIANT | NULL, PropertyValueBufferUsed: PDWORD): BOOL {
216
+ return Wevtapi.Load('EvtGetQueryInfo')(QueryOrSubscription, PropertyId, PropertyValueBufferSize, PropertyValueBuffer, PropertyValueBufferUsed);
217
+ }
218
+
219
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtnext
220
+ public static EvtNext(ResultSet: EVT_HANDLE, EventsSize: DWORD, Events: PEVT_HANDLE, Timeout: DWORD, Flags: DWORD, Returned: PDWORD): BOOL {
221
+ return Wevtapi.Load('EvtNext')(ResultSet, EventsSize, Events, Timeout, Flags, Returned);
222
+ }
223
+
224
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtnextchannelpath
225
+ public static EvtNextChannelPath(ChannelEnum: EVT_HANDLE, ChannelPathBufferSize: DWORD, ChannelPathBuffer: LPWSTR | NULL, ChannelPathBufferUsed: PDWORD): BOOL {
226
+ return Wevtapi.Load('EvtNextChannelPath')(ChannelEnum, ChannelPathBufferSize, ChannelPathBuffer, ChannelPathBufferUsed);
227
+ }
228
+
229
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtnexteventmetadata
230
+ public static EvtNextEventMetadata(EventMetadataEnum: EVT_HANDLE, Flags: DWORD): EVT_HANDLE {
231
+ return Wevtapi.Load('EvtNextEventMetadata')(EventMetadataEnum, Flags);
232
+ }
233
+
234
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtnextpublisherid
235
+ public static EvtNextPublisherId(PublisherEnum: EVT_HANDLE, PublisherIdBufferSize: DWORD, PublisherIdBuffer: LPWSTR | NULL, PublisherIdBufferUsed: PDWORD): BOOL {
236
+ return Wevtapi.Load('EvtNextPublisherId')(PublisherEnum, PublisherIdBufferSize, PublisherIdBuffer, PublisherIdBufferUsed);
237
+ }
238
+
239
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtopenchannelconfig
240
+ public static EvtOpenChannelConfig(Session: EVT_HANDLE | 0n, ChannelPath: LPCWSTR, Flags: DWORD): EVT_HANDLE {
241
+ return Wevtapi.Load('EvtOpenChannelConfig')(Session, ChannelPath, Flags);
242
+ }
243
+
244
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtopenchannelenum
245
+ public static EvtOpenChannelEnum(Session: EVT_HANDLE | 0n, Flags: DWORD): EVT_HANDLE {
246
+ return Wevtapi.Load('EvtOpenChannelEnum')(Session, Flags);
247
+ }
248
+
249
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtopeneventmetadataenum
250
+ public static EvtOpenEventMetadataEnum(PublisherMetadata: EVT_HANDLE, Flags: DWORD): EVT_HANDLE {
251
+ return Wevtapi.Load('EvtOpenEventMetadataEnum')(PublisherMetadata, Flags);
252
+ }
253
+
254
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtopenlog
255
+ public static EvtOpenLog(Session: EVT_HANDLE | 0n, Path: LPCWSTR, Flags: EvtOpenLogFlags): EVT_HANDLE {
256
+ return Wevtapi.Load('EvtOpenLog')(Session, Path, Flags);
257
+ }
258
+
259
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtopenpublisherenum
260
+ public static EvtOpenPublisherEnum(Session: EVT_HANDLE | 0n, Flags: DWORD): EVT_HANDLE {
261
+ return Wevtapi.Load('EvtOpenPublisherEnum')(Session, Flags);
262
+ }
263
+
264
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtopenpublishermetadata
265
+ public static EvtOpenPublisherMetadata(Session: EVT_HANDLE | 0n, PublisherId: LPCWSTR, LogFilePath: LPCWSTR | NULL, Locale: LCID, Flags: DWORD): EVT_HANDLE {
266
+ return Wevtapi.Load('EvtOpenPublisherMetadata')(Session, PublisherId, LogFilePath, Locale, Flags);
267
+ }
268
+
269
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtopensession
270
+ public static EvtOpenSession(LoginClass: EvtLoginClass, Login: PEVT_RPC_LOGIN, Timeout: DWORD, Flags: DWORD): EVT_HANDLE {
271
+ return Wevtapi.Load('EvtOpenSession')(LoginClass, Login, Timeout, Flags);
272
+ }
273
+
274
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtquery
275
+ public static EvtQuery(Session: EVT_HANDLE | 0n, Path: LPCWSTR | NULL, Query: LPCWSTR | NULL, Flags: EvtQueryFlags): EVT_HANDLE {
276
+ return Wevtapi.Load('EvtQuery')(Session, Path, Query, Flags);
277
+ }
278
+
279
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtrender
280
+ public static EvtRender(Context: EVT_HANDLE | 0n, Fragment: EVT_HANDLE, Flags: EvtRenderFlags, BufferSize: DWORD, Buffer: PVOID | NULL, BufferUsed: PDWORD, PropertyCount: PDWORD): BOOL {
281
+ return Wevtapi.Load('EvtRender')(Context, Fragment, Flags, BufferSize, Buffer, BufferUsed, PropertyCount);
282
+ }
283
+
284
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtsavechannelconfig
285
+ public static EvtSaveChannelConfig(ChannelConfig: EVT_HANDLE, Flags: DWORD): BOOL {
286
+ return Wevtapi.Load('EvtSaveChannelConfig')(ChannelConfig, Flags);
287
+ }
288
+
289
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtseek
290
+ public static EvtSeek(ResultSet: EVT_HANDLE, Position: LONGLONG, Bookmark: EVT_HANDLE | 0n, Timeout: DWORD, Flags: EvtSeekFlags): BOOL {
291
+ return Wevtapi.Load('EvtSeek')(ResultSet, Position, Bookmark, Timeout, Flags);
292
+ }
293
+
294
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtsetchannelconfigproperty
295
+ public static EvtSetChannelConfigProperty(ChannelConfig: EVT_HANDLE, PropertyId: EvtChannelConfigPropertyId, Flags: DWORD, PropertyValue: PEVT_VARIANT): BOOL {
296
+ return Wevtapi.Load('EvtSetChannelConfigProperty')(ChannelConfig, PropertyId, Flags, PropertyValue);
297
+ }
298
+
299
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtsubscribe
300
+ public static EvtSubscribe(
301
+ Session: EVT_HANDLE | 0n,
302
+ SignalEvent: HANDLE | 0n,
303
+ ChannelPath: LPCWSTR | NULL,
304
+ Query: LPCWSTR | NULL,
305
+ Bookmark: EVT_HANDLE | 0n,
306
+ Context: PVOID | NULL,
307
+ Callback: EVT_SUBSCRIBE_CALLBACK | NULL,
308
+ Flags: EvtSubscribeFlags,
309
+ ): EVT_HANDLE {
310
+ return Wevtapi.Load('EvtSubscribe')(Session, SignalEvent, ChannelPath, Query, Bookmark, Context, Callback, Flags);
311
+ }
312
+
313
+ // https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtupdatebookmark
314
+ public static EvtUpdateBookmark(Bookmark: EVT_HANDLE, Event: EVT_HANDLE): BOOL {
315
+ return Wevtapi.Load('EvtUpdateBookmark')(Bookmark, Event);
316
+ }
317
+ }
318
+
319
+ export default Wevtapi;
@@ -0,0 +1,269 @@
1
+ import type { Pointer } from 'bun:ffi';
2
+
3
+ import type { DWORD, HANDLE } from '@bun-win32/core';
4
+ export type { BOOL, DWORD, HANDLE, LPCWSTR, LPWSTR, NULL, PDWORD, PVOID } from '@bun-win32/core';
5
+
6
+ export const EVT_ALL_ACCESS = 0x0000_0007;
7
+ export const EVT_CLEAR_ACCESS = 0x0000_0004;
8
+ export const EVT_READ_ACCESS = 0x0000_0001;
9
+ export const EVT_VARIANT_TYPE_ARRAY = 0x0080;
10
+ export const EVT_VARIANT_TYPE_MASK = 0x007f;
11
+ export const EVT_WRITE_ACCESS = 0x0000_0002;
12
+
13
+ export enum EvtChannelClockType {
14
+ EvtChannelClockTypeSystemTime = 0,
15
+ EvtChannelClockTypeQPC,
16
+ }
17
+
18
+ export enum EvtChannelConfigPropertyId {
19
+ EvtChannelConfigEnabled = 0,
20
+ EvtChannelConfigIsolation,
21
+ EvtChannelConfigType,
22
+ EvtChannelConfigOwningPublisher,
23
+ EvtChannelConfigClassicEventlog,
24
+ EvtChannelConfigAccess,
25
+ EvtChannelLoggingConfigRetention,
26
+ EvtChannelLoggingConfigAutoBackup,
27
+ EvtChannelLoggingConfigMaxSize,
28
+ EvtChannelLoggingConfigLogFilePath,
29
+ EvtChannelPublishingConfigLevel,
30
+ EvtChannelPublishingConfigKeywords,
31
+ EvtChannelPublishingConfigControlGuid,
32
+ EvtChannelPublishingConfigBufferSize,
33
+ EvtChannelPublishingConfigMinBuffers,
34
+ EvtChannelPublishingConfigMaxBuffers,
35
+ EvtChannelPublishingConfigLatency,
36
+ EvtChannelPublishingConfigClockType,
37
+ EvtChannelPublishingConfigSidType,
38
+ EvtChannelPublisherList,
39
+ EvtChannelPublishingConfigFileMax,
40
+ EvtChannelConfigPropertyIdEND,
41
+ }
42
+
43
+ export enum EvtChannelIsolationType {
44
+ EvtChannelIsolationTypeApplication = 0,
45
+ EvtChannelIsolationTypeSystem,
46
+ EvtChannelIsolationTypeCustom,
47
+ }
48
+
49
+ export enum EvtChannelReferenceFlags {
50
+ EvtChannelReferenceImported = 0x0000_0001,
51
+ }
52
+
53
+ export enum EvtChannelSidType {
54
+ EvtChannelSidTypeNone = 0,
55
+ EvtChannelSidTypePublishing,
56
+ }
57
+
58
+ export enum EvtChannelType {
59
+ EvtChannelTypeAdmin = 0,
60
+ EvtChannelTypeOperational,
61
+ EvtChannelTypeAnalytic,
62
+ EvtChannelTypeDebug,
63
+ }
64
+
65
+ export enum EvtEventMetadataPropertyId {
66
+ EventMetadataEventID = 0,
67
+ EventMetadataEventVersion,
68
+ EventMetadataEventChannel,
69
+ EventMetadataEventLevel,
70
+ EventMetadataEventOpcode,
71
+ EventMetadataEventTask,
72
+ EventMetadataEventKeyword,
73
+ EventMetadataEventMessageID,
74
+ EventMetadataEventTemplate,
75
+ EvtEventMetadataPropertyIdEND,
76
+ }
77
+
78
+ export enum EvtEventPropertyId {
79
+ EvtEventQueryIDs = 0,
80
+ EvtEventPath,
81
+ EvtEventPropertyIdEND,
82
+ }
83
+
84
+ export enum EvtExportLogFlags {
85
+ EvtExportLogChannelPath = 0x0000_0001,
86
+ EvtExportLogFilePath = 0x0000_0002,
87
+ EvtExportLogTolerateQueryErrors = 0x0000_1000,
88
+ EvtExportLogOverwrite = 0x0000_2000,
89
+ }
90
+
91
+ export enum EvtFormatMessageFlags {
92
+ EvtFormatMessageEvent = 1,
93
+ EvtFormatMessageLevel,
94
+ EvtFormatMessageTask,
95
+ EvtFormatMessageOpcode,
96
+ EvtFormatMessageKeyword,
97
+ EvtFormatMessageChannel,
98
+ EvtFormatMessageProvider,
99
+ EvtFormatMessageId,
100
+ EvtFormatMessageXml,
101
+ }
102
+
103
+ export enum EvtLoginClass {
104
+ EvtRpcLogin = 1,
105
+ }
106
+
107
+ export enum EvtLogPropertyId {
108
+ EvtLogCreationTime = 0,
109
+ EvtLogLastAccessTime,
110
+ EvtLogLastWriteTime,
111
+ EvtLogFileSize,
112
+ EvtLogAttributes,
113
+ EvtLogNumberOfLogRecords,
114
+ EvtLogOldestRecordNumber,
115
+ EvtLogFull,
116
+ }
117
+
118
+ export enum EvtOpenLogFlags {
119
+ EvtOpenChannelPath = 0x0000_0001,
120
+ EvtOpenFilePath = 0x0000_0002,
121
+ }
122
+
123
+ export enum EvtPublisherMetadataPropertyId {
124
+ EvtPublisherMetadataPublisherGuid = 0,
125
+ EvtPublisherMetadataResourceFilePath,
126
+ EvtPublisherMetadataParameterFilePath,
127
+ EvtPublisherMetadataMessageFilePath,
128
+ EvtPublisherMetadataHelpLink,
129
+ EvtPublisherMetadataPublisherMessageID,
130
+ EvtPublisherMetadataChannelReferences,
131
+ EvtPublisherMetadataChannelReferencePath,
132
+ EvtPublisherMetadataChannelReferenceIndex,
133
+ EvtPublisherMetadataChannelReferenceID,
134
+ EvtPublisherMetadataChannelReferenceFlags,
135
+ EvtPublisherMetadataChannelReferenceMessageID,
136
+ EvtPublisherMetadataLevels,
137
+ EvtPublisherMetadataLevelName,
138
+ EvtPublisherMetadataLevelValue,
139
+ EvtPublisherMetadataLevelMessageID,
140
+ EvtPublisherMetadataTasks,
141
+ EvtPublisherMetadataTaskName,
142
+ EvtPublisherMetadataTaskEventGuid,
143
+ EvtPublisherMetadataTaskValue,
144
+ EvtPublisherMetadataTaskMessageID,
145
+ EvtPublisherMetadataOpcodes,
146
+ EvtPublisherMetadataOpcodeName,
147
+ EvtPublisherMetadataOpcodeValue,
148
+ EvtPublisherMetadataOpcodeMessageID,
149
+ EvtPublisherMetadataKeywords,
150
+ EvtPublisherMetadataKeywordName,
151
+ EvtPublisherMetadataKeywordValue,
152
+ EvtPublisherMetadataKeywordMessageID,
153
+ EvtPublisherMetadataPropertyIdEND,
154
+ }
155
+
156
+ export enum EvtQueryFlags {
157
+ EvtQueryChannelPath = 0x0000_0001,
158
+ EvtQueryFilePath = 0x0000_0002,
159
+ EvtQueryForwardDirection = 0x0000_0100,
160
+ EvtQueryReverseDirection = 0x0000_0200,
161
+ EvtQueryTolerateQueryErrors = 0x0000_1000,
162
+ }
163
+
164
+ export enum EvtQueryPropertyId {
165
+ EvtQueryNames = 0,
166
+ EvtQueryStatuses,
167
+ EvtQueryPropertyIdEND,
168
+ }
169
+
170
+ export enum EvtRenderContextFlags {
171
+ EvtRenderContextValues = 0,
172
+ EvtRenderContextSystem,
173
+ EvtRenderContextUser,
174
+ }
175
+
176
+ export enum EvtRenderFlags {
177
+ EvtRenderEventValues = 0,
178
+ EvtRenderEventXml,
179
+ EvtRenderBookmark,
180
+ }
181
+
182
+ export enum EvtRpcLoginFlags {
183
+ EvtRpcLoginAuthDefault = 0,
184
+ EvtRpcLoginAuthNegotiate,
185
+ EvtRpcLoginAuthKerberos,
186
+ EvtRpcLoginAuthNTLM,
187
+ }
188
+
189
+ export enum EvtSeekFlags {
190
+ EvtSeekRelativeToFirst = 1,
191
+ EvtSeekRelativeToLast = 2,
192
+ EvtSeekRelativeToCurrent = 3,
193
+ EvtSeekRelativeToBookmark = 4,
194
+ EvtSeekOriginMask = 7,
195
+ EvtSeekStrict = 0x0001_0000,
196
+ }
197
+
198
+ export enum EvtSubscribeFlags {
199
+ EvtSubscribeToFutureEvents = 1,
200
+ EvtSubscribeStartAtOldestRecord = 2,
201
+ EvtSubscribeStartAfterBookmark = 3,
202
+ EvtSubscribeOriginMask = 3,
203
+ EvtSubscribeTolerateQueryErrors = 0x0000_1000,
204
+ EvtSubscribeStrict = 0x0001_0000,
205
+ }
206
+
207
+ export enum EvtSubscribeNotifyAction {
208
+ EvtSubscribeActionError = 0,
209
+ EvtSubscribeActionDeliver,
210
+ }
211
+
212
+ export enum EvtSystemPropertyId {
213
+ EvtSystemProviderName = 0,
214
+ EvtSystemProviderGuid,
215
+ EvtSystemEventID,
216
+ EvtSystemQualifiers,
217
+ EvtSystemLevel,
218
+ EvtSystemTask,
219
+ EvtSystemOpcode,
220
+ EvtSystemKeywords,
221
+ EvtSystemTimeCreated,
222
+ EvtSystemEventRecordId,
223
+ EvtSystemActivityID,
224
+ EvtSystemRelatedActivityID,
225
+ EvtSystemProcessID,
226
+ EvtSystemThreadID,
227
+ EvtSystemChannel,
228
+ EvtSystemComputer,
229
+ EvtSystemUserID,
230
+ EvtSystemVersion,
231
+ EvtSystemPropertyIdEND,
232
+ }
233
+
234
+ export enum EvtVariantType {
235
+ EvtVarTypeNull = 0,
236
+ EvtVarTypeString,
237
+ EvtVarTypeAnsiString,
238
+ EvtVarTypeSByte,
239
+ EvtVarTypeByte,
240
+ EvtVarTypeInt16,
241
+ EvtVarTypeUInt16,
242
+ EvtVarTypeInt32,
243
+ EvtVarTypeUInt32,
244
+ EvtVarTypeInt64,
245
+ EvtVarTypeUInt64,
246
+ EvtVarTypeSingle,
247
+ EvtVarTypeDouble,
248
+ EvtVarTypeBoolean,
249
+ EvtVarTypeBinary,
250
+ EvtVarTypeGuid,
251
+ EvtVarTypeSizeT,
252
+ EvtVarTypeFileTime,
253
+ EvtVarTypeSysTime,
254
+ EvtVarTypeSid,
255
+ EvtVarTypeHexInt32,
256
+ EvtVarTypeHexInt64,
257
+ EvtVarTypeEvtHandle = 32,
258
+ EvtVarTypeEvtXml = 35,
259
+ }
260
+
261
+ export type EVT_HANDLE = HANDLE;
262
+ export type EVT_OBJECT_ARRAY_PROPERTY_HANDLE = HANDLE;
263
+ export type EVT_SUBSCRIBE_CALLBACK = Pointer;
264
+ export type LCID = DWORD;
265
+ export type LONGLONG = bigint;
266
+ export type PEVT_HANDLE = Pointer;
267
+ export type PEVT_RPC_LOGIN = Pointer;
268
+ export type PEVT_VARIANT = Pointer;
269
+ export type PLPCWSTR = Pointer;