@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.
Files changed (609) hide show
  1. package/.cli-package-build.json +1 -1
  2. package/README.md +16 -23
  3. package/SKILL.md +6 -44
  4. package/dist/src/activity-audit.d.ts +33 -46
  5. package/dist/src/activity-audit.js +120 -195
  6. package/dist/src/analysis-default.d.ts +10 -2
  7. package/dist/src/analysis-default.js +62 -47
  8. package/dist/src/analysis-storage.d.ts +13 -13
  9. package/dist/src/analysis-storage.js +127 -258
  10. package/dist/src/artifacts.d.ts +5 -1
  11. package/dist/src/artifacts.js +31 -46
  12. package/dist/src/audit-commands.d.ts +6 -1
  13. package/dist/src/audit-commands.js +9 -2
  14. package/dist/src/audit-retention.d.ts +5 -23
  15. package/dist/src/audit-retention.js +37 -150
  16. package/dist/src/binary.js +4 -13
  17. package/dist/src/budgets.d.ts +2 -2
  18. package/dist/src/budgets.js +7 -9
  19. package/dist/src/capture.js +17 -30
  20. package/dist/src/cli.d.ts +9 -4
  21. package/dist/src/cli.js +288 -473
  22. package/dist/src/code-references.d.ts +2 -13
  23. package/dist/src/code-references.js +7 -99
  24. package/dist/src/context-diagnostics.d.ts +1 -23
  25. package/dist/src/context-diagnostics.js +1 -83
  26. package/dist/src/core/coordinator.d.ts +298 -0
  27. package/dist/src/core/coordinator.js +591 -0
  28. package/dist/src/core/layout.d.ts +51 -0
  29. package/dist/src/core/layout.js +55 -0
  30. package/dist/src/core/legacy-import.d.ts +55 -0
  31. package/dist/src/core/legacy-import.js +193 -0
  32. package/dist/src/cross-results.d.ts +3 -3
  33. package/dist/src/cross-results.js +4 -42
  34. package/dist/src/cross.js +2 -3
  35. package/dist/src/debugger-results.d.ts +1 -6
  36. package/dist/src/debugger-results.js +21 -153
  37. package/dist/src/debugger.d.ts +21 -11
  38. package/dist/src/debugger.js +106 -168
  39. package/dist/src/decode-results.d.ts +2 -1
  40. package/dist/src/decode-results.js +4 -20
  41. package/dist/src/diagnostic-error.d.ts +1 -1
  42. package/dist/src/diagnostic-error.js +4 -23
  43. package/dist/src/die.js +1 -23
  44. package/dist/src/dnspy-runtime.js +5 -12
  45. package/dist/src/dnspy.js +13 -28
  46. package/dist/src/dotnet-diagnostics.js +1 -1
  47. package/dist/src/extensions.d.ts +2 -3
  48. package/dist/src/extensions.js +14 -91
  49. package/dist/src/frida-worker.js +0 -20
  50. package/dist/src/frida.js +3 -26
  51. package/dist/src/function-boundaries.d.ts +2 -2
  52. package/dist/src/function-boundaries.js +9 -61
  53. package/dist/src/function-entries.d.ts +2 -2
  54. package/dist/src/function-entries.js +6 -36
  55. package/dist/src/function-inspection.d.ts +2 -2
  56. package/dist/src/function-inspection.js +17 -33
  57. package/dist/src/function-results.d.ts +1 -3
  58. package/dist/src/function-results.js +2 -13
  59. package/dist/src/hub/admin.d.ts +101 -0
  60. package/dist/src/hub/admin.js +314 -0
  61. package/dist/src/hub/autostart.d.ts +111 -0
  62. package/dist/src/hub/autostart.js +207 -0
  63. package/dist/src/hub/bundle.d.ts +33 -0
  64. package/dist/src/hub/bundle.js +25 -0
  65. package/dist/src/hub/client.d.ts +90 -0
  66. package/dist/src/hub/client.js +256 -0
  67. package/dist/src/hub/commands.d.ts +13 -0
  68. package/dist/src/hub/commands.js +280 -0
  69. package/dist/src/hub/contract.d.ts +87 -0
  70. package/dist/src/hub/contract.js +3 -0
  71. package/dist/src/hub/extensions.d.ts +41 -0
  72. package/dist/src/hub/extensions.js +3 -0
  73. package/dist/src/hub/ghidra.d.ts +70 -0
  74. package/dist/src/hub/ghidra.js +197 -0
  75. package/dist/src/hub/index.d.ts +6 -0
  76. package/dist/src/hub/index.js +7 -0
  77. package/dist/src/{work/store.d.ts → hub/ledger-store.d.ts} +57 -94
  78. package/dist/src/hub/ledger-store.js +919 -0
  79. package/dist/src/hub/ledger.d.ts +4 -0
  80. package/dist/src/hub/ledger.js +173 -0
  81. package/dist/src/hub/lock.d.ts +7 -0
  82. package/dist/src/hub/lock.js +53 -0
  83. package/dist/src/hub/repository.d.ts +45 -0
  84. package/dist/src/hub/repository.js +130 -0
  85. package/dist/src/hub/server.d.ts +86 -0
  86. package/dist/src/hub/server.js +414 -0
  87. package/dist/src/hub/settings.d.ts +36 -0
  88. package/dist/src/hub/settings.js +112 -0
  89. package/dist/src/hub/storage.d.ts +13 -0
  90. package/dist/src/hub/storage.js +46 -0
  91. package/dist/src/hub/store.d.ts +75 -0
  92. package/dist/src/hub/store.js +188 -0
  93. package/dist/src/ilspy.js +1 -1
  94. package/dist/src/internal-timing.d.ts +2 -9
  95. package/dist/src/internal-timing.js +2 -95
  96. package/dist/src/lldb.js +3 -15
  97. package/dist/src/llvm.js +0 -9
  98. package/dist/src/managed-heap.js +3 -7
  99. package/dist/src/managed-metadata.js +2 -5
  100. package/dist/src/memory-inputs.d.ts +1 -4
  101. package/dist/src/memory-inputs.js +10 -40
  102. package/dist/src/mitmproxy.d.ts +35 -4
  103. package/dist/src/mitmproxy.js +59 -40
  104. package/dist/src/model.d.ts +0 -73
  105. package/dist/src/model.js +0 -45
  106. package/dist/src/mutations.d.ts +1 -1
  107. package/dist/src/mutations.js +5 -10
  108. package/dist/src/native/contract.d.ts +130 -0
  109. package/dist/src/native/ghidra.d.ts +58 -0
  110. package/dist/src/native/ghidra.js +77 -0
  111. package/dist/src/native/host.d.ts +71 -0
  112. package/dist/src/native/host.js +265 -0
  113. package/dist/src/native/index.d.ts +13 -0
  114. package/dist/src/native/index.js +19 -0
  115. package/dist/src/native/jvm.d.ts +54 -0
  116. package/dist/src/native/jvm.js +47 -0
  117. package/dist/src/native/worker.d.ts +70 -0
  118. package/dist/src/native/worker.js +240 -0
  119. package/dist/src/native-inputs.d.ts +9 -14
  120. package/dist/src/native-inputs.js +22 -110
  121. package/dist/src/native-merge-patches.d.ts +2 -2
  122. package/dist/src/native-merge-patches.js +14 -14
  123. package/dist/src/persistent-client.js +53 -25
  124. package/dist/src/procmon.js +17 -31
  125. package/dist/src/program-files.d.ts +42 -0
  126. package/dist/src/program-files.js +148 -0
  127. package/dist/src/queries.js +2 -15
  128. package/dist/src/query-policy.d.ts +0 -2
  129. package/dist/src/query-policy.js +1 -14
  130. package/dist/src/research.d.ts +59 -238
  131. package/dist/src/research.js +212 -906
  132. package/dist/src/runtime-identity.d.ts +8 -0
  133. package/dist/src/runtime-identity.js +26 -0
  134. package/dist/src/runtime-manager.d.ts +1 -11
  135. package/dist/src/runtime-manager.js +10 -145
  136. package/dist/src/runtime-selection.d.ts +1 -1
  137. package/dist/src/runtime-selection.js +5 -37
  138. package/dist/src/saved-materials.js +8 -51
  139. package/dist/src/scripts.d.ts +1 -1
  140. package/dist/src/scripts.js +15 -15
  141. package/dist/src/sdk-contracts.js +2 -2
  142. package/dist/src/sdk.js +8 -8
  143. package/dist/src/sevenzip.js +1 -3
  144. package/dist/src/strace.js +0 -3
  145. package/dist/src/string-anchors.d.ts +2 -3
  146. package/dist/src/string-anchors.js +8 -101
  147. package/dist/src/text-window.d.ts +5 -4
  148. package/dist/src/text-window.js +4 -4
  149. package/dist/src/tool-runtime/archives.d.ts +1 -1
  150. package/dist/src/tool-runtime/archives.js +11 -20
  151. package/dist/src/tool-runtime/catalog.js +2 -5
  152. package/dist/src/tool-runtime/commands.js +1 -3
  153. package/dist/src/tool-runtime/deadline.js +2 -7
  154. package/dist/src/tool-runtime/definition.js +1 -31
  155. package/dist/src/tool-runtime/identity.js +6 -87
  156. package/dist/src/tool-runtime/installer.d.ts +2 -6
  157. package/dist/src/tool-runtime/installer.js +14 -76
  158. package/dist/src/tool-runtime/java-arguments.js +4 -10
  159. package/dist/src/tool-runtime/launch-worker.js +2 -8
  160. package/dist/src/tool-runtime/run.d.ts +2 -0
  161. package/dist/src/tool-runtime/run.js +20 -8
  162. package/dist/src/tool-runtime/store.d.ts +3 -3
  163. package/dist/src/tool-runtime/store.js +21 -83
  164. package/dist/src/tool-runtime/supervisor.d.ts +6 -11
  165. package/dist/src/tool-runtime/supervisor.js +155 -214
  166. package/dist/src/tool-runtime/windows-helper.d.ts +5 -0
  167. package/dist/src/tool-runtime/windows-helper.js +13 -0
  168. package/dist/src/tool-runtime/windows-job.d.ts +5 -5
  169. package/dist/src/tool-runtime/windows-job.js +13 -31
  170. package/dist/src/tshark.js +14 -27
  171. package/dist/src/ui-results.d.ts +3 -2
  172. package/dist/src/ui-results.js +16 -53
  173. package/dist/src/ui.d.ts +12 -13
  174. package/dist/src/ui.js +32 -70
  175. package/dist/src/version-tracking.d.ts +25 -39
  176. package/dist/src/version-tracking.js +70 -174
  177. package/dist/src/windbg.d.ts +1 -1
  178. package/dist/src/windbg.js +2 -8
  179. package/dist/src/work/client.d.ts +63 -0
  180. package/dist/src/work/client.js +163 -0
  181. package/dist/src/work/commands.d.ts +3 -1
  182. package/dist/src/work/commands.js +158 -184
  183. package/dist/src/work/dashboard.d.ts +2 -2
  184. package/dist/src/work/dashboard.js +7 -8
  185. package/dist/src/work/legacy.d.ts +8 -0
  186. package/dist/src/work/legacy.js +70 -0
  187. package/dist/src/work/model.d.ts +0 -3
  188. package/dist/src/work/model.js +0 -10
  189. package/dist/src/work/timing.d.ts +3 -3
  190. package/dist/src/work/timing.js +21 -25
  191. package/dist/src/workspace.d.ts +4 -250
  192. package/dist/src/workspace.js +11 -699
  193. package/node_modules/@eyeauras/cli-factory/README.md +6 -0
  194. package/node_modules/@eyeauras/cli-factory/dist/src/cli.d.ts.map +1 -1
  195. package/node_modules/@eyeauras/cli-factory/dist/src/cli.js +76 -28
  196. package/node_modules/@eyeauras/cli-factory/dist/src/cli.js.map +1 -1
  197. package/node_modules/@eyeauras/cli-factory/dist/src/command.d.ts +1 -1
  198. package/node_modules/@eyeauras/cli-factory/dist/src/command.d.ts.map +1 -1
  199. package/node_modules/@eyeauras/cli-factory/dist/src/command.js +1 -0
  200. package/node_modules/@eyeauras/cli-factory/dist/src/command.js.map +1 -1
  201. package/node_modules/@eyeauras/cli-factory/dist/src/errors.d.ts +1 -1
  202. package/node_modules/@eyeauras/cli-factory/dist/src/errors.d.ts.map +1 -1
  203. package/node_modules/@eyeauras/cli-factory/dist/src/errors.js +18 -6
  204. package/node_modules/@eyeauras/cli-factory/dist/src/errors.js.map +1 -1
  205. package/node_modules/@eyeauras/cli-factory/dist/src/file-publication.d.ts +44 -0
  206. package/node_modules/@eyeauras/cli-factory/dist/src/file-publication.d.ts.map +1 -0
  207. package/node_modules/@eyeauras/cli-factory/dist/src/{profile-file.js → file-publication.js} +41 -113
  208. package/node_modules/@eyeauras/cli-factory/dist/src/file-publication.js.map +1 -0
  209. package/node_modules/@eyeauras/cli-factory/dist/src/help.d.ts +5 -0
  210. package/node_modules/@eyeauras/cli-factory/dist/src/help.d.ts.map +1 -0
  211. package/node_modules/@eyeauras/cli-factory/dist/src/help.js +17 -0
  212. package/node_modules/@eyeauras/cli-factory/dist/src/help.js.map +1 -0
  213. package/node_modules/@eyeauras/cli-factory/dist/src/index.d.ts +9 -4
  214. package/node_modules/@eyeauras/cli-factory/dist/src/index.d.ts.map +1 -1
  215. package/node_modules/@eyeauras/cli-factory/dist/src/index.js +5 -2
  216. package/node_modules/@eyeauras/cli-factory/dist/src/index.js.map +1 -1
  217. package/node_modules/@eyeauras/cli-factory/dist/src/json-rpc.d.ts.map +1 -1
  218. package/node_modules/@eyeauras/cli-factory/dist/src/json-rpc.js +11 -18
  219. package/node_modules/@eyeauras/cli-factory/dist/src/json-rpc.js.map +1 -1
  220. package/node_modules/@eyeauras/cli-factory/dist/src/output-write.d.ts +10 -0
  221. package/node_modules/@eyeauras/cli-factory/dist/src/output-write.d.ts.map +1 -0
  222. package/node_modules/@eyeauras/cli-factory/dist/src/output-write.js +69 -0
  223. package/node_modules/@eyeauras/cli-factory/dist/src/output-write.js.map +1 -0
  224. package/node_modules/@eyeauras/cli-factory/dist/src/output.d.ts +3 -1
  225. package/node_modules/@eyeauras/cli-factory/dist/src/output.d.ts.map +1 -1
  226. package/node_modules/@eyeauras/cli-factory/dist/src/output.js +74 -14
  227. package/node_modules/@eyeauras/cli-factory/dist/src/output.js.map +1 -1
  228. package/node_modules/@eyeauras/cli-factory/dist/src/pagination.d.ts +3 -0
  229. package/node_modules/@eyeauras/cli-factory/dist/src/pagination.d.ts.map +1 -0
  230. package/node_modules/@eyeauras/cli-factory/dist/src/pagination.js +9 -0
  231. package/node_modules/@eyeauras/cli-factory/dist/src/pagination.js.map +1 -0
  232. package/node_modules/@eyeauras/cli-factory/dist/src/permissions.d.ts.map +1 -1
  233. package/node_modules/@eyeauras/cli-factory/dist/src/permissions.js +3 -1
  234. package/node_modules/@eyeauras/cli-factory/dist/src/permissions.js.map +1 -1
  235. package/node_modules/@eyeauras/cli-factory/dist/src/stream-result.d.ts +16 -0
  236. package/node_modules/@eyeauras/cli-factory/dist/src/stream-result.d.ts.map +1 -0
  237. package/node_modules/@eyeauras/cli-factory/dist/src/stream-result.js +83 -0
  238. package/node_modules/@eyeauras/cli-factory/dist/src/stream-result.js.map +1 -0
  239. package/node_modules/@eyeauras/cli-factory/dist/src/types.d.ts +5 -0
  240. package/node_modules/@eyeauras/cli-factory/dist/src/types.d.ts.map +1 -1
  241. package/node_modules/@eyeauras/cli-factory/dist/src/view.d.ts +49 -7
  242. package/node_modules/@eyeauras/cli-factory/dist/src/view.d.ts.map +1 -1
  243. package/node_modules/@eyeauras/cli-factory/dist/src/view.js +83 -6
  244. package/node_modules/@eyeauras/cli-factory/dist/src/view.js.map +1 -1
  245. package/node_modules/@eyeauras/cli-factory/package.json +1 -1
  246. package/node_modules/@eyeauras/cli-factory-ipc/dist/cli-host.proto +19 -19
  247. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/build.d.ts +7 -1
  248. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/build.d.ts.map +1 -1
  249. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/build.js +9 -4
  250. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/build.js.map +1 -1
  251. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/host.d.ts.map +1 -1
  252. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/host.js +5 -4
  253. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/host.js.map +1 -1
  254. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/package-build.d.ts +11 -1
  255. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/package-build.d.ts.map +1 -1
  256. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/package-build.js +85 -57
  257. package/node_modules/@eyeauras/cli-factory-ipc/dist/src/package-build.js.map +1 -1
  258. package/node_modules/@eyeauras/cli-factory-ipc/package.json +2 -2
  259. package/package.json +4 -5
  260. package/references/native/InsightAnalyzerOptions.java +10 -0
  261. package/references/native/InsightAnchorScan.java +1 -11
  262. package/references/native/InsightCodeReferences.java +2 -3
  263. package/references/native/InsightCopyType.java +24 -0
  264. package/references/native/InsightFunctionBoundaries.java +0 -1
  265. package/references/native/InsightFunctionDatabases.java +20 -16
  266. package/references/native/InsightHelperCall.java +17 -0
  267. package/references/native/InsightHubServer.java +214 -0
  268. package/references/native/InsightNativeHost.java +112 -0
  269. package/references/native/InsightPlugins.java +0 -1
  270. package/references/native/InsightPythonWheels.java +3 -2
  271. package/references/native/InsightResearchQueries.java +3 -4
  272. package/references/native/InsightResearchView.java +4 -10
  273. package/references/native/InsightSdkFiles.java +7 -15
  274. package/references/native/InsightSdkScript.java +1 -4
  275. package/references/native/InsightSdkTools.java +36 -97
  276. package/references/native/InsightSdkTypes.java +13 -43
  277. package/references/native/InsightStringAnchors.java +1 -3
  278. package/references/native/InsightTraceState.java +13 -96
  279. package/references/native/InsightTraceTools.java +3 -5
  280. package/references/native/InsightVersionTracking.java +0 -6
  281. package/references/native/{HeadlessProgramMergeManager.java → InsightWcMerge.java} +17 -24
  282. package/references/native/InsightWcOps.java +449 -0
  283. package/references/native/InsightWcWorker.java +142 -0
  284. package/references/native/NATIVE-MERGE-NOTICE.txt +4 -8
  285. package/runtime/GhidraMCP-7.0.0.jar +0 -0
  286. package/runtime/managed/insight-heap/README.md +3 -3
  287. package/runtime/managed/insight-managed/README.md +3 -3
  288. package/runtime/native/binary/README.md +5 -4
  289. package/runtime/native/windows/DirectoryAlias.cs +24 -0
  290. package/runtime/native/windows/Insight.Windows.csproj +27 -0
  291. package/runtime/native/windows/Native.cs +36 -0
  292. package/runtime/native/windows/OwnedJob.cs +86 -0
  293. package/runtime/native/windows/Program.cs +50 -0
  294. package/runtime/native/windows/RegistryRedirect.cs +42 -0
  295. package/runtime/native/windows/insight-windows-x64.exe +0 -0
  296. package/runtime/native/windows/packages.lock.json +35 -0
  297. package/runtime/native/windows/provenance.json +17 -0
  298. package/runtime/research-view.provenance.json +6 -7
  299. package/runtime/toolbox.json +33 -114
  300. package/skill-bundle/insight-artifacts/SKILL.md +5 -19
  301. package/skill-bundle/insight-binary/SKILL.md +5 -35
  302. package/skill-bundle/insight-capture/SKILL.md +5 -45
  303. package/skill-bundle/insight-cli/SKILL.md +6 -44
  304. package/skill-bundle/insight-die/SKILL.md +5 -38
  305. package/skill-bundle/insight-dnspy/SKILL.md +5 -54
  306. package/skill-bundle/insight-dotnet-dump/SKILL.md +5 -35
  307. package/skill-bundle/insight-dotnet-stack/SKILL.md +5 -28
  308. package/skill-bundle/insight-dotnet-trace/SKILL.md +5 -34
  309. package/skill-bundle/insight-frida/SKILL.md +5 -56
  310. package/skill-bundle/insight-ghidra/SKILL.md +14 -113
  311. package/skill-bundle/insight-ilspy/SKILL.md +5 -34
  312. package/skill-bundle/insight-interop/SKILL.md +5 -43
  313. package/skill-bundle/insight-lldb/SKILL.md +5 -43
  314. package/skill-bundle/insight-llvm/SKILL.md +5 -45
  315. package/skill-bundle/insight-managed-heap/SKILL.md +5 -32
  316. package/skill-bundle/insight-managed-metadata/SKILL.md +5 -41
  317. package/skill-bundle/insight-mitmproxy/SKILL.md +5 -51
  318. package/skill-bundle/insight-overview/SKILL.md +5 -68
  319. package/skill-bundle/insight-procmon/SKILL.md +5 -38
  320. package/skill-bundle/insight-re/SKILL.md +10 -127
  321. package/skill-bundle/insight-sevenzip/SKILL.md +5 -31
  322. package/skill-bundle/insight-strace/SKILL.md +5 -35
  323. package/skill-bundle/insight-tshark/SKILL.md +5 -38
  324. package/skill-bundle/insight-windbg/SKILL.md +5 -35
  325. package/skill-bundle/manifest.json +1 -1
  326. package/skills/insight-artifacts/SKILL.md +5 -19
  327. package/skills/insight-binary/SKILL.md +5 -35
  328. package/skills/insight-capture/SKILL.md +5 -45
  329. package/skills/insight-die/SKILL.md +5 -38
  330. package/skills/insight-dnspy/SKILL.md +5 -54
  331. package/skills/insight-dotnet-dump/SKILL.md +5 -35
  332. package/skills/insight-dotnet-stack/SKILL.md +5 -28
  333. package/skills/insight-dotnet-trace/SKILL.md +5 -34
  334. package/skills/insight-frida/SKILL.md +5 -56
  335. package/skills/insight-ghidra/SKILL.md +14 -113
  336. package/skills/insight-ilspy/SKILL.md +5 -34
  337. package/skills/insight-interop/SKILL.md +5 -43
  338. package/skills/insight-lldb/SKILL.md +5 -43
  339. package/skills/insight-llvm/SKILL.md +5 -45
  340. package/skills/insight-managed-heap/SKILL.md +5 -32
  341. package/skills/insight-managed-metadata/SKILL.md +5 -41
  342. package/skills/insight-mitmproxy/SKILL.md +5 -51
  343. package/skills/insight-overview/SKILL.md +5 -68
  344. package/skills/insight-procmon/SKILL.md +5 -38
  345. package/skills/insight-re/SKILL.md +10 -127
  346. package/skills/insight-sevenzip/SKILL.md +5 -31
  347. package/skills/insight-strace/SKILL.md +5 -35
  348. package/skills/insight-tshark/SKILL.md +5 -38
  349. package/skills/insight-windbg/SKILL.md +5 -35
  350. package/dist/src/administration-results.d.ts +0 -1
  351. package/dist/src/administration-results.js +0 -84
  352. package/dist/src/administration.d.ts +0 -14
  353. package/dist/src/administration.js +0 -134
  354. package/dist/src/archive-contract.d.ts +0 -6
  355. package/dist/src/archive-contract.js +0 -108
  356. package/dist/src/archive.d.ts +0 -12
  357. package/dist/src/archive.js +0 -116
  358. package/dist/src/comment-effects.d.ts +0 -3
  359. package/dist/src/comment-effects.js +0 -55
  360. package/dist/src/context-credential.d.ts +0 -18
  361. package/dist/src/context-credential.js +0 -44
  362. package/dist/src/contexts.d.ts +0 -387
  363. package/dist/src/contexts.js +0 -2805
  364. package/dist/src/coordinator.d.ts +0 -41
  365. package/dist/src/coordinator.js +0 -160
  366. package/dist/src/cross-peer.d.ts +0 -20
  367. package/dist/src/cross-peer.js +0 -53
  368. package/dist/src/data-effects.d.ts +0 -3
  369. package/dist/src/data-effects.js +0 -103
  370. package/dist/src/debugger-caller.d.ts +0 -17
  371. package/dist/src/debugger-caller.js +0 -129
  372. package/dist/src/debugger-launch.d.ts +0 -2
  373. package/dist/src/debugger-launch.js +0 -17
  374. package/dist/src/debugger-supervisor.js +0 -179
  375. package/dist/src/directory-identity.d.ts +0 -6
  376. package/dist/src/directory-identity.js +0 -45
  377. package/dist/src/documentation-effects.d.ts +0 -5
  378. package/dist/src/documentation-effects.js +0 -56
  379. package/dist/src/function-effects.d.ts +0 -4
  380. package/dist/src/function-effects.js +0 -112
  381. package/dist/src/ghidra-processes.d.ts +0 -6
  382. package/dist/src/ghidra-processes.js +0 -138
  383. package/dist/src/ghidra.d.ts +0 -50
  384. package/dist/src/ghidra.js +0 -468
  385. package/dist/src/initial-model.d.ts +0 -7
  386. package/dist/src/initial-model.js +0 -115
  387. package/dist/src/initial-progress.d.ts +0 -4
  388. package/dist/src/initial-progress.js +0 -74
  389. package/dist/src/inline-script.d.ts +0 -15
  390. package/dist/src/inline-script.js +0 -61
  391. package/dist/src/legacy-migration.d.ts +0 -37
  392. package/dist/src/legacy-migration.js +0 -238
  393. package/dist/src/lifecycle.d.ts +0 -77
  394. package/dist/src/lifecycle.js +0 -315
  395. package/dist/src/merge.d.ts +0 -29
  396. package/dist/src/merge.js +0 -66
  397. package/dist/src/mutation-effects.d.ts +0 -4
  398. package/dist/src/mutation-effects.js +0 -321
  399. package/dist/src/native-queries.d.ts +0 -2
  400. package/dist/src/native-queries.js +0 -24
  401. package/dist/src/native-service.d.ts +0 -40
  402. package/dist/src/native-service.js +0 -406
  403. package/dist/src/projects.d.ts +0 -31
  404. package/dist/src/projects.js +0 -302
  405. package/dist/src/prototype-cli.d.ts +0 -8
  406. package/dist/src/prototype-cli.js +0 -155
  407. package/dist/src/query-results.d.ts +0 -2
  408. package/dist/src/query-results.js +0 -224
  409. package/dist/src/research-view.d.ts +0 -6
  410. package/dist/src/research-view.js +0 -9
  411. package/dist/src/sdk-files.d.ts +0 -29
  412. package/dist/src/sdk-files.js +0 -249
  413. package/dist/src/server.d.ts +0 -102
  414. package/dist/src/server.js +0 -663
  415. package/dist/src/storage-gc.d.ts +0 -23
  416. package/dist/src/storage-gc.js +0 -600
  417. package/dist/src/store.d.ts +0 -33
  418. package/dist/src/store.js +0 -178
  419. package/dist/src/sync-policy.d.ts +0 -22
  420. package/dist/src/sync-policy.js +0 -129
  421. package/dist/src/timed-backend.d.ts +0 -3
  422. package/dist/src/timed-backend.js +0 -24
  423. package/dist/src/timing-report.d.ts +0 -32
  424. package/dist/src/timing-report.js +0 -74
  425. package/dist/src/tool-runtime/native-process-proof.d.ts +0 -2
  426. package/dist/src/tool-runtime/native-process-proof.js +0 -26
  427. package/dist/src/transport.d.ts +0 -60
  428. package/dist/src/transport.js +0 -223
  429. package/dist/src/unresolved-guidance.d.ts +0 -46
  430. package/dist/src/unresolved-guidance.js +0 -55
  431. package/dist/src/work/backup.d.ts +0 -66
  432. package/dist/src/work/backup.js +0 -446
  433. package/dist/src/work/store.js +0 -1107
  434. package/dist/src/worker-lease.d.ts +0 -17
  435. package/dist/src/worker-lease.js +0 -50
  436. package/node_modules/@eyeauras/cli-factory/dist/src/profile-file.d.ts +0 -37
  437. package/node_modules/@eyeauras/cli-factory/dist/src/profile-file.d.ts.map +0 -1
  438. package/node_modules/@eyeauras/cli-factory/dist/src/profile-file.js.map +0 -1
  439. package/references/InsightRepositoryProbe.java +0 -55
  440. package/references/administration.md +0 -34
  441. package/references/agent-execution.md +0 -36
  442. package/references/agent-setup.md +0 -60
  443. package/references/archive.md +0 -32
  444. package/references/artifacts.md +0 -52
  445. package/references/debugger.md +0 -64
  446. package/references/extensions-and-sync.md +0 -125
  447. package/references/ilspy.md +0 -33
  448. package/references/managed-runtime.md +0 -162
  449. package/references/native/InsightArchivePayloads.java +0 -36
  450. package/references/native/InsightBlockTransfer.java +0 -57
  451. package/references/native/InsightGuiMain.java +0 -33
  452. package/references/native/InsightHeadlessMain.java +0 -18
  453. package/references/native/InsightImportProgress.java +0 -60
  454. package/references/native/InsightInitialImport.java +0 -48
  455. package/references/native/InsightInitialJournal.java +0 -57
  456. package/references/native/InsightInitialPublication.java +0 -142
  457. package/references/native/InsightInitialRecovery.java +0 -131
  458. package/references/native/InsightInlineExecutor.java +0 -143
  459. package/references/native/InsightInlineScript.java +0 -14
  460. package/references/native/InsightNativeCheckout.java +0 -487
  461. package/references/native/InsightNativeFingerprint.java +0 -80
  462. package/references/native/InsightNativeMigration.java +0 -155
  463. package/references/native/InsightNativeRead.java +0 -80
  464. package/references/native/InsightNativeReceipt.java +0 -31
  465. package/references/native/InsightNativeService.java +0 -43
  466. package/references/native/InsightNativeView.java +0 -40
  467. package/references/native/InsightOfflineAuthenticator.java +0 -20
  468. package/references/native/InsightOwnedScripts.java +0 -170
  469. package/references/native/InsightProjectFiles.java +0 -92
  470. package/references/native/InsightPublicationRecovery.java +0 -63
  471. package/references/native/InsightServerAdministration.java +0 -82
  472. package/references/native/InsightServerInit.java +0 -62
  473. package/references/native/InsightServerMain.java +0 -43
  474. package/references/native/InsightServerProbe.java +0 -29
  475. package/references/native/InsightSnapshotFields.java +0 -74
  476. package/references/native/InsightSnapshotInspect.java +0 -191
  477. package/references/native/InsightSnapshotPublisher.java +0 -123
  478. package/references/native/InsightStopDebugger.java +0 -20
  479. package/references/native/InsightTraceInspect.java +0 -24
  480. package/references/native/InsightWorkerLease.java +0 -132
  481. package/references/native-workflows.md +0 -124
  482. package/references/persistent-client.mjs +0 -147
  483. package/references/persistent.md +0 -90
  484. package/references/query-semantics.md +0 -109
  485. package/references/recovery.md +0 -235
  486. package/references/research.md +0 -296
  487. package/references/setup.md +0 -135
  488. package/references/sparse-navigation.md +0 -173
  489. package/references/storage.md +0 -139
  490. package/references/work-tracking.md +0 -261
  491. package/runtime/native/file-version.ps1 +0 -7
  492. package/runtime/native/mitmproxy/bridge.py +0 -180
  493. package/runtime/native/windows-job/DirectoryAlias.cs +0 -24
  494. package/runtime/native/windows-job/Insight.WindowsJob.csproj +0 -1
  495. package/runtime/native/windows-job/Insight.WindowsJob.dll +0 -0
  496. package/runtime/native/windows-job/OwnedJob.cs +0 -79
  497. package/runtime/native/windows-job/RegistryRedirect.cs +0 -45
  498. package/runtime/native/windows-job/packages.lock.json +0 -21
  499. package/runtime/native/windows-job/provenance.json +0 -16
  500. package/runtime/native/windows-job/windows-job.ps1 +0 -8
  501. package/skill-bundle/insight-artifacts/references/agent-execution.md +0 -36
  502. package/skill-bundle/insight-artifacts/references/artifacts.md +0 -52
  503. package/skill-bundle/insight-artifacts/references/recovery.md +0 -235
  504. package/skill-bundle/insight-artifacts/references/storage.md +0 -139
  505. package/skill-bundle/insight-binary/references/agent-execution.md +0 -36
  506. package/skill-bundle/insight-capture/references/agent-execution.md +0 -36
  507. package/skill-bundle/insight-cli/references/agent-execution.md +0 -36
  508. package/skill-bundle/insight-cli/references/agent-setup.md +0 -60
  509. package/skill-bundle/insight-cli/references/archive.md +0 -32
  510. package/skill-bundle/insight-cli/references/managed-runtime.md +0 -162
  511. package/skill-bundle/insight-cli/references/persistent-client.mjs +0 -147
  512. package/skill-bundle/insight-cli/references/persistent.md +0 -90
  513. package/skill-bundle/insight-cli/references/recovery.md +0 -235
  514. package/skill-bundle/insight-cli/references/setup.md +0 -135
  515. package/skill-bundle/insight-cli/references/storage.md +0 -139
  516. package/skill-bundle/insight-die/references/agent-execution.md +0 -36
  517. package/skill-bundle/insight-dnspy/references/agent-execution.md +0 -36
  518. package/skill-bundle/insight-dotnet-dump/references/agent-execution.md +0 -36
  519. package/skill-bundle/insight-dotnet-stack/references/agent-execution.md +0 -36
  520. package/skill-bundle/insight-dotnet-trace/references/agent-execution.md +0 -36
  521. package/skill-bundle/insight-frida/references/agent-execution.md +0 -36
  522. package/skill-bundle/insight-ghidra/references/administration.md +0 -34
  523. package/skill-bundle/insight-ghidra/references/agent-execution.md +0 -36
  524. package/skill-bundle/insight-ghidra/references/archive.md +0 -32
  525. package/skill-bundle/insight-ghidra/references/artifacts.md +0 -52
  526. package/skill-bundle/insight-ghidra/references/debugger.md +0 -64
  527. package/skill-bundle/insight-ghidra/references/extensions-and-sync.md +0 -125
  528. package/skill-bundle/insight-ghidra/references/managed-runtime.md +0 -162
  529. package/skill-bundle/insight-ghidra/references/native-workflows.md +0 -124
  530. package/skill-bundle/insight-ghidra/references/persistent-client.mjs +0 -147
  531. package/skill-bundle/insight-ghidra/references/persistent.md +0 -90
  532. package/skill-bundle/insight-ghidra/references/query-semantics.md +0 -109
  533. package/skill-bundle/insight-ghidra/references/recovery.md +0 -235
  534. package/skill-bundle/insight-ghidra/references/research.md +0 -296
  535. package/skill-bundle/insight-ghidra/references/setup.md +0 -135
  536. package/skill-bundle/insight-ghidra/references/sparse-navigation.md +0 -173
  537. package/skill-bundle/insight-ghidra/references/storage.md +0 -139
  538. package/skill-bundle/insight-ilspy/references/agent-execution.md +0 -36
  539. package/skill-bundle/insight-ilspy/references/ilspy.md +0 -33
  540. package/skill-bundle/insight-interop/references/agent-execution.md +0 -36
  541. package/skill-bundle/insight-lldb/references/agent-execution.md +0 -36
  542. package/skill-bundle/insight-llvm/references/agent-execution.md +0 -36
  543. package/skill-bundle/insight-managed-heap/references/agent-execution.md +0 -36
  544. package/skill-bundle/insight-managed-metadata/references/agent-execution.md +0 -36
  545. package/skill-bundle/insight-mitmproxy/references/agent-execution.md +0 -36
  546. package/skill-bundle/insight-overview/references/agent-execution.md +0 -36
  547. package/skill-bundle/insight-procmon/references/agent-execution.md +0 -36
  548. package/skill-bundle/insight-re/references/agent-execution.md +0 -36
  549. package/skill-bundle/insight-re/references/artifacts.md +0 -52
  550. package/skill-bundle/insight-re/references/persistent-client.mjs +0 -147
  551. package/skill-bundle/insight-re/references/persistent.md +0 -90
  552. package/skill-bundle/insight-re/references/recovery.md +0 -235
  553. package/skill-bundle/insight-re/references/storage.md +0 -139
  554. package/skill-bundle/insight-re/references/work-tracking.md +0 -261
  555. package/skill-bundle/insight-sevenzip/references/agent-execution.md +0 -36
  556. package/skill-bundle/insight-strace/references/agent-execution.md +0 -36
  557. package/skill-bundle/insight-tshark/references/agent-execution.md +0 -36
  558. package/skill-bundle/insight-windbg/references/agent-execution.md +0 -36
  559. package/skills/insight-artifacts/references/agent-execution.md +0 -36
  560. package/skills/insight-artifacts/references/artifacts.md +0 -52
  561. package/skills/insight-artifacts/references/recovery.md +0 -235
  562. package/skills/insight-artifacts/references/storage.md +0 -139
  563. package/skills/insight-binary/references/agent-execution.md +0 -36
  564. package/skills/insight-capture/references/agent-execution.md +0 -36
  565. package/skills/insight-die/references/agent-execution.md +0 -36
  566. package/skills/insight-dnspy/references/agent-execution.md +0 -36
  567. package/skills/insight-dotnet-dump/references/agent-execution.md +0 -36
  568. package/skills/insight-dotnet-stack/references/agent-execution.md +0 -36
  569. package/skills/insight-dotnet-trace/references/agent-execution.md +0 -36
  570. package/skills/insight-frida/references/agent-execution.md +0 -36
  571. package/skills/insight-ghidra/references/administration.md +0 -34
  572. package/skills/insight-ghidra/references/agent-execution.md +0 -36
  573. package/skills/insight-ghidra/references/archive.md +0 -32
  574. package/skills/insight-ghidra/references/artifacts.md +0 -52
  575. package/skills/insight-ghidra/references/debugger.md +0 -64
  576. package/skills/insight-ghidra/references/extensions-and-sync.md +0 -125
  577. package/skills/insight-ghidra/references/managed-runtime.md +0 -162
  578. package/skills/insight-ghidra/references/native-workflows.md +0 -124
  579. package/skills/insight-ghidra/references/persistent-client.mjs +0 -147
  580. package/skills/insight-ghidra/references/persistent.md +0 -90
  581. package/skills/insight-ghidra/references/query-semantics.md +0 -109
  582. package/skills/insight-ghidra/references/recovery.md +0 -235
  583. package/skills/insight-ghidra/references/research.md +0 -296
  584. package/skills/insight-ghidra/references/setup.md +0 -135
  585. package/skills/insight-ghidra/references/sparse-navigation.md +0 -173
  586. package/skills/insight-ghidra/references/storage.md +0 -139
  587. package/skills/insight-ilspy/references/agent-execution.md +0 -36
  588. package/skills/insight-ilspy/references/ilspy.md +0 -33
  589. package/skills/insight-interop/references/agent-execution.md +0 -36
  590. package/skills/insight-lldb/references/agent-execution.md +0 -36
  591. package/skills/insight-llvm/references/agent-execution.md +0 -36
  592. package/skills/insight-managed-heap/references/agent-execution.md +0 -36
  593. package/skills/insight-managed-metadata/references/agent-execution.md +0 -36
  594. package/skills/insight-mitmproxy/references/agent-execution.md +0 -36
  595. package/skills/insight-overview/references/agent-execution.md +0 -36
  596. package/skills/insight-procmon/references/agent-execution.md +0 -36
  597. package/skills/insight-re/references/agent-execution.md +0 -36
  598. package/skills/insight-re/references/artifacts.md +0 -52
  599. package/skills/insight-re/references/persistent-client.mjs +0 -147
  600. package/skills/insight-re/references/persistent.md +0 -90
  601. package/skills/insight-re/references/recovery.md +0 -235
  602. package/skills/insight-re/references/storage.md +0 -139
  603. package/skills/insight-re/references/work-tracking.md +0 -261
  604. package/skills/insight-sevenzip/references/agent-execution.md +0 -36
  605. package/skills/insight-strace/references/agent-execution.md +0 -36
  606. package/skills/insight-tshark/references/agent-execution.md +0 -36
  607. package/skills/insight-windbg/references/agent-execution.md +0 -36
  608. /package/dist/src/{debugger-supervisor.d.ts → native/contract.js} +0 -0
  609. /package/runtime/native/{windows-job → windows}/NuGet.Config +0 -0
