@finogeeks2026/finshield-opencode 0.0.0-stage → 0.11.50

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.
Files changed (143) hide show
  1. package/DESIGN.md +593 -0
  2. package/LICENSE.rtf +28 -0
  3. package/README.md +132 -2
  4. package/THIRD-PARTY-NOTICES.md +3131 -0
  5. package/bin/node.exe +4 -0
  6. package/dist/gui-experimental.cjs +96 -0
  7. package/dist/updater/server.js +1046 -0
  8. package/install/download-source.json +3 -0
  9. package/install/runtime.js +60 -0
  10. package/node_modules/@finogeeks2026/finsafe-sdk/LICENSE.rtf +28 -0
  11. package/node_modules/@finogeeks2026/finsafe-sdk/README.md +116 -0
  12. package/node_modules/@finogeeks2026/finsafe-sdk/bin/finsafe_native.dll +0 -0
  13. package/node_modules/@finogeeks2026/finsafe-sdk/native-build.json +5 -0
  14. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/README.md +6 -0
  15. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/index.js +12 -0
  16. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/package.json +24 -0
  17. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/win32_x64/koffi.lib +0 -0
  18. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/@koromix/koffi-win32-x64/win32_x64/koffi.node +0 -0
  19. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/CHANGELOG.md +1183 -0
  20. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/LICENSE.txt +22 -0
  21. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/README.md +42 -0
  22. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/cnoke.cjs +816 -0
  23. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/benchmarks.md +80 -0
  24. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/callbacks.md +182 -0
  25. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/composites.md +549 -0
  26. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/contribute.md +163 -0
  27. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/index.md +46 -0
  28. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/load.md +191 -0
  29. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/migration.md +256 -0
  30. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/misc.md +76 -0
  31. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/output.md +299 -0
  32. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/pointers.md +385 -0
  33. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/primitives.md +151 -0
  34. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/start.md +110 -0
  35. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/types.md +88 -0
  36. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/unions.md +0 -0
  37. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/doc/values.md +134 -0
  38. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/index.cjs +1 -0
  39. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/index.d.ts +389 -0
  40. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/index.js +2 -0
  41. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/indirect.cjs +1 -0
  42. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/indirect.js +2 -0
  43. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/lib/native/base/base.cc +11064 -0
  44. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/lib/native/base/base.hh +5951 -0
  45. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/lib/native/base/unicode.inc +408 -0
  46. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/package.json +68 -0
  47. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/CMakeLists.txt +249 -0
  48. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/index.cjs +296 -0
  49. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/index.js +281 -0
  50. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/indirect.cjs +295 -0
  51. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/indirect.js +280 -0
  52. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/arm64.cc +1408 -0
  53. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/arm64_asm.S +216 -0
  54. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/arm64_asm.asm +181 -0
  55. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/loong64.cc +5 -0
  56. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/loong64_asm.S +200 -0
  57. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/riscv64.cc +1345 -0
  58. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/riscv64_asm.S +200 -0
  59. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64sysv.cc +1434 -0
  60. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64sysv_asm.S +224 -0
  61. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64win.cc +1086 -0
  62. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64win_asm.S +162 -0
  63. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x64win_asm.asm +189 -0
  64. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x86.cc +1185 -0
  65. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x86_asm.S +217 -0
  66. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/abi/x86_asm.asm +174 -0
  67. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/call.cc +2094 -0
  68. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/call.hh +179 -0
  69. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/errno.inc +462 -0
  70. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/ffi.cc +3009 -0
  71. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/ffi.hh +461 -0
  72. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/parser.cc +218 -0
  73. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/parser.hh +54 -0
  74. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/primitives.inc +36 -0
  75. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/static.cjs +130 -0
  76. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/static.js +133 -0
  77. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/trampolines.cjs +77 -0
  78. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/type.cc +725 -0
  79. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/type.hh +71 -0
  80. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/util.cc +1040 -0
  81. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/util.hh +493 -0
  82. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/uv.cc +214 -0
  83. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/uv.def +11 -0
  84. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/uv.hh +112 -0
  85. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/win32.cc +198 -0
  86. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/src/koffi/src/win32.hh +148 -0
  87. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/LICENSE.md +9 -0
  88. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/README.md +95 -0
  89. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/napi-inl.deprecated.h +186 -0
  90. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/napi-inl.h +7211 -0
  91. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-addon-api/napi.h +3421 -0
  92. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/LICENSE +21 -0
  93. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/README.md +95 -0
  94. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/def/js_native_api.def +125 -0
  95. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/def/node_api.def +157 -0
  96. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/include/js_native_api.h +591 -0
  97. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/include/js_native_api_types.h +210 -0
  98. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/include/node_api.h +265 -0
  99. package/node_modules/@finogeeks2026/finsafe-sdk/node_modules/koffi/vendor/node-api-headers/include/node_api_types.h +58 -0
  100. package/node_modules/@finogeeks2026/finsafe-sdk/package.json +36 -0
  101. package/node_modules/@finogeeks2026/finsafe-sdk/release.json +4 -0
  102. package/node_modules/@finogeeks2026/finsafe-sdk/src/native.js +85 -0
  103. package/node_modules/@finogeeks2026/finsafe-sdk/src/shell.js +20 -0
  104. package/node_modules/@finogeeks2026/finsafe-sdk/src/status.js +57 -0
  105. package/package.json +47 -4
  106. package/policy/candidate.yaml +347 -0
  107. package/release.json +4 -0
  108. package/src/activation.js +2 -0
  109. package/src/attachment.js +34 -0
  110. package/src/connector.js +91 -0
  111. package/src/contract.js +8 -0
  112. package/src/desktop-contract.js +4 -0
  113. package/src/desktop.js +25 -0
  114. package/src/gui.tsx +58 -0
  115. package/src/host.js +38 -0
  116. package/src/index.js +12 -0
  117. package/src/instance-settings.js +27 -0
  118. package/src/known-folders.js +22 -0
  119. package/src/management.js +17 -0
  120. package/src/preparation.js +18 -0
  121. package/src/presentation.js +153 -0
  122. package/src/settings.js +18 -0
  123. package/ui/feedback.cjs +45 -0
  124. package/ui/page.cjs +225 -0
  125. package/ui/state.cjs +44 -0
  126. package/updater/bootstrap.js +41 -0
  127. package/updater/common/activation.js +81 -0
  128. package/updater/common/coordinator.js +329 -0
  129. package/updater/common/download.js +57 -0
  130. package/updater/common/index.js +12 -0
  131. package/updater/common/package.js +53 -0
  132. package/updater/common/protocol.js +38 -0
  133. package/updater/common/transport.js +65 -0
  134. package/updater/coordinator.js +2 -0
  135. package/updater/launch.js +40 -0
  136. package/updater/management.js +9 -0
  137. package/updater/native.js +18 -0
  138. package/updater/operations.js +45 -0
  139. package/updater/protocol.js +1 -0
  140. package/updater/server.js +100 -0
  141. package/updater/transport.js +10 -0
  142. package/updater/windows-launch-reader.js +40 -0
  143. package/updater/windows-launch.js +96 -0
