zedbee 0.1.0-beta.13 → 0.1.0-beta.14

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 (361) hide show
  1. package/SECURITY.md +2 -0
  2. package/dist/attribution/entities.d.ts.map +1 -1
  3. package/dist/attribution/entities.js +47 -68
  4. package/dist/attribution/entities.js.map +1 -1
  5. package/dist/attribution/metrics.d.ts +2 -0
  6. package/dist/attribution/metrics.d.ts.map +1 -1
  7. package/dist/attribution/metrics.js +8 -0
  8. package/dist/attribution/metrics.js.map +1 -1
  9. package/dist/attribution/pair-locations.js +1 -1
  10. package/dist/attribution/pair-locations.js.map +1 -1
  11. package/dist/attribution/source-identity.d.ts +6 -0
  12. package/dist/attribution/source-identity.d.ts.map +1 -0
  13. package/dist/attribution/source-identity.js +60 -0
  14. package/dist/attribution/source-identity.js.map +1 -0
  15. package/dist/cache/key.d.ts +6 -1
  16. package/dist/cache/key.d.ts.map +1 -1
  17. package/dist/cache/key.js +54 -21
  18. package/dist/cache/key.js.map +1 -1
  19. package/dist/cache/store.d.ts.map +1 -1
  20. package/dist/cache/store.js +7 -7
  21. package/dist/cache/store.js.map +1 -1
  22. package/dist/checks/applicability.d.ts.map +1 -1
  23. package/dist/checks/applicability.js +9 -6
  24. package/dist/checks/applicability.js.map +1 -1
  25. package/dist/checks/complexity/adapter.d.ts.map +1 -1
  26. package/dist/checks/complexity/adapter.js +61 -12
  27. package/dist/checks/complexity/adapter.js.map +1 -1
  28. package/dist/checks/complexity/pair-class-metrics.d.ts.map +1 -1
  29. package/dist/checks/complexity/pair-class-metrics.js +52 -19
  30. package/dist/checks/complexity/pair-class-metrics.js.map +1 -1
  31. package/dist/checks/dead-code/framework-entrypoints.d.ts +9 -0
  32. package/dist/checks/dead-code/framework-entrypoints.d.ts.map +1 -0
  33. package/dist/checks/dead-code/framework-entrypoints.js +47 -0
  34. package/dist/checks/dead-code/framework-entrypoints.js.map +1 -0
  35. package/dist/checks/dead-code/managed-config.d.ts +1 -0
  36. package/dist/checks/dead-code/managed-config.d.ts.map +1 -1
  37. package/dist/checks/dead-code/managed-config.js +6 -1
  38. package/dist/checks/dead-code/managed-config.js.map +1 -1
  39. package/dist/checks/dead-code/parse-report.d.ts.map +1 -1
  40. package/dist/checks/dead-code/parse-report.js +26 -23
  41. package/dist/checks/dead-code/parse-report.js.map +1 -1
  42. package/dist/checks/diagnostic-messages.d.ts +4 -0
  43. package/dist/checks/diagnostic-messages.d.ts.map +1 -0
  44. package/dist/checks/diagnostic-messages.js +50 -0
  45. package/dist/checks/diagnostic-messages.js.map +1 -0
  46. package/dist/checks/dispatch-adapter.d.ts +25 -0
  47. package/dist/checks/dispatch-adapter.d.ts.map +1 -0
  48. package/dist/checks/dispatch-adapter.js +133 -0
  49. package/dist/checks/dispatch-adapter.js.map +1 -0
  50. package/dist/checks/dispatch-cache.d.ts +9 -0
  51. package/dist/checks/dispatch-cache.d.ts.map +1 -0
  52. package/dist/checks/dispatch-cache.js +154 -0
  53. package/dist/checks/dispatch-cache.js.map +1 -0
  54. package/dist/checks/dispatch-context.d.ts +11 -0
  55. package/dist/checks/dispatch-context.d.ts.map +1 -0
  56. package/dist/checks/dispatch-context.js +155 -0
  57. package/dist/checks/dispatch-context.js.map +1 -0
  58. package/dist/checks/dispatch-target.d.ts +17 -0
  59. package/dist/checks/dispatch-target.d.ts.map +1 -0
  60. package/dist/checks/dispatch-target.js +167 -0
  61. package/dist/checks/dispatch-target.js.map +1 -0
  62. package/dist/checks/dispatcher.d.ts +3 -7
  63. package/dist/checks/dispatcher.d.ts.map +1 -1
  64. package/dist/checks/dispatcher.js +12 -642
  65. package/dist/checks/dispatcher.js.map +1 -1
  66. package/dist/checks/duplication/adapter.d.ts.map +1 -1
  67. package/dist/checks/duplication/adapter.js +44 -6
  68. package/dist/checks/duplication/adapter.js.map +1 -1
  69. package/dist/checks/duplication/clone-comparison.d.ts +6 -0
  70. package/dist/checks/duplication/clone-comparison.d.ts.map +1 -0
  71. package/dist/checks/duplication/clone-comparison.js +163 -0
  72. package/dist/checks/duplication/clone-comparison.js.map +1 -0
  73. package/dist/checks/duplication/normalize-clone.d.ts.map +1 -1
  74. package/dist/checks/duplication/normalize-clone.js +9 -0
  75. package/dist/checks/duplication/normalize-clone.js.map +1 -1
  76. package/dist/checks/duplication/source-tokens.d.ts +18 -0
  77. package/dist/checks/duplication/source-tokens.d.ts.map +1 -0
  78. package/dist/checks/duplication/source-tokens.js +68 -0
  79. package/dist/checks/duplication/source-tokens.js.map +1 -0
  80. package/dist/checks/duplication/types.d.ts +2 -0
  81. package/dist/checks/duplication/types.d.ts.map +1 -1
  82. package/dist/checks/engine-identity.d.ts.map +1 -1
  83. package/dist/checks/engine-identity.js +8 -7
  84. package/dist/checks/engine-identity.js.map +1 -1
  85. package/dist/checks/eslint/convert-message.d.ts +2 -0
  86. package/dist/checks/eslint/convert-message.d.ts.map +1 -1
  87. package/dist/checks/eslint/convert-message.js +34 -1
  88. package/dist/checks/eslint/convert-message.js.map +1 -1
  89. package/dist/checks/metadata.d.ts +4 -2
  90. package/dist/checks/metadata.d.ts.map +1 -1
  91. package/dist/checks/metadata.js +7 -4
  92. package/dist/checks/metadata.js.map +1 -1
  93. package/dist/checks/observation-result.d.ts.map +1 -1
  94. package/dist/checks/observation-result.js +24 -12
  95. package/dist/checks/observation-result.js.map +1 -1
  96. package/dist/checks/prettier/project-engine.d.ts +8 -14
  97. package/dist/checks/prettier/project-engine.d.ts.map +1 -1
  98. package/dist/checks/prettier/project-engine.js +33 -281
  99. package/dist/checks/prettier/project-engine.js.map +1 -1
  100. package/dist/checks/prettier/project-error.d.ts +7 -0
  101. package/dist/checks/prettier/project-error.d.ts.map +1 -0
  102. package/dist/checks/prettier/project-error.js +12 -0
  103. package/dist/checks/prettier/project-error.js.map +1 -0
  104. package/dist/checks/prettier/project-import-capture.d.ts +20 -0
  105. package/dist/checks/prettier/project-import-capture.d.ts.map +1 -0
  106. package/dist/checks/prettier/project-import-capture.js +173 -0
  107. package/dist/checks/prettier/project-import-capture.js.map +1 -0
  108. package/dist/checks/prettier/project-import-dependencies.d.ts +5 -0
  109. package/dist/checks/prettier/project-import-dependencies.d.ts.map +1 -0
  110. package/dist/checks/prettier/project-import-dependencies.js +84 -0
  111. package/dist/checks/prettier/project-import-dependencies.js.map +1 -0
  112. package/dist/checks/prettier/project-installation.d.ts +3 -0
  113. package/dist/checks/prettier/project-installation.d.ts.map +1 -0
  114. package/dist/checks/prettier/project-installation.js +204 -0
  115. package/dist/checks/prettier/project-installation.js.map +1 -0
  116. package/dist/checks/prettier/project-protocol.d.ts.map +1 -1
  117. package/dist/checks/prettier/project-protocol.js +15 -3
  118. package/dist/checks/prettier/project-protocol.js.map +1 -1
  119. package/dist/checks/prettier/project-snapshot-identity.d.ts +7 -0
  120. package/dist/checks/prettier/project-snapshot-identity.d.ts.map +1 -0
  121. package/dist/checks/prettier/project-snapshot-identity.js +63 -0
  122. package/dist/checks/prettier/project-snapshot-identity.js.map +1 -0
  123. package/dist/checks/prettier/project-types.d.ts +2 -0
  124. package/dist/checks/prettier/project-types.d.ts.map +1 -1
  125. package/dist/checks/prettier/project-worker.js +25 -3
  126. package/dist/checks/prettier/project-worker.js.map +1 -1
  127. package/dist/checks/prettier/project-workspace.d.ts +7 -0
  128. package/dist/checks/prettier/project-workspace.d.ts.map +1 -1
  129. package/dist/checks/prettier/project-workspace.js +101 -40
  130. package/dist/checks/prettier/project-workspace.js.map +1 -1
  131. package/dist/checks/project-inputs.d.ts.map +1 -1
  132. package/dist/checks/project-inputs.js +50 -12
  133. package/dist/checks/project-inputs.js.map +1 -1
  134. package/dist/checks/runner/process-group.d.ts.map +1 -1
  135. package/dist/checks/runner/process-group.js +30 -2
  136. package/dist/checks/runner/process-group.js.map +1 -1
  137. package/dist/checks/secrets/content.d.ts.map +1 -1
  138. package/dist/checks/secrets/content.js +19 -9
  139. package/dist/checks/secrets/content.js.map +1 -1
  140. package/dist/checks/typescript/configuration-paths.d.ts +4 -3
  141. package/dist/checks/typescript/configuration-paths.d.ts.map +1 -1
  142. package/dist/checks/typescript/configuration-paths.js +127 -58
  143. package/dist/checks/typescript/configuration-paths.js.map +1 -1
  144. package/dist/checks/typescript/convert-diagnostic.d.ts +2 -0
  145. package/dist/checks/typescript/convert-diagnostic.d.ts.map +1 -1
  146. package/dist/checks/typescript/convert-diagnostic.js +23 -5
  147. package/dist/checks/typescript/convert-diagnostic.js.map +1 -1
  148. package/dist/checks/vulnerabilities/inventory/normalize.d.ts +1 -0
  149. package/dist/checks/vulnerabilities/inventory/normalize.d.ts.map +1 -1
  150. package/dist/checks/vulnerabilities/inventory/normalize.js +5 -2
  151. package/dist/checks/vulnerabilities/inventory/normalize.js.map +1 -1
  152. package/dist/checks/vulnerabilities/inventory/parse-bun.d.ts.map +1 -1
  153. package/dist/checks/vulnerabilities/inventory/parse-bun.js +18 -7
  154. package/dist/checks/vulnerabilities/inventory/parse-bun.js.map +1 -1
  155. package/dist/checks/vulnerabilities/inventory/parse-yarn.d.ts.map +1 -1
  156. package/dist/checks/vulnerabilities/inventory/parse-yarn.js +21 -11
  157. package/dist/checks/vulnerabilities/inventory/parse-yarn.js.map +1 -1
  158. package/dist/commands/checks.d.ts +5 -2
  159. package/dist/commands/checks.d.ts.map +1 -1
  160. package/dist/commands/checks.js +18 -5
  161. package/dist/commands/checks.js.map +1 -1
  162. package/dist/commands/fix.d.ts.map +1 -1
  163. package/dist/commands/fix.js +6 -297
  164. package/dist/commands/fix.js.map +1 -1
  165. package/dist/commands/init.d.ts +4 -2
  166. package/dist/commands/init.d.ts.map +1 -1
  167. package/dist/commands/init.js +36 -379
  168. package/dist/commands/init.js.map +1 -1
  169. package/dist/commands/scan.d.ts.map +1 -1
  170. package/dist/commands/scan.js +1 -13
  171. package/dist/commands/scan.js.map +1 -1
  172. package/dist/config/load-config.d.ts.map +1 -1
  173. package/dist/config/load-config.js +6 -15
  174. package/dist/config/load-config.js.map +1 -1
  175. package/dist/config/selection-path.d.ts +7 -0
  176. package/dist/config/selection-path.d.ts.map +1 -0
  177. package/dist/config/selection-path.js +20 -0
  178. package/dist/config/selection-path.js.map +1 -0
  179. package/dist/core/check-label.d.ts +2 -0
  180. package/dist/core/check-label.d.ts.map +1 -0
  181. package/dist/core/check-label.js +19 -0
  182. package/dist/core/check-label.js.map +1 -0
  183. package/dist/core/freeze-result.d.ts +3 -0
  184. package/dist/core/freeze-result.d.ts.map +1 -0
  185. package/dist/core/freeze-result.js +10 -0
  186. package/dist/core/freeze-result.js.map +1 -0
  187. package/dist/core/immutable-map.d.ts +3 -0
  188. package/dist/core/immutable-map.d.ts.map +1 -0
  189. package/dist/core/immutable-map.js +33 -0
  190. package/dist/core/immutable-map.js.map +1 -0
  191. package/dist/core/kernel-lease.d.ts +17 -0
  192. package/dist/core/kernel-lease.d.ts.map +1 -0
  193. package/dist/core/kernel-lease.js +55 -0
  194. package/dist/core/kernel-lease.js.map +1 -0
  195. package/dist/fixes/apply-plan.d.ts.map +1 -1
  196. package/dist/fixes/apply-plan.js +2 -9
  197. package/dist/fixes/apply-plan.js.map +1 -1
  198. package/dist/fixes/build-plan.d.ts +4 -5
  199. package/dist/fixes/build-plan.d.ts.map +1 -1
  200. package/dist/fixes/build-plan.js +10 -465
  201. package/dist/fixes/build-plan.js.map +1 -1
  202. package/dist/fixes/exact-edits.d.ts +11 -1
  203. package/dist/fixes/exact-edits.d.ts.map +1 -1
  204. package/dist/fixes/exact-edits.js +101 -46
  205. package/dist/fixes/exact-edits.js.map +1 -1
  206. package/dist/fixes/plan-candidates.d.ts +8 -0
  207. package/dist/fixes/plan-candidates.d.ts.map +1 -0
  208. package/dist/fixes/plan-candidates.js +144 -0
  209. package/dist/fixes/plan-candidates.js.map +1 -0
  210. package/dist/fixes/prettier-provider.d.ts +3 -2
  211. package/dist/fixes/prettier-provider.d.ts.map +1 -1
  212. package/dist/fixes/prettier-provider.js +53 -0
  213. package/dist/fixes/prettier-provider.js.map +1 -1
  214. package/dist/fixes/public-plan.d.ts +8 -0
  215. package/dist/fixes/public-plan.d.ts.map +1 -0
  216. package/dist/fixes/public-plan.js +194 -0
  217. package/dist/fixes/public-plan.js.map +1 -0
  218. package/dist/fixes/working-preview.d.ts +18 -0
  219. package/dist/fixes/working-preview.d.ts.map +1 -0
  220. package/dist/fixes/working-preview.js +162 -0
  221. package/dist/fixes/working-preview.js.map +1 -0
  222. package/dist/git/change-set.d.ts.map +1 -1
  223. package/dist/git/change-set.js +1 -9
  224. package/dist/git/change-set.js.map +1 -1
  225. package/dist/git/client.d.ts +1 -1
  226. package/dist/git/client.d.ts.map +1 -1
  227. package/dist/git/client.js +14 -12
  228. package/dist/git/client.js.map +1 -1
  229. package/dist/init/formatter-setup.d.ts +29 -0
  230. package/dist/init/formatter-setup.d.ts.map +1 -0
  231. package/dist/init/formatter-setup.js +166 -0
  232. package/dist/init/formatter-setup.js.map +1 -0
  233. package/dist/init/import-provenance.d.ts +7 -0
  234. package/dist/init/import-provenance.d.ts.map +1 -0
  235. package/dist/init/import-provenance.js +58 -0
  236. package/dist/init/import-provenance.js.map +1 -0
  237. package/dist/init/install-dependency.d.mts +40 -0
  238. package/dist/init/install-dependency.mjs +427 -0
  239. package/dist/init/install-project.d.ts +1 -0
  240. package/dist/init/install-project.d.ts.map +1 -1
  241. package/dist/init/install-project.js +12 -31
  242. package/dist/init/install-project.js.map +1 -1
  243. package/dist/init/presentation.d.ts +54 -0
  244. package/dist/init/presentation.d.ts.map +1 -0
  245. package/dist/init/presentation.js +139 -0
  246. package/dist/init/presentation.js.map +1 -0
  247. package/dist/init/selection-policy.d.ts +29 -0
  248. package/dist/init/selection-policy.d.ts.map +1 -0
  249. package/dist/init/selection-policy.js +59 -0
  250. package/dist/init/selection-policy.js.map +1 -0
  251. package/dist/init/types.d.ts +7 -0
  252. package/dist/init/types.d.ts.map +1 -1
  253. package/dist/init/types.js.map +1 -1
  254. package/dist/init/write-config.d.ts.map +1 -1
  255. package/dist/init/write-config.js +3 -13
  256. package/dist/init/write-config.js.map +1 -1
  257. package/dist/inspection/inspect-repository.d.ts.map +1 -1
  258. package/dist/inspection/inspect-repository.js +4 -3
  259. package/dist/inspection/inspect-repository.js.map +1 -1
  260. package/dist/inspection/snapshot-registry.d.ts.map +1 -1
  261. package/dist/inspection/snapshot-registry.js +24 -2
  262. package/dist/inspection/snapshot-registry.js.map +1 -1
  263. package/dist/reporting/check-label.d.ts +1 -1
  264. package/dist/reporting/check-label.d.ts.map +1 -1
  265. package/dist/reporting/check-label.js +1 -18
  266. package/dist/reporting/check-label.js.map +1 -1
  267. package/dist/reporting/fix-plan-store.d.ts +7 -0
  268. package/dist/reporting/fix-plan-store.d.ts.map +1 -0
  269. package/dist/reporting/fix-plan-store.js +29 -0
  270. package/dist/reporting/fix-plan-store.js.map +1 -0
  271. package/dist/reporting/fix-presentation.d.ts +77 -0
  272. package/dist/reporting/fix-presentation.d.ts.map +1 -0
  273. package/dist/reporting/fix-presentation.js +262 -0
  274. package/dist/reporting/fix-presentation.js.map +1 -0
  275. package/dist/reporting/temporary-report-common.d.ts +27 -0
  276. package/dist/reporting/temporary-report-common.d.ts.map +1 -0
  277. package/dist/reporting/temporary-report-common.js +33 -0
  278. package/dist/reporting/temporary-report-common.js.map +1 -0
  279. package/dist/reporting/temporary-report-filesystem.d.ts +6 -0
  280. package/dist/reporting/temporary-report-filesystem.d.ts.map +1 -0
  281. package/dist/reporting/temporary-report-filesystem.js +124 -0
  282. package/dist/reporting/temporary-report-filesystem.js.map +1 -0
  283. package/dist/reporting/temporary-report-lifecycle.d.ts +19 -0
  284. package/dist/reporting/temporary-report-lifecycle.d.ts.map +1 -0
  285. package/dist/reporting/temporary-report-lifecycle.js +278 -0
  286. package/dist/reporting/temporary-report-lifecycle.js.map +1 -0
  287. package/dist/reporting/temporary-report-lock.d.ts +21 -0
  288. package/dist/reporting/temporary-report-lock.d.ts.map +1 -0
  289. package/dist/reporting/temporary-report-lock.js +106 -0
  290. package/dist/reporting/temporary-report-lock.js.map +1 -0
  291. package/dist/reporting/temporary-reports.d.ts +3 -24
  292. package/dist/reporting/temporary-reports.d.ts.map +1 -1
  293. package/dist/reporting/temporary-reports.js +10 -534
  294. package/dist/reporting/temporary-reports.js.map +1 -1
  295. package/dist/scan/run-scan.d.ts.map +1 -1
  296. package/dist/scan/run-scan.js +4 -12
  297. package/dist/scan/run-scan.js.map +1 -1
  298. package/dist/scan/source-excerpts.d.ts +1 -1
  299. package/dist/scan/source-excerpts.d.ts.map +1 -1
  300. package/dist/scan/source-excerpts.js +25 -27
  301. package/dist/scan/source-excerpts.js.map +1 -1
  302. package/dist/service/client-connection.d.ts +21 -0
  303. package/dist/service/client-connection.d.ts.map +1 -0
  304. package/dist/service/client-connection.js +219 -0
  305. package/dist/service/client-connection.js.map +1 -0
  306. package/dist/service/client-executor.d.ts +10 -0
  307. package/dist/service/client-executor.d.ts.map +1 -0
  308. package/dist/service/client-executor.js +69 -0
  309. package/dist/service/client-executor.js.map +1 -0
  310. package/dist/service/client-ownership.d.ts +16 -0
  311. package/dist/service/client-ownership.d.ts.map +1 -0
  312. package/dist/service/client-ownership.js +104 -0
  313. package/dist/service/client-ownership.js.map +1 -0
  314. package/dist/service/client-startup.d.ts +3 -0
  315. package/dist/service/client-startup.d.ts.map +1 -0
  316. package/dist/service/client-startup.js +123 -0
  317. package/dist/service/client-startup.js.map +1 -0
  318. package/dist/service/client.d.ts +2 -27
  319. package/dist/service/client.d.ts.map +1 -1
  320. package/dist/service/client.js +7 -490
  321. package/dist/service/client.js.map +1 -1
  322. package/dist/service/server-connection.d.ts +43 -0
  323. package/dist/service/server-connection.d.ts.map +1 -0
  324. package/dist/service/server-connection.js +327 -0
  325. package/dist/service/server-connection.js.map +1 -0
  326. package/dist/service/server.d.ts +1 -1
  327. package/dist/service/server.d.ts.map +1 -1
  328. package/dist/service/server.js +77 -343
  329. package/dist/service/server.js.map +1 -1
  330. package/dist/service/state.d.ts.map +1 -1
  331. package/dist/service/state.js +2 -25
  332. package/dist/service/state.js.map +1 -1
  333. package/dist/service/windows-pipe.d.ts +22 -14
  334. package/dist/service/windows-pipe.d.ts.map +1 -1
  335. package/dist/service/windows-pipe.js +384 -350
  336. package/dist/service/windows-pipe.js.map +1 -1
  337. package/dist/telemetry/details-store.js +1 -1
  338. package/dist/telemetry/details-store.js.map +1 -1
  339. package/dist/telemetry/schema.d.ts +5 -5
  340. package/dist/telemetry/state.d.ts +3 -2
  341. package/dist/telemetry/state.d.ts.map +1 -1
  342. package/dist/telemetry/state.js +112 -66
  343. package/dist/telemetry/state.js.map +1 -1
  344. package/dist/ui/init-app.d.ts +6 -14
  345. package/dist/ui/init-app.d.ts.map +1 -1
  346. package/dist/ui/init-app.js +39 -203
  347. package/dist/ui/init-app.js.map +1 -1
  348. package/dist/ui/init-operation.d.ts +19 -0
  349. package/dist/ui/init-operation.d.ts.map +1 -0
  350. package/dist/ui/init-operation.js +54 -0
  351. package/dist/ui/init-operation.js.map +1 -0
  352. package/dist/ui/init-view.d.ts +42 -0
  353. package/dist/ui/init-view.d.ts.map +1 -0
  354. package/dist/ui/init-view.js +199 -0
  355. package/dist/ui/init-view.js.map +1 -0
  356. package/docs/checks.md +24 -0
  357. package/docs/cli-reference.md +3 -1
  358. package/docs/managed-fixes.md +14 -0
  359. package/docs/privacy.md +22 -1
  360. package/package.json +1 -1
  361. package/plugins/swarm/references/scan.md +6 -13