@@ -0,0 +1,449 @@
1
+ import com.google.gson.*;
2
+ import ghidra.GhidraApplicationLayout;
3
+ import ghidra.app.plugin.core.analysis.AutoAnalysisManager;
4
+ import ghidra.app.util.importer.AutoImporter;
5
+ import ghidra.app.util.importer.MessageLog;
6
+ import ghidra.app.util.Option;
7
+ import ghidra.app.util.bin.ByteProvider;
8
+ import ghidra.app.util.bin.RandomAccessByteProvider;
9
+ import ghidra.app.util.opinion.LoadResults;
10
+ import ghidra.app.util.opinion.LoadSpec;
11
+ import ghidra.app.util.opinion.Loader;
12
+ import ghidra.program.model.lang.*;
13
+ import ghidra.program.util.DefaultLanguageService;
14
+ import ghidra.util.classfinder.ClassSearcher;
15
+ import java.math.BigInteger;
16
+ import ghidra.framework.*;
17
+ import ghidra.framework.client.*;
18
+ import ghidra.framework.data.*;
19
+ import ghidra.framework.model.*;
20
+ import ghidra.framework.project.DefaultProjectManager;
21
+ import ghidra.framework.store.ItemCheckoutStatus;
22
+ import ghidra.framework.store.LockException;
23
+ import ghidra.program.database.ProgramDB;
24
+ import ghidra.program.model.listing.Program;
25
+ import ghidra.util.task.*;
26
+ import java.io.PrintStream;
27
+ import java.nio.charset.StandardCharsets;
28
+ import java.nio.file.*;
29
+ import java.util.*;
30
+ import java.util.concurrent.TimeUnit;
31
+
32
+ /**
33
+ * Working-copy operations (#161). One request on stdin, one `INSIGHT_WC <json>` line on stdout.
34
+ * Every answer is read from Ghidra (repository versions, checkout, modified flag); nothing else is stored.
35
+ * A working copy is the Ghidra project `wc` in its root directory, holding one checkout of one program.
36
+ */
37
+ public final class InsightWcOps {
38
+ static final TaskMonitor MONITOR=TaskMonitor.DUMMY;
39
+ static final String PROJECT="wc";
40
+ static final Gson GSON=new GsonBuilder().serializeNulls().create();
41
+ /** A refusal with a stable code; the working copy is left as it was. */
42
+ static final class Refusal extends RuntimeException {final String code;Refusal(String code,String message){super(message);this.code=code;}}
43
+ static final class Manager extends DefaultProjectManager {Manager(){super();}}
44
+ static final class Factory extends ghidra.program.database.GhidraProgramMultiUserMergeManagerFactory {
45
+ @Override protected DomainObjectMergeManager doGetMergeManager(DomainObject result,DomainObject mine,DomainObject original,DomainObject latest){
46
+ return new InsightWcMerge((Program)result,(Program)mine,(Program)original,(Program)latest,((ProgramDB)latest).getChanges(),((ProgramDB)mine).getChanges());
47
+ }
48
+ }
49
+ static String text(JsonObject q,String name){if(!q.has(name)||q.get(name).isJsonNull())throw new Refusal("invalid","Missing "+name);return q.get(name).getAsString();}
50
+ static String parent(String path){int at=path.lastIndexOf('/');return at<=0?"/":path.substring(0,at);}
51
+ static String leaf(String path){return path.substring(path.lastIndexOf('/')+1);}
52
+ static void require(boolean value,String reason){if(!value)throw new IllegalStateException(reason);}
53
+
54
+ private static boolean registered;
55
+ static synchronized void initialize()throws Exception {
56
+ if(!Application.isInitialized())Application.initializeApplication(new GhidraApplicationLayout(),new HeadlessGhidraApplicationConfiguration());
57
+ if(!registered){
58
+ Class.forName("ghidra.program.database.ProgramMultiUserMergeManagerFactory");
59
+ PluggableServiceRegistry.registerPluggableService(ghidra.program.database.ProgramMultiUserMergeManagerFactory.class,new Factory());registered=true;
60
+ }
61
+ }
62
+ static RepositoryAdapter repository(JsonObject q)throws Exception {
63
+ String host=text(q,"host");int port=q.get("port").getAsInt();
64
+ RepositoryServerAdapter server=ClientUtil.getRepositoryServer(host,port,true);
65
+ if(server==null||!server.isConnected())throw new Refusal("unavailable","Ghidra Server "+host+":"+port+" is not reachable");
66
+ RepositoryAdapter repository=server.getRepository(text(q,"repository"));
67
+ try{if(repository==null)throw new RepositoryNotFoundException(text(q,"repository"));repository.connect();}
68
+ catch(RepositoryNotFoundException absent){throw new Refusal("not_found","Repository "+text(q,"repository")+" does not exist on "+host+":"+port);}
69
+ if(!repository.isConnected())throw new Refusal("unavailable","Repository "+text(q,"repository")+" is not reachable");
70
+ return repository;
71
+ }
72
+ static ProjectLocator locator(JsonObject q){return new ProjectLocator(Path.of(text(q,"root")).toAbsolutePath().toString(),PROJECT);}
73
+ /** Opens the copy for writing; a running worker holds Ghidra's project lock. */
74
+ static Project open(ProjectLocator locator)throws Exception {
75
+ try{return new Manager().openProject(locator,false,false);}
76
+ catch(LockException busy){throw new Refusal("busy","The working copy is open in a running worker; stop the worker first");}
77
+ }
78
+ /** The repository identity is the name; its address is whatever the hub reports now. Returns the project bound to the repository at its current address; Ghidra applies a new address on reopen. */
79
+ static Project bind(Project project,RepositoryAdapter repository)throws Exception {
80
+ ProjectData data=project.getProjectData();RepositoryAdapter bound=data.getRepository();
81
+ if(bound==null)throw new Refusal("invalid","The working copy is not a shared project");
82
+ if(!bound.getName().equals(repository.getName()))throw new Refusal("invalid","The working copy belongs to repository "+bound.getName());
83
+ ServerInfo was=bound.getServerInfo(),now=repository.getServerInfo();
84
+ if(was.getServerName().equalsIgnoreCase(now.getServerName())&&was.getPortNumber()==now.getPortNumber()){
85
+ if(!bound.isConnected())bound.connect();
86
+ return project;
87
+ }
88
+ if(data.hasInvalidCheckouts(data.findCheckedOutFiles(MONITOR),repository,MONITOR))
89
+ throw new Refusal("invalid","The repository at "+now+" does not know the checkouts of this working copy");
90
+ data.updateRepositoryInfo(repository,false,MONITOR);
91
+ ProjectLocator locator=project.getProjectLocator();project.close();
92
+ if(!repository.isConnected())repository.connect();
93
+ Project reopened=open(locator);RepositoryAdapter rebound=reopened.getProjectData().getRepository();
94
+ if(rebound!=null&&!rebound.isConnected())rebound.connect();
95
+ return reopened;
96
+ }
97
+ /**
98
+ * The project's own repository adapter, connected, when the copy is bound to the requested repository at the requested
99
+ * address: the operation then needs no second connection. Null when the address changed (the caller re-binds).
100
+ */
101
+ static RepositoryAdapter boundRepository(Project project,JsonObject q)throws Exception {
102
+ RepositoryAdapter bound=project.getProjectData().getRepository();
103
+ if(bound==null)throw new Refusal("invalid","The working copy is not a shared project");
104
+ if(!bound.getName().equals(text(q,"repository")))throw new Refusal("invalid","The working copy belongs to repository "+bound.getName());
105
+ String host=text(q,"host");int port=q.get("port").getAsInt();ServerInfo was=bound.getServerInfo();
106
+ if(!was.getServerName().equalsIgnoreCase(host)||was.getPortNumber()!=port)return null;
107
+ try{if(!bound.isConnected())bound.connect();}
108
+ catch(RepositoryNotFoundException absent){throw new Refusal("not_found","Repository "+bound.getName()+" does not exist on "+host+":"+port);}
109
+ catch(java.io.IOException unreachable){throw new Refusal("unavailable","Ghidra Server "+host+":"+port+" is not reachable");}
110
+ if(!bound.isConnected())throw new Refusal("unavailable","Repository "+bound.getName()+" is not reachable");
111
+ return bound;
112
+ }
113
+ static DomainFile file(Project project,String path){
114
+ DomainFile file=project.getProjectData().getFile(path);
115
+ if(file==null){project.getProjectData().refresh(false);file=project.getProjectData().getFile(path);}
116
+ return file;
117
+ }
118
+ /** Ghidra recovery data of an interrupted session is applied and saved into the working copy. */
119
+ static void recover(DomainFile file)throws Exception {
120
+ if(!file.canRecover())return;
121
+ Object consumer=new Object();DomainObject program=file.getDomainObject(consumer,false,true,MONITOR);
122
+ try{
123
+ if(program.isChanged())try{program.save("Recovered unsaved changes",MONITOR);}
124
+ catch(Throwable failure){
125
+ // Releasing an unsaved recovered program deletes Ghidra's recovery data; keep it for the next attempt.
126
+ failure.printStackTrace(System.err);System.err.flush();Runtime.getRuntime().halt(70);
127
+ }
128
+ }finally{program.release(consumer);}
129
+ }
130
+ /**
131
+ * Ends the copy's checkout and deletes its private file. In a long-lived process Ghidra may still hold that file's
132
+ * handles for a moment after an earlier operation (buffer files left to the collector, see InsightNativeHost), which
133
+ * Windows reports as in use. Ghidra ends the server checkout before it deletes the file, so only the deletion is
134
+ * left then: collect and delete the private file, for up to five seconds. A running worker never gets here: it
135
+ * holds the project lock, refused earlier as busy.
136
+ */
137
+ static void undoCheckout(Project project,DomainFile file,String path)throws Exception {
138
+ try{file.undoCheckout(false,true);return;}
139
+ catch(ghidra.util.exception.FileInUseException inUse){
140
+ var item=localItem(project,path);
141
+ for(int attempt=0;;attempt++){
142
+ System.gc();Thread.sleep(200);
143
+ try{item.delete(-1,ClientUtil.getUserName());break;}
144
+ catch(ghidra.util.exception.FileInUseException again){if(attempt>=25)throw again;}
145
+ }
146
+ project.getProjectData().refresh(true);
147
+ }
148
+ }
149
+ /**
150
+ * A fresh checkout of the copy's file. When Ghidra refuses it, the server checkouts an interrupted checkout of this
151
+ * project directory left behind are ended and the checkout is asked once more.
152
+ */
153
+ static DomainFile checkout(Project project,RepositoryAdapter repository,DomainFile file,String path)throws Exception {
154
+ try{if(file.checkout(false,MONITOR))return file(project,path);}
155
+ catch(java.io.IOException refused){/* asked again below */}
156
+ endStrayCheckouts(repository,project.getProjectLocator(),path,-1);
157
+ require(file.checkout(false,MONITOR),"Ghidra refused the checkout");
158
+ return file(project,path);
159
+ }
160
+ /** Server checkouts made from this project directory that the copy does not hold (an interrupted checkout). */
161
+ static void endStrayCheckouts(RepositoryAdapter repository,ProjectLocator locator,String path,long keep)throws Exception {
162
+ String mine=ItemCheckoutStatus.getProjectPath(locator.toString(),false),user=repository.getUser().getName();
163
+ for(var checkout:repository.getCheckouts(parent(path),leaf(path)))
164
+ if(checkout.getCheckoutId()!=keep&&user.equals(checkout.getUser())&&mine.equals(checkout.getProjectPath()))
165
+ repository.terminateCheckout(parent(path),leaf(path),checkout.getCheckoutId(),false);
166
+ }
167
+ static Map<String,Object> status(RepositoryAdapter repository,DomainFile file,String path)throws Exception {
168
+ var item=repository.getItem(parent(path),leaf(path));
169
+ if(item==null)throw new Refusal("not_found","Program "+path+" does not exist in repository "+repository.getName());
170
+ boolean out=file!=null&&file.isCheckedOut();ItemCheckoutStatus checkout=out?file.getCheckoutStatus():null;
171
+ Map<String,Object> result=new LinkedHashMap<>();
172
+ result.put("checkedOut",out);result.put("version",out?checkout.getCheckoutVersion():0);result.put("latestVersion",item.getVersion());
173
+ result.put("modified",out&&(file.modifiedSinceCheckout()||file.canRecover()));result.put("checkoutId",out?String.valueOf(checkout.getCheckoutId()):null);
174
+ return result;
175
+ }
176
+ static InsightWcMerge.Unresolved conflict(Throwable failure){
177
+ for(Throwable at=failure;at!=null;at=at.getCause()==at?null:at.getCause())if(at instanceof InsightWcMerge.Unresolved unresolved)return unresolved;
178
+ return null;
179
+ }
180
+ static Map<String,Object> conflictResult(InsightWcMerge.Unresolved conflict){
181
+ return new LinkedHashMap<>(Map.of("state","conflict","conflicts",1,"summary","Ghidra needs a decision: "+conflict.getMessage()));
182
+ }
183
+
184
+ /**
185
+ * Names the check-in of one checkout and local version in its version comment. A version whose comment carries the
186
+ * marker of this checkout and this local version holds exactly this copy's content.
187
+ */
188
+ static String checkinMarker(long checkoutId,int localVersion){return "[insight checkout "+checkoutId+" local "+localVersion+"]";}
189
+ /**
190
+ * The checked-out file in the working copy: its checkout version is the base this copy holds (the server's checkout
191
+ * record may differ), its current version rises with every save into the working copy.
192
+ */
193
+ static ghidra.framework.store.FolderItem localItem(Project project,String path)throws Exception {
194
+ var item=((DefaultProjectData)project.getProjectData()).getPrivateFileSystem().getItem(parent(path),leaf(path));
195
+ if(item==null)throw new IllegalStateException("The working copy has no local file for "+path);
196
+ return item;
197
+ }
198
+ /**
199
+ * A server version after the copy's own base that this user checked in from this checkout and local version: an
200
+ * earlier check-in whose reply was lost after the server committed it. Ghidra updates the local checkout and then the
201
+ * server's checkout record only after that reply, so the copy still has its old base and its changes. 0 if none.
202
+ */
203
+ static int lostCheckin(DomainFile file,int base,String user,String marker)throws Exception {
204
+ for(var version:file.getVersionHistory())
205
+ if(version.getVersion()>base&&user.equals(version.getUser())&&version.getComment()!=null&&version.getComment().endsWith(marker))return version.getVersion();
206
+ return 0;
207
+ }
208
+ /** A stage left this long is an interrupted import; a younger one may belong to a concurrent import of the same user. */
209
+ static final long STALE_STAGE_MS=3_600_000L;
210
+
211
+ static Map<String,Object> exists(JsonObject q)throws Exception {
212
+ String path=text(q,"programPath");RepositoryAdapter repository=repository(q);
213
+ try{return Map.of("exists",repository.getItem(parent(path),leaf(path))!=null);}finally{repository.disconnect();}
214
+ }
215
+ /** Loads `input` into memory with Ghidra's best guess, or with the explicit language, compiler spec, loader and options. */
216
+ static LoadResults<? extends DomainObject> load(JsonObject q,Path input,Object consumer)throws Exception {
217
+ String selected=q.has("loader")?text(q,"loader"):"";Language language=null;CompilerSpec compiler=null;
218
+ try{
219
+ if(q.has("language"))language=DefaultLanguageService.getLanguageService().getLanguage(new LanguageID(text(q,"language")));
220
+ else if(q.has("compilerSpec"))throw new Refusal("invalid","A compiler spec needs an explicit language");
221
+ if(language!=null)compiler=q.has("compilerSpec")?language.getCompilerSpecByID(new CompilerSpecID(text(q,"compilerSpec"))):language.getDefaultCompilerSpec();
222
+ }catch(LanguageNotFoundException|CompilerSpecNotFoundException unknown){throw new Refusal("invalid",unknown.getMessage());}
223
+ if(selected.isEmpty()){
224
+ if(q.has("loaderOptions"))throw new Refusal("invalid","Loader options need an explicit loader");
225
+ return language==null?AutoImporter.importByUsingBestGuess(input.toFile(),null,"/",consumer,new MessageLog(),MONITOR):
226
+ AutoImporter.importByLookingForLcs(input.toFile(),null,"/",language,compiler,consumer,new MessageLog(),MONITOR);
227
+ }
228
+ Loader loader=null;
229
+ for(Loader candidate:ClassSearcher.getInstances(Loader.class))
230
+ if(candidate.getClass().getName().equals(selected)||candidate.getClass().getSimpleName().equals(selected)||candidate.getName().equals(selected)){
231
+ if(loader!=null)throw new Refusal("invalid","Loader "+selected+" is ambiguous");loader=candidate;}
232
+ if(loader==null)throw new Refusal("invalid","Unknown loader "+selected+"; see ghidra formats loaders");
233
+ ByteProvider provider=new RandomAccessByteProvider(input.toFile());
234
+ try{
235
+ LoadSpec spec=null;
236
+ for(LoadSpec candidate:loader.findSupportedLoadSpecs(provider)){
237
+ if(language!=null){spec=new LoadSpec(loader,candidate.getDesiredImageBase(),new LanguageCompilerSpecPair(language.getLanguageID(),compiler.getCompilerSpecID()),true);break;}
238
+ if(candidate.isPreferred()&&candidate.isComplete()){spec=candidate;break;}
239
+ }
240
+ if(spec==null)throw new Refusal("invalid","Loader "+selected+" cannot load this file without an explicit --language");
241
+ Language effective=language!=null?language:spec.getLanguageCompilerSpec()==null?null:DefaultLanguageService.getLanguageService().getLanguage(spec.getLanguageCompilerSpec().languageID);
242
+ List<Option> options;
243
+ try{options=InsightSdkFiles.configured(loader.getDefaultOptions(provider,spec,null,false,false),q.has("loaderOptions")?q.getAsJsonObject("loaderOptions"):new JsonObject(),effective==null?null:effective.getAddressFactory());}
244
+ catch(IllegalArgumentException invalid){throw new Refusal("invalid",invalid.getMessage());}
245
+ String error=loader.validateOptions(provider,spec,options,null);if(error!=null)throw new Refusal("invalid","Loader rejected the options: "+error);
246
+ var loaded=loader.load(new Loader.ImporterSettings(provider,text(q,"name"),null,"/",false,spec,options,consumer,new MessageLog(),MONITOR));
247
+ if(loaded==null)throw new Refusal("invalid","Loader "+selected+" produced no program");
248
+ return loaded;
249
+ }finally{provider.close();}
250
+ }
251
+ static void imageBase(Program program,String hex){
252
+ int tx=program.startTransaction("Initial image base");boolean ok=false;
253
+ try{program.setImageBase(program.getAddressFactory().getDefaultAddressSpace().getAddress(new BigInteger(hex,16).longValue()),true);ok=true;}
254
+ catch(Exception invalid){throw new Refusal("invalid","Image base "+hex+" cannot be applied: "+invalid.getMessage());}
255
+ finally{program.endTransaction(tx,ok);}
256
+ }
257
+ /** Writes one repository version of the program as a packed file. */
258
+ static Map<String,Object> export(JsonObject q)throws Exception {
259
+ String path=text(q,"programPath");RepositoryAdapter repository=repository(q);Project project=null;
260
+ try{
261
+ var item=repository.getItem(parent(path),leaf(path));
262
+ if(item==null)throw new Refusal("not_found","Program "+path+" does not exist in repository "+repository.getName());
263
+ int version=q.has("version")&&q.get("version").getAsInt()>0?q.get("version").getAsInt():item.getVersion();
264
+ if(version>item.getVersion())throw new Refusal("not_found","Version "+version+" of "+path+" does not exist");
265
+ project=new Manager().createProject(new ProjectLocator(Path.of(text(q,"temp")).toAbsolutePath().toString(),"export"),repository,false);
266
+ DomainFile file=file(project,path);if(file==null)throw new Refusal("not_found","Program "+path+" is not visible in the repository");
267
+ Object consumer=new Object();DomainObject program=file.getReadOnlyDomainObject(consumer,version,MONITOR);
268
+ try{program.saveToPackedFile(Path.of(text(q,"output")).toFile(),MONITOR);}finally{program.release(consumer);}
269
+ return Map.of("version",version);
270
+ }finally{if(project!=null)project.close();repository.disconnect();}
271
+ }
272
+ /** After a refused publish: removes this user's stages of the program that interrupted imports left behind. */
273
+ static void sweepStages(RepositoryAdapter repository,String folderPath,String prefix,Exception refused){
274
+ try{
275
+ long now=System.currentTimeMillis();
276
+ for(var item:repository.getItemList(folderPath)){
277
+ String found=item.getName();
278
+ if(!(found.equals(prefix)||found.startsWith(prefix+"_"))||now-item.getVersionTime()<STALE_STAGE_MS)continue;
279
+ try{
280
+ for(var held:repository.getCheckouts(folderPath,found))repository.terminateCheckout(folderPath,found,held.getCheckoutId(),false);
281
+ repository.deleteItem(folderPath,found,-1);
282
+ }catch(java.io.IOException gone){/* removed concurrently */}
283
+ }
284
+ }catch(Exception sweep){refused.addSuppressed(sweep);}
285
+ }
286
+ /** Import into memory, publish under a per-client stage name, then move it into place: the server move refuses an existing item. */
287
+ static Map<String,Object> importPublish(JsonObject q)throws Exception {
288
+ String path=text(q,"programPath"),folderPath=parent(path),name=leaf(path);
289
+ RepositoryAdapter repository=repository(q);Project project=null;
290
+ try{
291
+ var present=repository.getItem(folderPath,name);
292
+ if(present!=null)return Map.of("state","exists","version",present.getVersion());
293
+ // One stage name per attempt: two imports of the same user (another session or process) never share a stage.
294
+ String prefix="__insight_stage_"+repository.getUser().getName()+"_"+name,stage=prefix+"_"+UUID.randomUUID().toString().replace("-","").substring(0,16);
295
+ Path temp=Path.of(text(q,"temp")),input=temp.resolve("input").resolve(text(q,"name").replaceAll("[\\\\/:*?\"<>|\\x00-\\x1f]","_"));
296
+ Files.createDirectories(input.getParent());Files.copy(Path.of(text(q,"file")),input,StandardCopyOption.REPLACE_EXISTING);
297
+ Object consumer=new Object();DomainFile created;
298
+ var loaded=load(q,input,consumer);
299
+ try{
300
+ if(loaded==null||loaded.size()<1||!(loaded.getPrimaryDomainObject() instanceof Program))throw new Refusal("invalid","Ghidra could not import "+text(q,"name"));
301
+ Program program=(Program)loaded.getPrimaryDomainObject();
302
+ if(q.has("imageBase"))imageBase(program,text(q,"imageBase"));
303
+ if(q.get("analysis").getAsBoolean()){
304
+ // Like Ghidra's headless analyzer: a timeout stops analysis and keeps what was analysed.
305
+ TaskMonitor monitor=q.has("timeoutSeconds")?TimeoutTaskMonitor.timeoutIn(q.get("timeoutSeconds").getAsLong(),TimeUnit.SECONDS):MONITOR;
306
+ ghidra.app.script.GhidraScriptUtil.acquireBundleHostReference();int tx=program.startTransaction("Initial analysis");
307
+ try{AutoAnalysisManager analysis=AutoAnalysisManager.getAnalysisManager(program);analysis.initializeOptions();analysis.reAnalyzeAll(null);
308
+ analysis.startAnalysis(monitor);if(monitor.isCancelled())analysis.cancelQueuedTasks();}
309
+ finally{program.endTransaction(tx,true);ghidra.app.script.GhidraScriptUtil.releaseBundleHostReference();}
310
+ }
311
+ // The project owns its repository connection and ends it on close: it stays open until the move.
312
+ project=new Manager().createProject(new ProjectLocator(temp.toAbsolutePath().toString(),"import"),repository,false);
313
+ DomainFolder folder=project.getProjectData().getRootFolder();
314
+ for(String part:folderPath.split("/"))if(!part.isEmpty())folder=folder.getFolder(part)!=null?folder.getFolder(part):folder.createFolder(part);
315
+ try{created=folder.createFile(stage,program,MONITOR);}
316
+ catch(Exception refused){sweepStages(repository,folderPath,prefix,refused);throw refused;}
317
+ }finally{if(loaded!=null)loaded.release(consumer);}
318
+ // Released first: Ghidra keeps an open file checked out.
319
+ try{created.addToVersionControl("insight import "+text(q,"name"),false,MONITOR);}
320
+ catch(Exception refused){sweepStages(repository,folderPath,prefix,refused);throw refused;}
321
+ try{repository.moveItem(folderPath,folderPath,stage,name);}
322
+ catch(Exception lost){
323
+ var winner=repository.getItem(folderPath,name);if(winner==null)throw lost;
324
+ repository.deleteItem(folderPath,stage,-1);
325
+ return Map.of("state","exists","version",winner.getVersion());
326
+ }
327
+ // addToVersionControl created version 1, which the move keeps.
328
+ return Map.of("state","published","version",1);
329
+ }finally{if(project!=null)project.close();repository.disconnect();}
330
+ }
331
+ /**
332
+ * Native check-in of the copy's checkout, keeping it checked out. The program may be open in a worker (`inUse`): Ghidra
333
+ * then moves the open, saved program onto the new version itself. An open program cannot take a fresh checkout, so a
334
+ * lost check-in found there answers `reopen` and the caller repeats the check-in with the program closed.
335
+ */
336
+ static Map<String,Object> checkin(Project project,RepositoryAdapter repository,DomainFile file,String path,String comment,boolean inUse)throws Exception {
337
+ long id=file.getCheckoutStatus().getCheckoutId();int latest=file.getLatestVersion();
338
+ if(!file.modifiedSinceCheckout())return Map.of("state","unchanged","version",latest);
339
+ var local=localItem(project,path);int localBase=local.getCheckoutVersion();
340
+ String marker=checkinMarker(id,local.getCurrentVersion());
341
+ int lost=localBase<latest?lostCheckin(file,localBase,repository.getUser().getName(),marker):0;
342
+ if(lost>0){
343
+ if(inUse)return Map.of("state","reopen");
344
+ // The server holds this exact content as version `lost`: take a fresh checkout of the latest version instead of publishing it again.
345
+ undoCheckout(project,file,path);checkout(project,repository,file(project,path),path);
346
+ return Map.of("state","published","version",lost);
347
+ }
348
+ // Ghidra Server runs one check-in of an item at a time; another agent's check-in in progress is waited out.
349
+ for(int pause=100;;pause=Math.min(pause*2,2000)){
350
+ try{file.checkin(new DefaultCheckinHandler(comment+"\n"+marker,true,false),MONITOR);break;}
351
+ catch(ghidra.util.exception.FileInUseException busy){
352
+ if(!String.valueOf(busy.getMessage()).startsWith("Another checkin is in progress"))throw busy;
353
+ Thread.sleep(pause);
354
+ }
355
+ catch(Throwable failure){
356
+ var unresolved=conflict(failure);if(unresolved==null)throw failure;
357
+ return conflictResult(unresolved);
358
+ }
359
+ }
360
+ // Ghidra creates no version when the merged copy equals the latest one (its changes were already published).
361
+ int published=file.getCheckoutStatus().getCheckoutVersion();
362
+ return Map.of("state",published>latest?"published":"unchanged","version",published);
363
+ }
364
+ /** Native Update of the copy's checkout to the latest version; an open, saved program is moved onto it by Ghidra. */
365
+ static Map<String,Object> update(Project project,RepositoryAdapter repository,DomainFile file,String path)throws Exception {
366
+ int base=file.getCheckoutStatus().getCheckoutVersion(),latest=file.getLatestVersion();
367
+ if(base>=latest)return Map.of("state","current","version",base);
368
+ try{file.merge(false,MONITOR);}
369
+ catch(Throwable failure){
370
+ var unresolved=conflict(failure);if(unresolved==null)throw failure;
371
+ return conflictResult(unresolved);
372
+ }
373
+ return Map.of("state","updated","version",file.getCheckoutStatus().getCheckoutVersion());
374
+ }
375
+ static Map<String,Object> copy(JsonObject q,String operation)throws Exception {
376
+ String path=text(q,"programPath");ProjectLocator locator=locator(q);boolean present=locator.getMarkerFile().exists();
377
+ if(operation.equals("status")&&!present){
378
+ RepositoryAdapter repository=repository(q);try{return status(repository,null,path);}finally{repository.disconnect();}
379
+ }
380
+ if(operation.equals("release")&&!present){
381
+ // Nothing local is left; end what an interrupted checkout or release may have left on the server.
382
+ RepositoryAdapter repository=repository(q);
383
+ try{if(repository.getItem(parent(path),leaf(path))!=null)endStrayCheckouts(repository,locator,path,-1);return Map.of("state","released","modified",false);}
384
+ finally{repository.disconnect();}
385
+ }
386
+ if(!present&&!operation.equals("checkout")&&!operation.equals("discard"))throw new Refusal("not_found","The working copy has no checkout yet");
387
+ RepositoryAdapter repository=null;Project project=null;
388
+ try{
389
+ if(!present){repository=repository(q);Files.createDirectories(Path.of(text(q,"root")));project=new Manager().createProject(locator,repository,false);}
390
+ else{
391
+ try{project=open(locator);}
392
+ catch(Refusal busy){
393
+ // A running worker holds the project; its checkout state is still readable without the lock.
394
+ if(!busy.code.equals("busy")||!operation.equals("status"))throw busy;
395
+ repository=repository(q);var data=new DefaultProjectData(locator,false,false);
396
+ try{return status(repository,data.getFile(path),path);}finally{data.close();}
397
+ }
398
+ // The copy's own connection serves the operation; a second one only re-binds the copy to a new address.
399
+ repository=boundRepository(project,q);
400
+ if(repository==null){repository=repository(q);project=bind(project,repository);}
401
+ }
402
+ DomainFile file=file(project,path);
403
+ if(file==null)throw new Refusal("not_found","Program "+path+" does not exist in repository "+repository.getName());
404
+ if(operation.equals("status"))return status(repository,file,path);
405
+ if(operation.equals("release")){
406
+ boolean modified=false;
407
+ if(file.isCheckedOut()){
408
+ modified=file.modifiedSinceCheckout()||file.canRecover();
409
+ if(modified&&!q.get("force").getAsBoolean())
410
+ throw new Refusal("modified","The working copy has unpublished changes; publish or discard them, or release with force");
411
+ undoCheckout(project,file,path);
412
+ }else endStrayCheckouts(repository,locator,path,-1);
413
+ return Map.of("state","released","modified",modified);
414
+ }
415
+ if(operation.equals("discard")&&file.isCheckedOut()){undoCheckout(project,file,path);file=file(project,path);}
416
+ if(!file.isCheckedOut()){
417
+ if(file.isHijacked())throw new Refusal("invalid","The working copy holds a private file at "+path+"; it is kept");
418
+ file=checkout(project,repository,file,path);
419
+ }
420
+ recover(file);
421
+ if(operation.equals("checkin"))return checkin(project,repository,file,path,text(q,"comment"),false);
422
+ if(operation.equals("update"))return update(project,repository,file,path);
423
+ require(operation.equals("checkout")||operation.equals("discard"),"Unknown operation "+operation);
424
+ return status(repository,file,path);
425
+ }finally{
426
+ if(project!=null)try{project.close();}catch(RuntimeException closed){/* closed while re-binding */}
427
+ if(repository!=null)repository.disconnect();
428
+ }
429
+ }
430
+ static Map<String,Object> handle(JsonObject q)throws Exception {
431
+ String operation=text(q,"operation");
432
+ if(operation.equals("exists"))return exists(q);
433
+ if(operation.equals("import"))return importPublish(q);
434
+ if(operation.equals("export"))return export(q);
435
+ return copy(q,operation);
436
+ }
437
+ public static void main(String[] args){
438
+ PrintStream out=new PrintStream(new java.io.FileOutputStream(java.io.FileDescriptor.out),true,StandardCharsets.UTF_8);System.setOut(System.err);
439
+ Object result;int code=0;
440
+ try{
441
+ JsonObject q=JsonParser.parseString(new String(System.in.readAllBytes(),StandardCharsets.UTF_8)).getAsJsonObject();
442
+ initialize();result=handle(q);
443
+ }catch(Refusal refusal){result=Map.of("error",refusal.code,"message",refusal.getMessage());}
444
+ catch(Throwable failure){failure.printStackTrace(System.err);code=1;
445
+ result=Map.of("error","failed","message",failure.getClass().getSimpleName()+": "+Objects.toString(failure.getMessage(),""));}
446
+ out.println("INSIGHT_WC "+GSON.toJson(result));out.flush();
447
+ System.exit(code);
448
+ }
449
+ }
@@ -0,0 +1,142 @@
1
+ import com.google.gson.*;
2
+ import com.xebyte.core.NamingPolicy;
3
+ import com.xebyte.headless.GhidraMCPHeadlessServer;
4
+ import com.xebyte.headless.HeadlessProgramProvider;
5
+ import ghidra.GhidraApplicationLayout;
6
+ import ghidra.framework.Application;
7
+ import ghidra.framework.client.RepositoryAdapter;
8
+ import ghidra.util.exception.FileInUseException;
9
+ import ghidra.framework.GhidraApplicationConfiguration;
10
+ import ghidra.framework.main.FrontEndTool;
11
+ import ghidra.framework.model.*;
12
+ import ghidra.framework.project.DefaultProjectManager;
13
+ import ghidra.program.model.listing.Program;
14
+ import java.io.*;
15
+ import java.nio.charset.StandardCharsets;
16
+ import java.util.*;
17
+ import javax.swing.SwingUtilities;
18
+
19
+ /**
20
+ * A worker on one working copy (#161): the GhidraMCP bridge on a loopback port, no token.
21
+ * stdin carries the worker's lifetime: `stop` or end of input saves changed programs into the working copy
22
+ * and exits, so a worker never outlives its owner. stdout carries one `INSIGHT_WC_READY <json>` line.
23
+ * Other stdin lines are requests `{"operation":"checkin"|"update",host,port,repository[,comment]}`, answered in order by one
24
+ * `INSIGHT_WC_REPLY <json>` line each: native check-in and Update run on the open program, which Ghidra moves onto the
25
+ * new version itself, so nothing is reopened. `{"state":"reopen"}` means this worker cannot (another repository address,
26
+ * a lost check-in, an open transaction): the owner stops it and repeats the request through InsightWcOps.
27
+ * Args: <request json> with root, programPath, bridgePort and mode.
28
+ */
29
+ public final class InsightWcWorker {
30
+ static Object field(Object owner,String name)throws Exception {var f=owner.getClass().getDeclaredField(name);f.setAccessible(true);return f.get(owner);}
31
+ /**
32
+ * The copy's program, with Ghidra recovery data of an interrupted session applied, in the project the bridge serves.
33
+ * The worker needs no server: the copy keeps the address it is bound to, and a check-in or Update on another address
34
+ * answers `reopen`, so the owner re-binds through InsightWcOps.
35
+ */
36
+ static DomainFile recovered(Project project,String path)throws Exception {
37
+ DomainFile file=InsightWcOps.file(project,path);
38
+ if(file==null||!file.isCheckedOut())throw new InsightWcOps.Refusal("not_found","The working copy has no checkout");
39
+ InsightWcOps.recover(file);return file;
40
+ }
41
+ /** One check-in or Update of the open program; the owner saved it first. */
42
+ static Map<String,Object> operate(Project project,String path,JsonObject q)throws Exception {
43
+ // Unsaved edits of the open program (a status read; needs no server).
44
+ if(InsightWcOps.text(q,"operation").equals("changed")){DomainFile open=InsightWcOps.file(project,path);return Map.of("changed",open!=null&&open.isChanged());}
45
+ InsightWcOps.initialize();
46
+ RepositoryAdapter repository=project.getProjectData().getRepository();
47
+ if(repository==null)throw new InsightWcOps.Refusal("invalid","The working copy is not a shared project");
48
+ ServerInfo bound=repository.getServerInfo();
49
+ // A new address needs a re-bind, which reopens the project: the owner does that with the program closed.
50
+ if(!bound.getServerName().equalsIgnoreCase(InsightWcOps.text(q,"host"))||bound.getPortNumber()!=q.get("port").getAsInt()
51
+ ||!repository.getName().equals(InsightWcOps.text(q,"repository")))return Map.of("state","reopen");
52
+ try{if(!repository.isConnected())repository.connect();}
53
+ catch(IOException unreachable){throw new InsightWcOps.Refusal("unavailable","Ghidra Server "+bound+" is not reachable");}
54
+ if(!repository.isConnected())throw new InsightWcOps.Refusal("unavailable","Ghidra Server "+bound+" is not reachable");
55
+ DomainFile file=InsightWcOps.file(project,path);
56
+ if(file==null||!file.isCheckedOut())throw new InsightWcOps.Refusal("not_found","The working copy has no checkout");
57
+ // Unsaved changes would be left out of the check-in; with an open transaction Ghidra refuses to move the open program.
58
+ if(file.isChanged())return Map.of("state","reopen");
59
+ try{
60
+ return switch(InsightWcOps.text(q,"operation")){
61
+ case "checkin"->InsightWcOps.checkin(project,repository,file,path,InsightWcOps.text(q,"comment"),true);
62
+ case "update"->InsightWcOps.update(project,repository,file,path);
63
+ default->throw new InsightWcOps.Refusal("invalid","Unknown worker operation");
64
+ };
65
+ }catch(FileInUseException busy){return Map.of("state","reopen");}
66
+ }
67
+ static Map<String,Object> reply(Project project,String path,String line){
68
+ try{return operate(project,path,JsonParser.parseString(line).getAsJsonObject());}
69
+ catch(InsightWcOps.Refusal refusal){return Map.of("error",refusal.code,"message",refusal.getMessage());}
70
+ catch(Throwable failure){failure.printStackTrace(System.err);
71
+ return Map.of("error","failed","message",failure.getClass().getSimpleName()+": "+Objects.toString(failure.getMessage(),""));}
72
+ }
73
+ public static void main(String[] args){
74
+ PrintStream out=new PrintStream(new FileOutputStream(FileDescriptor.out),true,StandardCharsets.UTF_8);System.setOut(System.err);
75
+ try{
76
+ JsonObject q=JsonParser.parseString(args[0]).getAsJsonObject();
77
+ String root=java.nio.file.Path.of(InsightWcOps.text(q,"root")).toAbsolutePath().toString(),path=InsightWcOps.text(q,"programPath"),port=InsightWcOps.text(q,"bridgePort");
78
+ Map<String,Object> ready=new LinkedHashMap<>();ready.put("pid",ProcessHandle.current().pid());ready.put("port",Integer.parseInt(port));
79
+ Runnable stop;Project[] active=new Project[1];
80
+ if(InsightWcOps.text(q,"mode").equals("gui")){
81
+ var configuration=new GhidraApplicationConfiguration();configuration.setShowSplashScreen(false);
82
+ Application.initializeApplication(new GhidraApplicationLayout(),configuration);
83
+ Project[] opened=new Project[1];
84
+ SwingUtilities.invokeAndWait(()->{
85
+ try{
86
+ var manager=new DefaultProjectManager(){};
87
+ var project=manager.openProject(InsightWcOps.locator(q),false,false);opened[0]=project;
88
+ var frontend=new FrontEndTool(manager);
89
+ if(project.getToolManager().getActiveWorkspace()==null)project.getToolManager().createWorkspace("Research").setActive();
90
+ frontend.setActiveProject(project);
91
+ var options=frontend.getOptions("GhidraMCP HTTP Server");
92
+ options.setInt("Server Port",Integer.parseInt(port));
93
+ options.setBoolean("Enable UDS Transport",false);options.setBoolean("Enable TCP Transport",true);
94
+ options.setBoolean("Strict Naming Enforcement",false);
95
+ frontend.addPlugin("com.xebyte.GhidraMCPPlugin");frontend.setVisible(true);
96
+ }catch(Exception failure){throw new RuntimeException(failure);}
97
+ });
98
+ recovered(opened[0],path);
99
+ // The caller opens the program in a tool through the bridge and saves through it before stopping.
100
+ active[0]=opened[0];
101
+ stop=()->{try{SwingUtilities.invokeAndWait(()->opened[0].close());}catch(Exception failure){failure.printStackTrace(System.err);}};
102
+ }else{
103
+ NamingPolicy.getInstance().setStrictNamingEnforcement(false,"insight facade");
104
+ GhidraMCPHeadlessServer server=new GhidraMCPHeadlessServer();
105
+ Thread bridge=new Thread(()->{
106
+ try{server.launch(new GhidraApplicationLayout(),new String[]{"--bind","127.0.0.1","--port",port});}
107
+ catch(Throwable failure){failure.printStackTrace(System.err);System.exit(1);}
108
+ },"insight-wc-bridge");
109
+ bridge.start();
110
+ for(long deadline=System.nanoTime()+180_000_000_000L;!(field(server,"programProvider")!=null&&Boolean.TRUE.equals(field(server,"running")));Thread.sleep(50))
111
+ if(System.nanoTime()>deadline||!bridge.isAlive())throw new IllegalStateException("The GhidraMCP bridge did not start");
112
+ HeadlessProgramProvider provider=(HeadlessProgramProvider)field(server,"programProvider");
113
+ if(!provider.openProject(InsightWcOps.locator(q).getMarkerFile().getAbsolutePath()))throw new IllegalStateException("The working copy could not be opened");
114
+ DomainFile file=recovered(provider.getProject(),path);
115
+ // The provider's own open writes nothing, so an untouched checkout stays unmodified.
116
+ Program program=provider.openDomainFile(file);
117
+ active[0]=provider.getProject();
118
+ ready.put("program",program.getDomainFile().getPathname());ready.put("readOnly",!program.getDomainFile().canSave()||!program.isChangeable());
119
+ stop=()->{
120
+ for(Program open:provider.getAllOpenPrograms())
121
+ if(open.isChanged()&&open.getDomainFile().canSave())try{open.save("insight worker stop",InsightWcOps.MONITOR);}catch(Exception failure){failure.printStackTrace(System.err);}
122
+ server.stop();
123
+ };
124
+ }
125
+ ready.put("root",root);
126
+ out.println("INSIGHT_WC_READY "+InsightWcOps.GSON.toJson(ready));out.flush();
127
+ try(var input=new BufferedReader(new InputStreamReader(System.in,StandardCharsets.UTF_8))){
128
+ for(String line;(line=input.readLine())!=null&&!line.trim().equals("stop");)
129
+ if(line.trim().startsWith("{")){out.println("INSIGHT_WC_REPLY "+InsightWcOps.GSON.toJson(reply(active[0],path,line)));out.flush();}
130
+ }catch(IOException closed){/* The owner is gone: stop as if asked. */}
131
+ stop.run();
132
+ // Leave Ghidra Server now instead of when its RMI lease of this client expires.
133
+ try{RepositoryAdapter bound=active[0]==null?null:active[0].getProjectData().getRepository();if(bound!=null)bound.disconnect();}catch(Throwable ignored){}
134
+ System.exit(0);
135
+ }catch(Throwable failure){
136
+ failure.printStackTrace(System.err);
137
+ String code=failure instanceof InsightWcOps.Refusal refusal?refusal.code:"failed";
138
+ out.println("INSIGHT_WC "+InsightWcOps.GSON.toJson(Map.of("error",code,"message",failure.getClass().getSimpleName()+": "+Objects.toString(failure.getMessage(),""))));out.flush();
139
+ System.exit(1);
140
+ }
141
+ }
142
+ }
@@ -1,14 +1,10 @@
1
1
  Native headless merge integration
