@bun-win32/tdh 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/tdh
2
+
3
+ How to use this package, not what the Win32 API does.
4
+
5
+ ## Usage
6
+
7
+ ```ts
8
+ import Tdh, { SomeFlag } from '@bun-win32/tdh';
9
+
10
+ // Methods bind lazily on first call
11
+ const result = Tdh.SomeFunctionW(arg1, arg2);
12
+
13
+ // Preload: array, single string, or no args (all symbols)
14
+ Tdh.Preload(['SomeFunctionW', 'AnotherFunction']);
15
+ Tdh.Preload('SomeFunctionW');
16
+ Tdh.Preload();
17
+ ```
18
+
19
+ ## Where To Look
20
+
21
+ | Need | Read |
22
+ | --------------------------------- | ---------------- |
23
+ | Find a method or its MS Docs link | `structs/Tdh.ts` |
24
+ | Find types, enums, constants | `types/Tdh.ts` |
25
+ | Quick examples | `README.md` |
26
+
27
+ `index.ts` re-exports the class and all types — import from `@bun-win32/tdh` directly.
28
+
29
+ ## Calling Convention
30
+
31
+ All documented `tdh.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
+ Tdh.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
+ Tdh.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,71 @@
1
+ # @bun-win32/tdh
2
+
3
+ Zero-dependency, zero-overhead Win32 TDH bindings for [Bun](https://bun.sh) on Windows.
4
+
5
+ ## Overview
6
+
7
+ `@bun-win32/tdh` exposes the `tdh.dll` exports using [Bun](https://bun.sh)'s FFI. It provides a single class, `Tdh`, 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
+ `tdh.dll` is the **Trace Data Helper** — the decoding layer for Event Tracing for Windows (ETW). It turns the opaque binary `EVENT_RECORD`s delivered by an ETW session into structured, named, human-readable data, and enumerates the providers and event schemas registered on the machine. Pair it with `@bun-win32/advapi32` (`StartTrace` / `OpenTrace` / `ProcessTrace`) to build a complete trace consumer.
12
+
13
+ ## Features
14
+
15
+ - [Bun](https://bun.sh)-first ergonomics on Windows 10/11.
16
+ - Direct FFI to `tdh.dll` (ETW event metadata, property formatting, provider/field/event-schema enumeration, value/bitmap decoding, manifest loading, and payload filters).
17
+ - In-source docs in `structs/Tdh.ts` with links to Microsoft Docs.
18
+ - Lazy binding on first call; optional eager preload (`Tdh.Preload()`).
19
+ - No wrapper overhead; calls map 1:1 to native APIs.
20
+ - Strongly-typed Win32 aliases (see `types/Tdh.ts`).
21
+
22
+ ## Requirements
23
+
24
+ - [Bun](https://bun.sh) runtime
25
+ - Windows 10 or later
26
+
27
+ ## Installation
28
+
29
+ ```sh
30
+ bun add @bun-win32/tdh
31
+ ```
32
+
33
+ ## Quick Start
34
+
35
+ ```ts
36
+ import Tdh from '@bun-win32/tdh';
37
+
38
+ // Optionally bind a subset up-front
39
+ Tdh.Preload(['TdhEnumerateProviders']);
40
+
41
+ // Two-call sizing pattern: first NULL to learn the size, then allocate.
42
+ const bufferSize = Buffer.alloc(4);
43
+
44
+ // ERROR_INSUFFICIENT_BUFFER (122) on the sizing call is expected.
45
+ Tdh.TdhEnumerateProviders(null, bufferSize.ptr);
46
+
47
+ const buffer = Buffer.alloc(bufferSize.readUInt32LE(0));
48
+ const status = Tdh.TdhEnumerateProviders(buffer.ptr, bufferSize.ptr);
49
+
50
+ if (status === 0) {
51
+ // PROVIDER_ENUMERATION_INFO: ULONG NumberOfProviders; ULONG Reserved; TRACE_PROVIDER_INFO[]
52
+ console.log('Registered ETW providers: %d', buffer.readUInt32LE(0));
53
+ }
54
+ ```
55
+
56
+ > [!NOTE]
57
+ > 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.
58
+
59
+ ## Examples
60
+
61
+ Run the included examples:
62
+
63
+ ```sh
64
+ bun run example:etw-live-monitor # Live, color-coded ETW event stream (cross-package with advapi32)
65
+ bun run example:provider-explorer # Full ETW provider + event-schema enumeration report
66
+ ```
67
+
68
+ ## Notes
69
+
70
+ - Either rely on lazy binding or call `Tdh.Preload()`.
71
+ - Windows only. Bun runtime required.
package/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ import Tdh from './structs/Tdh';
2
+
3
+ export * from './types/Tdh';
4
+ export default Tdh;
package/package.json ADDED
@@ -0,0 +1,59 @@
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 TDH bindings for Bun (FFI) on Windows.",
10
+ "devDependencies": {
11
+ "@bun-win32/advapi32": "1.0.11",
12
+ "@bun-win32/kernel32": "1.0.21",
13
+ "@types/bun": "latest"
14
+ },
15
+ "exports": {
16
+ ".": "./index.ts"
17
+ },
18
+ "license": "MIT",
19
+ "module": "index.ts",
20
+ "name": "@bun-win32/tdh",
21
+ "peerDependencies": {
22
+ "typescript": "^5"
23
+ },
24
+ "private": false,
25
+ "homepage": "https://github.com/ObscuritySRL/bun-win32#readme",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git://github.com/ObscuritySRL/bun-win32.git",
29
+ "directory": "packages/tdh"
30
+ },
31
+ "type": "module",
32
+ "version": "1.0.0",
33
+ "main": "./index.ts",
34
+ "keywords": [
35
+ "bun",
36
+ "ffi",
37
+ "win32",
38
+ "windows",
39
+ "tdh",
40
+ "bindings",
41
+ "typescript",
42
+ "dll"
43
+ ],
44
+ "files": [
45
+ "AI.md",
46
+ "README.md",
47
+ "index.ts",
48
+ "structs/*.ts",
49
+ "types/*.ts"
50
+ ],
51
+ "sideEffects": false,
52
+ "engines": {
53
+ "bun": ">=1.1.0"
54
+ },
55
+ "scripts": {
56
+ "example:etw-live-monitor": "bun ./example/etw-live-monitor.ts",
57
+ "example:provider-explorer": "bun ./example/provider-explorer.ts"
58
+ }
59
+ }
package/structs/Tdh.ts ADDED
@@ -0,0 +1,245 @@
1
+ import { type FFIFunction, FFIType } from 'bun:ffi';
2
+
3
+ import { Win32 } from '@bun-win32/core';
4
+
5
+ import type {
6
+ BOOLEAN,
7
+ DECODING_SOURCE,
8
+ EVENT_FIELD_TYPE,
9
+ LPCGUID,
10
+ LPCVOID,
11
+ LPGUID,
12
+ NULL,
13
+ PBOOLEAN,
14
+ PBYTE,
15
+ PCEVENT_DESCRIPTOR,
16
+ PEVENT_DESCRIPTOR,
17
+ PEVENT_FILTER_DESCRIPTOR,
18
+ PEVENT_MAP_INFO,
19
+ PEVENT_RECORD,
20
+ PPAYLOAD_FILTER_PREDICATE,
21
+ PPPROVIDER_FILTER_INFO,
22
+ PPROPERTY_DATA_DESCRIPTOR,
23
+ PPROVIDER_ENUMERATION_INFO,
24
+ PPROVIDER_EVENT_INFO,
25
+ PPROVIDER_FIELD_INFOARRAY,
26
+ PPVOID,
27
+ PTDH_CONTEXT,
28
+ PTDH_HANDLE,
29
+ PTRACE_EVENT_INFO,
30
+ PULONG,
31
+ PUSHORT,
32
+ PWCHAR,
33
+ PWSTR,
34
+ TDH_HANDLE,
35
+ TDHSTATUS,
36
+ ULONG,
37
+ ULONGLONG,
38
+ USHORT,
39
+ } from '../types/Tdh';
40
+
41
+ /**
42
+ * Thin, lazy-loaded FFI bindings for `tdh.dll`.
43
+ *
44
+ * Each static method corresponds one-to-one with a Win32 export declared in `Symbols`.
45
+ * The first call to a method binds the underlying native symbol via `bun:ffi` and
46
+ * memoizes it on the class for subsequent calls. For bulk, up-front binding, use `Preload`.
47
+ *
48
+ * Symbols are defined with explicit `FFIType` signatures and kept alphabetized.
49
+ * You normally do not access `Symbols` directly; call the static methods or preload
50
+ * a subset for hot paths.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * import Tdh from './structs/Tdh';
55
+ *
56
+ * // Lazy: bind on first call
57
+ * const status = Tdh.TdhEnumerateProviders(buffer.ptr, size.ptr);
58
+ *
59
+ * // Or preload a subset to avoid per-symbol lazy binding cost
60
+ * Tdh.Preload(['TdhGetEventInformation', 'TdhFormatProperty']);
61
+ * ```
62
+ */
63
+ class Tdh extends Win32 {
64
+ protected static override name = 'tdh.dll';
65
+
66
+ /** @inheritdoc */
67
+ protected static override readonly Symbols = {
68
+ TdhAggregatePayloadFilters: { args: [FFIType.u32, FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.u32 },
69
+ TdhCleanupPayloadEventFilterDescriptor: { args: [FFIType.ptr], returns: FFIType.u32 },
70
+ TdhCloseDecodingHandle: { args: [FFIType.u64], returns: FFIType.u32 },
71
+ TdhCreatePayloadFilter: { args: [FFIType.ptr, FFIType.ptr, FFIType.u8, FFIType.u32, FFIType.ptr, FFIType.ptr], returns: FFIType.u32 },
72
+ TdhDeletePayloadFilter: { args: [FFIType.ptr], returns: FFIType.u32 },
73
+ TdhEnumerateManifestProviderEvents: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.u32 },
74
+ TdhEnumerateProviderFieldInformation: { args: [FFIType.ptr, FFIType.i32, FFIType.ptr, FFIType.ptr], returns: FFIType.u32 },
75
+ TdhEnumerateProviderFilters: { args: [FFIType.ptr, FFIType.u32, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.u32 },
76
+ TdhEnumerateProviders: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.u32 },
77
+ TdhEnumerateProvidersForDecodingSource: { args: [FFIType.i32, FFIType.ptr, FFIType.u32, FFIType.ptr], returns: FFIType.u32 },
78
+ TdhFormatProperty: { args: [FFIType.ptr, FFIType.ptr, FFIType.u32, FFIType.u16, FFIType.u16, FFIType.u16, FFIType.u16, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.u32 },
79
+ TdhGetDecodingParameter: { args: [FFIType.u64, FFIType.ptr], returns: FFIType.u32 },
80
+ TdhGetEventInformation: { args: [FFIType.ptr, FFIType.u32, FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.u32 },
81
+ TdhGetEventMapInformation: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.u32 },
82
+ TdhGetManifestEventInformation: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.u32 },
83
+ TdhGetProperty: { args: [FFIType.ptr, FFIType.u32, FFIType.ptr, FFIType.u32, FFIType.ptr, FFIType.u32, FFIType.ptr], returns: FFIType.u32 },
84
+ TdhGetPropertySize: { args: [FFIType.ptr, FFIType.u32, FFIType.ptr, FFIType.u32, FFIType.ptr, FFIType.ptr], returns: FFIType.u32 },
85
+ TdhGetWppMessage: { args: [FFIType.u64, FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.u32 },
86
+ TdhGetWppProperty: { args: [FFIType.u64, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.u32 },
87
+ TdhLoadManifest: { args: [FFIType.ptr], returns: FFIType.u32 },
88
+ TdhLoadManifestFromBinary: { args: [FFIType.ptr], returns: FFIType.u32 },
89
+ TdhLoadManifestFromMemory: { args: [FFIType.ptr, FFIType.u32], returns: FFIType.u32 },
90
+ TdhOpenDecodingHandle: { args: [FFIType.ptr], returns: FFIType.u32 },
91
+ TdhQueryProviderFieldInformation: { args: [FFIType.ptr, FFIType.u64, FFIType.i32, FFIType.ptr, FFIType.ptr], returns: FFIType.u32 },
92
+ TdhSetDecodingParameter: { args: [FFIType.u64, FFIType.ptr], returns: FFIType.u32 },
93
+ TdhUnloadManifest: { args: [FFIType.ptr], returns: FFIType.u32 },
94
+ TdhUnloadManifestFromMemory: { args: [FFIType.ptr, FFIType.u32], returns: FFIType.u32 },
95
+ } as const satisfies Record<string, FFIFunction>;
96
+
97
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhaggregatepayloadfilters
98
+ public static TdhAggregatePayloadFilters(PayloadFilterCount: ULONG, PayloadFilterPtrs: PPVOID, EventMatchALLFlags: PBOOLEAN | NULL, EventFilterDescriptor: PEVENT_FILTER_DESCRIPTOR): TDHSTATUS {
99
+ return Tdh.Load('TdhAggregatePayloadFilters')(PayloadFilterCount, PayloadFilterPtrs, EventMatchALLFlags, EventFilterDescriptor);
100
+ }
101
+
102
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhcleanuppayloadeventfilterdescriptor
103
+ public static TdhCleanupPayloadEventFilterDescriptor(EventFilterDescriptor: PEVENT_FILTER_DESCRIPTOR): TDHSTATUS {
104
+ return Tdh.Load('TdhCleanupPayloadEventFilterDescriptor')(EventFilterDescriptor);
105
+ }
106
+
107
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhclosedecodinghandle
108
+ public static TdhCloseDecodingHandle(Handle: TDH_HANDLE): TDHSTATUS {
109
+ return Tdh.Load('TdhCloseDecodingHandle')(Handle);
110
+ }
111
+
112
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhcreatepayloadfilter
113
+ public static TdhCreatePayloadFilter(ProviderGuid: LPCGUID, EventDescriptor: PCEVENT_DESCRIPTOR, EventMatchANY: BOOLEAN, PayloadPredicateCount: ULONG, PayloadPredicates: PPAYLOAD_FILTER_PREDICATE, PayloadFilter: PPVOID): TDHSTATUS {
114
+ return Tdh.Load('TdhCreatePayloadFilter')(ProviderGuid, EventDescriptor, EventMatchANY, PayloadPredicateCount, PayloadPredicates, PayloadFilter);
115
+ }
116
+
117
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhdeletepayloadfilter
118
+ public static TdhDeletePayloadFilter(PayloadFilter: PPVOID): TDHSTATUS {
119
+ return Tdh.Load('TdhDeletePayloadFilter')(PayloadFilter);
120
+ }
121
+
122
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhenumeratemanifestproviderevents
123
+ public static TdhEnumerateManifestProviderEvents(ProviderGuid: LPGUID, Buffer: PPROVIDER_EVENT_INFO | NULL, BufferSize: PULONG): TDHSTATUS {
124
+ return Tdh.Load('TdhEnumerateManifestProviderEvents')(ProviderGuid, Buffer, BufferSize);
125
+ }
126
+
127
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhenumerateproviderfieldinformation
128
+ public static TdhEnumerateProviderFieldInformation(pGuid: LPGUID, EventFieldType: EVENT_FIELD_TYPE, pBuffer: PPROVIDER_FIELD_INFOARRAY | NULL, pBufferSize: PULONG): TDHSTATUS {
129
+ return Tdh.Load('TdhEnumerateProviderFieldInformation')(pGuid, EventFieldType, pBuffer, pBufferSize);
130
+ }
131
+
132
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhenumerateproviderfilters
133
+ public static TdhEnumerateProviderFilters(Guid: LPGUID, TdhContextCount: ULONG, TdhContext: PTDH_CONTEXT | NULL, FilterCount: PULONG, Buffer: PPPROVIDER_FILTER_INFO | NULL, BufferSize: PULONG): TDHSTATUS {
134
+ return Tdh.Load('TdhEnumerateProviderFilters')(Guid, TdhContextCount, TdhContext, FilterCount, Buffer, BufferSize);
135
+ }
136
+
137
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhenumerateproviders
138
+ public static TdhEnumerateProviders(pBuffer: PPROVIDER_ENUMERATION_INFO | NULL, pBufferSize: PULONG): TDHSTATUS {
139
+ return Tdh.Load('TdhEnumerateProviders')(pBuffer, pBufferSize);
140
+ }
141
+
142
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhenumerateprovidersfordecodingsource
143
+ public static TdhEnumerateProvidersForDecodingSource(filter: DECODING_SOURCE, buffer: PPROVIDER_ENUMERATION_INFO | NULL, bufferSize: ULONG, bufferRequired: PULONG): TDHSTATUS {
144
+ return Tdh.Load('TdhEnumerateProvidersForDecodingSource')(filter, buffer, bufferSize, bufferRequired);
145
+ }
146
+
147
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhformatproperty
148
+ public static TdhFormatProperty(
149
+ EventInfo: PTRACE_EVENT_INFO,
150
+ MapInfo: PEVENT_MAP_INFO | NULL,
151
+ PointerSize: ULONG,
152
+ PropertyInType: USHORT,
153
+ PropertyOutType: USHORT,
154
+ PropertyLength: USHORT,
155
+ UserDataLength: USHORT,
156
+ UserData: PBYTE,
157
+ BufferSize: PULONG,
158
+ Buffer: PWCHAR | NULL,
159
+ UserDataConsumed: PUSHORT,
160
+ ): TDHSTATUS {
161
+ return Tdh.Load('TdhFormatProperty')(EventInfo, MapInfo, PointerSize, PropertyInType, PropertyOutType, PropertyLength, UserDataLength, UserData, BufferSize, Buffer, UserDataConsumed);
162
+ }
163
+
164
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhgetdecodingparameter
165
+ public static TdhGetDecodingParameter(Handle: TDH_HANDLE, TdhContext: PTDH_CONTEXT): TDHSTATUS {
166
+ return Tdh.Load('TdhGetDecodingParameter')(Handle, TdhContext);
167
+ }
168
+
169
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhgeteventinformation
170
+ public static TdhGetEventInformation(Event: PEVENT_RECORD, TdhContextCount: ULONG, TdhContext: PTDH_CONTEXT | NULL, Buffer: PTRACE_EVENT_INFO | NULL, BufferSize: PULONG): TDHSTATUS {
171
+ return Tdh.Load('TdhGetEventInformation')(Event, TdhContextCount, TdhContext, Buffer, BufferSize);
172
+ }
173
+
174
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhgeteventmapinformation
175
+ public static TdhGetEventMapInformation(pEvent: PEVENT_RECORD, pMapName: PWSTR, pBuffer: PEVENT_MAP_INFO | NULL, pBufferSize: PULONG): TDHSTATUS {
176
+ return Tdh.Load('TdhGetEventMapInformation')(pEvent, pMapName, pBuffer, pBufferSize);
177
+ }
178
+
179
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhgetmanifesteventinformation
180
+ public static TdhGetManifestEventInformation(ProviderGuid: LPGUID, EventDescriptor: PEVENT_DESCRIPTOR, Buffer: PTRACE_EVENT_INFO | NULL, BufferSize: PULONG): TDHSTATUS {
181
+ return Tdh.Load('TdhGetManifestEventInformation')(ProviderGuid, EventDescriptor, Buffer, BufferSize);
182
+ }
183
+
184
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhgetproperty
185
+ public static TdhGetProperty(pEvent: PEVENT_RECORD, TdhContextCount: ULONG, pTdhContext: PTDH_CONTEXT | NULL, PropertyDataCount: ULONG, pPropertyData: PPROPERTY_DATA_DESCRIPTOR, BufferSize: ULONG, pBuffer: PBYTE): TDHSTATUS {
186
+ return Tdh.Load('TdhGetProperty')(pEvent, TdhContextCount, pTdhContext, PropertyDataCount, pPropertyData, BufferSize, pBuffer);
187
+ }
188
+
189
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhgetpropertysize
190
+ public static TdhGetPropertySize(pEvent: PEVENT_RECORD, TdhContextCount: ULONG, pTdhContext: PTDH_CONTEXT | NULL, PropertyDataCount: ULONG, pPropertyData: PPROPERTY_DATA_DESCRIPTOR, pPropertySize: PULONG): TDHSTATUS {
191
+ return Tdh.Load('TdhGetPropertySize')(pEvent, TdhContextCount, pTdhContext, PropertyDataCount, pPropertyData, pPropertySize);
192
+ }
193
+
194
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhgetwppmessage
195
+ public static TdhGetWppMessage(Handle: TDH_HANDLE, EventRecord: PEVENT_RECORD, BufferSize: PULONG, Buffer: PBYTE): TDHSTATUS {
196
+ return Tdh.Load('TdhGetWppMessage')(Handle, EventRecord, BufferSize, Buffer);
197
+ }
198
+
199
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhgetwppproperty
200
+ public static TdhGetWppProperty(Handle: TDH_HANDLE, EventRecord: PEVENT_RECORD, PropertyName: PWSTR, BufferSize: PULONG, Buffer: PBYTE): TDHSTATUS {
201
+ return Tdh.Load('TdhGetWppProperty')(Handle, EventRecord, PropertyName, BufferSize, Buffer);
202
+ }
203
+
204
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhloadmanifest
205
+ public static TdhLoadManifest(Manifest: PWSTR): TDHSTATUS {
206
+ return Tdh.Load('TdhLoadManifest')(Manifest);
207
+ }
208
+
209
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhloadmanifestfrombinary
210
+ public static TdhLoadManifestFromBinary(BinaryPath: PWSTR): TDHSTATUS {
211
+ return Tdh.Load('TdhLoadManifestFromBinary')(BinaryPath);
212
+ }
213
+
214
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhloadmanifestfrommemory
215
+ public static TdhLoadManifestFromMemory(pData: LPCVOID, cbData: ULONG): TDHSTATUS {
216
+ return Tdh.Load('TdhLoadManifestFromMemory')(pData, cbData);
217
+ }
218
+
219
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhopendecodinghandle
220
+ public static TdhOpenDecodingHandle(Handle: PTDH_HANDLE): TDHSTATUS {
221
+ return Tdh.Load('TdhOpenDecodingHandle')(Handle);
222
+ }
223
+
224
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhqueryproviderfieldinformation
225
+ public static TdhQueryProviderFieldInformation(pGuid: LPGUID, EventFieldValue: ULONGLONG, EventFieldType: EVENT_FIELD_TYPE, pBuffer: PPROVIDER_FIELD_INFOARRAY | NULL, pBufferSize: PULONG): TDHSTATUS {
226
+ return Tdh.Load('TdhQueryProviderFieldInformation')(pGuid, EventFieldValue, EventFieldType, pBuffer, pBufferSize);
227
+ }
228
+
229
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhsetdecodingparameter
230
+ public static TdhSetDecodingParameter(Handle: TDH_HANDLE, TdhContext: PTDH_CONTEXT): TDHSTATUS {
231
+ return Tdh.Load('TdhSetDecodingParameter')(Handle, TdhContext);
232
+ }
233
+
234
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhunloadmanifest
235
+ public static TdhUnloadManifest(Manifest: PWSTR): TDHSTATUS {
236
+ return Tdh.Load('TdhUnloadManifest')(Manifest);
237
+ }
238
+
239
+ // https://learn.microsoft.com/en-us/windows/win32/api/tdh/nf-tdh-tdhunloadmanifestfrommemory
240
+ public static TdhUnloadManifestFromMemory(pData: LPCVOID, cbData: ULONG): TDHSTATUS {
241
+ return Tdh.Load('TdhUnloadManifestFromMemory')(pData, cbData);
242
+ }
243
+ }
244
+
245
+ export default Tdh;
package/types/Tdh.ts ADDED
@@ -0,0 +1,188 @@
1
+ import type { Pointer } from 'bun:ffi';
2
+
3
+ import type { HANDLE, ULONG } from '@bun-win32/core';
4
+ export type { BOOLEAN, LPCVOID, NULL, PBYTE, PULONG, ULONG, USHORT } from '@bun-win32/core';
5
+
6
+ export enum DECODING_SOURCE {
7
+ DecodingSourceMax = 4,
8
+ DecodingSourceTlg = 3,
9
+ DecodingSourceWbem = 1,
10
+ DecodingSourceWPP = 2,
11
+ DecodingSourceXMLFile = 0,
12
+ }
13
+
14
+ export enum EVENT_FIELD_TYPE {
15
+ EventChannelInformation = 2,
16
+ EventInformationMax = 5,
17
+ EventKeywordInformation = 0,
18
+ EventLevelInformation = 1,
19
+ EventOpcodeInformation = 4,
20
+ EventTaskInformation = 3,
21
+ }
22
+
23
+ export enum MAP_FLAGS {
24
+ EVENTMAP_INFO_FLAG_MANIFEST_BITMAP = 0x0000_0002,
25
+ EVENTMAP_INFO_FLAG_MANIFEST_PATTERNMAP = 0x0000_0004,
26
+ EVENTMAP_INFO_FLAG_MANIFEST_VALUEMAP = 0x0000_0001,
27
+ EVENTMAP_INFO_FLAG_WBEM_BITMAP = 0x0000_0010,
28
+ EVENTMAP_INFO_FLAG_WBEM_FLAG = 0x0000_0020,
29
+ EVENTMAP_INFO_FLAG_WBEM_NO_MAP = 0x0000_0040,
30
+ EVENTMAP_INFO_FLAG_WBEM_VALUEMAP = 0x0000_0008,
31
+ }
32
+
33
+ export enum MAP_VALUETYPE {
34
+ EVENTMAP_ENTRY_VALUETYPE_STRING = 1,
35
+ EVENTMAP_ENTRY_VALUETYPE_ULONG = 0,
36
+ }
37
+
38
+ export enum PAYLOAD_OPERATOR {
39
+ PAYLOADFIELD_BETWEEN = 6,
40
+ PAYLOADFIELD_CONTAINS = 20,
41
+ PAYLOADFIELD_DOESNTCONTAIN = 21,
42
+ PAYLOADFIELD_EQ = 0,
43
+ PAYLOADFIELD_GE = 5,
44
+ PAYLOADFIELD_GT = 3,
45
+ PAYLOADFIELD_INVALID = 32,
46
+ PAYLOADFIELD_IS = 30,
47
+ PAYLOADFIELD_ISNOT = 31,
48
+ PAYLOADFIELD_LE = 2,
49
+ PAYLOADFIELD_LT = 4,
50
+ PAYLOADFIELD_MODULO = 8,
51
+ PAYLOADFIELD_NE = 1,
52
+ PAYLOADFIELD_NOTBETWEEN = 7,
53
+ }
54
+
55
+ export enum PROPERTY_FLAGS {
56
+ PropertyHasCustomSchema = 0x0000_0080,
57
+ PropertyHasTags = 0x0000_0040,
58
+ PropertyParamCount = 0x0000_0004,
59
+ PropertyParamFixedCount = 0x0000_0020,
60
+ PropertyParamFixedLength = 0x0000_0010,
61
+ PropertyParamLength = 0x0000_0002,
62
+ PropertyStruct = 0x0000_0001,
63
+ PropertyWBEMXmlFragment = 0x0000_0008,
64
+ }
65
+
66
+ export enum TDH_CONTEXT_TYPE {
67
+ TDH_CONTEXT_MAXIMUM = 5,
68
+ TDH_CONTEXT_PDB_PATH = 4,
69
+ TDH_CONTEXT_POINTERSIZE = 3,
70
+ TDH_CONTEXT_WPP_GMT = 2,
71
+ TDH_CONTEXT_WPP_TMFFILE = 0,
72
+ TDH_CONTEXT_WPP_TMFSEARCHPATH = 1,
73
+ }
74
+
75
+ export enum TDH_IN_TYPE {
76
+ TDH_INTYPE_ANSICHAR = 307,
77
+ TDH_INTYPE_ANSISTRING = 2,
78
+ TDH_INTYPE_BINARY = 14,
79
+ TDH_INTYPE_BOOLEAN = 13,
80
+ TDH_INTYPE_COUNTEDANSISTRING = 301,
81
+ TDH_INTYPE_COUNTEDSTRING = 300,
82
+ TDH_INTYPE_DOUBLE = 12,
83
+ TDH_INTYPE_FILETIME = 17,
84
+ TDH_INTYPE_FLOAT = 11,
85
+ TDH_INTYPE_GUID = 15,
86
+ TDH_INTYPE_HEXDUMP = 309,
87
+ TDH_INTYPE_HEXINT32 = 20,
88
+ TDH_INTYPE_HEXINT64 = 21,
89
+ TDH_INTYPE_INT16 = 5,
90
+ TDH_INTYPE_INT32 = 7,
91
+ TDH_INTYPE_INT64 = 9,
92
+ TDH_INTYPE_INT8 = 3,
93
+ TDH_INTYPE_MANIFEST_COUNTEDANSISTRING = 23,
94
+ TDH_INTYPE_MANIFEST_COUNTEDBINARY = 25,
95
+ TDH_INTYPE_MANIFEST_COUNTEDSTRING = 22,
96
+ TDH_INTYPE_NONNULLTERMINATEDANSISTRING = 305,
97
+ TDH_INTYPE_NONNULLTERMINATEDSTRING = 304,
98
+ TDH_INTYPE_NULL = 0,
99
+ TDH_INTYPE_POINTER = 16,
100
+ TDH_INTYPE_RESERVED24 = 24,
101
+ TDH_INTYPE_REVERSEDCOUNTEDANSISTRING = 303,
102
+ TDH_INTYPE_REVERSEDCOUNTEDSTRING = 302,
103
+ TDH_INTYPE_SID = 19,
104
+ TDH_INTYPE_SIZET = 308,
105
+ TDH_INTYPE_SYSTEMTIME = 18,
106
+ TDH_INTYPE_UINT16 = 6,
107
+ TDH_INTYPE_UINT32 = 8,
108
+ TDH_INTYPE_UINT64 = 10,
109
+ TDH_INTYPE_UINT8 = 4,
110
+ TDH_INTYPE_UNICODECHAR = 306,
111
+ TDH_INTYPE_UNICODESTRING = 1,
112
+ TDH_INTYPE_WBEMSID = 310,
113
+ }
114
+
115
+ export enum TDH_OUT_TYPE {
116
+ TDH_OUTTYPE_BOOLEAN = 13,
117
+ TDH_OUTTYPE_BYTE = 3,
118
+ TDH_OUTTYPE_CIMDATETIME = 26,
119
+ TDH_OUTTYPE_CODE_POINTER = 37,
120
+ TDH_OUTTYPE_CULTURE_INSENSITIVE_DATETIME = 33,
121
+ TDH_OUTTYPE_DATETIME = 2,
122
+ TDH_OUTTYPE_DATETIME_UTC = 38,
123
+ TDH_OUTTYPE_DOUBLE = 12,
124
+ TDH_OUTTYPE_ERRORCODE = 29,
125
+ TDH_OUTTYPE_ETWTIME = 27,
126
+ TDH_OUTTYPE_FLOAT = 11,
127
+ TDH_OUTTYPE_GUID = 14,
128
+ TDH_OUTTYPE_HEXBINARY = 15,
129
+ TDH_OUTTYPE_HEXINT16 = 17,
130
+ TDH_OUTTYPE_HEXINT32 = 18,
131
+ TDH_OUTTYPE_HEXINT64 = 19,
132
+ TDH_OUTTYPE_HEXINT8 = 16,
133
+ TDH_OUTTYPE_HRESULT = 32,
134
+ TDH_OUTTYPE_INT = 7,
135
+ TDH_OUTTYPE_IPV4 = 23,
136
+ TDH_OUTTYPE_IPV6 = 24,
137
+ TDH_OUTTYPE_JSON = 34,
138
+ TDH_OUTTYPE_LONG = 9,
139
+ TDH_OUTTYPE_NOPRINT = 301,
140
+ TDH_OUTTYPE_NTSTATUS = 31,
141
+ TDH_OUTTYPE_NULL = 0,
142
+ TDH_OUTTYPE_PID = 20,
143
+ TDH_OUTTYPE_PKCS7_WITH_TYPE_INFO = 36,
144
+ TDH_OUTTYPE_PORT = 22,
145
+ TDH_OUTTYPE_REDUCEDSTRING = 300,
146
+ TDH_OUTTYPE_SHORT = 5,
147
+ TDH_OUTTYPE_SOCKETADDRESS = 25,
148
+ TDH_OUTTYPE_STRING = 1,
149
+ TDH_OUTTYPE_TID = 21,
150
+ TDH_OUTTYPE_UNSIGNEDBYTE = 4,
151
+ TDH_OUTTYPE_UNSIGNEDINT = 8,
152
+ TDH_OUTTYPE_UNSIGNEDLONG = 10,
153
+ TDH_OUTTYPE_UNSIGNEDSHORT = 6,
154
+ TDH_OUTTYPE_UTF8 = 35,
155
+ TDH_OUTTYPE_WIN32ERROR = 30,
156
+ TDH_OUTTYPE_XML = 28,
157
+ }
158
+
159
+ export enum TEMPLATE_FLAGS {
160
+ TEMPLATE_CONTROL_GUID = 0x0000_0004,
161
+ TEMPLATE_EVENT_DATA = 0x0000_0001,
162
+ TEMPLATE_USER_DATA = 0x0000_0002,
163
+ }
164
+
165
+ export type LPCGUID = Pointer;
166
+ export type LPGUID = Pointer;
167
+ export type PBOOLEAN = Pointer;
168
+ export type PCEVENT_DESCRIPTOR = Pointer;
169
+ export type PEVENT_DESCRIPTOR = Pointer;
170
+ export type PEVENT_FILTER_DESCRIPTOR = Pointer;
171
+ export type PEVENT_MAP_INFO = Pointer;
172
+ export type PEVENT_RECORD = Pointer;
173
+ export type PPAYLOAD_FILTER_PREDICATE = Pointer;
174
+ export type PPPROVIDER_FILTER_INFO = Pointer;
175
+ export type PPROPERTY_DATA_DESCRIPTOR = Pointer;
176
+ export type PPROVIDER_ENUMERATION_INFO = Pointer;
177
+ export type PPROVIDER_EVENT_INFO = Pointer;
178
+ export type PPROVIDER_FIELD_INFOARRAY = Pointer;
179
+ export type PPVOID = Pointer;
180
+ export type PTDH_CONTEXT = Pointer;
181
+ export type PTDH_HANDLE = Pointer;
182
+ export type PTRACE_EVENT_INFO = Pointer;
183
+ export type PUSHORT = Pointer;
184
+ export type PWCHAR = Pointer;
185
+ export type PWSTR = Pointer;
186
+ export type TDHSTATUS = ULONG;
187
+ export type TDH_HANDLE = HANDLE;
188
+ export type ULONGLONG = bigint;