@@ -0,0 +1,112 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ #pragma once
4
+
5
+ #include "lib/native/base/base.hh"
6
+ #include "ffi.hh"
7
+
8
+ #include <napi.h>
9
+
10
+ extern "C" {
11
+
12
+ // The uv headers are not included in node-api-headers, but we only use a few
13
+ // uv types and functions, so just declare them here.
14
+
15
+ struct uv_loop_s;
16
+ struct uv_handle_s;
17
+
18
+ struct uv_poll_s {
19
+ void *data;
20
+ // Kinda opaque struct, use uv_handle_size() to allocate enough memory
21
+ };
22
+
23
+ typedef struct uv_loop_s uv_loop_t;
24
+ typedef struct uv_handle_s uv_handle_t;
25
+ typedef struct uv_poll_s uv_poll_t;
26
+
27
+ typedef enum {
28
+ UV_UNKNOWN_HANDLE = 0,
29
+ UV_ASYNC,
30
+ UV_CHECK,
31
+ UV_FS_EVENT,
32
+ UV_FS_POLL,
33
+ UV_HANDLE,
34
+ UV_IDLE,
35
+ UV_NAMED_PIPE,
36
+ UV_POLL,
37
+ UV_PREPARE,
38
+ UV_PROCESS,
39
+ UV_STREAM,
40
+ UV_TCP,
41
+ UV_TIMER,
42
+ UV_TTY,
43
+ UV_UDP,
44
+ UV_SIGNAL,
45
+ UV_FILE,
46
+ UV_HANDLE_TYPE_MAX
47
+ } uv_handle_type;
48
+
49
+ typedef void (*uv_close_cb)(uv_handle_t *handle);
50
+ typedef void (*uv_poll_cb)(uv_poll_t *handle, int status, int events);
51
+
52
+ enum uv_poll_event {
53
+ UV_READABLE = 1,
54
+ UV_WRITABLE = 2,
55
+ UV_DISCONNECT = 4,
56
+ UV_PRIORITIZED = 8
57
+ };
58
+
59
+ #if defined(_WIN32)
60
+ typedef uintptr_t uv_os_sock_t; // SOCKET
61
+ #define IMPORT __declspec(dllimport)
62
+ #else
63
+ typedef int uv_os_sock_t;
64
+ #define IMPORT
65
+ #endif
66
+
67
+ IMPORT void uv_ref(uv_handle_t *handle);
68
+ IMPORT void uv_unref(uv_handle_t *handle);
69
+ IMPORT void uv_close(uv_handle_t *handle, uv_close_cb close_cb);
70
+ IMPORT size_t uv_handle_size(uv_handle_type type);
71
+
72
+ IMPORT int uv_poll_init(uv_loop_t *loop, uv_poll_t *handle, int fd);
73
+ IMPORT int uv_poll_init_socket(uv_loop_t *loop, uv_poll_t *handle, uv_os_sock_t socket);
74
+ IMPORT int uv_poll_start(uv_poll_t *handle, int events, uv_poll_cb cb);
75
+ IMPORT int uv_poll_stop(uv_poll_t *handle);
76
+
77
+ IMPORT const char *uv_strerror(int err);
78
+
79
+ #undef IMPORT
80
+
81
+ };
82
+
83
+ namespace K {
84
+
85
+ class PollHandle: public Napi::ObjectWrap<PollHandle> {
86
+ Napi::Env env = nullptr;
87
+
88
+ uv_poll_t *handle = nullptr;
89
+ Napi::FunctionReference callback;
90
+
91
+ public:
92
+ static Napi::Function InitClass(InstanceData *instance);
93
+
94
+ PollHandle(const Napi::CallbackInfo &info);
95
+
96
+ void Finalize(Napi::BasicEnv env) override;
97
+
98
+ void Start(const Napi::CallbackInfo &info);
99
+ void Stop(const Napi::CallbackInfo &info);
100
+ void Close(const Napi::CallbackInfo &info);
101
+ void Ref(const Napi::CallbackInfo &info);
102
+ void Unref(const Napi::CallbackInfo &info);
103
+
104
+ private:
105
+ void Close();
106
+
107
+ static void OnPoll(uv_poll_t *handle, int status, int events);
108
+ };
109
+
110
+ Napi::Value Poll(const Napi::CallbackInfo &info);
111
+
112
+ }
@@ -0,0 +1,198 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: 2026 Niels Martignène <niels.martignene@protonmail.com>
3
+
4
+ #if defined(_WIN32)
5
+
6
+ #include "util.hh"
7
+ #include "win32.hh"
8
+
9
+ #if !defined(NOMINMAX)
10
+ #define NOMINMAX
11
+ #endif
12
+ #if !defined(WIN32_LEAN_AND_MEAN)
13
+ #define WIN32_LEAN_AND_MEAN
14
+ #endif
15
+ #include <windows.h>
16
+ #include <ntsecapi.h>
17
+ #include <processthreadsapi.h>
18
+
19
+ namespace K {
20
+
21
+ const HashMap<int, const char *> WindowsMachineNames = {
22
+ { 0x184, "Alpha AXP, 32-bit" },
23
+ { 0x284, "Alpha 64" },
24
+ { 0x1d3, "Matsushita AM33" },
25
+ { 0x8664, "AMD x64" },
26
+ { 0x1c0, "ARM little endian" },
27
+ { 0xaa64, "ARM64 little endian" },
28
+ { 0x1c4, "ARM Thumb-2 little endian" },
29
+ { 0x284, "AXP 64" },
30
+ { 0xebc, "EFI byte code" },
31
+ { 0x14c, "Intel 386+" },
32
+ { 0x200, "Intel Itanium" },
33
+ { 0x6232, "LoongArch 32-bit" },
34
+ { 0x6264, "LoongArch 64-bit" },
35
+ { 0x9041, "Mitsubishi M32R little endian" },
36
+ { 0x266, "MIPS16" },
37
+ { 0x366, "MIPS with FPU" },
38
+ { 0x466, "MIPS16 with FPU" },
39
+ { 0x1f0, "Power PC little endian" },
40
+ { 0x1f1, "Power PC with FP support" },
41
+ { 0x166, "MIPS little endian" },
42
+ { 0x5032, "RISC-V 32-bit" },
43
+ { 0x5064, "RISC-V 64-bit" },
44
+ { 0x5128, "RISC-V 128-bit" },
45
+ { 0x1a2, "Hitachi SH3" },
46
+ { 0x1a3, "Hitachi SH3 DSP" },
47
+ { 0x1a6, "Hitachi SH4" },
48
+ { 0x1a8, "Hitachi SH5" },
49
+ { 0x1c2, "Thumb" },
50
+ { 0x169, "MIPS little-endian WCE v2" }
51
+ };
52
+
53
+ HANDLE LoadWindowsLibrary(Napi::Env env, Span<const char> path)
54
+ {
55
+ BlockAllocator temp_alloc;
56
+
57
+ Span<wchar_t> filename_w = AllocateSpan<wchar_t>(&temp_alloc, path.len + 1);
58
+
59
+ if (ConvertUtf8ToWin32Wide(path, filename_w) < 0) {
60
+ ThrowError<Napi::Error>(env, "Invalid path string");
61
+ return nullptr;
62
+ }
63
+
64
+ HMODULE module = LoadLibraryW(filename_w.ptr);
65
+
66
+ if (!module) {
67
+ DWORD flags = LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR;
68
+
69
+ Span<const char> filename = NormalizePath(path, GetWorkingDirectory(), &temp_alloc);
70
+ Span<wchar_t> filename_w = AllocateSpan<wchar_t>(&temp_alloc, filename.len + 1);
71
+
72
+ if (ConvertUtf8ToWin32Wide(filename, filename_w) < 0) {
73
+ ThrowError<Napi::Error>(env, "Invalid path string");
74
+ return nullptr;
75
+ }
76
+
77
+ module = LoadLibraryExW(filename_w.ptr, nullptr, flags);
78
+ }
79
+
80
+ if (!module) {
81
+ if (GetLastError() == ERROR_BAD_EXE_FORMAT) {
82
+ int process = GetSelfMachine();
83
+ int dll = GetDllMachine(filename_w.ptr);
84
+
85
+ if (process >= 0 && dll >= 0 && dll != process) {
86
+ ThrowError<Napi::Error>(env, "Cannot load '%1' DLL in '%2' process",
87
+ WindowsMachineNames.FindValue(dll, "Unknown"),
88
+ WindowsMachineNames.FindValue(process, "Unknown"));
89
+ return nullptr;
90
+ }
91
+ }
92
+
93
+ ThrowError<Napi::Error>(env, "Failed to load shared library: %1", GetWin32ErrorString());
94
+ return nullptr;
95
+ }
96
+
97
+ return module;
98
+ }
99
+
100
+ // Fails silently on purpose
101
+ static bool ReadAt(HANDLE h, int32_t offset, void *buf, int len)
102
+ {
103
+ OVERLAPPED ov = {};
104
+ DWORD read;
105
+
106
+ ov.Offset = offset & 0x7FFFFFFFu;
107
+
108
+ if (offset < 0)
109
+ return false;
110
+ if (!ReadFile(h, buf, (DWORD)len, &read, &ov))
111
+ return false;
112
+ if (read != (DWORD)len)
113
+ return false;
114
+
115
+ return true;
116
+ }
117
+
118
+ static int GetFileMachine(HANDLE h, bool check_dll)
119
+ {
120
+ PE_DOS_HEADER dos = {};
121
+ PE_NT_HEADERS nt = {};
122
+
123
+ if (!ReadAt(h, 0, &dos, K_SIZE(dos)))
124
+ goto generic;
125
+ if (!ReadAt(h, dos.e_lfanew, &nt, K_SIZE(nt)))
126
+ goto generic;
127
+
128
+ if (dos.e_magic != 0x5A4D) // MZ
129
+ goto generic;
130
+ if (nt.Signature != 0x00004550) // PE\0\0
131
+ goto generic;
132
+ if (check_dll && !(nt.FileHeader.Characteristics & IMAGE_FILE_DLL))
133
+ goto generic;
134
+
135
+ return (int)nt.FileHeader.Machine;
136
+
137
+ generic:
138
+ LogError("Invalid or forbidden %1 file: %2", check_dll ? "DLL" : "executable", GetWin32ErrorString());
139
+ return -1;
140
+ }
141
+
142
+ int GetSelfMachine()
143
+ {
144
+ const char *filename = GetApplicationExecutable();
145
+
146
+ HANDLE h;
147
+ if (IsWin32Utf8()) {
148
+ h = CreateFileA(filename, GENERIC_READ,
149
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
150
+ nullptr, OPEN_EXISTING, 0, nullptr);
151
+ } else {
152
+ wchar_t filename_w[4096];
153
+ if (ConvertUtf8ToWin32Wide(filename, filename_w) < 0)
154
+ return -1;
155
+
156
+ h = CreateFileW(filename_w, GENERIC_READ,
157
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
158
+ nullptr, OPEN_EXISTING, 0, nullptr);
159
+ }
160
+ if (h == INVALID_HANDLE_VALUE) {
161
+ LogError("Cannot open '%1': %2", filename, GetWin32ErrorString());
162
+ return -1;
163
+ }
164
+ K_DEFER { CloseHandle(h); };
165
+
166
+ return GetFileMachine(h, false);
167
+ }
168
+
169
+ int GetDllMachine(const wchar_t *filename)
170
+ {
171
+ HANDLE h = CreateFileW((LPCWSTR)filename, GENERIC_READ,
172
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
173
+ nullptr, OPEN_EXISTING, 0, nullptr);
174
+ if (h == INVALID_HANDLE_VALUE) {
175
+ LogError("Cannot open '%1': %2", filename, GetWin32ErrorString());
176
+ return -1;
177
+ }
178
+ K_DEFER { CloseHandle(h); };
179
+
180
+ return GetFileMachine(h, true);
181
+ }
182
+
183
+ extern "C" int __cdecl SehHandler(void *ptr, void *, void *ctx, void *)
184
+ {
185
+ EXCEPTION_RECORD *rec = (EXCEPTION_RECORD *)ptr;
186
+
187
+ if (!(rec->ExceptionFlags & (EXCEPTION_UNWINDING | EXCEPTION_EXIT_UNWIND))) {
188
+ EXCEPTION_POINTERS ep = { rec, (CONTEXT *)ctx };
189
+ UnhandledExceptionFilter(&ep);
190
+ ExitProcess(rec->ExceptionCode);
191
+ }
192
+
193
+ return ExceptionContinueSearch;
194
+ }
195
+
196
+ }
197
+
198
+ #endif
@@ -0,0 +1,148 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: 2026 Niels Martignène <niels.martignene@protonmail.com>
3
+
4
+ #pragma once
5
+
6
+ #include "lib/native/base/base.hh"
7
+
8
+ #include <intrin.h>
9
+ #include <napi.h>
10
+
11
+ namespace K {
12
+
13
+ struct PE_DOS_HEADER {
14
+ uint16_t e_magic;
15
+ uint16_t e_cblp;
16
+ uint16_t e_cp;
17
+ uint16_t e_crlc;
18
+ uint16_t e_cparhdr;
19
+ uint16_t e_minalloc;
20
+ uint16_t e_maxalloc;
21
+ uint16_t e_ss;
22
+ uint16_t e_sp;
23
+ uint16_t e_csum;
24
+ uint16_t e_ip;
25
+ uint16_t e_cs;
26
+ uint16_t e_lfarlc;
27
+ uint16_t e_ovno;
28
+ uint16_t e_res[4];
29
+ uint16_t e_oemid;
30
+ uint16_t e_oeminfo;
31
+ uint16_t e_res2[10];
32
+ uint32_t e_lfanew;
33
+ };
34
+
35
+ struct PE_FILE_HEADER {
36
+ uint16_t Machine;
37
+ uint16_t NumberOfSections;
38
+ uint32_t TimeDateStamp;
39
+ uint32_t PointerToSymbolTable;
40
+ uint32_t NumberOfSymbols;
41
+ uint16_t SizeOfOptionalHeader;
42
+ uint16_t Characteristics;
43
+ };
44
+
45
+ struct PE_NT_HEADERS {
46
+ uint32_t Signature;
47
+ PE_FILE_HEADER FileHeader;
48
+
49
+ // ... OptionalHeader;
50
+ };
51
+
52
+ #if defined(_WIN64)
53
+
54
+ struct TEB {
55
+ void *ExceptionList;
56
+ void *StackBase;
57
+ void *StackLimit;
58
+ char _pad1[80];
59
+ unsigned long LastErrorValue;
60
+ char _pad2[5132];
61
+ void *DeallocationStack;
62
+ char _pad3[712];
63
+ uint32_t GuaranteedStackBytes;
64
+ char _pad4[162];
65
+ uint16_t SameTebFlags;
66
+ };
67
+ static_assert(offsetof(TEB, DeallocationStack) == 0x1478);
68
+ static_assert(offsetof(TEB, GuaranteedStackBytes) == 0x1748);
69
+ static_assert(offsetof(TEB, SameTebFlags) == 0x17EE);
70
+
71
+ #else
72
+
73
+ struct TEB {
74
+ void *ExceptionList;
75
+ void *StackBase;
76
+ void *StackLimit;
77
+ char _pad1[40];
78
+ unsigned long LastErrorValue;
79
+ char _pad2[3540];
80
+ void *DeallocationStack;
81
+ char _pad3[360];
82
+ uint32_t GuaranteedStackBytes;
83
+ char _pad4[78];
84
+ uint16_t SameTebFlags;
85
+ };
86
+ static_assert(offsetof(TEB, DeallocationStack) == 0xE0C);
87
+ static_assert(offsetof(TEB, GuaranteedStackBytes) == 0x0F78);
88
+ static_assert(offsetof(TEB, SameTebFlags) == 0xFCA);
89
+
90
+ struct SehFrame {
91
+ void *Next;
92
+ void *Handler;
93
+ };
94
+
95
+ #endif
96
+
97
+ static inline TEB *GetTEB()
98
+ {
99
+ #if defined(__aarch64__) || defined(_M_ARM64)
100
+ TEB *teb = (TEB *)__getReg(18);
101
+ #elif defined(__x86_64__) || defined(_M_AMD64)
102
+ TEB *teb = (TEB *)__readgsqword(0x30);
103
+ #else
104
+ TEB *teb = (TEB *)__readfsdword(0x18);
105
+ #endif
106
+
107
+ return teb;
108
+ }
109
+
110
+ #if defined(_WIN64)
111
+ #define ADJUST_TEB(Teb, Low, High) \
112
+ K_DEFER_C(base = (Teb)->StackBase, \
113
+ limit = (Teb)->StackLimit, \
114
+ dealloc = (Teb)->DeallocationStack) { \
115
+ (Teb)->StackBase = base; \
116
+ (Teb)->StackLimit = limit; \
117
+ (Teb)->DeallocationStack = dealloc; \
118
+ }; \
119
+ (Teb)->StackBase = (High); \
120
+ (Teb)->StackLimit = (Low); \
121
+ (Teb)->DeallocationStack = (Low);
122
+ #else
123
+ #define ADJUST_TEB(Teb, Low, High) \
124
+ K_DEFER_C(base = (Teb)->StackBase, \
125
+ limit = (Teb)->StackLimit, \
126
+ dealloc = (Teb)->DeallocationStack, \
127
+ seh = (Teb)->ExceptionList) { \
128
+ (Teb)->StackBase = base; \
129
+ (Teb)->StackLimit = limit; \
130
+ (Teb)->DeallocationStack = dealloc; \
131
+ (Teb)->ExceptionList = seh; \
132
+ }; \
133
+ (Teb)->StackBase = (High); \
134
+ (Teb)->StackLimit = (Low); \
135
+ (Teb)->DeallocationStack = (Low); \
136
+ (Teb)->ExceptionList = (High) - K_SIZE(SehFrame);
137
+ #endif
138
+
139
+ extern const HashMap<int, const char *> WindowsMachineNames;
140
+
141
+ void *LoadWindowsLibrary(Napi::Env env, Span<const char> path); // Returns HANDLE
142
+
143
+ int GetSelfMachine();
144
+ int GetDllMachine(const wchar_t *filename);
145
+
146
+ extern "C" int __cdecl SehHandler(void *ptr, void *, void *ctx, void *);
147
+
148
+ }
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 [Node.js API collaborators](https://github.com/nodejs/node-addon-api#collaborators)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,95 @@
1
+ # **node-addon-api module**
2
+
3
+ [![codecov](https://codecov.io/gh/nodejs/node-addon-api/branch/main/graph/badge.svg)](https://app.codecov.io/gh/nodejs/node-addon-api/tree/main)
4
+
5
+ [![NPM](https://nodei.co/npm/node-addon-api.png?downloads=true&downloadRank=true)](https://nodei.co/npm/node-addon-api/) [![NPM](https://nodei.co/npm-dl/node-addon-api.png?months=6&height=1)](https://nodei.co/npm/node-addon-api/)
6
+
7
+ This module contains **header-only C++ wrapper classes** which simplify
8
+ the use of the C based [Node-API](https://nodejs.org/dist/latest/docs/api/n-api.html)
9
+ provided by Node.js when using C++. It provides a C++ object model
10
+ and exception handling semantics with low overhead.
11
+
12
+ - [API References](doc/README.md)
13
+ - [Badges](#badges)
14
+ - [Contributing](#contributing)
15
+ - [License](#license)
16
+
17
+ ## API References
18
+
19
+ API references are available in the [doc](doc/README.md) directory.
20
+
21
+ <!-- x-release-please-start-version -->
22
+ ## Current version: 8.9.0
23
+ <!-- x-release-please-end -->
24
+
25
+ (See [CHANGELOG.md](CHANGELOG.md) for complete Changelog)
26
+
27
+ node-addon-api is based on [Node-API](https://nodejs.org/api/n-api.html) and supports using different Node-API versions.
28
+ This allows addons built with it to run with Node.js versions which support the targeted Node-API version.
29
+ **However** the node-addon-api support model is to support only the active LTS Node.js versions. This means that
30
+ every year there will be a new major which drops support for the Node.js LTS version which has gone out of service.
31
+
32
+ The oldest Node.js version supported by the current version of node-addon-api is Node.js 18.x.
33
+
34
+ ## Badges
35
+
36
+ The use of badges is recommended to indicate the minimum version of Node-API
37
+ required for the module. This helps to determine which Node.js major versions are
38
+ supported. Addon maintainers can consult the [Node-API support matrix][] to determine
39
+ which Node.js versions provide a given Node-API version. The following badges are
40
+ available:
41
+
42
+ ![Node-API v1 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v1%20Badge.svg)
43
+ ![Node-API v2 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v2%20Badge.svg)
44
+ ![Node-API v3 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v3%20Badge.svg)
45
+ ![Node-API v4 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v4%20Badge.svg)
46
+ ![Node-API v5 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v5%20Badge.svg)
47
+ ![Node-API v6 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v6%20Badge.svg)
48
+ ![Node-API v7 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v7%20Badge.svg)
49
+ ![Node-API v8 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v8%20Badge.svg)
50
+ ![Node-API v9 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v9%20Badge.svg)
51
+ ![Node-API Experimental Version Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20Experimental%20Version%20Badge.svg)
52
+
53
+ ## Contributing
54
+
55
+ We love contributions from the community to **node-addon-api**!
56
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for more details on our philosophy around extending this module.
57
+
58
+ ## Team members
59
+
60
+ ### Active
61
+
62
+ | Name | GitHub Link |
63
+ | ------------------- | ----------------------------------------------------- |
64
+ | Anna Henningsen | [addaleax](https://github.com/addaleax) |
65
+ | Chengzhong Wu | [legendecas](https://github.com/legendecas) |
66
+ | Jack Xia | [JckXia](https://github.com/JckXia) |
67
+ | Kevin Eady | [KevinEady](https://github.com/KevinEady) |
68
+ | Michael Dawson | [mhdawson](https://github.com/mhdawson) |
69
+ | Nicola Del Gobbo | [NickNaso](https://github.com/NickNaso) |
70
+ | Vladimir Morozov | [vmoroz](https://github.com/vmoroz) |
71
+
72
+ <details>
73
+
74
+ <summary>Emeritus</summary>
75
+
76
+ ### Emeritus
77
+
78
+ | Name | GitHub Link |
79
+ | ------------------- | ----------------------------------------------------- |
80
+ | Arunesh Chandra | [aruneshchandra](https://github.com/aruneshchandra) |
81
+ | Benjamin Byholm | [kkoopa](https://github.com/kkoopa) |
82
+ | Gabriel Schulhof | [gabrielschulhof](https://github.com/gabrielschulhof) |
83
+ | Hitesh Kanwathirtha | [digitalinfinity](https://github.com/digitalinfinity) |
84
+ | Jason Ginchereau | [jasongin](https://github.com/jasongin) |
85
+ | Jim Schlight | [jschlight](https://github.com/jschlight) |
86
+ | Sampson Gao | [sampsongao](https://github.com/sampsongao) |
87
+ | Taylor Woll | [boingoing](https://github.com/boingoing) |
88
+
89
+ </details>
90
+
91
+ ## License
92
+
93
+ Licensed under [MIT](./LICENSE.md)
94
+
95
+ [Node-API support matrix]: https://nodejs.org/dist/latest/docs/api/n-api.html#node-api-version-matrix