2
2
 
3
- HeadlessProgramMergeManager.java adapts orchestration from Ghidra 12.1.2
4
- MergeManager.java, developed by the National Security Agency and distributed
5
- under the Apache License, Version 2.0 (APACHE-2.0.txt). It is modified for
6
- synchronous headless operation and refuses unresolved native decisions.
7
- ProgramMultiUserMergeManager creates/orders all stock resolvers.
8
-
9
3
  native-merge-patches.ts extracts six SHA-256-pinned upstream source files from
10
- the selected Ghidra installation into owned compilation storage. The generated
11
- sources retain their original license headers. Headless entry/display assumptions
4
+ the selected Ghidra installation into owned compilation storage. The upstream
5
+ sources are developed by the National Security Agency and distributed under the
6
+ Apache License, Version 2.0 (APACHE-2.0.txt). The generated sources retain their
7
+ original license headers. Headless entry/display assumptions
12
8
  are adapted. A separate native MemoryMergeManager compatibility correction covers
13
9
  unchanged-null comments and symmetric deletion/update conflicts. The native Update
14
10
  adapter also saves an unchanged merge result through Ghidra's DB save API so its
Binary file
@@ -10,7 +10,7 @@ commits and full retained license notices. Microsoft authentication libraries ar
10
10
  upstream transitive dependencies; this helper never creates credentials or symbol
11
11
  server clients. The no-files locator returns no external image or downloaded symbol.
12
12
 
13
- The maintainer builder compiles twice in independent temporary directories with SDK
14
- 10.0.303, locked restore and canonical source paths, compares every shipped output,
15
- and records source, notices and binary hashes. Parsing runs under the common owned
13
+ The maintainer Cake task `BuildHeapHelper` (`--output`, optional `--dotnet`) compiles in a
14
+ temporary directory with SDK 10.0.303, locked restore and canonical source paths, and
15
+ records source, notices and binary hashes. Parsing runs under the common owned
16
16
  process deadline. Heap scan, field, string, stack and output bounds remain explicit.