@logtape/windows-eventlog 1.0.0-dev.225
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/LICENSE +20 -0
- package/README.md +129 -0
- package/dist/_virtual/rolldown_runtime.cjs +30 -0
- package/dist/ffi.bun.cjs +102 -0
- package/dist/ffi.bun.js +102 -0
- package/dist/ffi.bun.js.map +1 -0
- package/dist/ffi.deno.cjs +116 -0
- package/dist/ffi.deno.js +113 -0
- package/dist/ffi.deno.js.map +1 -0
- package/dist/ffi.node.cjs +78 -0
- package/dist/ffi.node.js +78 -0
- package/dist/ffi.node.js.map +1 -0
- package/dist/mod.cjs +12 -0
- package/dist/mod.d.cts +3 -0
- package/dist/mod.d.ts +3 -0
- package/dist/mod.js +4 -0
- package/dist/platform.cjs +30 -0
- package/dist/platform.js +30 -0
- package/dist/platform.js.map +1 -0
- package/dist/sink.bun.cjs +102 -0
- package/dist/sink.bun.d.cts +34 -0
- package/dist/sink.bun.d.cts.map +1 -0
- package/dist/sink.bun.d.ts +34 -0
- package/dist/sink.bun.d.ts.map +1 -0
- package/dist/sink.bun.js +102 -0
- package/dist/sink.bun.js.map +1 -0
- package/dist/sink.deno.cjs +116 -0
- package/dist/sink.deno.d.cts +34 -0
- package/dist/sink.deno.d.cts.map +1 -0
- package/dist/sink.deno.d.ts +34 -0
- package/dist/sink.deno.d.ts.map +1 -0
- package/dist/sink.deno.js +116 -0
- package/dist/sink.deno.js.map +1 -0
- package/dist/sink.node.cjs +112 -0
- package/dist/sink.node.d.cts +33 -0
- package/dist/sink.node.d.cts.map +1 -0
- package/dist/sink.node.d.ts +33 -0
- package/dist/sink.node.d.ts.map +1 -0
- package/dist/sink.node.js +112 -0
- package/dist/sink.node.js.map +1 -0
- package/dist/types.cjs +55 -0
- package/dist/types.d.cts +79 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +79 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +52 -0
- package/dist/types.js.map +1 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2024 Hong Minhee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
<!-- deno-fmt-ignore-file -->
|
|
2
|
+
|
|
3
|
+
LogTape Windows Event Log sink
|
|
4
|
+
==============================
|
|
5
|
+
|
|
6
|
+
[![JSR][JSR badge]][JSR]
|
|
7
|
+
[![npm][npm badge]][npm]
|
|
8
|
+
|
|
9
|
+
Windows Event Log sink for [LogTape]. This package provides a Windows Event Log
|
|
10
|
+
sink that sends log messages directly to the Windows Event Log system with
|
|
11
|
+
cross-runtime support and optimal performance.
|
|
12
|
+
|
|
13
|
+
[JSR]: https://jsr.io/@logtape/windows-eventlog
|
|
14
|
+
[JSR badge]: https://jsr.io/badges/@logtape/windows-eventlog
|
|
15
|
+
[npm]: https://www.npmjs.com/package/@logtape/windows-eventlog
|
|
16
|
+
[npm badge]: https://img.shields.io/npm/v/@logtape/windows-eventlog?logo=npm
|
|
17
|
+
[LogTape]: https://logtape.org/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
Features
|
|
21
|
+
--------
|
|
22
|
+
|
|
23
|
+
- *Native Windows integration*: Direct integration with Windows Event Log
|
|
24
|
+
system
|
|
25
|
+
- *Cross-runtime*: Works on Deno, Node.js, and Bun
|
|
26
|
+
- *High performance*: Uses runtime-optimized FFI implementations
|
|
27
|
+
- *Structured logging*: Preserves structured data in Event Log entries
|
|
28
|
+
- *Unicode support*: Full support for international characters and emoji
|
|
29
|
+
- *Platform safety*: Automatically restricts installation to Windows platforms
|
|
30
|
+
- *Zero dependencies*: No external dependencies for Deno and Bun
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
Installation
|
|
34
|
+
------------
|
|
35
|
+
|
|
36
|
+
This package is available on [JSR] and [npm]. You can install it for various
|
|
37
|
+
JavaScript runtimes and package managers:
|
|
38
|
+
|
|
39
|
+
~~~~ sh
|
|
40
|
+
deno add jsr:@logtape/windows-eventlog # for Deno
|
|
41
|
+
npm add @logtape/windows-eventlog # for npm
|
|
42
|
+
pnpm add @logtape/windows-eventlog # for pnpm
|
|
43
|
+
yarn add @logtape/windows-eventlog # for Yarn
|
|
44
|
+
bun add @logtape/windows-eventlog # for Bun
|
|
45
|
+
~~~~
|
|
46
|
+
|
|
47
|
+
> [!NOTE]
|
|
48
|
+
> This package is only available for Windows platforms. The package installation
|
|
49
|
+
> is restricted to Windows (`"os": ["win32"]`) to prevent accidental usage on
|
|
50
|
+
> other platforms.
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
Usage
|
|
54
|
+
-----
|
|
55
|
+
|
|
56
|
+
The quickest way to get started is to use the `getWindowsEventLogSink()`
|
|
57
|
+
function with your application source name:
|
|
58
|
+
|
|
59
|
+
~~~~ typescript
|
|
60
|
+
import { configure } from "@logtape/logtape";
|
|
61
|
+
import { getWindowsEventLogSink } from "@logtape/windows-eventlog";
|
|
62
|
+
|
|
63
|
+
await configure({
|
|
64
|
+
sinks: {
|
|
65
|
+
eventlog: getWindowsEventLogSink({
|
|
66
|
+
sourceName: "MyApplication",
|
|
67
|
+
}),
|
|
68
|
+
},
|
|
69
|
+
loggers: [
|
|
70
|
+
{ category: [], sinks: ["eventlog"], lowestLevel: "info" },
|
|
71
|
+
],
|
|
72
|
+
});
|
|
73
|
+
~~~~
|
|
74
|
+
|
|
75
|
+
You can also customize the sink behavior with additional options:
|
|
76
|
+
|
|
77
|
+
~~~~ typescript
|
|
78
|
+
import { configure } from "@logtape/logtape";
|
|
79
|
+
import { getWindowsEventLogSink } from "@logtape/windows-eventlog";
|
|
80
|
+
|
|
81
|
+
await configure({
|
|
82
|
+
sinks: {
|
|
83
|
+
eventlog: getWindowsEventLogSink({
|
|
84
|
+
sourceName: "MyApplication",
|
|
85
|
+
logName: "Application", // Default log name
|
|
86
|
+
eventIdMapping: {
|
|
87
|
+
error: 1001,
|
|
88
|
+
warning: 2001,
|
|
89
|
+
info: 3001,
|
|
90
|
+
},
|
|
91
|
+
}),
|
|
92
|
+
},
|
|
93
|
+
loggers: [
|
|
94
|
+
{ category: [], sinks: ["eventlog"], lowestLevel: "info" },
|
|
95
|
+
],
|
|
96
|
+
});
|
|
97
|
+
~~~~
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
Runtime support
|
|
101
|
+
---------------
|
|
102
|
+
|
|
103
|
+
The Windows Event Log sink works across multiple JavaScript runtimes on Windows:
|
|
104
|
+
|
|
105
|
+
- *Deno*: Uses [Deno's native FFI] for optimal performance
|
|
106
|
+
- *Node.js*: Uses the [koffi] library for FFI bindings
|
|
107
|
+
- *Bun*: Uses [Bun's native FFI] for maximum performance
|
|
108
|
+
|
|
109
|
+
[Deno's native FFI]: https://docs.deno.com/runtime/fundamentals/ffi/
|
|
110
|
+
[koffi]: https://koffi.dev/
|
|
111
|
+
[Bun's native FFI]: https://bun.sh/docs/api/ffi
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
Viewing logs
|
|
115
|
+
------------
|
|
116
|
+
|
|
117
|
+
Once your application writes to the Windows Event Log, you can view the logs using:
|
|
118
|
+
|
|
119
|
+
- *Event Viewer* (*eventvwr.msc*)
|
|
120
|
+
- *PowerShell*: `Get-WinEvent -FilterHashtable @{LogName='Application'; ProviderName='MyApplication'}`
|
|
121
|
+
- *Command Prompt*: `wevtutil qe Application /f:text /q:"*[System[Provider[@Name='MyApplication']]]"`
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
Docs
|
|
125
|
+
----
|
|
126
|
+
|
|
127
|
+
The docs of this package is available at
|
|
128
|
+
<https://logtape.org/manual/sinks#windows-event-log-sink>. For the API
|
|
129
|
+
references, see <https://jsr.io/@logtape/windows-eventlog>.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
|
|
25
|
+
Object.defineProperty(exports, '__toESM', {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return __toESM;
|
|
29
|
+
}
|
|
30
|
+
});
|
package/dist/ffi.bun.cjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const __logtape_logtape = require_rolldown_runtime.__toESM(require("@logtape/logtape"));
|
|
3
|
+
const bun_ffi = require_rolldown_runtime.__toESM(require("bun:ffi"));
|
|
4
|
+
|
|
5
|
+
//#region ffi.bun.ts
|
|
6
|
+
/**
|
|
7
|
+
* Bun FFI implementation for Windows Event Log API
|
|
8
|
+
*/
|
|
9
|
+
var WindowsEventLogFFI = class {
|
|
10
|
+
eventSource = null;
|
|
11
|
+
lib = null;
|
|
12
|
+
sourceName;
|
|
13
|
+
initialized = false;
|
|
14
|
+
metaLogger = (0, __logtape_logtape.getLogger)([
|
|
15
|
+
"logtape",
|
|
16
|
+
"meta",
|
|
17
|
+
"windows-eventlog"
|
|
18
|
+
]);
|
|
19
|
+
constructor(sourceName) {
|
|
20
|
+
this.sourceName = sourceName;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Initialize the FFI bindings and register event source
|
|
24
|
+
*/
|
|
25
|
+
initialize() {
|
|
26
|
+
if (this.initialized) return;
|
|
27
|
+
try {
|
|
28
|
+
this.lib = (0, bun_ffi.dlopen)("advapi32.dll", {
|
|
29
|
+
RegisterEventSourceA: {
|
|
30
|
+
args: [bun_ffi.FFIType.ptr, bun_ffi.FFIType.cstring],
|
|
31
|
+
returns: bun_ffi.FFIType.ptr
|
|
32
|
+
},
|
|
33
|
+
ReportEventA: {
|
|
34
|
+
args: [
|
|
35
|
+
bun_ffi.FFIType.ptr,
|
|
36
|
+
bun_ffi.FFIType.u16,
|
|
37
|
+
bun_ffi.FFIType.u16,
|
|
38
|
+
bun_ffi.FFIType.u32,
|
|
39
|
+
bun_ffi.FFIType.ptr,
|
|
40
|
+
bun_ffi.FFIType.u16,
|
|
41
|
+
bun_ffi.FFIType.u32,
|
|
42
|
+
bun_ffi.FFIType.ptr,
|
|
43
|
+
bun_ffi.FFIType.ptr
|
|
44
|
+
],
|
|
45
|
+
returns: bun_ffi.FFIType.bool
|
|
46
|
+
},
|
|
47
|
+
DeregisterEventSource: {
|
|
48
|
+
args: [bun_ffi.FFIType.ptr],
|
|
49
|
+
returns: bun_ffi.FFIType.bool
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
const encoder = new TextEncoder();
|
|
53
|
+
const sourceNameBuffer = encoder.encode(this.sourceName + "\0");
|
|
54
|
+
const result = this.lib.symbols.RegisterEventSourceA(null, sourceNameBuffer);
|
|
55
|
+
this.eventSource = typeof result === "number" ? result : null;
|
|
56
|
+
if (!this.eventSource || this.eventSource === 0) throw new Error(`Failed to register event source: ${this.sourceName}`);
|
|
57
|
+
this.initialized = true;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
throw new Error(`Failed to initialize Windows Event Log FFI: ${error}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Write an event to Windows Event Log
|
|
64
|
+
*/
|
|
65
|
+
writeEvent(eventType, eventId, message) {
|
|
66
|
+
if (!this.initialized || !this.eventSource || !this.lib) return;
|
|
67
|
+
try {
|
|
68
|
+
const encoder = new TextEncoder();
|
|
69
|
+
const messageBuffer = encoder.encode(message + "\0");
|
|
70
|
+
const ptrArray = new BigUint64Array(2);
|
|
71
|
+
ptrArray[0] = BigInt((0, bun_ffi.ptr)(messageBuffer));
|
|
72
|
+
ptrArray[1] = 0n;
|
|
73
|
+
const success = this.lib.symbols.ReportEventA(this.eventSource, eventType, 0, eventId, null, 1, 0, ptrArray, null);
|
|
74
|
+
if (!success) throw new Error(`ReportEventA returned false`);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Clean up resources
|
|
81
|
+
*/
|
|
82
|
+
dispose() {
|
|
83
|
+
if (this.initialized && this.eventSource && this.lib) {
|
|
84
|
+
try {
|
|
85
|
+
this.lib.symbols.DeregisterEventSource(this.eventSource);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
this.metaLogger.error("Failed to deregister event source during cleanup: {error}", { error });
|
|
88
|
+
}
|
|
89
|
+
this.eventSource = null;
|
|
90
|
+
this.initialized = false;
|
|
91
|
+
try {
|
|
92
|
+
this.lib.close();
|
|
93
|
+
} catch (error) {
|
|
94
|
+
this.metaLogger.error("Failed to close FFI library during cleanup: {error}", { error });
|
|
95
|
+
}
|
|
96
|
+
this.lib = null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
exports.WindowsEventLogFFI = WindowsEventLogFFI;
|
package/dist/ffi.bun.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { getLogger } from "@logtape/logtape";
|
|
2
|
+
import { FFIType, dlopen, ptr } from "bun:ffi";
|
|
3
|
+
|
|
4
|
+
//#region ffi.bun.ts
|
|
5
|
+
/**
|
|
6
|
+
* Bun FFI implementation for Windows Event Log API
|
|
7
|
+
*/
|
|
8
|
+
var WindowsEventLogFFI = class {
|
|
9
|
+
eventSource = null;
|
|
10
|
+
lib = null;
|
|
11
|
+
sourceName;
|
|
12
|
+
initialized = false;
|
|
13
|
+
metaLogger = getLogger([
|
|
14
|
+
"logtape",
|
|
15
|
+
"meta",
|
|
16
|
+
"windows-eventlog"
|
|
17
|
+
]);
|
|
18
|
+
constructor(sourceName) {
|
|
19
|
+
this.sourceName = sourceName;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Initialize the FFI bindings and register event source
|
|
23
|
+
*/
|
|
24
|
+
initialize() {
|
|
25
|
+
if (this.initialized) return;
|
|
26
|
+
try {
|
|
27
|
+
this.lib = dlopen("advapi32.dll", {
|
|
28
|
+
RegisterEventSourceA: {
|
|
29
|
+
args: [FFIType.ptr, FFIType.cstring],
|
|
30
|
+
returns: FFIType.ptr
|
|
31
|
+
},
|
|
32
|
+
ReportEventA: {
|
|
33
|
+
args: [
|
|
34
|
+
FFIType.ptr,
|
|
35
|
+
FFIType.u16,
|
|
36
|
+
FFIType.u16,
|
|
37
|
+
FFIType.u32,
|
|
38
|
+
FFIType.ptr,
|
|
39
|
+
FFIType.u16,
|
|
40
|
+
FFIType.u32,
|
|
41
|
+
FFIType.ptr,
|
|
42
|
+
FFIType.ptr
|
|
43
|
+
],
|
|
44
|
+
returns: FFIType.bool
|
|
45
|
+
},
|
|
46
|
+
DeregisterEventSource: {
|
|
47
|
+
args: [FFIType.ptr],
|
|
48
|
+
returns: FFIType.bool
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const encoder = new TextEncoder();
|
|
52
|
+
const sourceNameBuffer = encoder.encode(this.sourceName + "\0");
|
|
53
|
+
const result = this.lib.symbols.RegisterEventSourceA(null, sourceNameBuffer);
|
|
54
|
+
this.eventSource = typeof result === "number" ? result : null;
|
|
55
|
+
if (!this.eventSource || this.eventSource === 0) throw new Error(`Failed to register event source: ${this.sourceName}`);
|
|
56
|
+
this.initialized = true;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
throw new Error(`Failed to initialize Windows Event Log FFI: ${error}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Write an event to Windows Event Log
|
|
63
|
+
*/
|
|
64
|
+
writeEvent(eventType, eventId, message) {
|
|
65
|
+
if (!this.initialized || !this.eventSource || !this.lib) return;
|
|
66
|
+
try {
|
|
67
|
+
const encoder = new TextEncoder();
|
|
68
|
+
const messageBuffer = encoder.encode(message + "\0");
|
|
69
|
+
const ptrArray = new BigUint64Array(2);
|
|
70
|
+
ptrArray[0] = BigInt(ptr(messageBuffer));
|
|
71
|
+
ptrArray[1] = 0n;
|
|
72
|
+
const success = this.lib.symbols.ReportEventA(this.eventSource, eventType, 0, eventId, null, 1, 0, ptrArray, null);
|
|
73
|
+
if (!success) throw new Error(`ReportEventA returned false`);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Clean up resources
|
|
80
|
+
*/
|
|
81
|
+
dispose() {
|
|
82
|
+
if (this.initialized && this.eventSource && this.lib) {
|
|
83
|
+
try {
|
|
84
|
+
this.lib.symbols.DeregisterEventSource(this.eventSource);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
this.metaLogger.error("Failed to deregister event source during cleanup: {error}", { error });
|
|
87
|
+
}
|
|
88
|
+
this.eventSource = null;
|
|
89
|
+
this.initialized = false;
|
|
90
|
+
try {
|
|
91
|
+
this.lib.close();
|
|
92
|
+
} catch (error) {
|
|
93
|
+
this.metaLogger.error("Failed to close FFI library during cleanup: {error}", { error });
|
|
94
|
+
}
|
|
95
|
+
this.lib = null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
export { WindowsEventLogFFI };
|
|
102
|
+
//# sourceMappingURL=ffi.bun.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ffi.bun.js","names":["sourceName: string","eventType: EventType","eventId: number","message: string"],"sources":["../ffi.bun.ts"],"sourcesContent":["import { getLogger } from \"@logtape/logtape\";\n// @ts-types=\"npm:@types/bun@^1.2.16\"\nimport { dlopen, FFIType, ptr } from \"bun:ffi\";\nimport type { EventType } from \"./types.ts\";\n\n/**\n * Bun FFI implementation for Windows Event Log API\n */\nexport class WindowsEventLogFFI {\n private eventSource: number | null = null;\n // deno-lint-ignore no-explicit-any\n private lib: any = null;\n private sourceName: string;\n private initialized = false;\n private metaLogger = getLogger([\"logtape\", \"meta\", \"windows-eventlog\"]);\n\n constructor(sourceName: string) {\n this.sourceName = sourceName;\n }\n\n /**\n * Initialize the FFI bindings and register event source\n */\n initialize(): void {\n if (this.initialized) return;\n\n try {\n // Load advapi32.dll using Bun FFI\n this.lib = dlopen(\"advapi32.dll\", {\n RegisterEventSourceA: {\n args: [FFIType.ptr, FFIType.cstring],\n returns: FFIType.ptr,\n },\n ReportEventA: {\n args: [\n FFIType.ptr, // hEventLog\n FFIType.u16, // wType\n FFIType.u16, // wCategory\n FFIType.u32, // dwEventID\n FFIType.ptr, // lpUserSid\n FFIType.u16, // wNumStrings\n FFIType.u32, // dwDataSize\n FFIType.ptr, // lpStrings - pointer to array of string pointers\n FFIType.ptr, // lpRawData\n ],\n returns: FFIType.bool,\n },\n DeregisterEventSource: {\n args: [FFIType.ptr],\n returns: FFIType.bool,\n },\n });\n\n // Register event source using cstring\n // Create a buffer for the source name\n const encoder = new TextEncoder();\n const sourceNameBuffer = encoder.encode(this.sourceName + \"\\0\");\n\n const result = this.lib.symbols.RegisterEventSourceA(\n null,\n sourceNameBuffer,\n );\n this.eventSource = typeof result === \"number\" ? result : null;\n\n if (!this.eventSource || this.eventSource === 0) {\n throw new Error(\n `Failed to register event source: ${this.sourceName}`,\n );\n }\n\n this.initialized = true;\n } catch (error) {\n throw new Error(\n `Failed to initialize Windows Event Log FFI: ${error}`,\n );\n }\n }\n\n /**\n * Write an event to Windows Event Log\n */\n writeEvent(eventType: EventType, eventId: number, message: string): void {\n if (!this.initialized || !this.eventSource || !this.lib) {\n return;\n }\n\n try {\n // Use string array approach which works with Bun FFI\n const encoder = new TextEncoder();\n const messageBuffer = encoder.encode(message + \"\\0\");\n\n // Create pointer array for strings\n const ptrArray = new BigUint64Array(2);\n ptrArray[0] = BigInt(ptr(messageBuffer));\n ptrArray[1] = 0n; // null terminator\n\n const success = this.lib.symbols.ReportEventA(\n this.eventSource,\n eventType,\n 0, // category\n eventId,\n null, // user SID (null)\n 1, // number of strings\n 0, // data size\n ptrArray, // pointer to array of string pointers\n null, // raw data (null)\n );\n\n if (!success) {\n throw new Error(`ReportEventA returned false`);\n }\n } catch (error) {\n throw error;\n }\n }\n\n /**\n * Clean up resources\n */\n dispose(): void {\n if (this.initialized && this.eventSource && this.lib) {\n try {\n this.lib.symbols.DeregisterEventSource(this.eventSource);\n } catch (error) {\n this.metaLogger.error(\n \"Failed to deregister event source during cleanup: {error}\",\n { error },\n );\n }\n this.eventSource = null;\n this.initialized = false;\n\n try {\n this.lib.close();\n } catch (error) {\n this.metaLogger.error(\n \"Failed to close FFI library during cleanup: {error}\",\n { error },\n );\n }\n this.lib = null;\n }\n }\n}\n\n// cSpell: ignore cstring\n"],"mappings":";;;;;;;AAQA,IAAa,qBAAb,MAAgC;CAC9B,AAAQ,cAA6B;CAErC,AAAQ,MAAW;CACnB,AAAQ;CACR,AAAQ,cAAc;CACtB,AAAQ,aAAa,UAAU;EAAC;EAAW;EAAQ;CAAmB,EAAC;CAEvE,YAAYA,YAAoB;AAC9B,OAAK,aAAa;CACnB;;;;CAKD,aAAmB;AACjB,MAAI,KAAK,YAAa;AAEtB,MAAI;AAEF,QAAK,MAAM,OAAO,gBAAgB;IAChC,sBAAsB;KACpB,MAAM,CAAC,QAAQ,KAAK,QAAQ,OAAQ;KACpC,SAAS,QAAQ;IAClB;IACD,cAAc;KACZ,MAAM;MACJ,QAAQ;MACR,QAAQ;MACR,QAAQ;MACR,QAAQ;MACR,QAAQ;MACR,QAAQ;MACR,QAAQ;MACR,QAAQ;MACR,QAAQ;KACT;KACD,SAAS,QAAQ;IAClB;IACD,uBAAuB;KACrB,MAAM,CA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require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_types = require('./types.cjs');
|
|
3
|
+
const __logtape_logtape = require_rolldown_runtime.__toESM(require("@logtape/logtape"));
|
|
4
|
+
|
|
5
|
+
//#region ffi.deno.ts
|
|
6
|
+
const EVENTLOG_ERROR_TYPE = 1;
|
|
7
|
+
const EVENTLOG_WARNING_TYPE = 2;
|
|
8
|
+
const EVENTLOG_INFORMATION_TYPE = 4;
|
|
9
|
+
const FFI_SYMBOLS = {
|
|
10
|
+
RegisterEventSourceA: {
|
|
11
|
+
parameters: ["pointer", "pointer"],
|
|
12
|
+
result: "pointer"
|
|
13
|
+
},
|
|
14
|
+
DeregisterEventSource: {
|
|
15
|
+
parameters: ["pointer"],
|
|
16
|
+
result: "u32"
|
|
17
|
+
},
|
|
18
|
+
ReportEventA: {
|
|
19
|
+
parameters: [
|
|
20
|
+
"pointer",
|
|
21
|
+
"u16",
|
|
22
|
+
"u16",
|
|
23
|
+
"u32",
|
|
24
|
+
"pointer",
|
|
25
|
+
"u16",
|
|
26
|
+
"u32",
|
|
27
|
+
"pointer",
|
|
28
|
+
"pointer"
|
|
29
|
+
],
|
|
30
|
+
result: "u32"
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Windows Event Log FFI wrapper class for Deno.
|
|
35
|
+
* Provides direct access to Windows Event Log APIs through Deno's FFI.
|
|
36
|
+
*
|
|
37
|
+
* @since 1.0.0
|
|
38
|
+
*/
|
|
39
|
+
var WindowsEventLogFFI = class {
|
|
40
|
+
lib = null;
|
|
41
|
+
eventSource = null;
|
|
42
|
+
encoder = new TextEncoder();
|
|
43
|
+
metaLogger = (0, __logtape_logtape.getLogger)([
|
|
44
|
+
"logtape",
|
|
45
|
+
"meta",
|
|
46
|
+
"windows-eventlog"
|
|
47
|
+
]);
|
|
48
|
+
constructor(sourceName) {
|
|
49
|
+
this.sourceName = sourceName;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Initializes the FFI library and registers the event source.
|
|
53
|
+
* @throws {WindowsEventLogError} If initialization fails
|
|
54
|
+
*/
|
|
55
|
+
initialize() {
|
|
56
|
+
try {
|
|
57
|
+
this.lib = Deno.dlopen("advapi32.dll", FFI_SYMBOLS);
|
|
58
|
+
const sourceNamePtr = Deno.UnsafePointer.of(this.encoder.encode(this.sourceName + "\0"));
|
|
59
|
+
this.eventSource = this.lib.symbols.RegisterEventSourceA(null, sourceNamePtr);
|
|
60
|
+
if (!this.eventSource) throw new require_types.WindowsEventLogError(`Failed to register event source '${this.sourceName}'.`);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (error instanceof require_types.WindowsEventLogError) throw error;
|
|
63
|
+
throw new require_types.WindowsEventLogError(`Failed to initialize Windows Event Log FFI: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : void 0);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Writes a message to the Windows Event Log.
|
|
68
|
+
*
|
|
69
|
+
* @param eventType Event type (error, warning, info)
|
|
70
|
+
* @param eventId Event ID number
|
|
71
|
+
* @param message Message string to log
|
|
72
|
+
* @throws {WindowsEventLogError} If the write operation fails
|
|
73
|
+
*/
|
|
74
|
+
writeEvent(eventType, eventId, message) {
|
|
75
|
+
if (!this.lib || !this.eventSource) throw new require_types.WindowsEventLogError("FFI not initialized. Call initialize() first.");
|
|
76
|
+
try {
|
|
77
|
+
const messageBuffer = this.encoder.encode(message + "\0");
|
|
78
|
+
const messagePtr = Deno.UnsafePointer.of(messageBuffer);
|
|
79
|
+
const messagePtrValue = messagePtr ? Deno.UnsafePointer.value(messagePtr) : 0n;
|
|
80
|
+
const stringsArray = new BigUint64Array([messagePtrValue]);
|
|
81
|
+
const stringsPtr = Deno.UnsafePointer.of(stringsArray);
|
|
82
|
+
const result = this.lib.symbols.ReportEventA(this.eventSource, eventType, 0, eventId, null, 1, 0, stringsPtr, null);
|
|
83
|
+
if (result === 0) throw new require_types.WindowsEventLogError(`Failed to write event to Event Log.`);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (error instanceof require_types.WindowsEventLogError) throw error;
|
|
86
|
+
throw new require_types.WindowsEventLogError(`Error writing to Event Log: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : void 0);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Cleans up resources and deregisters the event source.
|
|
91
|
+
*/
|
|
92
|
+
dispose() {
|
|
93
|
+
if (this.lib && this.eventSource) {
|
|
94
|
+
try {
|
|
95
|
+
this.lib.symbols.DeregisterEventSource(this.eventSource);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
this.metaLogger.error("Failed to deregister event source during cleanup: {error}", { error });
|
|
98
|
+
}
|
|
99
|
+
this.eventSource = null;
|
|
100
|
+
}
|
|
101
|
+
if (this.lib) {
|
|
102
|
+
try {
|
|
103
|
+
this.lib.close();
|
|
104
|
+
} catch (error) {
|
|
105
|
+
this.metaLogger.error("Failed to close FFI library during cleanup: {error}", { error });
|
|
106
|
+
}
|
|
107
|
+
this.lib = null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
exports.EVENTLOG_ERROR_TYPE = EVENTLOG_ERROR_TYPE;
|
|
114
|
+
exports.EVENTLOG_INFORMATION_TYPE = EVENTLOG_INFORMATION_TYPE;
|
|
115
|
+
exports.EVENTLOG_WARNING_TYPE = EVENTLOG_WARNING_TYPE;
|
|
116
|
+
exports.WindowsEventLogFFI = WindowsEventLogFFI;
|
package/dist/ffi.deno.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { WindowsEventLogError } from "./types.js";
|
|
2
|
+
import { getLogger } from "@logtape/logtape";
|
|
3
|
+
|
|
4
|
+
//#region ffi.deno.ts
|
|
5
|
+
const EVENTLOG_ERROR_TYPE = 1;
|
|
6
|
+
const EVENTLOG_WARNING_TYPE = 2;
|
|
7
|
+
const EVENTLOG_INFORMATION_TYPE = 4;
|
|
8
|
+
const FFI_SYMBOLS = {
|
|
9
|
+
RegisterEventSourceA: {
|
|
10
|
+
parameters: ["pointer", "pointer"],
|
|
11
|
+
result: "pointer"
|
|
12
|
+
},
|
|
13
|
+
DeregisterEventSource: {
|
|
14
|
+
parameters: ["pointer"],
|
|
15
|
+
result: "u32"
|
|
16
|
+
},
|
|
17
|
+
ReportEventA: {
|
|
18
|
+
parameters: [
|
|
19
|
+
"pointer",
|
|
20
|
+
"u16",
|
|
21
|
+
"u16",
|
|
22
|
+
"u32",
|
|
23
|
+
"pointer",
|
|
24
|
+
"u16",
|
|
25
|
+
"u32",
|
|
26
|
+
"pointer",
|
|
27
|
+
"pointer"
|
|
28
|
+
],
|
|
29
|
+
result: "u32"
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Windows Event Log FFI wrapper class for Deno.
|
|
34
|
+
* Provides direct access to Windows Event Log APIs through Deno's FFI.
|
|
35
|
+
*
|
|
36
|
+
* @since 1.0.0
|
|
37
|
+
*/
|
|
38
|
+
var WindowsEventLogFFI = class {
|
|
39
|
+
lib = null;
|
|
40
|
+
eventSource = null;
|
|
41
|
+
encoder = new TextEncoder();
|
|
42
|
+
metaLogger = getLogger([
|
|
43
|
+
"logtape",
|
|
44
|
+
"meta",
|
|
45
|
+
"windows-eventlog"
|
|
46
|
+
]);
|
|
47
|
+
constructor(sourceName) {
|
|
48
|
+
this.sourceName = sourceName;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Initializes the FFI library and registers the event source.
|
|
52
|
+
* @throws {WindowsEventLogError} If initialization fails
|
|
53
|
+
*/
|
|
54
|
+
initialize() {
|
|
55
|
+
try {
|
|
56
|
+
this.lib = Deno.dlopen("advapi32.dll", FFI_SYMBOLS);
|
|
57
|
+
const sourceNamePtr = Deno.UnsafePointer.of(this.encoder.encode(this.sourceName + "\0"));
|
|
58
|
+
this.eventSource = this.lib.symbols.RegisterEventSourceA(null, sourceNamePtr);
|
|
59
|
+
if (!this.eventSource) throw new WindowsEventLogError(`Failed to register event source '${this.sourceName}'.`);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (error instanceof WindowsEventLogError) throw error;
|
|
62
|
+
throw new WindowsEventLogError(`Failed to initialize Windows Event Log FFI: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : void 0);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Writes a message to the Windows Event Log.
|
|
67
|
+
*
|
|
68
|
+
* @param eventType Event type (error, warning, info)
|
|
69
|
+
* @param eventId Event ID number
|
|
70
|
+
* @param message Message string to log
|
|
71
|
+
* @throws {WindowsEventLogError} If the write operation fails
|
|
72
|
+
*/
|
|
73
|
+
writeEvent(eventType, eventId, message) {
|
|
74
|
+
if (!this.lib || !this.eventSource) throw new WindowsEventLogError("FFI not initialized. Call initialize() first.");
|
|
75
|
+
try {
|
|
76
|
+
const messageBuffer = this.encoder.encode(message + "\0");
|
|
77
|
+
const messagePtr = Deno.UnsafePointer.of(messageBuffer);
|
|
78
|
+
const messagePtrValue = messagePtr ? Deno.UnsafePointer.value(messagePtr) : 0n;
|
|
79
|
+
const stringsArray = new BigUint64Array([messagePtrValue]);
|
|
80
|
+
const stringsPtr = Deno.UnsafePointer.of(stringsArray);
|
|
81
|
+
const result = this.lib.symbols.ReportEventA(this.eventSource, eventType, 0, eventId, null, 1, 0, stringsPtr, null);
|
|
82
|
+
if (result === 0) throw new WindowsEventLogError(`Failed to write event to Event Log.`);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error instanceof WindowsEventLogError) throw error;
|
|
85
|
+
throw new WindowsEventLogError(`Error writing to Event Log: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : void 0);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Cleans up resources and deregisters the event source.
|
|
90
|
+
*/
|
|
91
|
+
dispose() {
|
|
92
|
+
if (this.lib && this.eventSource) {
|
|
93
|
+
try {
|
|
94
|
+
this.lib.symbols.DeregisterEventSource(this.eventSource);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
this.metaLogger.error("Failed to deregister event source during cleanup: {error}", { error });
|
|
97
|
+
}
|
|
98
|
+
this.eventSource = null;
|
|
99
|
+
}
|
|
100
|
+
if (this.lib) {
|
|
101
|
+
try {
|
|
102
|
+
this.lib.close();
|
|
103
|
+
} catch (error) {
|
|
104
|
+
this.metaLogger.error("Failed to close FFI library during cleanup: {error}", { error });
|
|
105
|
+
}
|
|
106
|
+
this.lib = null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
export { EVENTLOG_ERROR_TYPE, EVENTLOG_INFORMATION_TYPE, EVENTLOG_WARNING_TYPE, WindowsEventLogFFI };
|
|
113
|
+
//# sourceMappingURL=ffi.deno.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ffi.deno.js","names":["sourceName: string","eventType: number","eventId: number","message: string"],"sources":["../ffi.deno.ts"],"sourcesContent":["import { getLogger } from \"@logtape/logtape\";\nimport { WindowsEventLogError } from \"./types.ts\";\n\n/**\n * Windows Event Log API constants and types for FFI.\n * @since 1.0.0\n */\n\n// Event Log types\nexport const EVENTLOG_SUCCESS = 0x0000;\nexport const EVENTLOG_ERROR_TYPE = 0x0001;\nexport const EVENTLOG_WARNING_TYPE = 0x0002;\nexport const EVENTLOG_INFORMATION_TYPE = 0x0004;\n\n// FFI symbol definitions for Windows Event Log APIs\nconst FFI_SYMBOLS = {\n RegisterEventSourceA: {\n parameters: [\"pointer\", \"pointer\"] as const,\n result: \"pointer\" as const,\n },\n DeregisterEventSource: {\n parameters: [\"pointer\"] as const,\n result: \"u32\" as const,\n },\n ReportEventA: {\n parameters: [\n \"pointer\", // hEventLog\n \"u16\", // wType\n \"u16\", // wCategory\n \"u32\", // dwEventID\n \"pointer\", // lpUserSid\n \"u16\", // wNumStrings\n \"u32\", // dwDataSize\n \"pointer\", // lpStrings\n \"pointer\", // lpRawData\n ] as const,\n result: \"u32\" as const,\n },\n} as const;\n\n/**\n * Windows Event Log FFI wrapper class for Deno.\n * Provides direct access to Windows Event Log APIs through Deno's FFI.\n *\n * @since 1.0.0\n */\nexport class WindowsEventLogFFI {\n private lib: Deno.DynamicLibrary<typeof FFI_SYMBOLS> | null = null;\n private eventSource: Deno.PointerValue | null = null;\n private encoder = new TextEncoder();\n private metaLogger = getLogger([\"logtape\", \"meta\", \"windows-eventlog\"]);\n\n constructor(private sourceName: string) {}\n\n /**\n * Initializes the FFI library and registers the event source.\n * @throws {WindowsEventLogError} If initialization fails\n */\n initialize(): void {\n try {\n // Load advapi32.dll\n this.lib = Deno.dlopen(\"advapi32.dll\", FFI_SYMBOLS);\n\n // Register event source\n const sourceNamePtr = Deno.UnsafePointer.of(\n this.encoder.encode(this.sourceName + \"\\0\"),\n );\n this.eventSource = this.lib.symbols.RegisterEventSourceA(\n null,\n sourceNamePtr,\n );\n\n if (!this.eventSource) {\n throw new WindowsEventLogError(\n `Failed to register event source '${this.sourceName}'.`,\n );\n }\n } catch (error) {\n if (error instanceof WindowsEventLogError) {\n throw error;\n }\n throw new WindowsEventLogError(\n `Failed to initialize Windows Event Log FFI: ${\n error instanceof Error ? error.message : String(error)\n }`,\n error instanceof Error ? error : undefined,\n );\n }\n }\n\n /**\n * Writes a message to the Windows Event Log.\n *\n * @param eventType Event type (error, warning, info)\n * @param eventId Event ID number\n * @param message Message string to log\n * @throws {WindowsEventLogError} If the write operation fails\n */\n writeEvent(eventType: number, eventId: number, message: string): void {\n if (!this.lib || !this.eventSource) {\n throw new WindowsEventLogError(\n \"FFI not initialized. Call initialize() first.\",\n );\n }\n\n try {\n // Prepare message string\n const messageBuffer = this.encoder.encode(message + \"\\0\");\n const messagePtr = Deno.UnsafePointer.of(messageBuffer);\n const messagePtrValue = messagePtr\n ? Deno.UnsafePointer.value(messagePtr)\n : 0n;\n const stringsArray = new BigUint64Array([messagePtrValue]);\n const stringsPtr = Deno.UnsafePointer.of(stringsArray);\n\n // Call ReportEventA\n const result = this.lib.symbols.ReportEventA(\n this.eventSource, // hEventLog\n eventType, // wType\n 0, // wCategory (0 = no category)\n eventId, // dwEventID\n null, // lpUserSid (null = current user)\n 1, // wNumStrings (1 string)\n 0, // dwDataSize (no additional data)\n stringsPtr, // lpStrings\n null, // lpRawData (no additional data)\n );\n\n if (result === 0) {\n throw new WindowsEventLogError(\n `Failed to write event to Event Log.`,\n );\n }\n } catch (error) {\n if (error instanceof WindowsEventLogError) {\n throw error;\n }\n throw new WindowsEventLogError(\n `Error writing to Event Log: ${\n error instanceof Error ? error.message : String(error)\n }`,\n error instanceof Error ? error : undefined,\n );\n }\n }\n\n /**\n * Cleans up resources and deregisters the event source.\n */\n dispose(): void {\n if (this.lib && this.eventSource) {\n try {\n this.lib.symbols.DeregisterEventSource(this.eventSource);\n } catch (error) {\n this.metaLogger.error(\n \"Failed to deregister event source during cleanup: {error}\",\n { error },\n );\n }\n this.eventSource = null;\n }\n\n if (this.lib) {\n try {\n this.lib.close();\n } catch (error) {\n this.metaLogger.error(\n \"Failed to close FFI library during cleanup: {error}\",\n { error },\n );\n }\n this.lib = null;\n }\n }\n}\n"],"mappings":";;;;AAUA,MAAa,sBAAsB;AACnC,MAAa,wBAAwB;AACrC,MAAa,4BAA4B;AAGzC,MAAM,cAAc;CAClB,sBAAsB;EACpB,YAAY,CAAC,WAAW,SAAU;EAClC,QAAQ;CACT;CACD,uBAAuB;EACrB,YAAY,CAAC,SAAU;EACvB,QAAQ;CACT;CACD,cAAc;EACZ,YAAY;GACV;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACD;EACD,QAAQ;CACT;AACF;;;;;;;AAQD,IAAa,qBAAb,MAAgC;CAC9B,AAAQ,MAAsD;CAC9D,AAAQ,cAAwC;CAChD,AA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