@eyeauras/insight-cli 0.8.4 → 0.9.1
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/.cli-package-build.json +1 -1
- package/README.md +16 -23
- package/SKILL.md +6 -44
- package/dist/src/activity-audit.d.ts +33 -46
- package/dist/src/activity-audit.js +120 -195
- package/dist/src/analysis-default.d.ts +10 -2
- package/dist/src/analysis-default.js +62 -47
- package/dist/src/analysis-storage.d.ts +13 -13
- package/dist/src/analysis-storage.js +127 -258
- package/dist/src/artifacts.d.ts +5 -1
- package/dist/src/artifacts.js +31 -46
- package/dist/src/audit-commands.d.ts +6 -1
- package/dist/src/audit-commands.js +9 -2
- package/dist/src/audit-retention.d.ts +5 -23
- package/dist/src/audit-retention.js +37 -150
- package/dist/src/binary.js +4 -13
- package/dist/src/budgets.d.ts +2 -2
- package/dist/src/budgets.js +7 -9
- package/dist/src/capture.js +17 -30
- package/dist/src/cli.d.ts +9 -4
- package/dist/src/cli.js +288 -473
- package/dist/src/code-references.d.ts +2 -13
- package/dist/src/code-references.js +7 -99
- package/dist/src/context-diagnostics.d.ts +1 -23
- package/dist/src/context-diagnostics.js +1 -83
- package/dist/src/core/coordinator.d.ts +298 -0
- package/dist/src/core/coordinator.js +591 -0
- package/dist/src/core/layout.d.ts +51 -0
- package/dist/src/core/layout.js +55 -0
- package/dist/src/core/legacy-import.d.ts +55 -0
- package/dist/src/core/legacy-import.js +193 -0
- package/dist/src/cross-results.d.ts +3 -3
- package/dist/src/cross-results.js +4 -42
- package/dist/src/cross.js +2 -3
- package/dist/src/debugger-results.d.ts +1 -6
- package/dist/src/debugger-results.js +21 -153
- package/dist/src/debugger.d.ts +21 -11
- package/dist/src/debugger.js +106 -168
- package/dist/src/decode-results.d.ts +2 -1
- package/dist/src/decode-results.js +4 -20
- package/dist/src/diagnostic-error.d.ts +1 -1
- package/dist/src/diagnostic-error.js +4 -23
- package/dist/src/die.js +1 -23
- package/dist/src/dnspy-runtime.js +5 -12
- package/dist/src/dnspy.js +13 -28
- package/dist/src/dotnet-diagnostics.js +1 -1
- package/dist/src/extensions.d.ts +2 -3
- package/dist/src/extensions.js +14 -91
- package/dist/src/frida-worker.js +0 -20
- package/dist/src/frida.js +3 -26
- package/dist/src/function-boundaries.d.ts +2 -2
- package/dist/src/function-boundaries.js +9 -61
- package/dist/src/function-entries.d.ts +2 -2
- package/dist/src/function-entries.js +6 -36
- package/dist/src/function-inspection.d.ts +2 -2
- package/dist/src/function-inspection.js +17 -33
- package/dist/src/function-results.d.ts +1 -3
- package/dist/src/function-results.js +2 -13
- package/dist/src/hub/admin.d.ts +101 -0
- package/dist/src/hub/admin.js +314 -0
- package/dist/src/hub/autostart.d.ts +111 -0
- package/dist/src/hub/autostart.js +207 -0
- package/dist/src/hub/bundle.d.ts +33 -0
- package/dist/src/hub/bundle.js +25 -0
- package/dist/src/hub/client.d.ts +90 -0
- package/dist/src/hub/client.js +256 -0
- package/dist/src/hub/commands.d.ts +13 -0
- package/dist/src/hub/commands.js +280 -0
- package/dist/src/hub/contract.d.ts +87 -0
- package/dist/src/hub/contract.js +3 -0
- package/dist/src/hub/extensions.d.ts +41 -0
- package/dist/src/hub/extensions.js +3 -0
- package/dist/src/hub/ghidra.d.ts +70 -0
- package/dist/src/hub/ghidra.js +197 -0
- package/dist/src/hub/index.d.ts +6 -0
- package/dist/src/hub/index.js +7 -0
- package/dist/src/{work/store.d.ts → hub/ledger-store.d.ts} +57 -94
- package/dist/src/hub/ledger-store.js +919 -0
- package/dist/src/hub/ledger.d.ts +4 -0
- package/dist/src/hub/ledger.js +173 -0
- package/dist/src/hub/lock.d.ts +7 -0
- package/dist/src/hub/lock.js +53 -0
- package/dist/src/hub/repository.d.ts +45 -0
- package/dist/src/hub/repository.js +130 -0
- package/dist/src/hub/server.d.ts +86 -0
- package/dist/src/hub/server.js +414 -0
- package/dist/src/hub/settings.d.ts +36 -0
- package/dist/src/hub/settings.js +112 -0
- package/dist/src/hub/storage.d.ts +13 -0
- package/dist/src/hub/storage.js +46 -0
- package/dist/src/hub/store.d.ts +75 -0
- package/dist/src/hub/store.js +188 -0
- package/dist/src/ilspy.js +1 -1
- package/dist/src/internal-timing.d.ts +2 -9
- package/dist/src/internal-timing.js +2 -95
- package/dist/src/lldb.js +3 -15
- package/dist/src/llvm.js +0 -9
- package/dist/src/managed-heap.js +3 -7
- package/dist/src/managed-metadata.js +2 -5
- package/dist/src/memory-inputs.d.ts +1 -4
- package/dist/src/memory-inputs.js +10 -40
- package/dist/src/mitmproxy.d.ts +35 -4
- package/dist/src/mitmproxy.js +59 -40
- package/dist/src/model.d.ts +0 -73
- package/dist/src/model.js +0 -45
- package/dist/src/mutations.d.ts +1 -1
- package/dist/src/mutations.js +5 -10
- package/dist/src/native/contract.d.ts +130 -0
- package/dist/src/native/ghidra.d.ts +58 -0
- package/dist/src/native/ghidra.js +77 -0
- package/dist/src/native/host.d.ts +71 -0
- package/dist/src/native/host.js +265 -0
- package/dist/src/native/index.d.ts +13 -0
- package/dist/src/native/index.js +19 -0
- package/dist/src/native/jvm.d.ts +54 -0
- package/dist/src/native/jvm.js +47 -0
- package/dist/src/native/worker.d.ts +70 -0
- package/dist/src/native/worker.js +240 -0
- package/dist/src/native-inputs.d.ts +9 -14
- package/dist/src/native-inputs.js +22 -110
- package/dist/src/native-merge-patches.d.ts +2 -2
- package/dist/src/native-merge-patches.js +14 -14
- package/dist/src/persistent-client.js +53 -25
- package/dist/src/procmon.js +17 -31
- package/dist/src/program-files.d.ts +42 -0
- package/dist/src/program-files.js +148 -0
- package/dist/src/queries.js +2 -15
- package/dist/src/query-policy.d.ts +0 -2
- package/dist/src/query-policy.js +1 -14
- package/dist/src/research.d.ts +59 -238
- package/dist/src/research.js +212 -906
- package/dist/src/runtime-identity.d.ts +8 -0
- package/dist/src/runtime-identity.js +26 -0
- package/dist/src/runtime-manager.d.ts +1 -11
- package/dist/src/runtime-manager.js +10 -145
- package/dist/src/runtime-selection.d.ts +1 -1
- package/dist/src/runtime-selection.js +5 -37
- package/dist/src/saved-materials.js +8 -51
- package/dist/src/scripts.d.ts +1 -1
- package/dist/src/scripts.js +15 -15
- package/dist/src/sdk-contracts.js +2 -2
- package/dist/src/sdk.js +8 -8
- package/dist/src/sevenzip.js +1 -3
- package/dist/src/strace.js +0 -3
- package/dist/src/string-anchors.d.ts +2 -3
- package/dist/src/string-anchors.js +8 -101
- package/dist/src/text-window.d.ts +5 -4
- package/dist/src/text-window.js +4 -4
- package/dist/src/tool-runtime/archives.d.ts +1 -1
- package/dist/src/tool-runtime/archives.js +11 -20
- package/dist/src/tool-runtime/catalog.js +2 -5
- package/dist/src/tool-runtime/commands.js +1 -3
- package/dist/src/tool-runtime/deadline.js +2 -7
- package/dist/src/tool-runtime/definition.js +1 -31
- package/dist/src/tool-runtime/identity.js +6 -87
- package/dist/src/tool-runtime/installer.d.ts +2 -6
- package/dist/src/tool-runtime/installer.js +14 -76
- package/dist/src/tool-runtime/java-arguments.js +4 -10
- package/dist/src/tool-runtime/launch-worker.js +2 -8
- package/dist/src/tool-runtime/run.d.ts +2 -0
- package/dist/src/tool-runtime/run.js +20 -8
- package/dist/src/tool-runtime/store.d.ts +3 -3
- package/dist/src/tool-runtime/store.js +21 -83
- package/dist/src/tool-runtime/supervisor.d.ts +6 -11
- package/dist/src/tool-runtime/supervisor.js +155 -214
- package/dist/src/tool-runtime/windows-helper.d.ts +5 -0
- package/dist/src/tool-runtime/windows-helper.js +13 -0
- package/dist/src/tool-runtime/windows-job.d.ts +5 -5
- package/dist/src/tool-runtime/windows-job.js +13 -31
- package/dist/src/tshark.js +14 -27
- package/dist/src/ui-results.d.ts +3 -2
- package/dist/src/ui-results.js +16 -53
- package/dist/src/ui.d.ts +12 -13
- package/dist/src/ui.js +32 -70
- package/dist/src/version-tracking.d.ts +25 -39
- package/dist/src/version-tracking.js +70 -174
- package/dist/src/windbg.d.ts +1 -1
- package/dist/src/windbg.js +2 -8
- package/dist/src/work/client.d.ts +63 -0
- package/dist/src/work/client.js +163 -0
- package/dist/src/work/commands.d.ts +3 -1
- package/dist/src/work/commands.js +158 -184
- package/dist/src/work/dashboard.d.ts +2 -2
- package/dist/src/work/dashboard.js +7 -8
- package/dist/src/work/legacy.d.ts +8 -0
- package/dist/src/work/legacy.js +70 -0
- package/dist/src/work/model.d.ts +0 -3
- package/dist/src/work/model.js +0 -10
- package/dist/src/work/timing.d.ts +3 -3
- package/dist/src/work/timing.js +21 -25
- package/dist/src/workspace.d.ts +4 -250
- package/dist/src/workspace.js +11 -699
- package/node_modules/@eyeauras/cli-factory/README.md +6 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/cli.d.ts.map +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/cli.js +76 -28
- package/node_modules/@eyeauras/cli-factory/dist/src/cli.js.map +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/command.d.ts +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/command.d.ts.map +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/command.js +1 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/command.js.map +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/errors.d.ts +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/errors.d.ts.map +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/errors.js +18 -6
- package/node_modules/@eyeauras/cli-factory/dist/src/errors.js.map +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/file-publication.d.ts +44 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/file-publication.d.ts.map +1 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/{profile-file.js → file-publication.js} +41 -113
- package/node_modules/@eyeauras/cli-factory/dist/src/file-publication.js.map +1 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/help.d.ts +5 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/help.d.ts.map +1 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/help.js +17 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/help.js.map +1 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/index.d.ts +9 -4
- package/node_modules/@eyeauras/cli-factory/dist/src/index.d.ts.map +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/index.js +5 -2
- package/node_modules/@eyeauras/cli-factory/dist/src/index.js.map +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/json-rpc.d.ts.map +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/json-rpc.js +11 -18
- package/node_modules/@eyeauras/cli-factory/dist/src/json-rpc.js.map +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/output-write.d.ts +10 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/output-write.d.ts.map +1 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/output-write.js +69 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/output-write.js.map +1 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/output.d.ts +3 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/output.d.ts.map +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/output.js +74 -14
- package/node_modules/@eyeauras/cli-factory/dist/src/output.js.map +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/pagination.d.ts +3 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/pagination.d.ts.map +1 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/pagination.js +9 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/pagination.js.map +1 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/permissions.d.ts.map +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/permissions.js +3 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/permissions.js.map +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/stream-result.d.ts +16 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/stream-result.d.ts.map +1 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/stream-result.js +83 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/stream-result.js.map +1 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/types.d.ts +5 -0
- package/node_modules/@eyeauras/cli-factory/dist/src/types.d.ts.map +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/view.d.ts +49 -7
- package/node_modules/@eyeauras/cli-factory/dist/src/view.d.ts.map +1 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/view.js +83 -6
- package/node_modules/@eyeauras/cli-factory/dist/src/view.js.map +1 -1
- package/node_modules/@eyeauras/cli-factory/package.json +1 -1
- package/node_modules/@eyeauras/cli-factory-ipc/dist/cli-host.proto +19 -19
- package/node_modules/@eyeauras/cli-factory-ipc/dist/src/build.d.ts +7 -1
- package/node_modules/@eyeauras/cli-factory-ipc/dist/src/build.d.ts.map +1 -1
- package/node_modules/@eyeauras/cli-factory-ipc/dist/src/build.js +9 -4
- package/node_modules/@eyeauras/cli-factory-ipc/dist/src/build.js.map +1 -1
- package/node_modules/@eyeauras/cli-factory-ipc/dist/src/host.d.ts.map +1 -1
- package/node_modules/@eyeauras/cli-factory-ipc/dist/src/host.js +5 -4
- package/node_modules/@eyeauras/cli-factory-ipc/dist/src/host.js.map +1 -1
- package/node_modules/@eyeauras/cli-factory-ipc/dist/src/package-build.d.ts +11 -1
- package/node_modules/@eyeauras/cli-factory-ipc/dist/src/package-build.d.ts.map +1 -1
- package/node_modules/@eyeauras/cli-factory-ipc/dist/src/package-build.js +85 -57
- package/node_modules/@eyeauras/cli-factory-ipc/dist/src/package-build.js.map +1 -1
- package/node_modules/@eyeauras/cli-factory-ipc/package.json +2 -2
- package/package.json +4 -5
- package/references/native/InsightAnalyzerOptions.java +10 -0
- package/references/native/InsightAnchorScan.java +1 -11
- package/references/native/InsightCodeReferences.java +2 -3
- package/references/native/InsightCopyType.java +24 -0
- package/references/native/InsightFunctionBoundaries.java +0 -1
- package/references/native/InsightFunctionDatabases.java +20 -16
- package/references/native/InsightHelperCall.java +17 -0
- package/references/native/InsightHubServer.java +214 -0
- package/references/native/InsightNativeHost.java +112 -0
- package/references/native/InsightPlugins.java +0 -1
- package/references/native/InsightPythonWheels.java +3 -2
- package/references/native/InsightResearchQueries.java +3 -4
- package/references/native/InsightResearchView.java +4 -10
- package/references/native/InsightSdkFiles.java +7 -15
- package/references/native/InsightSdkScript.java +1 -4
- package/references/native/InsightSdkTools.java +36 -97
- package/references/native/InsightSdkTypes.java +13 -43
- package/references/native/InsightStringAnchors.java +1 -3
- package/references/native/InsightTraceState.java +13 -96
- package/references/native/InsightTraceTools.java +3 -5
- package/references/native/InsightVersionTracking.java +0 -6
- package/references/native/{HeadlessProgramMergeManager.java → InsightWcMerge.java} +17 -24
- package/references/native/InsightWcOps.java +449 -0
- package/references/native/InsightWcWorker.java +142 -0
- package/references/native/NATIVE-MERGE-NOTICE.txt +4 -8
- package/runtime/GhidraMCP-7.0.0.jar +0 -0
- package/runtime/managed/insight-heap/README.md +3 -3
- package/runtime/managed/insight-managed/README.md +3 -3
- package/runtime/native/binary/README.md +5 -4
- package/runtime/native/windows/DirectoryAlias.cs +24 -0
- package/runtime/native/windows/Insight.Windows.csproj +27 -0
- package/runtime/native/windows/Native.cs +36 -0
- package/runtime/native/windows/OwnedJob.cs +86 -0
- package/runtime/native/windows/Program.cs +50 -0
- package/runtime/native/windows/RegistryRedirect.cs +42 -0
- package/runtime/native/windows/insight-windows-x64.exe +0 -0
- package/runtime/native/windows/packages.lock.json +35 -0
- package/runtime/native/windows/provenance.json +17 -0
- package/runtime/research-view.provenance.json +6 -7
- package/runtime/toolbox.json +33 -114
- package/skill-bundle/insight-artifacts/SKILL.md +5 -19
- package/skill-bundle/insight-binary/SKILL.md +5 -35
- package/skill-bundle/insight-capture/SKILL.md +5 -45
- package/skill-bundle/insight-cli/SKILL.md +6 -44
- package/skill-bundle/insight-die/SKILL.md +5 -38
- package/skill-bundle/insight-dnspy/SKILL.md +5 -54
- package/skill-bundle/insight-dotnet-dump/SKILL.md +5 -35
- package/skill-bundle/insight-dotnet-stack/SKILL.md +5 -28
- package/skill-bundle/insight-dotnet-trace/SKILL.md +5 -34
- package/skill-bundle/insight-frida/SKILL.md +5 -56
- package/skill-bundle/insight-ghidra/SKILL.md +14 -113
- package/skill-bundle/insight-ilspy/SKILL.md +5 -34
- package/skill-bundle/insight-interop/SKILL.md +5 -43
- package/skill-bundle/insight-lldb/SKILL.md +5 -43
- package/skill-bundle/insight-llvm/SKILL.md +5 -45
- package/skill-bundle/insight-managed-heap/SKILL.md +5 -32
- package/skill-bundle/insight-managed-metadata/SKILL.md +5 -41
- package/skill-bundle/insight-mitmproxy/SKILL.md +5 -51
- package/skill-bundle/insight-overview/SKILL.md +5 -68
- package/skill-bundle/insight-procmon/SKILL.md +5 -38
- package/skill-bundle/insight-re/SKILL.md +10 -127
- package/skill-bundle/insight-sevenzip/SKILL.md +5 -31
- package/skill-bundle/insight-strace/SKILL.md +5 -35
- package/skill-bundle/insight-tshark/SKILL.md +5 -38
- package/skill-bundle/insight-windbg/SKILL.md +5 -35
- package/skill-bundle/manifest.json +1 -1
- package/skills/insight-artifacts/SKILL.md +5 -19
- package/skills/insight-binary/SKILL.md +5 -35
- package/skills/insight-capture/SKILL.md +5 -45
- package/skills/insight-die/SKILL.md +5 -38
- package/skills/insight-dnspy/SKILL.md +5 -54
- package/skills/insight-dotnet-dump/SKILL.md +5 -35
- package/skills/insight-dotnet-stack/SKILL.md +5 -28
- package/skills/insight-dotnet-trace/SKILL.md +5 -34
- package/skills/insight-frida/SKILL.md +5 -56
- package/skills/insight-ghidra/SKILL.md +14 -113
- package/skills/insight-ilspy/SKILL.md +5 -34
- package/skills/insight-interop/SKILL.md +5 -43
- package/skills/insight-lldb/SKILL.md +5 -43
- package/skills/insight-llvm/SKILL.md +5 -45
- package/skills/insight-managed-heap/SKILL.md +5 -32
- package/skills/insight-managed-metadata/SKILL.md +5 -41
- package/skills/insight-mitmproxy/SKILL.md +5 -51
- package/skills/insight-overview/SKILL.md +5 -68
- package/skills/insight-procmon/SKILL.md +5 -38
- package/skills/insight-re/SKILL.md +10 -127
- package/skills/insight-sevenzip/SKILL.md +5 -31
- package/skills/insight-strace/SKILL.md +5 -35
- package/skills/insight-tshark/SKILL.md +5 -38
- package/skills/insight-windbg/SKILL.md +5 -35
- package/dist/src/administration-results.d.ts +0 -1
- package/dist/src/administration-results.js +0 -84
- package/dist/src/administration.d.ts +0 -14
- package/dist/src/administration.js +0 -134
- package/dist/src/archive-contract.d.ts +0 -6
- package/dist/src/archive-contract.js +0 -108
- package/dist/src/archive.d.ts +0 -12
- package/dist/src/archive.js +0 -116
- package/dist/src/comment-effects.d.ts +0 -3
- package/dist/src/comment-effects.js +0 -55
- package/dist/src/context-credential.d.ts +0 -18
- package/dist/src/context-credential.js +0 -44
- package/dist/src/contexts.d.ts +0 -387
- package/dist/src/contexts.js +0 -2805
- package/dist/src/coordinator.d.ts +0 -41
- package/dist/src/coordinator.js +0 -160
- package/dist/src/cross-peer.d.ts +0 -20
- package/dist/src/cross-peer.js +0 -53
- package/dist/src/data-effects.d.ts +0 -3
- package/dist/src/data-effects.js +0 -103
- package/dist/src/debugger-caller.d.ts +0 -17
- package/dist/src/debugger-caller.js +0 -129
- package/dist/src/debugger-launch.d.ts +0 -2
- package/dist/src/debugger-launch.js +0 -17
- package/dist/src/debugger-supervisor.js +0 -179
- package/dist/src/directory-identity.d.ts +0 -6
- package/dist/src/directory-identity.js +0 -45
- package/dist/src/documentation-effects.d.ts +0 -5
- package/dist/src/documentation-effects.js +0 -56
- package/dist/src/function-effects.d.ts +0 -4
- package/dist/src/function-effects.js +0 -112
- package/dist/src/ghidra-processes.d.ts +0 -6
- package/dist/src/ghidra-processes.js +0 -138
- package/dist/src/ghidra.d.ts +0 -50
- package/dist/src/ghidra.js +0 -468
- package/dist/src/initial-model.d.ts +0 -7
- package/dist/src/initial-model.js +0 -115
- package/dist/src/initial-progress.d.ts +0 -4
- package/dist/src/initial-progress.js +0 -74
- package/dist/src/inline-script.d.ts +0 -15
- package/dist/src/inline-script.js +0 -61
- package/dist/src/legacy-migration.d.ts +0 -37
- package/dist/src/legacy-migration.js +0 -238
- package/dist/src/lifecycle.d.ts +0 -77
- package/dist/src/lifecycle.js +0 -315
- package/dist/src/merge.d.ts +0 -29
- package/dist/src/merge.js +0 -66
- package/dist/src/mutation-effects.d.ts +0 -4
- package/dist/src/mutation-effects.js +0 -321
- package/dist/src/native-queries.d.ts +0 -2
- package/dist/src/native-queries.js +0 -24
- package/dist/src/native-service.d.ts +0 -40
- package/dist/src/native-service.js +0 -406
- package/dist/src/projects.d.ts +0 -31
- package/dist/src/projects.js +0 -302
- package/dist/src/prototype-cli.d.ts +0 -8
- package/dist/src/prototype-cli.js +0 -155
- package/dist/src/query-results.d.ts +0 -2
- package/dist/src/query-results.js +0 -224
- package/dist/src/research-view.d.ts +0 -6
- package/dist/src/research-view.js +0 -9
- package/dist/src/sdk-files.d.ts +0 -29
- package/dist/src/sdk-files.js +0 -249
- package/dist/src/server.d.ts +0 -102
- package/dist/src/server.js +0 -663
- package/dist/src/storage-gc.d.ts +0 -23
- package/dist/src/storage-gc.js +0 -600
- package/dist/src/store.d.ts +0 -33
- package/dist/src/store.js +0 -178
- package/dist/src/sync-policy.d.ts +0 -22
- package/dist/src/sync-policy.js +0 -129
- package/dist/src/timed-backend.d.ts +0 -3
- package/dist/src/timed-backend.js +0 -24
- package/dist/src/timing-report.d.ts +0 -32
- package/dist/src/timing-report.js +0 -74
- package/dist/src/tool-runtime/native-process-proof.d.ts +0 -2
- package/dist/src/tool-runtime/native-process-proof.js +0 -26
- package/dist/src/transport.d.ts +0 -60
- package/dist/src/transport.js +0 -223
- package/dist/src/unresolved-guidance.d.ts +0 -46
- package/dist/src/unresolved-guidance.js +0 -55
- package/dist/src/work/backup.d.ts +0 -66
- package/dist/src/work/backup.js +0 -446
- package/dist/src/work/store.js +0 -1107
- package/dist/src/worker-lease.d.ts +0 -17
- package/dist/src/worker-lease.js +0 -50
- package/node_modules/@eyeauras/cli-factory/dist/src/profile-file.d.ts +0 -37
- package/node_modules/@eyeauras/cli-factory/dist/src/profile-file.d.ts.map +0 -1
- package/node_modules/@eyeauras/cli-factory/dist/src/profile-file.js.map +0 -1
- package/references/InsightRepositoryProbe.java +0 -55
- package/references/administration.md +0 -34
- package/references/agent-execution.md +0 -36
- package/references/agent-setup.md +0 -60
- package/references/archive.md +0 -32
- package/references/artifacts.md +0 -52
- package/references/debugger.md +0 -64
- package/references/extensions-and-sync.md +0 -125
- package/references/ilspy.md +0 -33
- package/references/managed-runtime.md +0 -162
- package/references/native/InsightArchivePayloads.java +0 -36
- package/references/native/InsightBlockTransfer.java +0 -57
- package/references/native/InsightGuiMain.java +0 -33
- package/references/native/InsightHeadlessMain.java +0 -18
- package/references/native/InsightImportProgress.java +0 -60
- package/references/native/InsightInitialImport.java +0 -48
- package/references/native/InsightInitialJournal.java +0 -57
- package/references/native/InsightInitialPublication.java +0 -142
- package/references/native/InsightInitialRecovery.java +0 -131
- package/references/native/InsightInlineExecutor.java +0 -143
- package/references/native/InsightInlineScript.java +0 -14
- package/references/native/InsightNativeCheckout.java +0 -487
- package/references/native/InsightNativeFingerprint.java +0 -80
- package/references/native/InsightNativeMigration.java +0 -155
- package/references/native/InsightNativeRead.java +0 -80
- package/references/native/InsightNativeReceipt.java +0 -31
- package/references/native/InsightNativeService.java +0 -43
- package/references/native/InsightNativeView.java +0 -40
- package/references/native/InsightOfflineAuthenticator.java +0 -20
- package/references/native/InsightOwnedScripts.java +0 -170
- package/references/native/InsightProjectFiles.java +0 -92
- package/references/native/InsightPublicationRecovery.java +0 -63
- package/references/native/InsightServerAdministration.java +0 -82
- package/references/native/InsightServerInit.java +0 -62
- package/references/native/InsightServerMain.java +0 -43
- package/references/native/InsightServerProbe.java +0 -29
- package/references/native/InsightSnapshotFields.java +0 -74
- package/references/native/InsightSnapshotInspect.java +0 -191
- package/references/native/InsightSnapshotPublisher.java +0 -123
- package/references/native/InsightStopDebugger.java +0 -20
- package/references/native/InsightTraceInspect.java +0 -24
- package/references/native/InsightWorkerLease.java +0 -132
- package/references/native-workflows.md +0 -124
- package/references/persistent-client.mjs +0 -147
- package/references/persistent.md +0 -90
- package/references/query-semantics.md +0 -109
- package/references/recovery.md +0 -235
- package/references/research.md +0 -296
- package/references/setup.md +0 -135
- package/references/sparse-navigation.md +0 -173
- package/references/storage.md +0 -139
- package/references/work-tracking.md +0 -261
- package/runtime/native/file-version.ps1 +0 -7
- package/runtime/native/mitmproxy/bridge.py +0 -180
- package/runtime/native/windows-job/DirectoryAlias.cs +0 -24
- package/runtime/native/windows-job/Insight.WindowsJob.csproj +0 -1
- package/runtime/native/windows-job/Insight.WindowsJob.dll +0 -0
- package/runtime/native/windows-job/OwnedJob.cs +0 -79
- package/runtime/native/windows-job/RegistryRedirect.cs +0 -45
- package/runtime/native/windows-job/packages.lock.json +0 -21
- package/runtime/native/windows-job/provenance.json +0 -16
- package/runtime/native/windows-job/windows-job.ps1 +0 -8
- package/skill-bundle/insight-artifacts/references/agent-execution.md +0 -36
- package/skill-bundle/insight-artifacts/references/artifacts.md +0 -52
- package/skill-bundle/insight-artifacts/references/recovery.md +0 -235
- package/skill-bundle/insight-artifacts/references/storage.md +0 -139
- package/skill-bundle/insight-binary/references/agent-execution.md +0 -36
- package/skill-bundle/insight-capture/references/agent-execution.md +0 -36
- package/skill-bundle/insight-cli/references/agent-execution.md +0 -36
- package/skill-bundle/insight-cli/references/agent-setup.md +0 -60
- package/skill-bundle/insight-cli/references/archive.md +0 -32
- package/skill-bundle/insight-cli/references/managed-runtime.md +0 -162
- package/skill-bundle/insight-cli/references/persistent-client.mjs +0 -147
- package/skill-bundle/insight-cli/references/persistent.md +0 -90
- package/skill-bundle/insight-cli/references/recovery.md +0 -235
- package/skill-bundle/insight-cli/references/setup.md +0 -135
- package/skill-bundle/insight-cli/references/storage.md +0 -139
- package/skill-bundle/insight-die/references/agent-execution.md +0 -36
- package/skill-bundle/insight-dnspy/references/agent-execution.md +0 -36
- package/skill-bundle/insight-dotnet-dump/references/agent-execution.md +0 -36
- package/skill-bundle/insight-dotnet-stack/references/agent-execution.md +0 -36
- package/skill-bundle/insight-dotnet-trace/references/agent-execution.md +0 -36
- package/skill-bundle/insight-frida/references/agent-execution.md +0 -36
- package/skill-bundle/insight-ghidra/references/administration.md +0 -34
- package/skill-bundle/insight-ghidra/references/agent-execution.md +0 -36
- package/skill-bundle/insight-ghidra/references/archive.md +0 -32
- package/skill-bundle/insight-ghidra/references/artifacts.md +0 -52
- package/skill-bundle/insight-ghidra/references/debugger.md +0 -64
- package/skill-bundle/insight-ghidra/references/extensions-and-sync.md +0 -125
- package/skill-bundle/insight-ghidra/references/managed-runtime.md +0 -162
- package/skill-bundle/insight-ghidra/references/native-workflows.md +0 -124
- package/skill-bundle/insight-ghidra/references/persistent-client.mjs +0 -147
- package/skill-bundle/insight-ghidra/references/persistent.md +0 -90
- package/skill-bundle/insight-ghidra/references/query-semantics.md +0 -109
- package/skill-bundle/insight-ghidra/references/recovery.md +0 -235
- package/skill-bundle/insight-ghidra/references/research.md +0 -296
- package/skill-bundle/insight-ghidra/references/setup.md +0 -135
- package/skill-bundle/insight-ghidra/references/sparse-navigation.md +0 -173
- package/skill-bundle/insight-ghidra/references/storage.md +0 -139
- package/skill-bundle/insight-ilspy/references/agent-execution.md +0 -36
- package/skill-bundle/insight-ilspy/references/ilspy.md +0 -33
- package/skill-bundle/insight-interop/references/agent-execution.md +0 -36
- package/skill-bundle/insight-lldb/references/agent-execution.md +0 -36
- package/skill-bundle/insight-llvm/references/agent-execution.md +0 -36
- package/skill-bundle/insight-managed-heap/references/agent-execution.md +0 -36
- package/skill-bundle/insight-managed-metadata/references/agent-execution.md +0 -36
- package/skill-bundle/insight-mitmproxy/references/agent-execution.md +0 -36
- package/skill-bundle/insight-overview/references/agent-execution.md +0 -36
- package/skill-bundle/insight-procmon/references/agent-execution.md +0 -36
- package/skill-bundle/insight-re/references/agent-execution.md +0 -36
- package/skill-bundle/insight-re/references/artifacts.md +0 -52
- package/skill-bundle/insight-re/references/persistent-client.mjs +0 -147
- package/skill-bundle/insight-re/references/persistent.md +0 -90
- package/skill-bundle/insight-re/references/recovery.md +0 -235
- package/skill-bundle/insight-re/references/storage.md +0 -139
- package/skill-bundle/insight-re/references/work-tracking.md +0 -261
- package/skill-bundle/insight-sevenzip/references/agent-execution.md +0 -36
- package/skill-bundle/insight-strace/references/agent-execution.md +0 -36
- package/skill-bundle/insight-tshark/references/agent-execution.md +0 -36
- package/skill-bundle/insight-windbg/references/agent-execution.md +0 -36
- package/skills/insight-artifacts/references/agent-execution.md +0 -36
- package/skills/insight-artifacts/references/artifacts.md +0 -52
- package/skills/insight-artifacts/references/recovery.md +0 -235
- package/skills/insight-artifacts/references/storage.md +0 -139
- package/skills/insight-binary/references/agent-execution.md +0 -36
- package/skills/insight-capture/references/agent-execution.md +0 -36
- package/skills/insight-die/references/agent-execution.md +0 -36
- package/skills/insight-dnspy/references/agent-execution.md +0 -36
- package/skills/insight-dotnet-dump/references/agent-execution.md +0 -36
- package/skills/insight-dotnet-stack/references/agent-execution.md +0 -36
- package/skills/insight-dotnet-trace/references/agent-execution.md +0 -36
- package/skills/insight-frida/references/agent-execution.md +0 -36
- package/skills/insight-ghidra/references/administration.md +0 -34
- package/skills/insight-ghidra/references/agent-execution.md +0 -36
- package/skills/insight-ghidra/references/archive.md +0 -32
- package/skills/insight-ghidra/references/artifacts.md +0 -52
- package/skills/insight-ghidra/references/debugger.md +0 -64
- package/skills/insight-ghidra/references/extensions-and-sync.md +0 -125
- package/skills/insight-ghidra/references/managed-runtime.md +0 -162
- package/skills/insight-ghidra/references/native-workflows.md +0 -124
- package/skills/insight-ghidra/references/persistent-client.mjs +0 -147
- package/skills/insight-ghidra/references/persistent.md +0 -90
- package/skills/insight-ghidra/references/query-semantics.md +0 -109
- package/skills/insight-ghidra/references/recovery.md +0 -235
- package/skills/insight-ghidra/references/research.md +0 -296
- package/skills/insight-ghidra/references/setup.md +0 -135
- package/skills/insight-ghidra/references/sparse-navigation.md +0 -173
- package/skills/insight-ghidra/references/storage.md +0 -139
- package/skills/insight-ilspy/references/agent-execution.md +0 -36
- package/skills/insight-ilspy/references/ilspy.md +0 -33
- package/skills/insight-interop/references/agent-execution.md +0 -36
- package/skills/insight-lldb/references/agent-execution.md +0 -36
- package/skills/insight-llvm/references/agent-execution.md +0 -36
- package/skills/insight-managed-heap/references/agent-execution.md +0 -36
- package/skills/insight-managed-metadata/references/agent-execution.md +0 -36
- package/skills/insight-mitmproxy/references/agent-execution.md +0 -36
- package/skills/insight-overview/references/agent-execution.md +0 -36
- package/skills/insight-procmon/references/agent-execution.md +0 -36
- package/skills/insight-re/references/agent-execution.md +0 -36
- package/skills/insight-re/references/artifacts.md +0 -52
- package/skills/insight-re/references/persistent-client.mjs +0 -147
- package/skills/insight-re/references/persistent.md +0 -90
- package/skills/insight-re/references/recovery.md +0 -235
- package/skills/insight-re/references/storage.md +0 -139
- package/skills/insight-re/references/work-tracking.md +0 -261
- package/skills/insight-sevenzip/references/agent-execution.md +0 -36
- package/skills/insight-strace/references/agent-execution.md +0 -36
- package/skills/insight-tshark/references/agent-execution.md +0 -36
- package/skills/insight-windbg/references/agent-execution.md +0 -36
- /package/dist/src/{debugger-supervisor.d.ts → native/contract.js} +0 -0
- /package/runtime/native/{windows-job → windows}/NuGet.Config +0 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
// The hub process (`hub run`): HTTP API from contract.ts over hub.db, blobs/ and a Ghidra Server child.
|
|
2
|
+
import { currentIdentity } from '../runtime-identity.js';
|
|
3
|
+
import { createServer } from 'node:http';
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import { mkdir } from 'node:fs/promises';
|
|
6
|
+
import { CliError } from '@eyeauras/cli-factory';
|
|
7
|
+
import { GHIDRA_IDLE_STOP_MS, HUB_API_VERSION, HUB_IDLE_EXIT_MS, ghidraBasePort, hubPaths } from '../core/layout.js';
|
|
8
|
+
import { packageVersion } from '../package-version.js';
|
|
9
|
+
import { acquireHubLock } from './lock.js';
|
|
10
|
+
import { BlobStore, HubStore, isSha256, projectName } from './store.js';
|
|
11
|
+
import { GhidraChild } from './ghidra.js';
|
|
12
|
+
import { hubError, invalid, listenAddress, localDialHost } from './settings.js';
|
|
13
|
+
import { hubExtensionFactories } from './extensions.js';
|
|
14
|
+
import { adminRoute, gate } from './admin.js';
|
|
15
|
+
/** Contract codes plus 'hub.frozen' (project frozen for a move) and 'hub.moved' (project tombstone). */
|
|
16
|
+
const statusOf = { 'hub.invalid': 400, 'hub.not_found': 404, 'hub.runtime_mismatch': 409, 'hub.runtime_missing': 409, 'hub.incompatible': 409, 'hub.unavailable': 503,
|
|
17
|
+
'hub.frozen': 409, 'hub.moved': 410 };
|
|
18
|
+
/** Hub project ids (HubStore.newProject, bundles and legacy imports): only such path segments are looked up as projects. */
|
|
19
|
+
const projectIdPattern = /^[a-f0-9]{32}$/;
|
|
20
|
+
const loopback = (address) => !!address && /^(?:127\.|::1$|::ffff:127\.)/.test(address);
|
|
21
|
+
/** Addresses a hub on `listen` binds: the configured one and the loopback of its family, where local clients dial (settings.ts localDialHost). */
|
|
22
|
+
export function hubAddresses(listen) {
|
|
23
|
+
const local = localDialHost(listen);
|
|
24
|
+
return listen === 'localhost' || listen === local ? [local] : [listen, local];
|
|
25
|
+
}
|
|
26
|
+
export class Hub {
|
|
27
|
+
o;
|
|
28
|
+
lock;
|
|
29
|
+
store;
|
|
30
|
+
extensions;
|
|
31
|
+
blobs;
|
|
32
|
+
ghidra;
|
|
33
|
+
waitingForAddress = false;
|
|
34
|
+
servers = [];
|
|
35
|
+
lastRequest = Date.now();
|
|
36
|
+
/** Requests in progress (a long blob transfer counts until its response closes). */
|
|
37
|
+
active = 0;
|
|
38
|
+
timer;
|
|
39
|
+
bindTimer;
|
|
40
|
+
stopped;
|
|
41
|
+
resolveDone;
|
|
42
|
+
/** Resolves after shutdown completed. */
|
|
43
|
+
done = new Promise(resolve => { this.resolveDone = resolve; });
|
|
44
|
+
projectQueue = Promise.resolve();
|
|
45
|
+
log;
|
|
46
|
+
constructor(o, lock) {
|
|
47
|
+
this.o = o;
|
|
48
|
+
this.lock = lock;
|
|
49
|
+
this.log = o.log ?? (m => process.stderr.write(new Date().toISOString() + ' ' + m + '\n'));
|
|
50
|
+
this.store = new HubStore(o.dataRoot);
|
|
51
|
+
this.blobs = new BlobStore(o.dataRoot);
|
|
52
|
+
this.extensions = hubExtensionFactories.map(f => f({ db: this.store.db, dataRoot: o.dataRoot })).filter((e) => !!e);
|
|
53
|
+
const child = { dataRoot: o.dataRoot, host: o.listen, port: ghidraBasePort(o.port), log: this.log,
|
|
54
|
+
frozen: () => this.store.projects().filter(p => this.store.projectState(p.id).state !== 'active').map(p => p.repository) };
|
|
55
|
+
this.ghidra = o.ghidraChild?.(child) ?? new GhidraChild(child);
|
|
56
|
+
const recorded = this.store.runtime();
|
|
57
|
+
// A recorded runtime whose Java is gone (uninstalled) no longer binds the hub; the next local client offers its own.
|
|
58
|
+
if (recorded && o.javaExists !== false && !(o.javaExists ?? existsSync)(recorded.java))
|
|
59
|
+
this.log(`Recorded Ghidra runtime ${recorded.fingerprint} is no longer installed (${recorded.java}).`);
|
|
60
|
+
else if (recorded)
|
|
61
|
+
this.ghidra.runtime = { ...recorded, fingerprint: currentIdentity(recorded) };
|
|
62
|
+
if (!this.ghidra.runtime && o.runtime)
|
|
63
|
+
this.adopt(o.runtime);
|
|
64
|
+
}
|
|
65
|
+
/** Records the runtime the hub runs Ghidra Server with; only while it has none, or on an explicit replacement. */
|
|
66
|
+
adopt(runtime) {
|
|
67
|
+
this.ghidra.runtime = { java: runtime.java, ghidraHome: runtime.ghidraHome, fingerprint: runtime.fingerprint };
|
|
68
|
+
this.store.setRuntime(this.ghidra.runtime);
|
|
69
|
+
this.log(`Ghidra runtime ${runtime.fingerprint} (${runtime.ghidraHome}).`);
|
|
70
|
+
}
|
|
71
|
+
/** Explicit runtime replacement from a local caller (`hub config set --runtime profile`): Ghidra Server must be free. */
|
|
72
|
+
async replaceRuntime(body) {
|
|
73
|
+
const value = (name) => { const v = body[name]; if (typeof v !== 'string' || !v)
|
|
74
|
+
invalid(name + ' is required.'); return v; };
|
|
75
|
+
const next = { java: value('java'), ghidraHome: value('ghidraHome'), fingerprint: value('fingerprint') }, previous = this.ghidra.runtime?.fingerprint ?? null;
|
|
76
|
+
if (previous === next.fingerprint && this.ghidra.runtime?.java === next.java && this.ghidra.runtime.ghidraHome === next.ghidraHome)
|
|
77
|
+
return { runtime: next, previous, changed: false };
|
|
78
|
+
if (this.ghidra.running && this.ghidra.clients > 0)
|
|
79
|
+
throw hubError('hub.unavailable', `Ghidra Server has ${this.ghidra.clients} connected client(s); switch the runtime when they are done.`);
|
|
80
|
+
await this.ghidra.stop();
|
|
81
|
+
this.adopt(next);
|
|
82
|
+
return { runtime: next, previous, changed: true };
|
|
83
|
+
}
|
|
84
|
+
/** Takes hub.lock and starts serving; fails when another hub owns the data root. */
|
|
85
|
+
static async start(o) {
|
|
86
|
+
o = { ...o, listen: listenAddress(o.listen) };
|
|
87
|
+
await mkdir(o.dataRoot, { recursive: true });
|
|
88
|
+
const lock = await acquireHubLock(hubPaths(o.dataRoot).lock);
|
|
89
|
+
if (!lock)
|
|
90
|
+
throw hubError('hub.unavailable', 'Another hub already runs on data root ' + o.dataRoot + '.');
|
|
91
|
+
let hub;
|
|
92
|
+
try {
|
|
93
|
+
hub = new Hub(o, lock);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
lock.release();
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
await hub.bind();
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
for (const s of hub.servers)
|
|
104
|
+
s.close();
|
|
105
|
+
hub.store.close();
|
|
106
|
+
lock.release();
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
const idle = Math.min(o.idleExitMs ?? HUB_IDLE_EXIT_MS, o.ghidraIdleStopMs ?? GHIDRA_IDLE_STOP_MS);
|
|
110
|
+
hub.timer = setInterval(() => void hub.tick().catch(e => hub.log('Idle check failed: ' + e.message)), Math.max(50, Math.min(60_000, Math.floor(idle / 4))));
|
|
111
|
+
hub.log(`Hub ${hub.store.hubId} ${hub.version} on ${o.listen}:${o.port}, data root ${o.dataRoot}.`);
|
|
112
|
+
return hub;
|
|
113
|
+
}
|
|
114
|
+
get version() { return this.o.version ?? packageVersion; }
|
|
115
|
+
addresses() { return hubAddresses(this.o.listen); }
|
|
116
|
+
listenOn(address) {
|
|
117
|
+
return new Promise((resolve, reject) => {
|
|
118
|
+
// No overall request timeout: a long blob upload is not cut; headers still arrive within a minute.
|
|
119
|
+
const server = createServer({ requestTimeout: 0, headersTimeout: 60_000 }, (q, s) => void this.handle(q, s));
|
|
120
|
+
server.once('error', reject);
|
|
121
|
+
server.listen(this.o.port, address, () => { server.off('error', reject); resolve(server); });
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
async bind() {
|
|
125
|
+
const [primary, ...others] = this.addresses();
|
|
126
|
+
for (const address of others)
|
|
127
|
+
this.servers.push(await this.listenOn(address));
|
|
128
|
+
try {
|
|
129
|
+
this.servers.push(await this.listenOn(primary));
|
|
130
|
+
this.waitingForAddress = false;
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
const code = error.code;
|
|
134
|
+
if (code !== 'EADDRNOTAVAIL' || !others.length)
|
|
135
|
+
throw error;
|
|
136
|
+
if (!this.waitingForAddress)
|
|
137
|
+
this.log(`Listen address ${primary} is not available yet; retrying.`);
|
|
138
|
+
this.waitingForAddress = true;
|
|
139
|
+
this.bindTimer = setTimeout(() => void this.retryBind(primary), 2000);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async retryBind(address) {
|
|
143
|
+
if (this.stopped)
|
|
144
|
+
return;
|
|
145
|
+
try {
|
|
146
|
+
this.servers.push(await this.listenOn(address));
|
|
147
|
+
this.waitingForAddress = false;
|
|
148
|
+
this.log(`Listening on ${address}:${this.o.port}.`);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
this.bindTimer = setTimeout(() => void this.retryBind(address), 2000);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
status() {
|
|
155
|
+
const r = this.ghidra.runtime;
|
|
156
|
+
return { hubId: this.store.hubId, version: this.version, apiVersion: HUB_API_VERSION, dataRoot: this.o.dataRoot, pid: process.pid, listen: this.o.listen, port: this.o.port,
|
|
157
|
+
waitingForAddress: this.waitingForAddress,
|
|
158
|
+
// Not in HubStatus: other requests in progress besides the asking one; a version restart waits for none.
|
|
159
|
+
...{ activeRequests: Math.max(0, this.active - 1) },
|
|
160
|
+
ghidra: { running: this.ghidra.running, host: this.o.listen, port: ghidraBasePort(this.o.port), runtimeFingerprint: r?.fingerprint ?? null,
|
|
161
|
+
// Not in HubStatus: connected Ghidra clients, used by clients to decide whether a version restart is safe.
|
|
162
|
+
...{ clients: this.ghidra.clients } } };
|
|
163
|
+
}
|
|
164
|
+
/** Idle decisions: Ghidra Server stops without clients; the hub exits unless the OS has an autostart registration. */
|
|
165
|
+
async tick(now = Date.now()) {
|
|
166
|
+
if (this.stopped)
|
|
167
|
+
return;
|
|
168
|
+
if (this.ghidra.running && this.ghidra.clients === 0 && now - this.ghidra.lastActive >= (this.o.ghidraIdleStopMs ?? GHIDRA_IDLE_STOP_MS)) {
|
|
169
|
+
this.log('Ghidra Server idle; stopping it.');
|
|
170
|
+
await this.ghidra.stop();
|
|
171
|
+
}
|
|
172
|
+
// Idle means no request in progress and none for the idle period.
|
|
173
|
+
if (this.active > 0) {
|
|
174
|
+
this.lastRequest = now;
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (this.ghidra.running || this.ghidra.pid !== undefined || now - this.lastRequest < (this.o.idleExitMs ?? HUB_IDLE_EXIT_MS))
|
|
178
|
+
return;
|
|
179
|
+
if (await this.o.autostartRegistered()) {
|
|
180
|
+
this.lastRequest = now;
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
this.log('Hub idle and not registered for autostart; exiting.');
|
|
184
|
+
await this.shutdown();
|
|
185
|
+
}
|
|
186
|
+
shutdown() {
|
|
187
|
+
return this.stopped ??= (async () => {
|
|
188
|
+
clearInterval(this.timer);
|
|
189
|
+
clearTimeout(this.bindTimer);
|
|
190
|
+
try {
|
|
191
|
+
await this.ghidra.stop();
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
this.log('Stopping Ghidra Server failed: ' + error.message);
|
|
195
|
+
}
|
|
196
|
+
await Promise.all(this.servers.map(s => new Promise(r => { s.close(r); s.closeAllConnections(); })));
|
|
197
|
+
for (const e of this.extensions)
|
|
198
|
+
try {
|
|
199
|
+
e.close?.();
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
this.log('Closing extension ' + e.prefix + ' failed: ' + error.message);
|
|
203
|
+
}
|
|
204
|
+
this.store.close();
|
|
205
|
+
this.lock.release();
|
|
206
|
+
this.log('Hub stopped.');
|
|
207
|
+
this.resolveDone();
|
|
208
|
+
})();
|
|
209
|
+
}
|
|
210
|
+
async ensureGhidra(body, remote) {
|
|
211
|
+
const fingerprint = body.runtimeFingerprint;
|
|
212
|
+
if (typeof fingerprint !== 'string' || !fingerprint)
|
|
213
|
+
invalid('runtimeFingerprint is required.');
|
|
214
|
+
if (this.waitingForAddress)
|
|
215
|
+
throw hubError('hub.unavailable', `Listen address ${this.o.listen} is not available yet; Ghidra Server cannot bind it.`);
|
|
216
|
+
const current = this.ghidra.runtime;
|
|
217
|
+
if (current && current.fingerprint !== fingerprint)
|
|
218
|
+
// Never switched silently: other machines work against this runtime.
|
|
219
|
+
throw hubError('hub.runtime_mismatch', `Hub Ghidra runtime ${current.fingerprint} differs from the client runtime ${fingerprint}. ` +
|
|
220
|
+
'Use the hub runtime on this machine, or switch the hub on its own machine with `insight-cli hub config set --runtime profile`.');
|
|
221
|
+
if (!current) {
|
|
222
|
+
// A hub without a runtime adopts the one a local client offers; paths of remote machines mean nothing here.
|
|
223
|
+
const offered = typeof body.java === 'string' && !!body.java && typeof body.ghidraHome === 'string' && !!body.ghidraHome && loopback(remote);
|
|
224
|
+
if (!offered)
|
|
225
|
+
throw hubError('hub.runtime_missing', `The hub has no Ghidra runtime yet and the client runtime ${fingerprint} cannot be used remotely; run an insight-cli Ghidra command on the hub machine first.`);
|
|
226
|
+
this.adopt({ java: String(body.java), ghidraHome: String(body.ghidraHome), fingerprint: fingerprint });
|
|
227
|
+
}
|
|
228
|
+
await this.ghidra.ensure();
|
|
229
|
+
return { host: this.o.listen, port: ghidraBasePort(this.o.port), runtimeFingerprint: fingerprint };
|
|
230
|
+
}
|
|
231
|
+
createProject(name) {
|
|
232
|
+
const task = this.projectQueue.then(async () => {
|
|
233
|
+
const existing = this.store.projectByName(name);
|
|
234
|
+
if (existing)
|
|
235
|
+
return existing;
|
|
236
|
+
// The repository exists before the row that refers to it.
|
|
237
|
+
const project = HubStore.newProject(name);
|
|
238
|
+
await this.ghidra.createRepository(project.repository);
|
|
239
|
+
return this.store.insertProject(project);
|
|
240
|
+
});
|
|
241
|
+
this.projectQueue = task.catch(() => { });
|
|
242
|
+
return task;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Changes that add blob references (target registration, extension writes) run concurrently (shared); hub gc's blob
|
|
246
|
+
* removal runs alone (exclusive). SQLite serializes the writes themselves.
|
|
247
|
+
*/
|
|
248
|
+
shared = 0;
|
|
249
|
+
exclusive;
|
|
250
|
+
sharedDrained;
|
|
251
|
+
async blobReferences(action) {
|
|
252
|
+
while (this.exclusive)
|
|
253
|
+
await this.exclusive.catch(() => { });
|
|
254
|
+
this.shared++;
|
|
255
|
+
try {
|
|
256
|
+
return await action();
|
|
257
|
+
}
|
|
258
|
+
finally {
|
|
259
|
+
if (--this.shared === 0)
|
|
260
|
+
this.sharedDrained?.();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
blobRemoval(action) {
|
|
264
|
+
const previous = this.exclusive;
|
|
265
|
+
const task = (async () => {
|
|
266
|
+
if (previous)
|
|
267
|
+
await previous.catch(() => { });
|
|
268
|
+
if (this.shared)
|
|
269
|
+
await new Promise(r => { this.sharedDrained = r; });
|
|
270
|
+
this.sharedDrained = undefined;
|
|
271
|
+
return action();
|
|
272
|
+
})();
|
|
273
|
+
const held = task.finally(() => { if (this.exclusive === held)
|
|
274
|
+
this.exclusive = undefined; });
|
|
275
|
+
this.exclusive = held;
|
|
276
|
+
return task;
|
|
277
|
+
}
|
|
278
|
+
/** Admin operations run one at a time: they read and change repositories as a whole. */
|
|
279
|
+
adminQueue = Promise.resolve();
|
|
280
|
+
admin(operation, body, local) {
|
|
281
|
+
const task = this.adminQueue.then(() => adminRoute(this, operation, body, local));
|
|
282
|
+
this.adminQueue = task.catch(() => { });
|
|
283
|
+
return task;
|
|
284
|
+
}
|
|
285
|
+
async handle(q, s) {
|
|
286
|
+
this.lastRequest = Date.now();
|
|
287
|
+
this.active++;
|
|
288
|
+
s.once('close', () => { this.active--; this.lastRequest = Date.now(); });
|
|
289
|
+
const send = (status, value) => { const body = Buffer.from(JSON.stringify(value)); s.writeHead(status, { 'content-type': 'application/json', 'content-length': body.length }); s.end(body); };
|
|
290
|
+
try {
|
|
291
|
+
const url = new URL(q.url ?? '/', 'http://hub'), parts = url.pathname.split('/').filter(Boolean).map(decodeURIComponent), method = q.method ?? 'GET';
|
|
292
|
+
const json = async () => {
|
|
293
|
+
const chunks = [];
|
|
294
|
+
let size = 0;
|
|
295
|
+
for await (const c of q) {
|
|
296
|
+
size += c.length;
|
|
297
|
+
if (size > 1 << 20)
|
|
298
|
+
invalid('Request body is too large.');
|
|
299
|
+
chunks.push(c);
|
|
300
|
+
}
|
|
301
|
+
if (!size)
|
|
302
|
+
return {};
|
|
303
|
+
try {
|
|
304
|
+
const v = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
305
|
+
if (v && typeof v === 'object' && !Array.isArray(v))
|
|
306
|
+
return v;
|
|
307
|
+
}
|
|
308
|
+
catch { }
|
|
309
|
+
return invalid('Request body must be a JSON object.');
|
|
310
|
+
};
|
|
311
|
+
const route = method + ' /' + parts.map((p, i) => i % 2 ? ':' : p).join('/');
|
|
312
|
+
const extension = this.extensions.find(e => e.prefix === parts[0]);
|
|
313
|
+
if (extension) {
|
|
314
|
+
// Extension data of a moved project is refused; writes of a frozen one too (project id in the path or as body.projectId).
|
|
315
|
+
// The extension tells reads from writes (ledger reads are POSTs too); reads of a frozen project work.
|
|
316
|
+
// Each project id is looked up once per request; the extension learns from the same lookup whether it exists.
|
|
317
|
+
const write = extension.isWrite ? extension.isWrite({ method, parts: parts.slice(1) }) : method !== 'GET' && method !== 'HEAD', states = new Map();
|
|
318
|
+
const project = (id) => { if (!states.has(id))
|
|
319
|
+
states.set(id, projectIdPattern.test(id) ? this.store.findProjectState(id) : undefined); return states.get(id); };
|
|
320
|
+
const check = (value) => { if (typeof value === 'string' && project(value))
|
|
321
|
+
gate(this, value, write, project(value)); };
|
|
322
|
+
parts.slice(1).forEach(check);
|
|
323
|
+
// A write's body is read before it takes the blob lock: a slow upload does not hold hub gc.
|
|
324
|
+
const read = write ? await json() : undefined;
|
|
325
|
+
const handle = () => extension.handle({ method, parts: parts.slice(1), body: async () => { const b = read ?? await json(); check(b.projectId); return b; }, client: String(q.headers['x-insight-client'] ?? 'unknown-client'),
|
|
326
|
+
exists: id => project(id) !== undefined });
|
|
327
|
+
// A write may reference blobs, so it does not interleave with the blob removal of hub gc.
|
|
328
|
+
return send(200, await (write ? this.blobReferences(handle) : handle()));
|
|
329
|
+
}
|
|
330
|
+
switch (route) {
|
|
331
|
+
case 'GET /status': return send(200, this.status());
|
|
332
|
+
case 'POST /shutdown':
|
|
333
|
+
send(200, { stopping: true });
|
|
334
|
+
setImmediate(() => void this.shutdown());
|
|
335
|
+
return;
|
|
336
|
+
case 'POST /ghidra/:':
|
|
337
|
+
if (parts[1] !== 'ensure')
|
|
338
|
+
break;
|
|
339
|
+
return send(200, await this.ensureGhidra(await json(), q.socket.remoteAddress));
|
|
340
|
+
case 'GET /projects': return send(200, this.store.projects());
|
|
341
|
+
case 'POST /projects': {
|
|
342
|
+
const name = projectName((await json()).name), existing = this.store.projectByName(name);
|
|
343
|
+
if (existing) {
|
|
344
|
+
gate(this, existing.id, false);
|
|
345
|
+
return send(200, existing);
|
|
346
|
+
}
|
|
347
|
+
return send(200, await this.createProject(name));
|
|
348
|
+
}
|
|
349
|
+
case 'GET /projects/:/targets':
|
|
350
|
+
gate(this, parts[1], false);
|
|
351
|
+
return send(200, this.store.targets(parts[1]));
|
|
352
|
+
case 'GET /projects/:/targets/:':
|
|
353
|
+
gate(this, parts[1], false);
|
|
354
|
+
return send(200, this.store.target(parts[1], parts[3]));
|
|
355
|
+
case 'POST /admin/:': return send(200, await this.admin(parts[1], await json(), loopback(q.socket.remoteAddress)));
|
|
356
|
+
case 'POST /projects/:/targets': {
|
|
357
|
+
// A `size` field of older clients is ignored: the target records the stored binary's size.
|
|
358
|
+
const b = await json(), sha256 = b.sha256, name = b.name;
|
|
359
|
+
if (!isSha256(sha256))
|
|
360
|
+
invalid('sha256 must be 64 lowercase hex characters.');
|
|
361
|
+
if (typeof name !== 'string' || !name || name.length > 260 || /[\0-\x1f]/.test(name))
|
|
362
|
+
invalid('Target name must be 1-260 printable characters.');
|
|
363
|
+
gate(this, parts[1], true);
|
|
364
|
+
const createdBy = typeof b.createdBy === 'string' && b.createdBy ? b.createdBy : String(q.headers['x-insight-client'] ?? 'unknown-client');
|
|
365
|
+
// The blob check and the registration do not interleave with hub gc removing unreferenced blobs.
|
|
366
|
+
const registered = await this.blobReferences(async () => {
|
|
367
|
+
const size = await this.blobs.size(sha256);
|
|
368
|
+
return size === undefined ? undefined : this.store.registerTarget(parts[1], { sha256: sha256, name: name, size, createdBy });
|
|
369
|
+
});
|
|
370
|
+
if (!registered) {
|
|
371
|
+
s.writeHead(409, { 'content-type': 'application/json' });
|
|
372
|
+
return s.end(JSON.stringify({ error: { code: 'hub.invalid', message: `Binary ${sha256} is not on the hub; upload it first.` } }));
|
|
373
|
+
}
|
|
374
|
+
return send(200, registered);
|
|
375
|
+
}
|
|
376
|
+
case 'HEAD /blobs/:':
|
|
377
|
+
case 'GET /blobs/:':
|
|
378
|
+
case 'PUT /blobs/:': {
|
|
379
|
+
const sha256 = parts[1];
|
|
380
|
+
if (!isSha256(sha256))
|
|
381
|
+
invalid('sha256 must be 64 lowercase hex characters.');
|
|
382
|
+
if (method === 'PUT')
|
|
383
|
+
return send(200, await this.blobs.put(sha256, q));
|
|
384
|
+
const size = await this.blobs.size(sha256);
|
|
385
|
+
if (size === undefined) {
|
|
386
|
+
if (method === 'HEAD') {
|
|
387
|
+
s.writeHead(404);
|
|
388
|
+
return s.end();
|
|
389
|
+
}
|
|
390
|
+
throw hubError('hub.not_found', 'Binary ' + sha256 + ' is not on the hub.');
|
|
391
|
+
}
|
|
392
|
+
s.writeHead(200, { 'content-type': 'application/octet-stream', 'content-length': size });
|
|
393
|
+
if (method === 'HEAD')
|
|
394
|
+
return s.end();
|
|
395
|
+
this.blobs.read(sha256).on('error', () => s.destroy()).pipe(s);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
throw hubError('hub.not_found', `No route ${method} ${url.pathname}.`);
|
|
400
|
+
}
|
|
401
|
+
catch (error) {
|
|
402
|
+
const code = error instanceof CliError && error.code in statusOf ? error.code : undefined;
|
|
403
|
+
if (!code)
|
|
404
|
+
this.log(`${q.method} ${q.url} failed: ${error.stack ?? error}`);
|
|
405
|
+
if (s.headersSent) {
|
|
406
|
+
s.destroy();
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
send(code ? statusOf[code] : 500, { error: { code: code ?? 'hub.unavailable', message: error.message } });
|
|
410
|
+
if (!q.complete)
|
|
411
|
+
q.resume();
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CliError } from '@eyeauras/cli-factory';
|
|
2
|
+
import { type HubSettings } from '../core/layout.js';
|
|
3
|
+
import type { HubErrorCode } from './contract.js';
|
|
4
|
+
/**
|
|
5
|
+
* Factory's CliError accepts only codes without underscores, while the contract's HubErrorCode has them
|
|
6
|
+
* ('hub.not_found', 'hub.runtime_mismatch'). The error is built with a valid code and then carries the contract code.
|
|
7
|
+
*/
|
|
8
|
+
export declare function hubError(code: HubErrorCode, message: string): CliError;
|
|
9
|
+
export declare function invalid(message: string): never;
|
|
10
|
+
/** True for an all-zero (wildcard) IPv4 or IPv6 address. */
|
|
11
|
+
export declare const isWildcard: (address: string) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The hub listen address: a concrete host. Ghidra Server advertises the address it binds to its clients, so a wildcard
|
|
14
|
+
* (0.0.0.0, ::) would be handed to remote machines as an address to dial; it is refused.
|
|
15
|
+
*/
|
|
16
|
+
export declare const listenAddress: (value: unknown) => string;
|
|
17
|
+
/** `host` for use in a URL: IPv6 is bracketed. */
|
|
18
|
+
export declare const urlHost: (address: string) => string;
|
|
19
|
+
export declare const port: (value: unknown, name?: string) => number;
|
|
20
|
+
/** `host:port` of a remote hub; an IPv6 host is bracketed (`[fd7a::1]:13100`). */
|
|
21
|
+
export declare const remoteAddress: (value: unknown) => string;
|
|
22
|
+
export declare const minutes: (value: unknown) => number;
|
|
23
|
+
export declare function validateHubSettings(value: unknown): HubSettings;
|
|
24
|
+
/** Our own file, written validated by writeHubSettings: reading only parses it. */
|
|
25
|
+
export declare function readHubSettings(roaming: string): Promise<HubSettings>;
|
|
26
|
+
export declare function writeHubSettings(roaming: string, settings: HubSettings): Promise<HubSettings>;
|
|
27
|
+
/**
|
|
28
|
+
* Loopback address of an own hub listening on `listen`. The hub always binds the loopback of its address family next to
|
|
29
|
+
* the configured address (server.ts hubAddresses), so local clients, `hub status` and `hub stop` dial this.
|
|
30
|
+
*/
|
|
31
|
+
export declare const localDialHost: (listen: string) => "127.0.0.1" | "::1";
|
|
32
|
+
/** Address a local client uses for its own hub: the loopback of the listen address's family. */
|
|
33
|
+
export declare const localHubUrl: (s: Pick<HubSettings, "listen" | "port">) => string;
|
|
34
|
+
export declare const hubUrl: (s: HubSettings) => string;
|
|
35
|
+
/** Fields whose change needs a restart of a running hub. */
|
|
36
|
+
export declare const restartFields: readonly ["hub", "listen", "port", "dataRoot", "ghidraIdleMinutes"];
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Installation hub settings (docs/HUB.md, Configuration).
|
|
2
|
+
import { CliError } from '@eyeauras/cli-factory';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { isIP } from 'node:net';
|
|
5
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
6
|
+
import { defaultHubSettings, hubSettingsPath } from '../core/layout.js';
|
|
7
|
+
import { atomicWrite } from '../tool-runtime/store.js';
|
|
8
|
+
/**
|
|
9
|
+
* Factory's CliError accepts only codes without underscores, while the contract's HubErrorCode has them
|
|
10
|
+
* ('hub.not_found', 'hub.runtime_mismatch'). The error is built with a valid code and then carries the contract code.
|
|
11
|
+
*/
|
|
12
|
+
export function hubError(code, message) {
|
|
13
|
+
const error = new CliError(message, { code: code.replace(/_(\w)/g, (_, c) => c.toUpperCase()) });
|
|
14
|
+
Object.defineProperty(error, 'code', { value: code, enumerable: true });
|
|
15
|
+
return error;
|
|
16
|
+
}
|
|
17
|
+
export function invalid(message) { throw hubError('hub.invalid', message); }
|
|
18
|
+
/** A host name or IP address; IPv6 may be bracketed. Returns it unbracketed. */
|
|
19
|
+
const host = (value, name) => {
|
|
20
|
+
const text = typeof value === 'string' ? value : '', bare = /^\[.*\]$/.test(text) ? text.slice(1, -1) : text;
|
|
21
|
+
if (!(isIP(bare) === 6 || (bare === text && (isIP(text) === 4 || /^(?=.{1,253}$)[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)*$/.test(text)))))
|
|
22
|
+
invalid(name + ' must be a host name or IP address.');
|
|
23
|
+
return bare;
|
|
24
|
+
};
|
|
25
|
+
/** True for an all-zero (wildcard) IPv4 or IPv6 address. */
|
|
26
|
+
export const isWildcard = (address) => { const a = address.replace(/^\[|\]$/g, ''); return isIP(a) !== 0 && !/[1-9a-fA-F]/.test(a.replace(/^::ffff:/i, '')); };
|
|
27
|
+
/**
|
|
28
|
+
* The hub listen address: a concrete host. Ghidra Server advertises the address it binds to its clients, so a wildcard
|
|
29
|
+
* (0.0.0.0, ::) would be handed to remote machines as an address to dial; it is refused.
|
|
30
|
+
*/
|
|
31
|
+
export const listenAddress = (value) => {
|
|
32
|
+
const address = host(value, 'Listen address');
|
|
33
|
+
if (isWildcard(address))
|
|
34
|
+
invalid(`Listen address ${address} is a wildcard; use a concrete address: 127.0.0.1 for this machine only, or this machine's address on the shared network (e.g. its Tailscale IP).`);
|
|
35
|
+
return address;
|
|
36
|
+
};
|
|
37
|
+
/** `host` for use in a URL: IPv6 is bracketed. */
|
|
38
|
+
export const urlHost = (address) => isIP(address) === 6 ? '[' + address + ']' : address;
|
|
39
|
+
export const port = (value, name = 'port') => {
|
|
40
|
+
const n = typeof value === 'string' && /^\d+$/.test(value) ? Number(value) : value;
|
|
41
|
+
if (typeof n !== 'number' || !Number.isInteger(n) || n < 1 || n > 65532)
|
|
42
|
+
invalid(name + ' must be an integer from 1 to 65532 (Ghidra uses the next three ports).');
|
|
43
|
+
return n;
|
|
44
|
+
};
|
|
45
|
+
/** `host:port` of a remote hub; an IPv6 host is bracketed (`[fd7a::1]:13100`). */
|
|
46
|
+
export const remoteAddress = (value) => {
|
|
47
|
+
const text = String(value ?? ''), at = text.lastIndexOf(':'), hostPart = text.slice(0, at);
|
|
48
|
+
if (at < 1)
|
|
49
|
+
invalid('Remote hub must be host:port.');
|
|
50
|
+
if (hostPart.includes(':') && !/^\[.*\]$/.test(hostPart))
|
|
51
|
+
invalid('Remote hub must be host:port with an IPv6 host in brackets, e.g. [fd7a::1]:13100.');
|
|
52
|
+
host(hostPart, 'Remote host');
|
|
53
|
+
port(text.slice(at + 1), 'Remote port');
|
|
54
|
+
return text;
|
|
55
|
+
};
|
|
56
|
+
export const minutes = (value) => {
|
|
57
|
+
const n = typeof value === 'string' && /^\d+$/.test(value) ? Number(value) : value;
|
|
58
|
+
if (typeof n !== 'number' || !Number.isInteger(n) || n < 1)
|
|
59
|
+
invalid('Ghidra idle minutes must be a positive integer.');
|
|
60
|
+
return n;
|
|
61
|
+
};
|
|
62
|
+
export function validateHubSettings(value) {
|
|
63
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
64
|
+
invalid('Hub settings must be a JSON object.');
|
|
65
|
+
const v = value;
|
|
66
|
+
if (v.schema !== 1)
|
|
67
|
+
invalid('Hub settings schema must be 1.');
|
|
68
|
+
if (v.hub !== 'local' && v.hub !== 'remote')
|
|
69
|
+
invalid("Hub mode must be 'local' or 'remote'.");
|
|
70
|
+
const settings = { schema: 1, hub: v.hub, listen: listenAddress(v.listen), port: port(v.port) };
|
|
71
|
+
if (v.hub === 'remote')
|
|
72
|
+
settings.remote = remoteAddress(v.remote);
|
|
73
|
+
else if (v.remote !== undefined)
|
|
74
|
+
settings.remote = remoteAddress(v.remote);
|
|
75
|
+
if (v.dataRoot !== undefined) {
|
|
76
|
+
if (typeof v.dataRoot !== 'string' || !isAbsolute(v.dataRoot))
|
|
77
|
+
invalid('Hub data root must be an absolute path.');
|
|
78
|
+
settings.dataRoot = resolve(v.dataRoot);
|
|
79
|
+
}
|
|
80
|
+
if (v.ghidraIdleMinutes !== undefined)
|
|
81
|
+
settings.ghidraIdleMinutes = minutes(v.ghidraIdleMinutes);
|
|
82
|
+
return settings;
|
|
83
|
+
}
|
|
84
|
+
/** Our own file, written validated by writeHubSettings: reading only parses it. */
|
|
85
|
+
export async function readHubSettings(roaming) {
|
|
86
|
+
let content;
|
|
87
|
+
try {
|
|
88
|
+
content = await readFile(hubSettingsPath(roaming), 'utf8');
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (error.code === 'ENOENT')
|
|
92
|
+
return defaultHubSettings();
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
return JSON.parse(content);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return invalid('Hub settings at ' + hubSettingsPath(roaming) + ' are not valid JSON.');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export async function writeHubSettings(roaming, settings) { const valid = validateHubSettings(settings); await atomicWrite(hubSettingsPath(roaming), valid); return valid; }
|
|
103
|
+
/**
|
|
104
|
+
* Loopback address of an own hub listening on `listen`. The hub always binds the loopback of its address family next to
|
|
105
|
+
* the configured address (server.ts hubAddresses), so local clients, `hub status` and `hub stop` dial this.
|
|
106
|
+
*/
|
|
107
|
+
export const localDialHost = (listen) => isIP(listen.replace(/^\[|\]$/g, '')) === 6 ? '::1' : '127.0.0.1';
|
|
108
|
+
/** Address a local client uses for its own hub: the loopback of the listen address's family. */
|
|
109
|
+
export const localHubUrl = (s) => `http://${urlHost(localDialHost(s.listen))}:${s.port}`;
|
|
110
|
+
export const hubUrl = (s) => s.hub === 'remote' ? 'http://' + s.remote : localHubUrl(s);
|
|
111
|
+
/** Fields whose change needs a restart of a running hub. */
|
|
112
|
+
export const restartFields = ['hub', 'listen', 'port', 'dataRoot', 'ghidraIdleMinutes'];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copies the data root. `whileLocked` (e.g. switching the setting to the destination) runs while the
|
|
3
|
+
* source hub.lock is still held, so no hub can start on the source between the copy and the switch.
|
|
4
|
+
*/
|
|
5
|
+
export declare function copyDataRoot(source: string, destination: string, whileLocked?: () => Promise<void>): Promise<{
|
|
6
|
+
files: number;
|
|
7
|
+
bytes: number;
|
|
8
|
+
}>;
|
|
9
|
+
/** Deletes a moved-away data root. */
|
|
10
|
+
export declare function removeDataRoot(root: string): Promise<{
|
|
11
|
+
deleted: boolean;
|
|
12
|
+
reason?: string;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// `hub storage move` (docs/HUB.md, Storage and garbage collection): copy a stopped hub's data root, and only then let
|
|
2
|
+
// the caller switch the setting. The source lock is held for the whole copy.
|
|
3
|
+
import { rename, rm } from 'node:fs/promises';
|
|
4
|
+
import { isAbsolute, relative, resolve } from 'node:path';
|
|
5
|
+
import { hubPaths } from '../core/layout.js';
|
|
6
|
+
import { acquireHubLock } from './lock.js';
|
|
7
|
+
import { copyTree, exists, listFiles } from './repository.js';
|
|
8
|
+
import { hubError, invalid } from './settings.js';
|
|
9
|
+
/** Derived state that a hub rebuilds (compiled wrapper, JVM home), the lock, and interrupted imports are not moved. */
|
|
10
|
+
const derived = (path) => /^(hub\.lock(-.*)?|runtime|incoming)(\/|$)/.test(path);
|
|
11
|
+
const inside = (parent, child) => { const r = relative(parent, child); return r === '' || !!r && !r.startsWith('..') && !isAbsolute(r); };
|
|
12
|
+
/**
|
|
13
|
+
* Copies the data root. `whileLocked` (e.g. switching the setting to the destination) runs while the
|
|
14
|
+
* source hub.lock is still held, so no hub can start on the source between the copy and the switch.
|
|
15
|
+
*/
|
|
16
|
+
export async function copyDataRoot(source, destination, whileLocked) {
|
|
17
|
+
source = resolve(source);
|
|
18
|
+
destination = resolve(destination);
|
|
19
|
+
if (inside(source, destination) || inside(destination, source))
|
|
20
|
+
invalid('The new hub data root must not contain or lie inside the current one.');
|
|
21
|
+
if (!await exists(source))
|
|
22
|
+
invalid(`Hub data root ${source} does not exist.`);
|
|
23
|
+
if (await exists(destination) && (await listFiles(destination)).length)
|
|
24
|
+
invalid(`${destination} exists and is not empty.`);
|
|
25
|
+
const lock = await acquireHubLock(hubPaths(source).lock, 0);
|
|
26
|
+
if (!lock)
|
|
27
|
+
throw hubError('hub.unavailable', 'The hub still runs on ' + source + '; it must be stopped for the move.');
|
|
28
|
+
try {
|
|
29
|
+
const stage = destination + '.partial';
|
|
30
|
+
await rm(stage, { recursive: true, force: true });
|
|
31
|
+
// Nothing writes the source while it is copied: its hub.lock is held.
|
|
32
|
+
const copied = await copyTree(source, stage, derived);
|
|
33
|
+
await rm(destination, { recursive: true, force: true });
|
|
34
|
+
await rename(stage, destination);
|
|
35
|
+
await whileLocked?.();
|
|
36
|
+
return { files: copied.length, bytes: copied.reduce((n, f) => n + f.size, 0) };
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
lock.release();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Deletes a moved-away data root. */
|
|
43
|
+
export async function removeDataRoot(root) {
|
|
44
|
+
await rm(resolve(root), { recursive: true, force: true });
|
|
45
|
+
return { deleted: true };
|
|
46
|
+
}
|