@@ -1,397 +1,431 @@
1
- import koffi from "koffi";
1
+ import { createRequire } from "node:module";
2
2
  import { ServiceUnavailableError } from "./protocol.js";
3
- // Loaded only on Windows. All handles are noninherited and every descriptor is freed.
4
- const kernel = koffi.load("kernel32.dll"), security = koffi.load("advapi32.dll");
5
- const ptr = koffi.out(koffi.pointer("void *"));
6
- const uint = koffi.out(koffi.pointer("uint32"));
7
- const integer = koffi.out(koffi.pointer("int"));
8
- const close = kernel.func("int __stdcall CloseHandle(void *)");
9
- const free = kernel.func("void * __stdcall LocalFree(void *)");
10
- const errorCode = kernel.func("uint32 __stdcall GetLastError()");
11
- const open = kernel.func("void * __stdcall CreateFileW(const char16_t *, uint32, uint32, void *, uint32, uint32, void *)");
12
- const createDirectory = kernel.func("int __stdcall CreateDirectoryW(const char16_t *, void *)");
13
- const currentProcess = kernel.func("void * __stdcall GetCurrentProcess()");
14
- const openToken = security.func("__stdcall", "OpenProcessToken", "int", [
15
- "void *",
16
- "uint32",
17
- ptr,
18
- ]);
19
- const getToken = security.func("__stdcall", "GetTokenInformation", "int", [
20
- "void *",
21
- "int",
22
- "void *",
23
- "uint32",
24
- uint,
25
- ]);
26
- const sidString = security.func("__stdcall", "ConvertSidToStringSidW", "int", [
27
- "void *",
28
- ptr,
29
- ]);
30
- const parseSid = security.func("__stdcall", "ConvertStringSidToSidW", "int", [
31
- "str16",
32
- ptr,
33
- ]);
34
- const convert = security.func("__stdcall", "ConvertStringSecurityDescriptorToSecurityDescriptorW", "int", ["str16", "uint32", ptr, "void *"]);
35
- const getDacl = security.func("__stdcall", "GetSecurityDescriptorDacl", "int", [
36
- "void *",
37
- integer,
38
- ptr,
39
- integer,
40
- ]);
41
- const getSecurity = security.func("__stdcall", "GetSecurityInfo", "uint32", [
42
- "void *",
43
- "int",
44
- "uint32",
45
- ptr,
46
- "void *",
47
- ptr,
48
- "void *",
49
- ptr,
50
- ]);
51
- const setSecurity = security.func("uint32 __stdcall SetSecurityInfo(void *, int, uint32, void *, void *, void *, void *)");
52
- const getControl = security.func("__stdcall", "GetSecurityDescriptorControl", "int", ["void *", koffi.out(koffi.pointer("uint16")), uint]);
53
- const equalSid = security.func("int __stdcall EqualSid(void *, void *)");
54
- const getAce = security.func("__stdcall", "GetAce", "int", [
55
- "void *",
56
- "uint32",
57
- ptr,
58
- ]);
59
- const fileInfo = kernel.func("int __stdcall GetFileInformationByHandleEx(void *, int, void *, uint32)");
60
- const lockFile = kernel.func("int __stdcall LockFileEx(void *, uint32, uint32, uint32, uint32, void *)");
61
- const attributes = koffi.struct({
62
- length: "uint32",
63
- descriptor: "void *",
64
- inherit: "int",
65
- });
66
- const overlapped = koffi.struct({
67
- internal: "uintptr_t",
68
- internalHigh: "uintptr_t",
69
- offset: "uint32",
70
- offsetHigh: "uint32",
71
- event: "void *",
72
- });
73
- function fail() {
74
- const code = errorCode();
75
- if (code === 2 || code === 3)
76
- throw Object.assign(new ServiceUnavailableError(), { code: "ENOENT" });
77
- throw new ServiceUnavailableError();
78
- }
79
- function validHandle(handle) {
80
- return (!!handle &&
81
- koffi.address(handle) !== (1n << BigInt(koffi.sizeof("void *") * 8)) - 1n);
82
- }
83
- function checkedClose(handle) {
84
- if (!close(handle))
3
+ const require = createRequire(import.meta.url);
4
+ function loadBindings() {
5
+ const koffi = require("koffi");
6
+ // Loaded only on Windows. All handles are noninherited and every descriptor is freed.
7
+ const kernel = koffi.load("kernel32.dll"), security = koffi.load("advapi32.dll");
8
+ const ptr = koffi.out(koffi.pointer("void *"));
9
+ const uint = koffi.out(koffi.pointer("uint32"));
10
+ const integer = koffi.out(koffi.pointer("int"));
11
+ const close = kernel.func("int __stdcall CloseHandle(void *)");
12
+ const free = kernel.func("void * __stdcall LocalFree(void *)");
13
+ const errorCode = kernel.func("uint32 __stdcall GetLastError()");
14
+ const open = kernel.func("void * __stdcall CreateFileW(const char16_t *, uint32, uint32, void *, uint32, uint32, void *)");
15
+ const createDirectory = kernel.func("int __stdcall CreateDirectoryW(const char16_t *, void *)");
16
+ const currentProcess = kernel.func("void * __stdcall GetCurrentProcess()");
17
+ const openToken = security.func("__stdcall", "OpenProcessToken", "int", [
18
+ "void *",
19
+ "uint32",
20
+ ptr,
21
+ ]);
22
+ const getToken = security.func("__stdcall", "GetTokenInformation", "int", [
23
+ "void *",
24
+ "int",
25
+ "void *",
26
+ "uint32",
27
+ uint,
28
+ ]);
29
+ const sidString = security.func("__stdcall", "ConvertSidToStringSidW", "int", ["void *", ptr]);
30
+ const parseSid = security.func("__stdcall", "ConvertStringSidToSidW", "int", [
31
+ "str16",
32
+ ptr,
33
+ ]);
34
+ const convert = security.func("__stdcall", "ConvertStringSecurityDescriptorToSecurityDescriptorW", "int", ["str16", "uint32", ptr, "void *"]);
35
+ const getDacl = security.func("__stdcall", "GetSecurityDescriptorDacl", "int", ["void *", integer, ptr, integer]);
36
+ const getSecurity = security.func("__stdcall", "GetSecurityInfo", "uint32", [
37
+ "void *",
38
+ "int",
39
+ "uint32",
40
+ ptr,
41
+ "void *",
42
+ ptr,
43
+ "void *",
44
+ ptr,
45
+ ]);
46
+ const setSecurity = security.func("uint32 __stdcall SetSecurityInfo(void *, int, uint32, void *, void *, void *, void *)");
47
+ const getControl = security.func("__stdcall", "GetSecurityDescriptorControl", "int", ["void *", koffi.out(koffi.pointer("uint16")), uint]);
48
+ const equalSid = security.func("int __stdcall EqualSid(void *, void *)");
49
+ const getAce = security.func("__stdcall", "GetAce", "int", [
50
+ "void *",
51
+ "uint32",
52
+ ptr,
53
+ ]);
54
+ const fileInfo = kernel.func("int __stdcall GetFileInformationByHandleEx(void *, int, void *, uint32)");
55
+ const lockFile = kernel.func("int __stdcall LockFileEx(void *, uint32, uint32, uint32, uint32, void *)");
56
+ const attributes = koffi.struct({
57
+ length: "uint32",
58
+ descriptor: "void *",
59
+ inherit: "int",
60
+ });
61
+ const overlapped = koffi.struct({
62
+ internal: "uintptr_t",
63
+ internalHigh: "uintptr_t",
64
+ offset: "uint32",
65
+ offsetHigh: "uint32",
66
+ event: "void *",
67
+ });
68
+ function fail() {
69
+ const code = errorCode();
70
+ if (code === 2 || code === 3)
71
+ throw Object.assign(new ServiceUnavailableError(), { code: "ENOENT" });
85
72
  throw new ServiceUnavailableError();
86
- }
87
- function withIdentity(run) {
88
- const token = [null];
89
- if (!openToken(currentProcess(), 8, token))
90
- fail();
91
- try {
92
- const length = [0];
93
- getToken(token[0], 1, null, 0, length);
94
- if (errorCode() !== 122 || !length[0] || length[0] > 65536)
95
- fail();
96
- const bytes = Buffer.alloc(length[0]);
97
- if (!getToken(token[0], 1, bytes, bytes.length, length))
98
- fail();
99
- const sid = koffi.decode(bytes, "void *");
100
- const text = [null];
101
- if (!sidString(sid, text))
102
- fail();
103
- try {
104
- return run(sid, koffi.decode(text[0], "char16_t", -1));
105
- }
106
- finally {
107
- free(text[0]);
108
- }
109
73
  }
110
- finally {
111
- checkedClose(token[0]);
74
+ function validHandle(handle) {
75
+ return (!!handle &&
76
+ koffi.address(handle) !== (1n << BigInt(koffi.sizeof("void *") * 8)) - 1n);
112
77
  }
113
- }
114
- function withDescriptor(run, mode = "state") {
115
- return withIdentity((sid, text) => {
116
- const descriptor = [null];
117
- if (!convert(`O:${text}D:P${mode === "pipe" ? "(D;;FA;;;S-1-5-2)" : ""}(A;${mode === "state" ? "OICI" : ""};${mode === "job" ? "GA" : "FA"};;;${text})`, 1, descriptor, null))
78
+ function checkedClose(handle) {
79
+ if (!close(handle))
80
+ throw new ServiceUnavailableError();
81
+ }
82
+ function withIdentity(run) {
83
+ const token = [null];
84
+ if (!openToken(currentProcess(), 8, token))
118
85
  fail();
119
86
  try {
120
- const present = [0], acl = [null], defaulted = [0];
121
- if (!getDacl(descriptor[0], present, acl, defaulted) ||
122
- !present[0] ||
123
- !acl[0])
87
+ const length = [0];
88
+ getToken(token[0], 1, null, 0, length);
89
+ if (errorCode() !== 122 || !length[0] || length[0] > 65536)
90
+ fail();
91
+ const bytes = Buffer.alloc(length[0]);
92
+ if (!getToken(token[0], 1, bytes, bytes.length, length))
124
93
  fail();
125
- return run(descriptor[0], acl[0], sid);
94
+ const sid = koffi.decode(bytes, "void *");
95
+ const text = [null];
96
+ if (!sidString(sid, text))
97
+ fail();
98
+ try {
99
+ return run(sid, koffi.decode(text[0], "char16_t", -1));
100
+ }
101
+ finally {
102
+ free(text[0]);
103
+ }
126
104
  }
127
105
  finally {
128
- free(descriptor[0]);
106
+ checkedClose(token[0]);
129
107
  }
130
- });
131
- }
132
- function verify(handle, kind, pipe = false) {
133
- withIdentity((sid) => {
134
- const descriptor = [null], owner = [null], acl = [null];
135
- if (getSecurity(handle, kind, 1 | 4, owner, null, acl, null, descriptor) !== 0)
136
- throw new ServiceUnavailableError();
137
- try {
138
- const control = [0], revision = [0];
139
- if (!owner[0] ||
140
- !acl[0] ||
141
- !equalSid(owner[0], sid) ||
142
- !getControl(descriptor[0], control, revision) ||
143
- !(control[0] & 0x1000))
144
- throw new ServiceUnavailableError();
145
- const header = Buffer.from(koffi.decode(acl[0], "uint8", 8));
146
- const count = pipe ? 2 : 1;
147
- if (header.readUInt16LE(4) !== count)
148
- throw new ServiceUnavailableError();
149
- for (let index = 0; index < count; index++) {
150
- const denyNetwork = pipe && index === 0;
151
- const ace = [null];
152
- if (!getAce(acl[0], index, ace))
108
+ }
109
+ function withDescriptor(run, mode = "state") {
110
+ return withIdentity((sid, text) => {
111
+ const descriptor = [null];
112
+ if (!convert(`O:${text}D:P${mode === "pipe" ? "(D;;FA;;;S-1-5-2)" : ""}(A;${mode === "state" ? "OICI" : ""};${mode === "job" ? "GA" : "FA"};;;${text})`, 1, descriptor, null))
113
+ fail();
114
+ try {
115
+ const present = [0], acl = [null], defaulted = [0];
116
+ if (!getDacl(descriptor[0], present, acl, defaulted) ||
117
+ !present[0] ||
118
+ !acl[0])
153
119
  fail();
154
- const entry = Buffer.from(koffi.decode(ace[0], "uint8", 8));
155
- const size = entry.readUInt16LE(2), mask = entry.readUInt32LE(4);
156
- if (entry[0] !== (denyNetwork ? 1 : 0) ||
157
- (pipe ? entry[1] !== 0 : (entry[1] & ~3) !== 0) ||
158
- size < 16 ||
159
- size > 1024 ||
160
- (pipe
161
- ? mask !== 0x001f01ff
162
- : mask !== 0x001f01ff &&
163
- mask !== 0x10000000 &&
164
- mask !== 0x001f001f &&
165
- mask !== 0x001f003f))
120
+ return run(descriptor[0], acl[0], sid);
121
+ }
122
+ finally {
123
+ free(descriptor[0]);
124
+ }
125
+ });
126
+ }
127
+ function verify(handle, kind, pipe = false) {
128
+ withIdentity((sid) => {
129
+ const descriptor = [null], owner = [null], acl = [null];
130
+ if (getSecurity(handle, kind, 1 | 4, owner, null, acl, null, descriptor) !==
131
+ 0)
132
+ throw new ServiceUnavailableError();
133
+ try {
134
+ const control = [0], revision = [0];
135
+ if (!owner[0] ||
136
+ !acl[0] ||
137
+ !equalSid(owner[0], sid) ||
138
+ !getControl(descriptor[0], control, revision) ||
139
+ !(control[0] & 0x1000))
140
+ throw new ServiceUnavailableError();
141
+ const header = Buffer.from(koffi.decode(acl[0], "uint8", 8));
142
+ const count = pipe ? 2 : 1;
143
+ if (header.readUInt16LE(4) !== count)
166
144
  throw new ServiceUnavailableError();
167
- const aceBytes = Buffer.from(koffi.decode(ace[0], "uint8", size));
168
- if (denyNetwork) {
169
- const network = [null];
170
- if (!parseSid("S-1-5-2", network))
145
+ for (let index = 0; index < count; index++) {
146
+ const denyNetwork = pipe && index === 0;
147
+ const ace = [null];
148
+ if (!getAce(acl[0], index, ace))
171
149
  fail();
172
- try {
173
- if (!equalSid(aceBytes.subarray(8), network[0]))
174
- throw new ServiceUnavailableError();
175
- }
176
- finally {
177
- free(network[0]);
150
+ const entry = Buffer.from(koffi.decode(ace[0], "uint8", 8));
151
+ const size = entry.readUInt16LE(2), mask = entry.readUInt32LE(4);
152
+ if (entry[0] !== (denyNetwork ? 1 : 0) ||
153
+ (pipe ? entry[1] !== 0 : (entry[1] & ~3) !== 0) ||
154
+ size < 16 ||
155
+ size > 1024 ||
156
+ (pipe
157
+ ? mask !== 0x001f01ff
158
+ : mask !== 0x001f01ff &&
159
+ mask !== 0x10000000 &&
160
+ mask !== 0x001f001f &&
161
+ mask !== 0x001f003f))
162
+ throw new ServiceUnavailableError();
163
+ const aceBytes = Buffer.from(koffi.decode(ace[0], "uint8", size));
164
+ if (denyNetwork) {
165
+ const network = [null];
166
+ if (!parseSid("S-1-5-2", network))
167
+ fail();
168
+ try {
169
+ if (!equalSid(aceBytes.subarray(8), network[0]))
170
+ throw new ServiceUnavailableError();
171
+ }
172
+ finally {
173
+ free(network[0]);
174
+ }
178
175
  }
176
+ else if (!equalSid(aceBytes.subarray(8), sid))
177
+ throw new ServiceUnavailableError();
179
178
  }
180
- else if (!equalSid(aceBytes.subarray(8), sid))
181
- throw new ServiceUnavailableError();
182
179
  }
180
+ finally {
181
+ free(descriptor[0]);
182
+ }
183
+ });
184
+ }
185
+ function pathHandle(path, access = 0x20000 | 0x80) {
186
+ // OPEN_REPARSE_POINT inspects the lexical entry; BACKUP_SEMANTICS permits dirs.
187
+ const handle = open(path, access, 1 | 2, null, 3, 0x00200000 | 0x02000000, null);
188
+ if (!validHandle(handle))
189
+ fail();
190
+ try {
191
+ const info = Buffer.alloc(8);
192
+ if (!fileInfo(handle, 9, info, info.length) ||
193
+ info.readUInt32LE() & 0x400)
194
+ throw new ServiceUnavailableError();
195
+ return handle;
196
+ }
197
+ catch (error) {
198
+ checkedClose(handle);
199
+ throw error;
200
+ }
201
+ }
202
+ function verifyWindowsPath(path, ownerOnly) {
203
+ // Ancestors need attribute inspection, not access to their security descriptor.
204
+ const handle = pathHandle(path, ownerOnly ? 0x20000 | 0x80 : 0x80);
205
+ try {
206
+ if (ownerOnly)
207
+ verify(handle, 1);
183
208
  }
184
209
  finally {
185
- free(descriptor[0]);
210
+ checkedClose(handle);
186
211
  }
187
- });
188
- }
189
- function pathHandle(path, access = 0x20000 | 0x80) {
190
- // OPEN_REPARSE_POINT inspects the lexical entry; BACKUP_SEMANTICS permits dirs.
191
- const handle = open(path, access, 1 | 2, null, 3, 0x00200000 | 0x02000000, null);
192
- if (!validHandle(handle))
193
- fail();
194
- try {
195
- const info = Buffer.alloc(8);
196
- if (!fileInfo(handle, 9, info, info.length) || info.readUInt32LE() & 0x400)
197
- throw new ServiceUnavailableError();
198
- return handle;
199
212
  }
200
- catch (error) {
201
- checkedClose(handle);
202
- throw error;
213
+ function createWindowsDirectory(path) {
214
+ withDescriptor((descriptor) => {
215
+ const bytes = Buffer.alloc(koffi.sizeof(attributes));
216
+ koffi.encode(bytes, attributes, {
217
+ length: bytes.length,
218
+ descriptor,
219
+ inherit: 0,
220
+ });
221
+ if (!createDirectory(path, bytes) && errorCode() !== 183)
222
+ fail();
223
+ });
224
+ verifyWindowsPath(path, true);
203
225
  }
204
- }
205
- export function verifyWindowsPath(path, ownerOnly) {
206
- // Ancestors need attribute inspection, not access to their security descriptor.
207
- const handle = pathHandle(path, ownerOnly ? 0x20000 | 0x80 : 0x80);
208
- try {
209
- if (ownerOnly)
226
+ /** Only the caller's just-created exclusive unpublished metadata file. */
227
+ function restrictCreatedWindowsPath(path) {
228
+ const handle = pathHandle(path, 0x20000 | 0x40000 | 0x80000 | 0x80);
229
+ try {
230
+ withDescriptor((_descriptor, acl, owner) => {
231
+ if (setSecurity(handle, 1, 1 | 4 | 0x80000000, owner, null, acl, null) !==
232
+ 0)
233
+ throw new ServiceUnavailableError();
234
+ });
210
235
  verify(handle, 1);
236
+ }
237
+ finally {
238
+ checkedClose(handle);
239
+ }
211
240
  }
212
- finally {
213
- checkedClose(handle);
214
- }
215
- }
216
- export function createWindowsDirectory(path) {
217
- withDescriptor((descriptor) => {
218
- const bytes = Buffer.alloc(koffi.sizeof(attributes));
219
- koffi.encode(bytes, attributes, {
220
- length: bytes.length,
221
- descriptor,
222
- inherit: 0,
241
+ function openWindowsStateLease(path, create = true) {
242
+ let handle;
243
+ withDescriptor((descriptor) => {
244
+ const bytes = Buffer.alloc(koffi.sizeof(attributes));
245
+ koffi.encode(bytes, attributes, {
246
+ length: bytes.length,
247
+ descriptor,
248
+ inherit: 0,
249
+ });
250
+ handle = open(path, 0x80000000 | 0x40000000 | 0x20000, 1 | 2, bytes, create ? 4 : 3, 0x00200000, null);
223
251
  });
224
- if (!createDirectory(path, bytes) && errorCode() !== 183)
252
+ if (!validHandle(handle))
225
253
  fail();
226
- });
227
- verifyWindowsPath(path, true);
228
- }
229
- /** Only the caller's just-created exclusive unpublished metadata file. */
230
- export function restrictCreatedWindowsPath(path) {
231
- const handle = pathHandle(path, 0x20000 | 0x40000 | 0x80000 | 0x80);
232
- try {
233
- withDescriptor((_descriptor, acl, owner) => {
234
- if (setSecurity(handle, 1, 1 | 4 | 0x80000000, owner, null, acl, null) !== 0)
254
+ try {
255
+ const info = Buffer.alloc(8);
256
+ if (!fileInfo(handle, 9, info, info.length) ||
257
+ info.readUInt32LE() & 0x400)
235
258
  throw new ServiceUnavailableError();
236
- });
237
- verify(handle, 1);
238
- }
239
- finally {
240
- checkedClose(handle);
259
+ const standard = Buffer.alloc(24);
260
+ if (!fileInfo(handle, 1, standard, standard.length) ||
261
+ standard.readBigInt64LE(8) !== 0n ||
262
+ standard.readUInt32LE(16) !== 1 ||
263
+ standard[20] !== 0 ||
264
+ standard[21] !== 0)
265
+ throw new ServiceUnavailableError();
266
+ verify(handle, 1);
267
+ const overlap = Buffer.alloc(koffi.sizeof(overlapped));
268
+ let closed = false, acquired = false;
269
+ return {
270
+ acquire() {
271
+ if (closed)
272
+ throw new ServiceUnavailableError();
273
+ if (acquired)
274
+ return true;
275
+ if (lockFile(handle, 1 | 2, 0, 1, 0, overlap)) {
276
+ acquired = true;
277
+ return true;
278
+ }
279
+ if (errorCode() === 33)
280
+ return false;
281
+ throw new ServiceUnavailableError();
282
+ },
283
+ close() {
284
+ if (!closed) {
285
+ checkedClose(handle);
286
+ closed = true;
287
+ }
288
+ },
289
+ };
290
+ }
291
+ catch (error) {
292
+ if (handle)
293
+ checkedClose(handle);
294
+ throw error;
295
+ }
241
296
  }
242
- }
243
- export function openWindowsStateLease(path, create = true) {
244
- let handle;
245
- withDescriptor((descriptor) => {
246
- const bytes = Buffer.alloc(koffi.sizeof(attributes));
247
- koffi.encode(bytes, attributes, {
248
- length: bytes.length,
249
- descriptor,
250
- inherit: 0,
251
- });
252
- handle = open(path, 0x80000000 | 0x40000000 | 0x20000, 1 | 2, bytes, create ? 4 : 3, 0x00200000, null);
253
- });
254
- if (!validHandle(handle))
255
- fail();
256
- try {
257
- const info = Buffer.alloc(8);
258
- if (!fileInfo(handle, 9, info, info.length) || info.readUInt32LE() & 0x400)
259
- throw new ServiceUnavailableError();
260
- const standard = Buffer.alloc(24);
261
- if (!fileInfo(handle, 1, standard, standard.length) ||
262
- standard.readBigInt64LE(8) !== 0n ||
263
- standard.readUInt32LE(16) !== 1 ||
264
- standard[20] !== 0 ||
265
- standard[21] !== 0)
297
+ /** No Node private handle fields: open only the controlled local pipe endpoint. */
298
+ function restrictWindowsPipe(endpoint) {
299
+ if (!/^\\\\\.\\pipe\\zedbee-[a-f0-9]{64}$/u.test(endpoint))
266
300
  throw new ServiceUnavailableError();
267
- verify(handle, 1);
268
- const overlap = Buffer.alloc(koffi.sizeof(overlapped));
269
- let closed = false, acquired = false;
270
- return {
271
- acquire() {
272
- if (closed)
301
+ const handle = open(endpoint, 0x20000 | 0x40000 | 0x80000, 0, null, 3, 0, null);
302
+ if (!validHandle(handle))
303
+ fail();
304
+ try {
305
+ withDescriptor((_descriptor, acl, owner) => {
306
+ if (setSecurity(handle, 6, 1 | 4 | 0x80000000, owner, null, acl, null) !==
307
+ 0)
273
308
  throw new ServiceUnavailableError();
274
- if (acquired)
275
- return true;
276
- if (lockFile(handle, 1 | 2, 0, 1, 0, overlap)) {
277
- acquired = true;
278
- return true;
279
- }
280
- if (errorCode() === 33)
281
- return false;
282
- throw new ServiceUnavailableError();
283
- },
284
- close() {
285
- if (!closed) {
286
- checkedClose(handle);
287
- closed = true;
288
- }
289
- },
290
- };
291
- }
292
- catch (error) {
293
- if (handle)
309
+ }, "pipe");
310
+ verify(handle, 6, true);
311
+ }
312
+ finally {
294
313
  checkedClose(handle);
295
- throw error;
314
+ }
296
315
  }
297
- }
298
- /** No Node private handle fields: open only the controlled local pipe endpoint. */
299
- export function restrictWindowsPipe(endpoint) {
300
- if (!/^\\\\\.\\pipe\\zedbee-[a-f0-9]{64}$/u.test(endpoint))
301
- throw new ServiceUnavailableError();
302
- const handle = open(endpoint, 0x20000 | 0x40000 | 0x80000, 0, null, 3, 0, null);
303
- if (!validHandle(handle))
304
- fail();
305
- try {
306
- withDescriptor((_descriptor, acl, owner) => {
307
- if (setSecurity(handle, 6, 1 | 4 | 0x80000000, owner, null, acl, null) !== 0)
308
- throw new ServiceUnavailableError();
309
- }, "pipe");
310
- verify(handle, 6, true);
316
+ const createJob = kernel.func("void * __stdcall CreateJobObjectW(void *, const char16_t *)");
317
+ const openJob = kernel.func("void * __stdcall OpenJobObjectW(uint32, int, const char16_t *)");
318
+ const terminateJob = kernel.func("int __stdcall TerminateJobObject(void *, uint32)");
319
+ const accounting = koffi.struct({
320
+ totalUser: "int64",
321
+ totalKernel: "int64",
322
+ periodUser: "int64",
323
+ periodKernel: "int64",
324
+ pageFaults: "uint32",
325
+ totalProcesses: "uint32",
326
+ activeProcesses: "uint32",
327
+ terminated: "uint32",
328
+ });
329
+ const queryJob = kernel.func("int __stdcall QueryInformationJobObject(void *, int, void *, uint32, void *)");
330
+ function jobName(name) {
331
+ if (!/^Local\\zedbee-[a-f0-9]{64}$/u.test(name))
332
+ throw new ServiceUnavailableError();
311
333
  }
312
- finally {
313
- checkedClose(handle);
334
+ function createOwnedWindowsJobHandle(name) {
335
+ jobName(name);
336
+ return withDescriptor((descriptor) => {
337
+ const bytes = Buffer.alloc(koffi.sizeof(attributes));
338
+ koffi.encode(bytes, attributes, {
339
+ length: bytes.length,
340
+ descriptor,
341
+ inherit: 0,
342
+ });
343
+ const handle = createJob(bytes, name);
344
+ if (!handle)
345
+ fail();
346
+ try {
347
+ if (errorCode() === 183)
348
+ throw new ServiceUnavailableError();
349
+ verify(handle, 6);
350
+ return handle;
351
+ }
352
+ catch (error) {
353
+ checkedClose(handle);
354
+ throw error;
355
+ }
356
+ }, "job");
314
357
  }
315
- }
316
- const createJob = kernel.func("void * __stdcall CreateJobObjectW(void *, const char16_t *)");
317
- const openJob = kernel.func("void * __stdcall OpenJobObjectW(uint32, int, const char16_t *)");
318
- const terminateJob = kernel.func("int __stdcall TerminateJobObject(void *, uint32)");
319
- const accounting = koffi.struct({
320
- totalUser: "int64",
321
- totalKernel: "int64",
322
- periodUser: "int64",
323
- periodKernel: "int64",
324
- pageFaults: "uint32",
325
- totalProcesses: "uint32",
326
- activeProcesses: "uint32",
327
- terminated: "uint32",
328
- });
329
- const queryJob = kernel.func("int __stdcall QueryInformationJobObject(void *, int, void *, uint32, void *)");
330
- function jobName(name) {
331
- if (!/^Local\\zedbee-[a-f0-9]{64}$/u.test(name))
332
- throw new ServiceUnavailableError();
333
- }
334
- export function createOwnedWindowsJobHandle(name) {
335
- jobName(name);
336
- return withDescriptor((descriptor) => {
337
- const bytes = Buffer.alloc(koffi.sizeof(attributes));
338
- koffi.encode(bytes, attributes, {
339
- length: bytes.length,
340
- descriptor,
341
- inherit: 0,
342
- });
343
- const handle = createJob(bytes, name);
358
+ function openWindowsJobWitness(name) {
359
+ jobName(name);
360
+ const handle = openJob(0x20000 | 4 | 8, 0, name);
344
361
  if (!handle)
345
362
  fail();
346
363
  try {
347
- if (errorCode() === 183)
348
- throw new ServiceUnavailableError();
349
364
  verify(handle, 6);
350
- return handle;
351
365
  }
352
366
  catch (error) {
353
367
  checkedClose(handle);
354
368
  throw error;
355
369
  }
356
- }, "job");
357
- }
358
- export function openWindowsJobWitness(name) {
359
- jobName(name);
360
- const handle = openJob(0x20000 | 4 | 8, 0, name);
361
- if (!handle)
362
- fail();
363
- try {
364
- verify(handle, 6);
365
- }
366
- catch (error) {
367
- checkedClose(handle);
368
- throw error;
370
+ let closed = false;
371
+ const finish = () => {
372
+ if (!closed) {
373
+ checkedClose(handle);
374
+ closed = true;
375
+ }
376
+ };
377
+ return {
378
+ close: finish,
379
+ async stop() {
380
+ if (closed)
381
+ return;
382
+ if (!terminateJob(handle, 0x5a454442))
383
+ throw new ServiceUnavailableError();
384
+ const state = Buffer.alloc(koffi.sizeof(accounting));
385
+ while (true) {
386
+ if (!queryJob(handle, 1, state, state.length, null))
387
+ throw new ServiceUnavailableError();
388
+ if (state.readUInt32LE(koffi.offsetof(accounting, "activeProcesses")) === 0)
389
+ break;
390
+ await new Promise((resolve) => setTimeout(resolve, 20));
391
+ }
392
+ finish();
393
+ },
394
+ };
369
395
  }
370
- let closed = false;
371
- const finish = () => {
372
- if (!closed) {
373
- checkedClose(handle);
374
- closed = true;
375
- }
376
- };
377
396
  return {
378
- close: finish,
379
- async stop() {
380
- if (closed)
381
- return;
382
- if (!terminateJob(handle, 0x5a454442))
383
- throw new ServiceUnavailableError();
384
- const state = Buffer.alloc(koffi.sizeof(accounting));
385
- while (true) {
386
- if (!queryJob(handle, 1, state, state.length, null))
387
- throw new ServiceUnavailableError();
388
- if (state.readUInt32LE(koffi.offsetof(accounting, "activeProcesses")) ===
389
- 0)
390
- break;
391
- await new Promise((resolve) => setTimeout(resolve, 20));
392
- }
393
- finish();
394
- },
397
+ verifyWindowsPath,
398
+ createWindowsDirectory,
399
+ restrictCreatedWindowsPath,
400
+ openWindowsStateLease,
401
+ restrictWindowsPipe,
402
+ createOwnedWindowsJobHandle,
403
+ openWindowsJobWitness,
395
404
  };
396
405
  }
406
+ let cached;
407
+ function bindings() {
408
+ return (cached ??= loadBindings());
409
+ }
410
+ export function verifyWindowsPath(...args) {
411
+ return bindings().verifyWindowsPath(...args);
412
+ }
413
+ export function createWindowsDirectory(...args) {
414
+ return bindings().createWindowsDirectory(...args);
415
+ }
416
+ export function restrictCreatedWindowsPath(...args) {
417
+ return bindings().restrictCreatedWindowsPath(...args);
418
+ }
419
+ export function openWindowsStateLease(...args) {
420
+ return bindings().openWindowsStateLease(...args);
421
+ }
422
+ export function restrictWindowsPipe(...args) {
423
+ return bindings().restrictWindowsPipe(...args);
424
+ }
425
+ export function createOwnedWindowsJobHandle(...args) {
426
+ return bindings().createOwnedWindowsJobHandle(...args);
427
+ }
428
+ export function openWindowsJobWitness(...args) {
429
+ return bindings().openWindowsJobWitness(...args);
430
+ }
397
431
  //# sourceMappingURL=windows-pipe.js.map