@jshookmcp/jshook 0.3.1 → 0.3.2

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 (226) hide show
  1. package/LICENSE +661 -661
  2. package/README.md +11 -3
  3. package/README.zh.md +11 -3
  4. package/dist/{AntiCheatDetector-CGVGNfy5.mjs → AntiCheatDetector-B6d4Qe9D.mjs} +1 -1
  5. package/dist/BrowserSessionCoordinator-BJ-HOxo0.mjs +1 -0
  6. package/dist/{CodeInjector-BlgyqTOk.mjs → CodeInjector-Cll_7bLJ.mjs} +1 -1
  7. package/dist/ConsoleMonitor-CxDJV15E.mjs +306 -0
  8. package/dist/DOMInspector-C19J4zeq.mjs +95 -0
  9. package/dist/DetailedDataManager-DmQ1LT-W.mjs +1 -0
  10. package/dist/ExtensionManager-BD724zkO.mjs +1 -0
  11. package/dist/ExtensionManager.tools-oVMJgPcN.mjs +1 -0
  12. package/dist/{HardwareBreakpoint-OcJqNFVc.mjs → HardwareBreakpoint-BUfPdp0f.mjs} +1 -1
  13. package/dist/{HeapAnalyzer-CqAxZzeS.mjs → HeapAnalyzer-B_aqY8oj.mjs} +1 -1
  14. package/dist/MCPServer.search.handlers.domain-BbS-6LnX.mjs +1 -0
  15. package/dist/MemoryController-X1XNSn1n.mjs +2 -0
  16. package/dist/{MemoryScanSession-CaxAjZJf.mjs → MemoryScanSession-DG_F-PjE.mjs} +1 -1
  17. package/dist/{MemoryScanner-BLYnMJy6.mjs → MemoryScanner-g1_L1ub5.mjs} +1 -1
  18. package/dist/{NativeMemoryManager.impl-CI554XbY.mjs → NativeMemoryManager.impl-DniBe2wf.mjs} +1 -1
  19. package/dist/{NativeMemoryManager.utils-DM4NC3FE.mjs → NativeMemoryManager.utils-BHy1P_jM.mjs} +1 -1
  20. package/dist/NetworkMonitor-B_-au6aV.mjs +185 -0
  21. package/dist/{PEAnalyzer-DJyaJTQJ.mjs → PEAnalyzer-yWQaGrcx.mjs} +1 -1
  22. package/dist/PageController-Dfsm1_o7.mjs +1 -0
  23. package/dist/{PointerChainEngine-5nF9eNlu.mjs → PointerChainEngine-BhCUkmxY.mjs} +1 -1
  24. package/dist/ProcessRegistry-C-bN48oR.mjs +1 -0
  25. package/dist/{ResponseBuilder-B2lu4KEl.mjs → ResponseBuilder-BfWP-uaT.mjs} +1 -1
  26. package/dist/RingBuffer-Dm54ELKT.mjs +1 -0
  27. package/dist/{ScriptManager-fgqiALgj.mjs → ScriptManager-LWGPTdvD.mjs} +1 -1
  28. package/dist/ServerRuntimeState-D2bWHqEE.mjs +1 -0
  29. package/dist/{Speedhack-l6s8L2Qw.mjs → Speedhack-yseDPSZ9.mjs} +1 -1
  30. package/dist/{StructureAnalyzer-A-WamfYE.mjs → StructureAnalyzer-C5lpuZkg.mjs} +1 -1
  31. package/dist/ToolCatalog-CYdD9F5f.mjs +1 -0
  32. package/dist/ToolProbe-C7ZU2x7M.mjs +1 -0
  33. package/dist/ToolRegistry-C5oB8KP8.mjs +1 -0
  34. package/dist/{ToolRouter.policy-CFHoN_Lw.mjs → ToolRouter.policy-CfhJczkt.mjs} +2 -2
  35. package/dist/{TraceRecorder-Dd8jLXpi.mjs → TraceRecorder-BiJWBXHX.mjs} +1 -1
  36. package/dist/{Win32Debug-CQteFL4F.mjs → Win32Debug-CYrIQBvr.mjs} +1 -1
  37. package/dist/{WorkflowEngine-CxEp2WXH.mjs → WorkflowEngine-D876meOO.mjs} +1 -1
  38. package/dist/analysis-D4swdMvq.mjs +6 -0
  39. package/dist/{antidebug-BOTZH6-0.mjs → antidebug-7L3ygj_9.mjs} +4 -4
  40. package/dist/apk-packer-BqXcInnX.mjs +1 -0
  41. package/dist/{artifactRetention-NBdncOEW.mjs → artifactRetention-BCPQASm7.mjs} +1 -1
  42. package/dist/{artifacts-B5xQuEa_.mjs → artifacts-CkodUM4j.mjs} +1 -1
  43. package/dist/betterSqlite3-Brtq-SIQ.mjs +1 -0
  44. package/dist/{binary-instrument-Cf9qqLlM.mjs → binary-instrument-DU7V6TUM.mjs} +1 -1
  45. package/dist/binary-secrets-PdMVoyt0.mjs +1 -0
  46. package/dist/{boringssl-inspector-BST5vtKx.mjs → boringssl-inspector-BBaJwwkU.mjs} +1 -1
  47. package/dist/browser-Qqco2rOT.mjs +11 -0
  48. package/dist/collector-Bpl6qy2L.mjs +1 -0
  49. package/dist/constants-BYj8Xek8.mjs +1 -0
  50. package/dist/{coordination-BbijHEHH.mjs → coordination-CWXW1o8K.mjs} +1 -1
  51. package/dist/dart-inspector-7AkPeZ_Q.mjs +0 -0
  52. package/dist/{debugger-CRJq_krh.mjs → debugger-DyALjYMk.mjs} +1 -1
  53. package/dist/{definitions-DZ8uKusP.mjs → definitions-BWxBke3r.mjs} +1 -1
  54. package/dist/{definitions-CYFbewnd.mjs → definitions-BYwATKc-.mjs} +1 -1
  55. package/dist/{definitions-DJklW2sS.mjs → definitions-B_83XfNQ.mjs} +1 -1
  56. package/dist/definitions-Bf3H1EwV.mjs +1 -0
  57. package/dist/{definitions-BGobEDQa.mjs → definitions-BftdXgXI.mjs} +1 -1
  58. package/dist/definitions-Bio5XJYy.mjs +1 -0
  59. package/dist/definitions-C3qNgSn1.mjs +1 -0
  60. package/dist/{definitions-NoVp_9Pm.mjs → definitions-CB6vmOer.mjs} +1 -1
  61. package/dist/{definitions-CoQFbggH.mjs → definitions-CMZRSy3k.mjs} +1 -1
  62. package/dist/{definitions-DI9YXsJk.mjs → definitions-CQd7yCQH.mjs} +1 -1
  63. package/dist/{definitions-CIO9O-Sw.mjs → definitions-CT8ln6GQ.mjs} +1 -1
  64. package/dist/{definitions-BGwNSkVm.mjs → definitions-Cenu6mxo.mjs} +1 -1
  65. package/dist/definitions-D4g-MS10.mjs +1 -0
  66. package/dist/{definitions-CuJRsJ6N.mjs → definitions-D5wl_8HN.mjs} +1 -1
  67. package/dist/{definitions-jXPaVy4P.mjs → definitions-DAQm1Xar.mjs} +1 -1
  68. package/dist/definitions-DP1vgxEY.mjs +1 -0
  69. package/dist/{definitions-Dds_zrWx.mjs → definitions-DxFNRQNK2.mjs} +1 -1
  70. package/dist/{definitions-DtE0XLrT.mjs → definitions-Ibci7e_L.mjs} +1 -1
  71. package/dist/{definitions-CCP9gphV.mjs → definitions-OeLvmlQy.mjs} +1 -1
  72. package/dist/{definitions-BbxOUiP-.mjs → definitions-RZYGD_Ey.mjs} +1 -1
  73. package/dist/definitions-Tls8c0A0.mjs +1 -0
  74. package/dist/{definitions-LaYTuwQd.mjs → definitions-bybDvnG0.mjs} +1 -1
  75. package/dist/{definitions-Dgrg7f3D.mjs → definitions-l7TjdE6V.mjs} +1 -1
  76. package/dist/{encoding-DGcr6Aj_.mjs → encoding-ycOaz8Vr.mjs} +1 -1
  77. package/dist/{ensure-browser-core-Buls24LQ.mjs → ensure-browser-core-DxWC-NTp.mjs} +1 -1
  78. package/dist/{factory-Cx_1LorX.mjs → factory-CKr4fAE1.mjs} +1 -1
  79. package/dist/{graphql-HLf3MS8H.mjs → graphql-B2TiPEow.mjs} +4 -4
  80. package/dist/{handlers-D49r1-1P.mjs → handlers-8zN_vBIz.mjs} +1 -1
  81. package/dist/handlers-B62K4FTc.mjs +1 -0
  82. package/dist/{handlers-BZoPla6E.mjs → handlers-BpDlVVVU.mjs} +1 -1
  83. package/dist/{handlers-DmQzIc44.mjs → handlers-CMJK7m1c.mjs} +1 -1
  84. package/dist/{handlers-BLMa4X7l.mjs → handlers-D2ZOul9p.mjs} +2 -2
  85. package/dist/{handlers-DW5AbYs5.mjs → handlers-D5E40ssn.mjs} +3 -3
  86. package/dist/{handlers-BP12ZsWc.mjs → handlers-DGbdQAgD.mjs} +2 -2
  87. package/dist/handlers-DHO3rjsW.mjs +1 -0
  88. package/dist/{handlers-DCE45Ww8.mjs → handlers-FJ80VzUI.mjs} +1 -1
  89. package/dist/handlers-VHWrxbM_.mjs +1 -0
  90. package/dist/{handlers-BggKiVx9.mjs → handlers-l8QIKqBj.mjs} +1 -1
  91. package/dist/{handlers-DnJRGp7t.mjs → handlers-mPFiNPe8.mjs} +1 -1
  92. package/dist/{handlers-pVNpaw4A.mjs → handlers-yo_xYzT8.mjs} +1 -1
  93. package/dist/handlers.impl-D9Hh8Bgl.mjs +1 -0
  94. package/dist/{hooks-DDKppogd.mjs → hooks-D4XLfgtV.mjs} +1 -1
  95. package/dist/index.mjs +11 -15
  96. package/dist/jadx-search-B_Yse0Zh.mjs +5 -0
  97. package/dist/maintenance-BUpIukhg.mjs +1 -0
  98. package/dist/{manifest-yu2xiQqe.mjs → manifest-0Jpt_AQa.mjs} +1 -1
  99. package/dist/{manifest-DMJlcsTR.mjs → manifest-B3fZbSWR.mjs} +1 -1
  100. package/dist/{manifest-De-6Wf2R.mjs → manifest-B7NB2rh2.mjs} +1 -1
  101. package/dist/manifest-BDi4nbH1.mjs +1 -0
  102. package/dist/{manifest-ais9Afrw.mjs → manifest-BLDfkE7n.mjs} +1 -1
  103. package/dist/manifest-BcXbB4gf.mjs +1 -0
  104. package/dist/{manifest-DsVh7Y4U.mjs → manifest-Bdnc_vrc.mjs} +1 -1
  105. package/dist/manifest-BuYKgCnp.mjs +1 -0
  106. package/dist/{manifest-Cx2IVMUY.mjs → manifest-CBfNnGPV.mjs} +1 -1
  107. package/dist/{manifest-DC-SMF6b.mjs → manifest-CPS1Xv69.mjs} +1 -1
  108. package/dist/{manifest-CGq4NpqH2.mjs → manifest-CQH9FhwI.mjs} +1 -1
  109. package/dist/{manifest-CRIJq4Hs.mjs → manifest-CRryuZF4.mjs} +1 -1
  110. package/dist/manifest-CctIumog.mjs +1 -0
  111. package/dist/manifest-CvTe5ZGV2.mjs +1 -0
  112. package/dist/{manifest-H-EpAyZQ.mjs → manifest-D-5GH0DV.mjs} +1 -1
  113. package/dist/{manifest-CtPmHAdn.mjs → manifest-D3Ssf3IC.mjs} +1 -1
  114. package/dist/{manifest-BeP_zJGb2.mjs → manifest-D5ck3NvC.mjs} +1 -1
  115. package/dist/{manifest-CeQmtQOY.mjs → manifest-D9jUUJAu.mjs} +1 -1
  116. package/dist/{manifest-C7qV1z7F.mjs → manifest-DCx6w2XV.mjs} +1 -1
  117. package/dist/{manifest-CFn0359q2.mjs → manifest-DG19q-Ld.mjs} +1 -1
  118. package/dist/{manifest-CJMGt7Qy.mjs → manifest-DLMlD0Zc.mjs} +1 -1
  119. package/dist/{manifest-CDeUZGUZ.mjs → manifest-DYpn8w_h.mjs} +1 -1
  120. package/dist/manifest-DYzWI8Xs.mjs +1 -0
  121. package/dist/{manifest-DKUorv5M.mjs → manifest-D_obs5F4.mjs} +1 -1
  122. package/dist/{manifest-D610kxZr.mjs → manifest-DujQqEQR.mjs} +2 -2
  123. package/dist/manifest-DwL2ik8P.mjs +1 -0
  124. package/dist/manifest-ItF5P8A12.mjs +1 -0
  125. package/dist/{manifest-tmb54wmA.mjs → manifest-KZphqIyX.mjs} +1 -1
  126. package/dist/{manifest-BPuE6oH2.mjs → manifest-LG42zPLY2.mjs} +1 -1
  127. package/dist/{manifest-D44TaRJU.mjs → manifest-LLdI5m4T.mjs} +1 -1
  128. package/dist/{manifest-Dgh0uDW-.mjs → manifest-QYbQXJn0.mjs} +1 -1
  129. package/dist/{manifest-BFGxlDRh.mjs → manifest-RcpX_MyZ.mjs} +2 -2
  130. package/dist/{manifest-CDiCtaQT.mjs → manifest-YgVd8Sgz.mjs} +1 -1
  131. package/dist/{manifest-D16xPXro.mjs → manifest-Zy7Odg5J.mjs} +1 -1
  132. package/dist/manifest-ff1H7Pdp.mjs +1 -0
  133. package/dist/{manifest-C_hEIjSx.mjs → manifest-iuhF6pTL2.mjs} +1 -1
  134. package/dist/{manifest-DWUUWBz0.mjs → manifest-nXHmtMSp2.mjs} +1 -1
  135. package/dist/{manifest-C1nZkTkO.mjs → manifest-xWfu6iLo.mjs} +1 -1
  136. package/dist/{manifest-C0g67k6U.mjs → manifest-yC16OhL2.mjs} +1 -1
  137. package/dist/manifest-ztWJoXy4.mjs +1 -0
  138. package/dist/modules-BPBcSaM-.mjs +333 -0
  139. package/dist/{mojo-ipc-VGlv3Qyp.mjs → mojo-ipc-BhwsdVUW.mjs} +1 -1
  140. package/dist/native/scripts/linux/enum-windows.sh +12 -12
  141. package/dist/native/scripts/macos/enum-windows.applescript +22 -22
  142. package/dist/native-j8l473zn.mjs +961 -0
  143. package/dist/network-T0VRwNPd.mjs +7 -0
  144. package/dist/{outputPaths-BonGThuc.mjs → outputPaths-B4Ic4RZh.mjs} +2 -2
  145. package/dist/platform-CzaQtISh.mjs +93 -0
  146. package/dist/process-CWhsCWrf.mjs +2 -0
  147. package/dist/proxy-DZFlDsG3.mjs +2 -0
  148. package/dist/{registry-DUHIPE-v.mjs → registry-DH4sc1dt.mjs} +1 -1
  149. package/dist/renderer-pid-9tJnZ_9N.mjs +1 -0
  150. package/dist/{search-defaults-D2bY-rzH.mjs → search-defaults-lYBVn_3L.mjs} +1 -1
  151. package/dist/server/plugin-api.d.mts +19 -36
  152. package/dist/server/plugin-api.mjs +1 -1
  153. package/dist/{shared-state-board-Cyg-xh_k.mjs → shared-state-board-BSjXLUV1.mjs} +1 -1
  154. package/dist/{sourcemap-D6Q1UuAp.mjs → sourcemap-Dh3Ai_ur.mjs} +1 -1
  155. package/dist/streaming-BcJ0B6ao.mjs +1 -0
  156. package/dist/transform-DOxzeWPB.mjs +103 -0
  157. package/dist/wasm-CZ_HTfKR.mjs +174 -0
  158. package/dist/{webcrack-CsLLJIs9.mjs → webcrack-C1iYG_EX.mjs} +3 -3
  159. package/dist/{workflow-CYIXtrWD.mjs → workflow-BdwQmARn.mjs} +4 -4
  160. package/package.json +16 -15
  161. package/src/native/scripts/linux/enum-windows.sh +12 -12
  162. package/src/native/scripts/macos/enum-windows.applescript +22 -22
  163. package/dist/ConsoleMonitor-Dkqc0HNi.mjs +0 -490
  164. package/dist/DOMInspector-BYY_EJ0C.mjs +0 -95
  165. package/dist/DetailedDataManager-BniBJlVv.mjs +0 -1
  166. package/dist/ExtensionManager-erMpqcLk.mjs +0 -1
  167. package/dist/MCPServer.search.handlers.domain-DVbWL1bT.mjs +0 -1
  168. package/dist/MemoryController-BaqstM5w.mjs +0 -2
  169. package/dist/PageController-D9jVkH0i.mjs +0 -1
  170. package/dist/ProcessRegistry-Hf12LlR9.mjs +0 -1
  171. package/dist/ToolCatalog-D_IKl1Hu.mjs +0 -1
  172. package/dist/ToolProbe-xsfALmN3.mjs +0 -1
  173. package/dist/ToolRegistry-B0Zs-phN.mjs +0 -1
  174. package/dist/analysis-BuR-NgX8.mjs +0 -5
  175. package/dist/betterSqlite3-CGaxz4AX.mjs +0 -1
  176. package/dist/browser-C4Le3xqA.mjs +0 -11
  177. package/dist/collector-CKO8RPK8.mjs +0 -1
  178. package/dist/constants-Cp6hBrrx.mjs +0 -1
  179. package/dist/definitions-CdWEuIkI.mjs +0 -1
  180. package/dist/definitions-OvGsfxdt.mjs +0 -1
  181. package/dist/handlers-D3iev8g1.mjs +0 -1
  182. package/dist/handlers-De5u62Ga2.mjs +0 -1
  183. package/dist/handlers-S9Ws0IGy.mjs +0 -2
  184. package/dist/handlers.impl-CD2_kOcC.mjs +0 -1
  185. package/dist/maintenance-CutEO84j.mjs +0 -1
  186. package/dist/manifest-BXry5N09.mjs +0 -1
  187. package/dist/manifest-Cq0j7GZt.mjs +0 -1
  188. package/dist/manifest-DD3rtxvV.mjs +0 -1
  189. package/dist/manifest-Dm0o3i2U.mjs +0 -1
  190. package/dist/manifest-DtEFSRaq.mjs +0 -1
  191. package/dist/manifest-zrbrpKCC.mjs +0 -1
  192. package/dist/modules-p-PUNv9r.mjs +0 -332
  193. package/dist/network-BjZ1Y-GB.mjs +0 -7
  194. package/dist/platform-C446Lf97.mjs +0 -93
  195. package/dist/process-C9f2A5zk.mjs +0 -962
  196. package/dist/proxy-CvRepxgV.mjs +0 -1
  197. package/dist/streaming-CTX58tbb.mjs +0 -1
  198. package/dist/transform-Cv9P2vVD.mjs +0 -103
  199. package/dist/wasm-DaJa8J0V.mjs +0 -174
  200. /package/dist/{CacheAdapters-CdAxBmVW.mjs → CacheAdapters-CsNtQIR8.mjs} +0 -0
  201. /package/dist/{DarwinAPI-DC4HGGLl.mjs → DarwinAPI-ZfQdpLNI.mjs} +0 -0
  202. /package/dist/{EventBus-DgciURGg.mjs → EventBus-DL8iLA09.mjs} +0 -0
  203. /package/dist/{EvidenceGraphBridge-BIfgB7HP.mjs → EvidenceGraphBridge-BtbwXsLC.mjs} +0 -0
  204. /package/dist/{FingerprintManager-N7BZqjxP.mjs → FingerprintManager-DT0EAUEo.mjs} +0 -0
  205. /package/dist/{HookGeneratorBuilders.core.generators.storage-Bf1fbrNK.mjs → HookGeneratorBuilders.core.generators.storage-DzD6dIJd.mjs} +0 -0
  206. /package/dist/{InstrumentationSession-DxXs0sCp.mjs → InstrumentationSession-D_G1ZPyd.mjs} +0 -0
  207. /package/dist/{PrerequisiteError-Bl3dK8XA.mjs → PrerequisiteError-BjCQA-gK.mjs} +0 -0
  208. /package/dist/{ReverseEvidenceGraph-B931HeoW.mjs → ReverseEvidenceGraph-BhSYYdiI.mjs} +0 -0
  209. /package/dist/{StealthVerifier-Dhbj4B4P.mjs → StealthVerifier-BmcxfwSF.mjs} +0 -0
  210. /package/dist/{VersionDetector-DMoUWyNm.mjs → VersionDetector-CHT36Az0.mjs} +0 -0
  211. /package/dist/{Win32API-Bhi5xFBe.mjs → Win32API-eUCF57l_.mjs} +0 -0
  212. /package/dist/{authorization-schema-B40obG1A.mjs → authorization-schema-BOFwSXUN.mjs} +0 -0
  213. /package/dist/{bind-helpers-BlAOQrFQ.mjs → bind-helpers-m2U8glkF.mjs} +0 -0
  214. /package/dist/{capabilities-DbYCv-HF.mjs → capabilities-CyXuKUl1.mjs} +0 -0
  215. /package/dist/{concurrency-CcK46d0h.mjs → concurrency-DCr8WQ2M.mjs} +0 -0
  216. /package/dist/{evidence-graph-bridge-B0yhGPcs.mjs → evidence-graph-bridge-CV_UdYqj.mjs} +0 -0
  217. /package/dist/{flat-target-session-CO5g78k3.mjs → flat-target-session-DvcQX7J5.mjs} +0 -0
  218. /package/dist/{formatAddress-C7j2fDlM.mjs → formatAddress-vLA_hOJt.mjs} +0 -0
  219. /package/dist/{handlers-Dv_runVv.mjs → handlers-0yKLRIfo.mjs} +0 -0
  220. /package/dist/{matchesWildcardPattern-BGqLSmEs.mjs → matchesWildcardPattern-BAG6LvX5.mjs} +0 -0
  221. /package/dist/{parse-args-Cuk7-xUt.mjs → parse-args-Bw413PlW.mjs} +0 -0
  222. /package/dist/{playwright-cdp-fallback-BwVR-_T3.mjs → playwright-cdp-fallback-DqFdx9-s.mjs} +0 -0
  223. /package/dist/{ssrf-policy-T96MR3r6.mjs → ssrf-policy-CsIJGkpd.mjs} +0 -0
  224. /package/dist/{tool-builder-CI9914Tf.mjs → tool-builder-qif8M9-K.mjs} +0 -0
  225. /package/dist/{types-DtThH00r.mjs → types-D9EiE5o9.mjs} +0 -0
  226. /package/dist/{types-CuyefmGT.mjs → types-Fz69RzbZ.mjs} +0 -0
@@ -0,0 +1,961 @@
1
+ import{t as e}from"./logger-sBC6IdRT.mjs";import{$t as t,Jt as n,Q as r,Qt as i,Tn as a,Xt as o,Yt as s,Z as c,Zt as l,cn as u,di as d,dn as f,dt as p,en as m,fi as h,in as g,ln as _,nn as v,on as y,qt as b,rn as x,sn as S,tn as C,wn as w}from"./constants-BYj8Xek8.mjs";import{t as T}from"./ProcessRegistry-C-bN48oR.mjs";import{n as ee,r as E,t as D}from"./types-D9EiE5o9.mjs";import{v as O}from"./Win32API-eUCF57l_.mjs";import{i as k,r as A}from"./factory-CKr4fAE1.mjs";import{r as j,t as M}from"./NativeMemoryManager.utils-BHy1P_jM.mjs";import{t as N}from"./NativeMemoryManager.impl-DniBe2wf.mjs";import{existsSync as P,promises as te,readFileSync as ne}from"fs";import{platform as re,tmpdir as F}from"node:os";import{closeSync as ie,openSync as ae,promises as I,readFileSync as oe,readSync as se}from"node:fs";import{join as L}from"node:path";import{fileURLToPath as ce}from"node:url";import{exec as R,execFile as le,spawn as z}from"child_process";import{promisify as B}from"util";let V=null;function ue(){if(V)return V;try{return V=ce(new URL(`.`,import.meta.url)),V}catch{return null}}var H=class{scriptCache=new Map;scriptsDir;constructor(){let e=ue();e&&P(L(e,`native`,`scripts`))?this.scriptsDir=L(e,`native`,`scripts`):e&&P(L(e,`scripts`))?this.scriptsDir=L(e,`scripts`):P(L(process.cwd(),`dist`,`native`,`scripts`))?this.scriptsDir=L(process.cwd(),`dist`,`native`,`scripts`):P(L(process.cwd(),`src`,`native`,`scripts`))?this.scriptsDir=L(process.cwd(),`src`,`native`,`scripts`):this.scriptsDir=L(process.cwd(),`dist`,`native`,`scripts`)}async loadScript(e){if(this.scriptCache.has(e))return this.scriptCache.get(e);let t=re(),n=t===`win32`?`windows`:t===`darwin`?`macos`:`linux`,r=L(this.scriptsDir,n,e),i=await te.readFile(r,`utf-8`);return this.scriptCache.set(e,i),i}getScriptPath(e){let t=re(),n=t===`win32`?`windows`:t===`darwin`?`macos`:`linux`;return L(this.scriptsDir,n,e)}clearCache(){this.scriptCache.clear()}},de=class{scriptLoader;browserSignatures=new Map([[`chrome`,{windowClasses:[`Chrome_WidgetWin_0`,`Chrome_WidgetWin_1`,`Chrome_WidgetWin_*`],processNames:[`chrome.exe`,`chrome`],mainWindowTitle:/.*- Google Chrome$/,debugPorts:[9222,9229,9333]}],[`edge`,{windowClasses:[`Edge_WidgetWin_0`,`Edge_WidgetWin_1`,`Edge_WidgetWin_*`],processNames:[`msedge.exe`,`msedge`],mainWindowTitle:/.*- Microsoft Edge$/,debugPorts:[9222,9229]}],[`firefox`,{windowClasses:[`MozillaWindowClass`],processNames:[`firefox.exe`,`firefox`],mainWindowTitle:/.*- Mozilla Firefox$/,debugPorts:[9222]}]]);constructor(){this.scriptLoader=new H}sanitizePsInput(e){return e.replace(/[`$"'{}();|<>@#%!\\\n\r]/g,``)}escapePowerShellSingleQuoted(e){return this.sanitizePsInput(e).replace(/'/g,`''`)}async discoverBrowsers(){let e=[];for(let[t,n]of this.browserSignatures){let r=await this.findBySignature(t,n);e.push(...r)}return e}async findBySignature(e,t){let n=[],r=new Set;for(let i of t.processNames){let t=await this.findByProcessName(i);for(let i of t)r.has(i.pid)||(r.add(i.pid),n.push({type:e,pid:i.pid,hwnd:i.hwnd,title:i.title}))}for(let i of t.windowClasses){let t=await this.findByWindowClass(i);for(let i of t)r.has(i.pid)||(r.add(i.pid),n.push({type:e,pid:i.pid,hwnd:i.hwnd,title:i.title}))}for(let e of n){let n=await this.detectDebugPort(e.pid,t.debugPorts);n&&(e.debugPort=n)}return n}async findByWindowClass(e){let t=this.scriptLoader.getScriptPath(`enum-windows-by-class.ps1`);try{let n=this.escapePowerShellSingleQuoted(e),{execFile:r}=await import(`child_process`),{promisify:i}=await import(`util`),{stdout:a}=await i(r)(`powershell.exe`,[`-NoProfile`,`-ExecutionPolicy`,`Bypass`,`-File`,t,`-ClassPattern`,n],{maxBuffer:1024*1024*10});return this.parseWindowsResult(a,e)}catch(t){return console.error(`Failed to find windows by class '${e}':`,t),[]}}async findByProcessName(e){try{let t=`$Pattern='${this.escapePowerShellSingleQuoted(e)}'; Get-Process -Name "*$Pattern*" -ErrorAction SilentlyContinueSelect-Object Id, ProcessName, Path, MainWindowTitle, MainWindowHandle, CPU, WorkingSet64ConvertTo-Json -Compress`,{execFile:n}=await import(`child_process`),{promisify:r}=await import(`util`),{stdout:i}=await r(n)(`powershell.exe`,[`-NoProfile`,`-Command`,t],{maxBuffer:1024*1024*10});return this.parseProcessResult(i,e)}catch(t){return console.error(`Failed to find process by name '${e}':`,t),[]}}parseWindowsResult(e,t){let n=[];if(!e.trim()||e.trim()===`null`)return n;try{let t=JSON.parse(e.trim()),r=Array.isArray(t)?t:[t];for(let e of r){let t=`unknown`,r=e.Title||``;for(let[e,n]of this.browserSignatures)if(n.mainWindowTitle?.test(r)){t=e;break}if(t===`unknown`)for(let[n,r]of this.browserSignatures){for(let i of r.windowClasses){let r=i.replace(/\*/g,`.*`);if(new RegExp(r).test(e.ClassName||``)){t=n;break}}if(t!==`unknown`)break}n.push({type:t,pid:e.ProcessId,hwnd:e.Handle,title:e.Title})}}catch(e){console.error(`Failed to parse windows result:`,e)}return n}parseProcessResult(e,t){let n=[];if(!e.trim()||e.trim()===`null`)return n;try{let t=JSON.parse(e.trim()),r=Array.isArray(t)?t:[t];for(let e of r){let t=`unknown`,r=(e.ProcessName||``).toLowerCase();r.includes(`chrome`)?t=`chrome`:r.includes(`msedge`)||r.includes(`edge`)?t=`edge`:r.includes(`firefox`)&&(t=`firefox`),n.push({type:t,pid:e.Id,hwnd:e.MainWindowHandle?.toString(),title:e.MainWindowTitle})}}catch(e){console.error(`Failed to parse process result:`,e)}return n}async detectDebugPort(e,t){let n=await this.checkDebugPortFromCommandLine(e);if(n)return n;for(let n of t)if(await this.checkPort(e,n))return n;return null}async checkDebugPortFromCommandLine(e){let{execFile:t}=await import(`child_process`),{promisify:n}=await import(`util`),r=n(t);try{if(!Number.isFinite(e)||e<=0)return null;let{stdout:t}=await r(`powershell.exe`,[`-NoProfile`,`-Command`,`Get-CimInstance Win32_Process -Filter "ProcessId = ${Math.trunc(e)}"Select-Object CommandLine, ParentProcessId | ConvertTo-Json -Compress`],{maxBuffer:1024*1024});if(!t.trim()||t.trim()===`null`)return null;let n=(JSON.parse(t.trim()).CommandLine||``).match(/--remote-debugging-port=(\d+)/);return n?.[1]?parseInt(n[1],10):null}catch{return null}}async checkPort(e,t){let{execFile:n}=await import(`child_process`),{promisify:r}=await import(`util`),i=r(n);try{if(!Number.isFinite(e)||e<=0||!Number.isFinite(t)||t<=0)return!1;let{stdout:n}=await i(`powershell.exe`,[`-NoProfile`,`-Command`,`Get-NetTCPConnection -OwningProcess ${Math.trunc(e)} -State Listen -ErrorAction SilentlyContinueSelect-Object LocalPort | ConvertTo-Json -Compress`],{maxBuffer:1024*1024});if(!n.trim()||n.trim()===`null`)return!1;let r=JSON.parse(n.trim()),a=Array.isArray(r)?r:[r];for(let e of a)if(e.LocalPort===t)return!0;return!1}catch{return!1}}};function U(e,t){return t?typeof t==`string`?e.includes(t):t.test(e):!1}async function fe(e,t){let n={rendererProcesses:[],utilityProcesses:[]};try{let r;if(e.processNamePattern instanceof RegExp){let n=await t.findProcesses(``),i=e.processNamePattern;r=n.filter(e=>i.test(e.name))}else{let n=e.processNamePattern||`chromium`;r=await t.findProcesses(n)}for(let e of r){let r=await t.getProcessCommandLine(e.pid);if(r?.commandLine){let t=r.commandLine.toLowerCase();t.includes(`--type=renderer`)?n.rendererProcesses.push({...e,...r}):t.includes(`--type=gpu-process`)?n.gpuProcess={...e,...r}:t.includes(`--type=utility`)?n.utilityProcesses.push({...e,...r}):t.includes(`--type=`)||(n.mainProcess={...e,...r})}else n.mainProcess||=e}let i=[n.mainProcess?.pid,...n.rendererProcesses.map(e=>e.pid)].filter(Boolean),a=t=>U(t.title,e.windowTitlePattern)||U(t.className,e.windowClassPattern);for(let e of i){let r=(await t.getProcessWindows(e)).find(a);if(r){n.targetWindow=r;break}}return t.logInfo(`Chromium processes found:`,{main:n.mainProcess?.pid,renderers:n.rendererProcesses.length,hasTargetWindow:!!n.targetWindow}),n}catch(e){return t.logError(`Failed to find Chromium processes:`,e),n}}const pe={processNamePattern:/^(chromium|chrome|msedge)$/i,windowClassPattern:`Chrome_WidgetWin`},W=B(R);function me(e){return String(e||``).replace(/[`$"'{}();|<>@#%!\\\n\r]/g,``)}function G(e){let t=Math.trunc(Number(e));if(!Number.isFinite(t)||t<=0)throw Error(`Invalid PID: ${e}`);return t}var he=class{powershellPath=`powershell.exe`;scriptLoader;browserDiscovery;processCache=new Map;constructor(){this.scriptLoader=new H,this.browserDiscovery=new de,e.info(`ProcessManager initialized for Windows platform`)}async findProcesses(t){try{let n=me(String(t||``).trim()),r=n.toLowerCase()||`*`,i=Date.now(),o=this.processCache.get(r);if(o&&o.expiresAt>i)return o.snapshot;let s;s=n?`Get-Process -Name "*${n.replace(/"/g,`""`)}*" -ErrorAction SilentlyContinue Select-Object Id, ProcessName, Path, MainWindowTitle, MainWindowHandle, CPU, WorkingSet64 ConvertTo-Json -Compress`:`Get-Process -ErrorAction SilentlyContinue | Select-Object Id, ProcessName, Path, MainWindowTitle, MainWindowHandle, CPU, WorkingSet64 | ConvertTo-Json -Compress`;let{stdout:c}=await W(`${this.powershellPath} -NoProfile -Command "${s}"`,{maxBuffer:a}),l=c.trim(),u=[];if(l&&l!==`null`){let e=JSON.parse(l),t=Array.isArray(e)?e:[e];for(let e of t)u.push({pid:e.Id,name:e.ProcessName,executablePath:e.Path})}let d=new Map;for(let e of u)d.set(e.pid,e);let f=this.computeProcessDiff(o?.byPid??new Map,d);this.processCache.set(r,{expiresAt:i+3e3,snapshot:u,byPid:d,lastDelta:f});let p=n.length>0?`'${n}'`:`all`;return e.info(`Found ${u.length} processes matching ${p}`),u}catch(n){return e.error(`Failed to find processes with pattern '${t}':`,n),[]}}computeProcessDiff(e,t){let n=[],r=[],i=[];for(let[r,a]of t){let t=e.get(r);if(!t){n.push(a);continue}(t.pid!==a.pid||t.name!==a.name||t.executablePath!==a.executablePath)&&i.push({before:t,after:a})}for(let[n,i]of e)t.has(n)||r.push(i);return{added:n,removed:r,changed:i}}async getProcessByPid(t){try{t=G(t);let e=`Get-Process -Id ${t} -ErrorAction SilentlyContinue | Select-Object Id, ProcessName, Path, MainWindowTitle, MainWindowHandle, CPU, WorkingSet64, StartTime | ConvertTo-Json -Compress`,{stdout:n}=await W(`${this.powershellPath} -NoProfile -Command "${e}"`,{maxBuffer:1024*1024});if(!n.trim()||n.trim()===`null`)return null;let r=JSON.parse(n.trim());return{pid:r.Id,name:r.ProcessName,executablePath:r.Path,windowTitle:r.MainWindowTitle,windowHandle:r.MainWindowHandle?.toString(),cpuUsage:r.CPU,memoryUsage:r.WorkingSet64}}catch(n){return e.error(`Failed to get process by PID ${t}:`,n),null}}async getProcessWindows(t){try{t=G(t);let e=await this.scriptLoader.getScriptPath(`enum-windows.ps1`),{stdout:n}=await W(`${this.powershellPath} -NoProfile -ExecutionPolicy Bypass -File "${e}" -TargetPid ${t}`,{maxBuffer:1024*1024});if(!n.trim()||n.trim()===`null`)return[];let r=JSON.parse(n.trim()),i=[],a=Array.isArray(r)?r:[r];for(let e of a)i.push({handle:e.Handle,title:e.Title,className:e.ClassName,processId:e.ProcessId,threadId:0});return i}catch(n){return e.error(`Failed to get windows for PID ${t}:`,n),[]}}async findChromiumProcesses(t=pe){return fe(t,{findProcesses:e=>this.findProcesses(e),getProcessCommandLine:e=>this.getProcessCommandLine(e),getProcessWindows:e=>this.getProcessWindows(e),logInfo:(t,n)=>e.info(t,n),logError:(t,n)=>e.error(t,n)})}async findChromiumAppProcesses(){return this.findChromiumProcesses()}async getProcessCommandLine(t){try{t=G(t);let e=`Get-CimInstance Win32_Process -Filter 'ProcessId = ${t}' | Select-Object CommandLine, ParentProcessId | ConvertTo-Json -Compress`,{stdout:n}=await W(`${this.powershellPath} -NoProfile -Command "${e}"`,{maxBuffer:1024*1024});if(!n.trim()||n.trim()===`null`)return{};let r=JSON.parse(n.trim());return{commandLine:r.CommandLine,parentPid:r.ParentProcessId}}catch(n){return e.error(`Failed to get command line for PID ${t}:`,n),{}}}async checkDebugPort(t,n){try{t=G(t);let e=n?.commandLine??(await this.getProcessCommandLine(t)).commandLine;if(e){let t=e.match(/--remote-debugging-port=(\d+)/);if(t?.[1])return parseInt(t[1],10)}let r=`Get-NetTCPConnection -OwningProcess ${t} -State Listen -ErrorAction SilentlyContinueSelect-Object LocalPort | ConvertTo-Json -Compress`,{stdout:i}=await W(`${this.powershellPath} -NoProfile -Command "${r}"`,{maxBuffer:1024*1024});if(i.trim()&&i.trim()!==`null`){let e=JSON.parse(i.trim()),t=Array.isArray(e)?e:[e];for(let e of t)if(c.includes(e.LocalPort))return e.LocalPort}return null}catch(n){return e.error(`Failed to check debug port for PID ${t}:`,n),null}}async findPidByListeningPort(e){try{let t=`Get-NetTCPConnection -LocalPort ${e} -State Listen -ErrorAction SilentlyContinueSelect-Object -First 1 OwningProcess | ConvertTo-Json -Compress`,{stdout:n}=await W(`${this.powershellPath} -NoProfile -Command "${t}"`,{maxBuffer:1024*1024});if(!n.trim()||n.trim()===`null`)return null;let r=JSON.parse(n.trim()),i=Array.isArray(r)?r[0]:r,a=i?.OwningProcess??i?.owningProcess??i,o=Number(a);return Number.isFinite(o)&&o>0?o:null}catch{return null}}async launchWithDebug(t,n=r,i=[]){try{let r=z(t,[`--remote-debugging-port=${n}`,...i],{detached:!0,stdio:`ignore`});r.unref(),T.register(r);let a=r.pid||0,o=t.split(/[\\/]/).pop()||`unknown`,s=a>0?a:null;for(let i=0;i<d;i++){let i=await this.findPidByListeningPort(n);if(i&&i>0&&(s=i),s&&s>0){let a=await this.getProcessByPid(s);if(a)return e.info(`Launched process with debug port ${n}:`,{pid:r.pid,resolvedPid:s,executable:t}),a;if(i&&i===s)return e.info(`Launched process with debug port ${n}:`,{pid:r.pid,resolvedPid:s,executable:t}),{pid:s,name:o,executablePath:t}}await new Promise(e=>setTimeout(e,h))}return e.info(`Launched process with debug port ${n}:`,{pid:r.pid,resolvedPid:s,executable:t}),s&&s>0?{pid:s,name:o,executablePath:t}:null}catch(t){return e.error(`Failed to launch process with debug:`,t),null}}async injectDll(t,n){try{if(!Number.isFinite(t)||t<=0)return e.error(`Invalid PID for injectDll: ${t}`),!1;let r=this.scriptLoader.getScriptPath(`inject-dll.ps1`),i=Math.trunc(t),a=String(n).replace(/'/g,`''`);return await W(`${this.powershellPath} -NoProfile -ExecutionPolicy Bypass -File "${r}" -TargetPid ${i} -DllPath '${a}'`,{maxBuffer:1024*1024}),e.warn(`DLL injection is disabled for safety in this implementation`),!1}catch(t){return e.error(`DLL injection failed:`,t),!1}}async killProcess(t){try{if(!Number.isFinite(t)||t<=0)return e.error(`Invalid PID for killProcess: ${t}`),!1;let n=Math.trunc(t),r=`Stop-Process -Id ${n} -Force -ErrorAction SilentlyContinue; Write-Output "Process ${n} killed"`;return await W(`${this.powershellPath} -NoProfile -Command "${r}"`,{maxBuffer:1024*1024}),e.info(`Process ${n} killed successfully`),!0}catch(n){return e.error(`Failed to kill process ${t}:`,n),!1}}async discoverBrowsers(){try{let t=await this.browserDiscovery.discoverBrowsers();return e.info(`Discovered ${t.length} browser instances`),t}catch(t){return e.error(`Failed to discover browsers:`,t),[]}}async findBrowserByWindowClass(t){try{let n=await this.browserDiscovery.findByWindowClass(t);return e.info(`Found ${n.length} browsers matching window class '${t}'`),n}catch(n){return e.error(`Failed to find browser by window class '${t}':`,n),[]}}async findBrowserByProcessName(t){try{let n=await this.browserDiscovery.findByProcessName(t);return e.info(`Found ${n.length} browsers matching process name '${t}'`),n}catch(n){return e.error(`Failed to find browser by process name '${t}':`,n),[]}}async detectBrowserDebugPort(t,n){try{let r=n||c,i=await this.browserDiscovery.detectDebugPort(t,r);return i?e.info(`Detected debug port ${i} for process ${t}`):e.warn(`No debug port detected for process ${t}`),i}catch(n){return e.error(`Failed to detect debug port for PID ${t}:`,n),null}}};const K=B(R);function ge(e){return String(e||``).replace(/[^\w\s.@/\-:,+]/g,``)}function q(e){let t=Math.trunc(Number(e));if(!Number.isFinite(t)||t<=0)throw Error(`Invalid PID: ${e}`);return t}var _e=class{isWayland=!1;constructor(){this.detectDisplayServer(),e.info(`LinuxProcessManager initialized`,{displayServer:this.isWayland?`Wayland`:`X11`})}async detectDisplayServer(){try{let{stdout:e}=await K(`echo $XDG_SESSION_TYPE`);this.isWayland=e.trim()===`wayland`}catch{this.isWayland=!1}}async findProcesses(t){try{let{stdout:n}=await K(`ps aux | grep -i "${ge(t)}" | grep -v grep || true`,{maxBuffer:a}),r=[],i=n.trim().split(`
2
+ `).filter(e=>e.trim());for(let e of i){let t=e.trim().split(/\s+/);if(t.length>=11){let e=parseInt(t[1]||`0`,10);if(isNaN(e))continue;let n=parseFloat(t[2]||`0`),i=parseFloat(t[3]||`0`),a=t.slice(10).join(` `);r.push({pid:e,name:t[10]||a.split(` `)[0]||`unknown`,commandLine:a,cpuUsage:n,memoryUsage:i*1024*1024})}}return e.info(`Found ${r.length} processes matching '${t}'`),r}catch(n){return e.error(`Failed to find processes with pattern '${t}':`,n),[]}}async getProcessByPid(t){try{t=q(t);let{stdout:e}=await K(`cat /proc/${t}/status 2>/dev/null || echo ""`),{stdout:n}=await K(`cat /proc/${t}/cmdline 2>/dev/null | tr '\0' ' ' || echo ""`),{stdout:r}=await K(`cat /proc/${t}/stat 2>/dev/null || echo ""`);if(!e.trim())return null;let i={};for(let t of e.split(`
3
+ `)){let[e,n]=t.split(`:`);e&&n&&(i[e.trim()]=n.trim())}let a=r.trim().split(` `),o=a.length>13?parseInt(a[13]||`0`,10):0,s=a.length>14?parseInt(a[14]||`0`,10):0;return{pid:t,name:i.Name||`unknown`,executablePath:await this.getProcessPath(t),commandLine:n.trim()||void 0,parentPid:i.PPid?parseInt(i.PPid,10):void 0,memoryUsage:i.VmRSS?parseInt(i.VmRSS.replace(/\D/g,``),10)*1024:void 0,cpuUsage:o+s}}catch(n){return e.error(`Failed to get process by PID ${t}:`,n),null}}async getProcessPath(e){try{e=q(e);let{stdout:t}=await K(`readlink -f /proc/${e}/exe 2>/dev/null || echo ""`);return t.trim()||void 0}catch{return}}async getProcessWindows(t){let n=[];try{if(t=q(t),this.isWayland){e.debug(`Attempting Wayland window enumeration via compositor-specific APIs`);try{let{stdout:e}=await K(`hyprctl clients -j 2>/dev/null`);if(e.trim()){let r=JSON.parse(e);for(let e of r)e.pid===t&&n.push({handle:e.address||e.window||`0`,title:e.title||``,className:e.class||``,processId:t,threadId:0});if(n.length>0)return n}}catch{}try{let{stdout:n}=await K(`gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "global.get_window_actors().filter(w => w.meta_window.get_pid() === ${t}).map(w => w.meta_window.get_title() + '|' + w.meta_window.get_wm_class())" 2>/dev/null`);(n.includes(String(t))||n.includes(`,`))&&e.debug(`GNOME Wayland window query returned data, but reliable parsing is not yet implemented`)}catch{}}let{stdout:r}=await K(`which xdotool 2>/dev/null || echo ""`);if(!r.trim())return this.isWayland&&n.length===0?e.warn(`Wayland native enumeration failed and xdotool is missing. Install xdotool for XWayland fallback.`):this.isWayland||e.warn(`xdotool not found. Install it for window management: sudo apt-get install xdotool`),n;let{stdout:i}=await K(`xdotool search --all --pid ${t} 2>/dev/null || true`),a=i.trim().split(`
4
+ `).filter(e=>e.trim());for(let e of a)try{let{stdout:r}=await K(`xdotool getwindowname ${e} 2>/dev/null || echo ""`),{stdout:i}=await K(`xdotool getwindowclassname ${e} 2>/dev/null || echo ""`);n.push({handle:e,title:r.trim(),className:i.trim(),processId:t,threadId:0})}catch{}return n}catch(r){return e.error(`Failed to get windows for PID ${t}:`,r),n}}async findChromeProcesses(){let t={rendererProcesses:[],utilityProcesses:[]};try{let n=await this.findProcesses(`chrome`),r=await Promise.all(n.map(e=>this.getProcessByPid(e.pid)));for(let e=0;e<n.length;e++){let i=n[e],a=r[e];if(a?.commandLine){let e=a.commandLine.toLowerCase();e.includes(`--type=renderer`)?t.rendererProcesses.push({...i,...a}):e.includes(`--type=gpu-process`)?t.gpuProcess={...i,...a}:e.includes(`--type=utility`)?t.utilityProcesses.push({...i,...a}):e.includes(`--type=`)||(t.mainProcess={...i,...a})}else t.mainProcess||=i}let i=[t.mainProcess?.pid,...t.rendererProcesses.map(e=>e.pid)].filter(Boolean);for(let e of i){let n=(await this.getProcessWindows(e)).find(e=>e.title.includes(`Chrome`)||e.className.includes(`Chrome`)||e.title.includes(`Chromium`));if(n){t.targetWindow=n;break}}return e.info(`Chrome processes found:`,{main:t.mainProcess?.pid,renderers:t.rendererProcesses.length,hasTargetWindow:!!t.targetWindow}),t}catch(n){return e.error(`Failed to find Chrome processes:`,n),t}}async getProcessCommandLine(t){try{t=q(t);let{stdout:e}=await K(`cat /proc/${t}/cmdline 2>/dev/null | tr '\0' ' ' || echo ""`),{stdout:n}=await K(`cat /proc/${t}/status 2>/dev/null | grep PPid || echo ""`),r=n.match(/PPid:\s*(\d+)/);return{commandLine:e.trim()||void 0,parentPid:r?.[1]?parseInt(r[1],10):void 0}}catch(n){return e.error(`Failed to get command line for PID ${t}:`,n),{}}}async checkDebugPort(t,n){try{t=q(t);let e=n?.commandLine??(await this.getProcessCommandLine(t)).commandLine;if(e){let t=e.match(/--remote-debugging-port=(\d+)/);if(t?.[1])return parseInt(t[1],10)}let{stdout:r}=await K(`ss -tlnp 2>/dev/null | grep "pid=${t}" || netstat -tlnp 2>/dev/null | grep "${t}" || true`,{maxBuffer:1024*1024});for(let e of c)if(r.includes(`:${e}`))return e;return null}catch(n){return e.error(`Failed to check debug port for PID ${t}:`,n),null}}async launchWithDebug(t,n=r,i=[]){try{let r=z(t,[`--remote-debugging-port=${n}`,...i],{detached:!0,stdio:`ignore`});if(r.unref(),T.register(r),await new Promise(e=>setTimeout(e,w)),!r.pid)return e.error(`Failed to spawn process: PID is undefined for ${t}`),null;let a=await this.getProcessByPid(r.pid);return e.info(`Launched process with debug port ${n}:`,{pid:r.pid,executable:t}),a}catch(t){return e.error(`Failed to launch process with debug:`,t),null}}async killProcess(t){try{return t=q(t),await K(`kill -9 ${t} 2>/dev/null || kill -15 ${t}`),e.info(`Process ${t} killed successfully`),!0}catch(n){return e.error(`Failed to kill process ${t}:`,n),!1}}isRunningOnWayland(){return this.isWayland}};const J=B(R),ve=B(le);function ye(e){return String(e||``).replace(/[^\w\s.@/\-:,+]/g,``)}function Y(e){let t=Math.trunc(Number(e));if(!Number.isFinite(t)||t<=0)throw Error(`Invalid PID: ${e}`);return t}function be(e,t){let n=e;for(let[e,r]of Object.entries(t)){let t=RegExp(`\\{\\{${e}\\}\\}`,`g`);n=n.replace(t,String(r))}return n}var xe=class{constructor(){e.info(`MacProcessManager initialized`)}async findProcesses(t){try{let{stdout:n}=await J(`ps aux | grep -i "${ye(t)}" | grep -v grep || true`,{maxBuffer:a}),r=[],i=n.trim().split(`
5
+ `).filter(e=>e.trim());for(let e of i){let t=e.trim().split(/\s+/);if(t.length>=11){let e=parseInt(t[1]||`0`,10);if(isNaN(e))continue;let n=parseFloat(t[2]||`0`),i=parseFloat(t[3]||`0`),a=t.slice(10).join(` `);r.push({pid:e,name:t[10]||a.split(` `)[0]||`unknown`,commandLine:a,cpuUsage:n,memoryUsage:i*1024*1024})}}return e.info(`Found ${r.length} processes matching '${t}'`),r}catch(n){return e.error(`Failed to find processes with pattern '${t}':`,n),[]}}async getProcessByPid(t){try{t=Y(t);let{stdout:e}=await J(`ps -p ${t} -o pid,ppid,pcpu,pmem,comm,args 2>/dev/null || echo ""`),n=e.trim().split(`
6
+ `).filter(e=>e.trim());if(n.length<2)return null;let r=(n[1]||``).trim().split(/\s+/);return r.length>=6?{pid:parseInt(r[0]||`0`,10),parentPid:parseInt(r[1]||`0`,10),name:r[4]||`unknown`,executablePath:await this.getProcessPath(t),commandLine:r.slice(5).join(` `),cpuUsage:parseFloat(r[2]||`0`),memoryUsage:parseFloat(r[3]||`0`)*1024*1024}:null}catch(n){return e.error(`Failed to get process by PID ${t}:`,n),null}}async getProcessPath(e){try{e=Y(e);let{stdout:t}=await J(`ps -p ${e} -o comm= 2>/dev/null || echo ""`);return t.trim()||void 0}catch{return}}async getProcessWindows(t){try{t=Y(t);let e=await this.getProcessByPid(t);if(!e)return[];let{stdout:n}=await J(`osascript -e '${`
7
+ tell application "System Events"
8
+ set processList to {}
9
+ try
10
+ set targetProcess to first process whose unix id is ${t}
11
+ set procName to name of targetProcess
12
+ set windowList to {}
13
+
14
+ tell targetProcess
15
+ repeat with win in windows
16
+ set winInfo to {|
17
+ title:name of win,
18
+ className:procName,
19
+ processId:${t},
20
+ handle:"applescript-window"
21
+ |}
22
+ set end of windowList to winInfo
23
+ end repeat
24
+ end tell
25
+
26
+ return windowList
27
+ on error
28
+ return {}
29
+ end try
30
+ end tell
31
+ `.replace(/'/g,`'"'"'`)}' 2>/dev/null || echo "[]"`,{timeout:p}),r=[];if(n.trim()&&n.trim()!==`[]`){let i=n.match(/title:([^,}]+)/g);if(i)for(let n of i){let i=n.replace(`title:`,``).trim();r.push({handle:`mac-window-${t}`,title:i,className:e.name,processId:t,threadId:0})}}return r}catch(n){return e.error(`Failed to get windows for PID ${t}:`,n),[]}}async getProcessWindowsCG(t){try{t=Y(t);let{stdout:e}=await ve(`python3`,[`-c`,be(await new H().loadScript(`process_list.py`),{PID:t})],{timeout:f*2,windowsHide:!0}),n=[];try{let t=JSON.parse(e.trim());for(let e of t)n.push({handle:e.handle,title:e.title,className:e.className,processId:e.processId,threadId:0,bounds:e.bounds?{x:e.bounds.X||0,y:e.bounds.Y||0,width:e.bounds.Width||0,height:e.bounds.Height||0}:void 0})}catch{}return n}catch(n){return e.error(`Failed to get windows via CoreGraphics for PID ${t}:`,n),[]}}async findChromeProcesses(){let t={rendererProcesses:[],utilityProcesses:[]};try{let n=await this.findProcesses(`chrome`),r=await Promise.all(n.map(e=>this.getProcessByPid(e.pid)));for(let e=0;e<n.length;e++){let i=n[e],a=r[e];if(a?.commandLine){let e=a.commandLine.toLowerCase();e.includes(`--type=renderer`)?t.rendererProcesses.push({...i,...a}):e.includes(`--type=gpu-process`)?t.gpuProcess={...i,...a}:e.includes(`--type=utility`)?t.utilityProcesses.push({...i,...a}):e.includes(`--type=`)||(t.mainProcess={...i,...a})}else t.mainProcess||=i}if(t.mainProcess){let e=await this.getProcessWindowsCG(t.mainProcess.pid);e.length>0&&(t.targetWindow=e[0])}return e.info(`Chrome processes found:`,{main:t.mainProcess?.pid,renderers:t.rendererProcesses.length,hasTargetWindow:!!t.targetWindow}),t}catch(n){return e.error(`Failed to find Chrome processes:`,n),t}}async getProcessCommandLine(t){try{t=Y(t);let{stdout:e}=await J(`ps -p ${t} -o ppid=,args= 2>/dev/null || echo ""`),n=e.trim().split(/\s+/);return n.length>=2?{parentPid:parseInt(n[0]||`0`,10),commandLine:n.slice(1).join(` `)||void 0}:{}}catch(n){return e.error(`Failed to get command line for PID ${t}:`,n),{}}}async checkDebugPort(t,n){try{t=Y(t);let e=n?.commandLine??(await this.getProcessCommandLine(t)).commandLine;if(e){let t=e.match(/--remote-debugging-port=(\d+)/);if(t?.[1])return parseInt(t[1],10)}let{stdout:r}=await J(`lsof -Pan -p ${t} -i 2>/dev/null | grep LISTEN || true`,{maxBuffer:1024*1024});for(let e of c)if(r.includes(`:${e}`))return e;return null}catch(n){return e.error(`Failed to check debug port for PID ${t}:`,n),null}}async launchWithDebug(t,n=r,i=[]){try{let r=z(t,[`--remote-debugging-port=${n}`,...i],{detached:!0,stdio:`ignore`});if(r.unref(),T.register(r),await new Promise(e=>setTimeout(e,w)),!r.pid)return e.error(`Failed to spawn process: PID is undefined for ${t}`),null;let a=await this.getProcessByPid(r.pid);return e.info(`Launched process with debug port ${n}:`,{pid:r.pid,executable:t}),a}catch(t){return e.error(`Failed to launch process with debug:`,t),null}}async killProcess(t){try{return t=Y(t),await J(`kill -9 ${t} 2>/dev/null || kill -15 ${t}`),e.info(`Process ${t} killed successfully`),!0}catch(n){return e.error(`Failed to kill process ${t}:`,n),!1}}};const Se=/^(?:0x)?[0-9a-fA-F]{1,16}$/;async function Ce(t,n,r){try{let{stdout:e}=await E(`
32
+ Add-Type @"
33
+ using System;
34
+ using System.Runtime.InteropServices;
35
+ using System.ComponentModel;
36
+
37
+ public class MemoryReader {
38
+ [DllImport("kernel32.dll", SetLastError = true)]
39
+ public static extern IntPtr OpenProcess(int access, bool inherit, int pid);
40
+
41
+ [DllImport("kernel32.dll", SetLastError = true)]
42
+ public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr addr, byte[] buffer, int size, out int read);
43
+
44
+ [DllImport("kernel32.dll", SetLastError = true)]
45
+ public static extern bool CloseHandle(IntPtr handle);
46
+
47
+ const int PROCESS_VM_READ = 0x0010;
48
+ const int PROCESS_QUERY_INFORMATION = 0x0400;
49
+
50
+ public static string ReadMemory(int pid, long address, int size) {
51
+ IntPtr hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, false, pid);
52
+ if (hProcess == IntPtr.Zero) {
53
+ int error = Marshal.GetLastWin32Error();
54
+ throw new Win32Exception(error, "Failed to open process. Run as Administrator.");
55
+ }
56
+
57
+ try {
58
+ byte[] buffer = new byte[size];
59
+ int bytesRead;
60
+ bool success = ReadProcessMemory(hProcess, (IntPtr)address, buffer, size, out bytesRead);
61
+
62
+ if (!success) {
63
+ int error = Marshal.GetLastWin32Error();
64
+ throw new Win32Exception(error, "Failed to read memory");
65
+ }
66
+
67
+ return BitConverter.ToString(buffer, 0, bytesRead).Replace("-", " ");
68
+ } finally {
69
+ CloseHandle(hProcess);
70
+ }
71
+ }
72
+ }
73
+ "@
74
+
75
+ try {
76
+ $result = [MemoryReader]::ReadMemory(${t}, ${n}, ${r})
77
+ @{ success = $true; data = $result } | ConvertTo-Json -Compress
78
+ } catch {
79
+ @{ success = $false; error = $_.Exception.Message } | ConvertTo-Json -Compress
80
+ }
81
+ `,{maxBuffer:1024*1024*10}),i=e.trim();if(!i)throw Error(`PowerShell returned empty output`);let a=JSON.parse(i);return{success:a.success,data:a.data,error:a.error}}catch(t){return e.error(`Windows memory read failed:`,t),{success:!1,error:t instanceof Error?t.message:`PowerShell execution failed. Run as Administrator.`}}}let X=null,we=!1;async function Te(){if(we)return X;try{let{createPlatformProvider:e}=await import(`./factory-CKr4fAE1.mjs`).then(e=>e.n),t=e();(await t.checkAvailability()).available&&(X=t)}catch{}return we=!0,X}function Ee(e,t){return e.subarray(0,t).toString(`hex`).toUpperCase().replace(/../g,`$& `)}async function De(t,n,r){try{let i=await Te();if(i){let a=i.openProcess(t,!1);try{let t=i.readMemory(a,BigInt(n),r);return e.debug(`Native Linux memory read succeeded`),{success:!0,data:Ee(t.data,t.bytesRead).trim()}}finally{i.closeProcess(a)}}}catch(t){e.debug(`Native Linux read failed, falling back to dd:`,t)}try{let{stdout:e}=await D(`dd if=/proc/${t}/mem bs=1 skip=${n} count=${r} 2>/dev/null | xxd -p | tr -d '\\n' || echo ""`,{maxBuffer:1024*1024*10,timeout:x});return e.trim()?{success:!0,data:(e.trim().match(/.{1,2}/g)?.join(` `)||e.trim()).toUpperCase()}:{success:!1,error:`Failed to read memory. Requires ptrace access or root. Check kernel.yama.ptrace_scope if access denied.`}}catch(t){return e.error(`Linux memory read failed:`,t),{success:!1,error:`Memory read failed. Requires ptrace access or root (check kernel.yama.ptrace_scope).`}}}async function Oe(t,n,r,i){if(n===0)return{success:!1,error:`Invalid address: null pointer (0x0)`};if(r<=0||r>o)return{success:!1,error:`Invalid size: must be 1–${o} bytes`};let a=`0x${n.toString(16)}`;try{let{createPlatformProvider:i}=await import(`./factory-CKr4fAE1.mjs`).then(e=>e.n),a=i();if((await a.checkAvailability()).available){let i=a.openProcess(t,!1);try{let t=a.readMemory(i,BigInt(n),r),o=Array.from(t.data.subarray(0,t.bytesRead)).map(e=>e.toString(16).padStart(2,`0`).toUpperCase()).join(` `);return e.debug(`Native Mach memory read succeeded (zero-pause)`),{success:!0,data:o}}finally{a.closeProcess(i)}}}catch(t){e.debug(`Native Mach read failed, falling back to lldb:`,t)}let s=await i(t,a);if(!s.success)return{success:!1,error:`Cannot verify memory region: ${s.error}`};if(!s.isReadable)return{success:!1,error:`Address ${a} is not readable (protection: ${s.protection??`unknown`})`};let c=`/tmp/mread_${t}_${Date.now()}.bin`;try{let{stdout:e}=await D(`lldb --batch -p ${t} -o "memory read --outfile ${c} --binary ${a} -c ${r}" -o "process detach"`,{timeout:u,maxBuffer:1024*1024*10});if(!e.includes(`bytes written`))return{success:!1,error:`lldb memory read failed: ${(e.split(`
82
+ `).find(e=>e.includes(`error:`))??e).trim()}`};let n=await I.readFile(c);return{success:!0,data:Array.from(n).map(e=>e.toString(16).padStart(2,`0`).toUpperCase()).join(` `)}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}finally{await I.unlink(c).catch(()=>{})}}async function ke(t,n,r,i,a){try{if(!Se.test(r))return{success:!1,error:`Invalid address format. Use hex like "0x12345678"`};let s=parseInt(r,16);if(isNaN(s))return{success:!1,error:`Invalid address format. Use hex like "0x12345678"`};if(i<=0||i>o)return{success:!1,error:`Read size must be 1–${o} bytes (${(o/1024/1024).toFixed(0)} MB)`};if(t===`win32`&&O())try{let t=await N.readMemory(n,r,i);if(t.success)return e.debug(`Native memory read succeeded`),t;e.warn(`Native memory read failed, falling back to PowerShell:`,t.error)}catch(t){e.warn(`Native memory read error, falling back to PowerShell:`,t)}switch(t){case`win32`:return Ce(n,s,i);case`linux`:return De(n,s,i);case`darwin`:return Oe(n,s,i,a);default:return{success:!1,error:`Memory operations not supported on platform: ${t}`}}}catch(t){return e.error(`Memory read failed:`,t),{success:!1,error:t instanceof Error?t.message:String(t)}}}async function Ae(t,n,r){try{let{stdout:e}=await E(`
83
+ Add-Type @"
84
+ using System;
85
+ using System.Runtime.InteropServices;
86
+ using System.ComponentModel;
87
+
88
+ public class MemoryWriter {
89
+ [DllImport("kernel32.dll", SetLastError = true)]
90
+ public static extern IntPtr OpenProcess(int access, bool inherit, int pid);
91
+
92
+ [DllImport("kernel32.dll", SetLastError = true)]
93
+ public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr addr, byte[] buffer, int size, out int written);
94
+
95
+ [DllImport("kernel32.dll", SetLastError = true)]
96
+ public static extern bool CloseHandle(IntPtr handle);
97
+
98
+ const int PROCESS_VM_WRITE = 0x0020;
99
+ const int PROCESS_VM_OPERATION = 0x0008;
100
+
101
+ public static int WriteMemory(int pid, long address, string hexData) {
102
+ IntPtr hProcess = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_OPERATION, false, pid);
103
+ if (hProcess == IntPtr.Zero) {
104
+ int error = Marshal.GetLastWin32Error();
105
+ throw new Win32Exception(error, "Failed to open process. Run as Administrator.");
106
+ }
107
+
108
+ try {
109
+ byte[] buffer = new byte[hexData.Length / 2];
110
+ for (int i = 0; i < hexData.Length; i += 2) {
111
+ buffer[i / 2] = Convert.ToByte(hexData.Substring(i, 2), 16);
112
+ }
113
+
114
+ int bytesWritten;
115
+ bool success = WriteProcessMemory(hProcess, (IntPtr)address, buffer, buffer.Length, out bytesWritten);
116
+
117
+ if (!success) {
118
+ int error = Marshal.GetLastWin32Error();
119
+ throw new Win32Exception(error, "Failed to write memory");
120
+ }
121
+
122
+ return bytesWritten;
123
+ } finally {
124
+ CloseHandle(hProcess);
125
+ }
126
+ }
127
+ }
128
+ "@
129
+
130
+ try {
131
+ $bytesWritten = [MemoryWriter]::WriteMemory(${t}, ${n}, "${r.toString(`hex`).toUpperCase()}")
132
+ @{ success = $true; bytesWritten = $bytesWritten } | ConvertTo-Json -Compress
133
+ } catch {
134
+ @{ success = $false; error = $_.Exception.Message } | ConvertTo-Json -Compress
135
+ }
136
+ `,{maxBuffer:1024*1024}),i=e.trim();if(!i)throw Error(`PowerShell returned empty output`);let a=JSON.parse(i);return{success:a.success,bytesWritten:a.bytesWritten,error:a.error}}catch(t){return e.error(`Windows memory write failed:`,t),{success:!1,error:t instanceof Error?t.message:`PowerShell execution failed. Run as Administrator.`}}}let Z=null,je=!1;async function Me(){if(je)return Z;try{let{createPlatformProvider:e}=await import(`./factory-CKr4fAE1.mjs`).then(e=>e.n),t=e();(await t.checkAvailability()).available&&(Z=t)}catch{}return je=!0,Z}async function Ne(t,n,r){try{let i=await Me();if(i){let a=i.openProcess(t,!0);try{let t=i.writeMemory(a,BigInt(n),r);return e.debug(`Native Linux memory write succeeded`),{success:!0,bytesWritten:t.bytesWritten}}finally{i.closeProcess(a)}}}catch(t){e.debug(`Native Linux write failed, falling back to dd:`,t)}try{let{stderr:e}=await D(`printf "${r.toString(`hex`)}" | xxd -r -p | dd of=/proc/${t}/mem bs=1 seek=${n} conv=notrunc`,{maxBuffer:1024*1024,timeout:_});return e&&/error|denied|cannot/i.test(e)?{success:!1,error:`Memory write failed. Requires ptrace access or root. Check kernel.yama.ptrace_scope if access denied.`}:{success:!0,bytesWritten:r.length}}catch(t){return e.error(`Linux memory write failed:`,t),{success:!1,error:`Memory write failed. Requires ptrace access or root (check kernel.yama.ptrace_scope).`}}}async function Pe(t,n,r,i){if(n===0)return{success:!1,error:`Invalid address: null pointer (0x0)`};if(r.length===0||r.length>l)return{success:!1,error:`Invalid write size: must be 1–${l} bytes`};let a=`0x${n.toString(16)}`;try{let{createPlatformProvider:i}=await import(`./factory-CKr4fAE1.mjs`).then(e=>e.n),a=i();if((await a.checkAvailability()).available){let i=a.openProcess(t,!0);try{let t=a.writeMemory(i,BigInt(n),r);return e.debug(`Native Mach memory write succeeded (zero-pause)`),{success:!0,bytesWritten:t.bytesWritten}}finally{a.closeProcess(i)}}}catch(t){e.debug(`Native Mach write failed, falling back to lldb:`,t)}let o=await i(t,a);if(!o.success)return{success:!1,error:`Cannot verify memory region: ${o.error}`};if(!o.isWritable)return{success:!1,error:`Address ${a} is not writable (protection: ${o.protection??`unknown`})`};try{let{stdout:e}=await D(`lldb --batch -p ${t} -o "memory write ${a} ${Array.from(r).map(e=>`0x${e.toString(16).padStart(2,`0`)}`).join(` `)}" -o "process detach"`,{timeout:_,maxBuffer:1024*1024});return e.includes(`error:`)?{success:!1,error:`lldb memory write failed: ${(e.split(`
137
+ `).find(e=>e.includes(`error:`))??e).trim()}`}:{success:!0,bytesWritten:r.length}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}}const Fe=/^(?:0x)?[0-9a-fA-F]{1,16}$/;async function Ie(t,n,r,i,a=`hex`,o){try{if(!Fe.test(r))return{success:!1,error:`Invalid address format. Use hex like "0x12345678"`};let s=parseInt(r,16);if(isNaN(s))return{success:!1,error:`Invalid address format`};let c;try{if(a===`base64`)c=Buffer.from(i,`base64`);else{let e=i.replace(/\s/g,``);c=Buffer.from(e,`hex`)}}catch{return{success:!1,error:`Invalid ${a} data`}}if(c.length===0||c.length>l)return{success:!1,error:`Write size must be 1–${l} bytes (${(l/1024).toFixed(0)} KB)`};if(t===`win32`&&O())try{let t=await N.writeMemory(n,r,i,a);if(t.success)return e.debug(`Native memory write succeeded`),t;e.warn(`Native memory write failed, falling back to PowerShell:`,t.error)}catch(t){e.warn(`Native memory write error, falling back to PowerShell:`,t)}switch(t){case`win32`:return Ae(n,s,c);case`linux`:return Ne(n,s,c);case`darwin`:return Pe(n,s,c,o);default:return{success:!1,error:`Memory operations not supported on platform: ${t}`}}}catch(t){return e.error(`Memory write failed:`,t),{success:!1,error:t instanceof Error?t.message:String(t)}}}const Le=1e3;async function Re(e,t,n){if(t.length>Le)return{success:!1,results:[],error:`Too many patches (${t.length}), max ${Le}`};let r=[];for(let i of t){let t=await n(e,i.address,i.data,i.encoding||`hex`);r.push({address:i.address,success:t.success,error:t.error})}let i=r.every(e=>e.success);return{success:i,results:r,error:i?void 0:`Failed to write ${r.filter(e=>!e.success).length} of ${r.length} patches`}}function ze(e,t){let n=[],r=[];switch(t){case`hex`:{let t=e.trim().split(/\s+/);for(let e of t)if(e===`??`||e===`**`||e===`?`)n.push(0),r.push(0);else{let t=parseInt(e,16);isNaN(t)||(n.push(t),r.push(1))}break}case`int32`:{let t=parseInt(e);if(!isNaN(t)){let e=Buffer.allocUnsafe(4);e.writeInt32LE(t,0),n=Array.from(e),r=[1,1,1,1]}break}case`int64`:{let t=BigInt.asIntN(64,BigInt(e)),i=Buffer.allocUnsafe(8);i.writeBigInt64LE(t,0),n=Array.from(i),r=[1,1,1,1,1,1,1,1];break}case`float`:{let t=parseFloat(e);if(!isNaN(t)){let e=Buffer.allocUnsafe(4);e.writeFloatLE(t,0),n=Array.from(e),r=[1,1,1,1]}break}case`double`:{let t=parseFloat(e);if(!isNaN(t)){let e=Buffer.allocUnsafe(8);e.writeDoubleLE(t,0),n=Array.from(e),r=[1,1,1,1,1,1,1,1]}break}case`string`:{let t=Buffer.from(e,`utf8`);n=Array.from(t),r=n.map(()=>1);break}}if(n.length===0)throw Error(`Invalid pattern`);return{patternBytes:n,mask:r}}function Be(e,t){let n=[],r=[];switch(t){case`hex`:{let t=e.trim().split(/\s+/);for(let e of t)if(e===`??`||e===`?`||e===`**`)n.push(0),r.push(0);else{let t=parseInt(e,16);if(isNaN(t))throw Error(`Invalid hex byte: ${e}`);n.push(t),r.push(1)}if(!n.length)throw Error(`Pattern is empty`);break}case`int32`:{let t=parseInt(e);if(isNaN(t))throw Error(`Invalid int32 value`);let i=Buffer.allocUnsafe(4);i.writeInt32LE(t,0);let a=Array.from(i);n.push(...a),r.push(...a.map(()=>1));break}case`int64`:{let t=Buffer.allocUnsafe(8);t.writeBigInt64LE(BigInt.asIntN(64,BigInt(e)),0);let i=Array.from(t);n.push(...i),r.push(...i.map(()=>1));break}case`float`:{let t=parseFloat(e);if(isNaN(t))throw Error(`Invalid float value`);let i=Buffer.allocUnsafe(4);i.writeFloatLE(t,0);let a=Array.from(i);n.push(...a),r.push(...a.map(()=>1));break}case`double`:{let t=parseFloat(e);if(isNaN(t))throw Error(`Invalid double value`);let i=Buffer.allocUnsafe(8);i.writeDoubleLE(t,0);let a=Array.from(i);n.push(...a),r.push(...a.map(()=>1));break}case`string`:{let t=Array.from(Buffer.from(e,`utf8`));n.push(...t),r.push(...t.map(()=>1));break}default:throw Error(`Unsupported pattern type: ${t}`)}return{bytes:n,mask:r}}function Ve(e,t,n){let{patternBytes:r,mask:i}=ze(t,n);return`
138
+ Add-Type @"
139
+ using System;
140
+ using System.Runtime.InteropServices;
141
+ using System.Collections.Generic;
142
+ using System.ComponentModel;
143
+
144
+ public class MemoryScanner {
145
+ [DllImport("kernel32.dll", SetLastError = true)]
146
+ public static extern IntPtr OpenProcess(int access, bool inherit, int pid);
147
+
148
+ [DllImport("kernel32.dll", SetLastError = true)]
149
+ public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr addr, byte[] buffer, int size, out int read);
150
+
151
+ [DllImport("kernel32.dll", SetLastError = true)]
152
+ public static extern int VirtualQueryEx(IntPtr hProcess, IntPtr addr, out MEMORY_BASIC_INFORMATION info, int size);
153
+
154
+ [DllImport("kernel32.dll", SetLastError = true)]
155
+ public static extern bool CloseHandle(IntPtr handle);
156
+
157
+ const int PROCESS_VM_READ = 0x0010;
158
+ const int PROCESS_QUERY_INFORMATION = 0x0400;
159
+
160
+ [StructLayout(LayoutKind.Sequential)]
161
+ public struct MEMORY_BASIC_INFORMATION {
162
+ public IntPtr BaseAddress;
163
+ public IntPtr AllocationBase;
164
+ public uint AllocationProtect;
165
+ public IntPtr RegionSize;
166
+ public uint State;
167
+ public uint Protect;
168
+ public uint Type;
169
+ }
170
+
171
+ const uint MEM_COMMIT = 0x1000;
172
+ const uint PAGE_READONLY = 0x02;
173
+ const uint PAGE_READWRITE = 0x04;
174
+ const uint PAGE_WRITECOPY = 0x08;
175
+ const uint PAGE_EXECUTE_READ = 0x20;
176
+ const uint PAGE_EXECUTE_READWRITE = 0x40;
177
+
178
+ public static List<string> ScanMemory(int pid, byte[] pattern, byte[] mask, int maxResults = 10000) {
179
+ var results = new List<string>();
180
+ IntPtr hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, false, pid);
181
+ if (hProcess == IntPtr.Zero) {
182
+ int error = Marshal.GetLastWin32Error();
183
+ throw new Win32Exception(error, "Failed to open process. Run as Administrator.");
184
+ }
185
+
186
+ try {
187
+ IntPtr addr = IntPtr.Zero;
188
+ MEMORY_BASIC_INFORMATION info;
189
+ int infoSize = Marshal.SizeOf(typeof(MEMORY_BASIC_INFORMATION));
190
+ int scannedRegions = 0;
191
+
192
+ while (VirtualQueryEx(hProcess, addr, out info, infoSize) == infoSize) {
193
+ scannedRegions++;
194
+ bool isReadable = (info.State == MEM_COMMIT) &&
195
+ ((info.Protect & PAGE_READONLY) != 0 ||
196
+ (info.Protect & PAGE_READWRITE) != 0 ||
197
+ (info.Protect & PAGE_WRITECOPY) != 0 ||
198
+ (info.Protect & PAGE_EXECUTE_READ) != 0 ||
199
+ (info.Protect & PAGE_EXECUTE_READWRITE) != 0);
200
+
201
+ if (isReadable && info.RegionSize.ToInt64() > 0 && info.RegionSize.ToInt64() < 1073741824) {
202
+ long regionSize = info.RegionSize.ToInt64();
203
+ if (regionSize > 16777216) regionSize = 16777216; // bound scan window per region (16MB)
204
+ byte[] buffer = new byte[(int)regionSize];
205
+ int bytesRead;
206
+
207
+ if (ReadProcessMemory(hProcess, info.BaseAddress, buffer, buffer.Length, out bytesRead)) {
208
+ for (int i = 0; i <= bytesRead - pattern.Length; i++) {
209
+ if (PatternMatch(buffer, i, pattern, mask)) {
210
+ long foundAddr = info.BaseAddress.ToInt64() + i;
211
+ results.Add("0x" + foundAddr.ToString("X"));
212
+ if (results.Count >= maxResults) break;
213
+ }
214
+ }
215
+ }
216
+ }
217
+
218
+ if (results.Count >= maxResults) break;
219
+ if (scannedRegions >= 50000) break;
220
+ long baseAddr = info.BaseAddress.ToInt64();
221
+ long regionSizeRaw = info.RegionSize.ToInt64();
222
+ if (regionSizeRaw <= 0) break;
223
+ long nextAddr = baseAddr + regionSizeRaw;
224
+ if (nextAddr <= baseAddr) break;
225
+ addr = new IntPtr(nextAddr);
226
+ if (addr.ToInt64() >= 0x7FFFFFFF0000) break;
227
+ }
228
+
229
+ return results;
230
+ } finally {
231
+ CloseHandle(hProcess);
232
+ }
233
+ }
234
+
235
+ private static bool PatternMatch(byte[] buffer, int offset, byte[] pattern, byte[] mask) {
236
+ for (int i = 0; i < pattern.Length; i++) {
237
+ if (mask[i] == 1 && buffer[offset + i] != pattern[i]) {
238
+ return false;
239
+ }
240
+ }
241
+ return true;
242
+ }
243
+ }
244
+ "@
245
+
246
+ try {
247
+ $patternBytes = @(${r.join(`,`)})
248
+ $maskBytes = @(${i.join(`,`)})
249
+ $results = [MemoryScanner]::ScanMemory(${e}, $patternBytes, $maskBytes, 1000)
250
+ @{
251
+ success = $true;
252
+ addresses = $results;
253
+ stats = @{
254
+ patternLength = $patternBytes.Length;
255
+ resultsFound = $results.Count
256
+ }
257
+ } | ConvertTo-Json -Compress
258
+ } catch {
259
+ @{ success = $false; error = $_.Exception.Message } | ConvertTo-Json -Compress
260
+ }
261
+ `.trim()}async function He(t,n,r){try{if(j())try{let i=await N.scanMemory(t,n,r);if(i.success)return i;e.warn(`Native Windows memory scan failed, falling back to PowerShell`,{pid:t,patternType:r,error:i.error,nativeAvailable:j()})}catch(n){e.warn(`Native Windows memory scan threw, falling back to PowerShell`,{pid:t,patternType:r,error:n instanceof Error?n.message:String(n),nativeAvailable:j()})}let{stdout:i,stderr:a}=await E(Ve(t,n,r),{maxBuffer:g,timeout:y});if(a&&a.includes(`Error`))return{success:!1,addresses:[],error:a};let o=i.trim();if(!o)throw Error(`PowerShell returned empty output`);let s=JSON.parse(o);return{success:s.success,addresses:s.addresses||[],error:s.error,stats:s.stats}}catch(t){return e.error(`Windows memory scan failed:`,t),{success:!1,addresses:[],error:t instanceof Error?t.message:`PowerShell execution failed. Run as Administrator.`}}}function Ue(e,t,n){let r=n;switch(r?.code){case`ENOENT`:case`ESRCH`:return`Process ${e} no longer exists or /proc/${e}/${t} is unavailable.`;case`EACCES`:case`EPERM`:return`Cannot access /proc/${e}/${t}. Requires root privileges or ptrace access.`;default:return r instanceof Error?r.message:String(n)}}async function We(t,n,r){let i,a;try{let e=ze(n,r);i=e.patternBytes,a=e.mask}catch(e){return{success:!1,addresses:[],error:e instanceof Error?e.message:`Invalid pattern`}}try{let n;try{n=oe(`/proc/${t}/maps`,`utf-8`)}catch(e){return{success:!1,addresses:[],error:Ue(t,`maps`,e)}}let r=k(n),o=Array.isArray(r)?r.filter(e=>e.permissions.read):[],s;try{s=ae(`/proc/${t}/mem`,`r`)}catch(e){return{success:!1,addresses:[],error:Ue(t,`mem`,e)}}let c=new Set,l=16*1024*1024,u=1e4,d=Math.max(i.length-1,0);try{for(let n of o){if(c.size>=u)break;if(n.end<=n.start)continue;let r=0n,o=Buffer.alloc(0),f=n.end-n.start;for(;r<f&&c.size<u;){let p=f-r,m=Number(p>BigInt(l)?BigInt(l):p),h=Buffer.allocUnsafe(m),g;try{g=se(s,h,0,m,n.start+r)}catch(i){let a=i;if(a?.code===`EIO`||a?.code===`EFAULT`||a?.code===`EACCES`||a?.code===`EPERM`){e.debug(`Skipping unreadable Linux memory region chunk`,{pid:t,start:`0x${n.start.toString(16)}`,offset:r.toString(),code:a.code});break}throw i}if(g<=0)break;let _=g===m?h:h.subarray(0,g),v=o.length>0?Buffer.concat([o,_]):_,y=n.start+r-BigInt(o.length),b=BigInt(g),x=r+b>=f||g<m,S=x?0:Math.min(d,v.length),C=v.length-S,w=M(v,i,a);for(let e of w){if(!x&&e>=C)continue;let t=y+BigInt(e);if(!(t<n.start||t>=n.end)&&(c.add(`0x${t.toString(16)}`),c.size>=u))break}if(o=S>0?v.subarray(v.length-S):Buffer.alloc(0),r+=b,g<m){e.debug(`Linux memory scan stopped after short read`,{pid:t,start:`0x${n.start.toString(16)}`,requested:m,bytesRead:g});break}}}}finally{ie(s)}let f=Array.from(c);return{success:!0,addresses:f,stats:{patternLength:i.length,resultsFound:f.length}}}catch(e){return{success:!1,addresses:[],error:e instanceof Error?e.message:String(e)}}}async function Ge(t,n,r){let i,a;try{let e=Be(n,r);i=e.bytes,a=e.mask}catch(e){return{success:!1,addresses:[],error:e instanceof Error?e.message:`Invalid pattern`}}try{let e=await Ke(t,i,a);if(e)return e}catch(t){e.debug(`Native Mach scan failed, falling back to lldb:`,t)}return qe(t,i,a)}async function Ke(t,n,r){let{createPlatformProvider:i}=await import(`./factory-CKr4fAE1.mjs`).then(e=>e.n),a=i();if(!(await a.checkAvailability()).available)return null;let o=a.openProcess(t,!1),s=[],c=1e3;try{let e=0n;for(let t=0;t<5e4&&s.length<c;t++){let t=a.queryRegion(o,e);if(!t)break;if(t.isReadable&&t.size>0&&t.size<=33554432)try{let e=M(a.readMemory(o,t.baseAddress,t.size).data,n,r);for(let n of e)if(s.push(`0x${(t.baseAddress+BigInt(n)).toString(16)}`),s.length>=c)break}catch{}if(e=t.baseAddress+BigInt(t.size),e<=t.baseAddress)break}}finally{a.closeProcess(o)}return e.debug(`Native Mach scan completed (zero-pause): ${s.length} results`),{success:!0,addresses:s,stats:{patternLength:n.length,resultsFound:s.length}}}async function qe(e,t,n){let r=t.map(e=>`0x${e.toString(16)}`).join(`,`),i=n.join(`,`),a=`${e}_${Date.now()}`,o=`/tmp/lldb_scan_${a}.py`,s=`/tmp/lldb_scan_${a}.txt`,c=`
262
+ import lldb, json, sys
263
+
264
+ def __lldb_init_module(debugger, internal_dict):
265
+ proc = debugger.GetSelectedTarget().GetProcess()
266
+ pat = bytes([${r}])
267
+ mask = [${i}]
268
+ results = []
269
+ rl = proc.GetMemoryRegions()
270
+ for i in range(rl.GetSize()):
271
+ info = lldb.SBMemoryRegionInfo()
272
+ rl.GetMemoryRegionAtIndex(i, info)
273
+ if not info.IsReadable():
274
+ continue
275
+ s = info.GetRegionBase()
276
+ sz = info.GetRegionEnd() - s
277
+ if sz > 32 * 1024 * 1024:
278
+ continue
279
+ err = lldb.SBError()
280
+ data = proc.ReadMemory(s, sz, err)
281
+ if not err.Success():
282
+ continue
283
+ n = len(pat)
284
+ for j in range(len(data) - n + 1):
285
+ match = True
286
+ for k in range(n):
287
+ if mask[k] == 1 and data[j+k] != pat[k]:
288
+ match = False
289
+ break
290
+ if match:
291
+ results.append(hex(s + j))
292
+ if len(results) >= 1000:
293
+ break
294
+ if len(results) >= 1000:
295
+ break
296
+ sys.stdout.write('SCAN_RESULT:' + json.dumps({
297
+ 'success': True,
298
+ 'addresses': results,
299
+ 'stats': {'patternLength': len(pat), 'resultsFound': len(results)}
300
+ }) + '\\n')
301
+ sys.stdout.flush()
302
+ `;await I.writeFile(o,c,`utf8`),await I.writeFile(s,`command script import ${o}\nprocess detach\n`,`utf8`);try{let{stdout:t}=await D(`lldb --batch -p ${e} --source ${s}`,{timeout:y,maxBuffer:1024*1024*5}),n=t.split(`
303
+ `).find(e=>e.startsWith(`SCAN_RESULT:`));if(!n)return{success:!1,addresses:[],error:`lldb scan returned no result. ${t.split(`
304
+ `).find(e=>e.includes(`error:`))??``}`.trim()};try{return JSON.parse(n.slice(12))}catch{let e=t.split(`
305
+ `).find(e=>e.includes(`error:`))??``;if(e)return{success:!1,addresses:[],error:e.trim()};throw Error(`Unexpected end of JSON input`)}}catch(e){return{success:!1,addresses:[],error:e instanceof Error?e.message:String(e)}}finally{await I.unlink(o).catch(()=>{}),await I.unlink(s).catch(()=>{})}}async function Je(t,n,r,i=`hex`,a=!1){let o=!1;try{switch(a&&(o=await Ze(t,n),o?e.info(`Suspended process ${n} for consistent memory scan`):e.warn(`Could not suspend process ${n} — scanning unsuspended`)),t){case`win32`:return await He(n,r,i);case`linux`:return await We(n,r,i);case`darwin`:return await Ge(n,r,i);default:return{success:!1,addresses:[],error:`Memory scan not supported on ${t}`}}}catch(t){return e.error(`Memory scan failed:`,t),{success:!1,addresses:[],error:t instanceof Error?t.message:String(t)}}finally{o&&(await Qe(t,n),e.info(`Resumed process ${n} after memory scan`))}}async function Ye(e,t,n,r=`hex`,i,a){let o=[];for(let e of n){let t=parseInt(e,16);isNaN(t)||o.push(t)}if(o.length===0)return{success:!1,addresses:[],error:`No valid addresses provided`};let s=await a(e,t,r);if(!s.success||s.addresses.length===0)return{success:!0,addresses:[],stats:{resultsFound:0,patternLength:t.length}};let c=[];for(let e of s.addresses){let t=parseInt(e,16);o.some(e=>Math.abs(e-t)<256)&&(c.includes(e)||c.push(e))}return{success:!0,addresses:c,stats:{resultsFound:c.length,patternLength:t.length}}}async function Xe(e,t){let{machTaskSelf:n,taskForPid:r,machPortDeallocate:i,KERN:a}=await import(`./DarwinAPI-ZfQdpLNI.mjs`).then(e=>e.t),o=n(),{kr:s,task:c}=r(o,e);if(s!==a.SUCCESS)return!1;try{return t(c)}finally{i(o,c)}}async function Ze(n,r){try{switch(n){case`darwin`:{let{taskSuspend:e,KERN:t}=await import(`./DarwinAPI-ZfQdpLNI.mjs`).then(e=>e.t);return Xe(r,n=>e(n)===t.SUCCESS)}case`linux`:{let{execAsync:e}=await import(`./types-D9EiE5o9.mjs`).then(e=>e.i);return await e(`kill -STOP ${r}`,{timeout:m}),!0}case`win32`:{let{execAsync:e}=await import(`./types-D9EiE5o9.mjs`).then(e=>e.i);return await e(`powershell -NoProfile -Command "(Add-Type -MemberDefinition '[DllImport("ntdll.dll")] public static extern int NtSuspendProcess(IntPtr h);' -Name W -Namespace N -PassThru)::NtSuspendProcess((Get-Process -Id ${r}).Handle)"`,{timeout:t}),!0}default:return!1}}catch(t){return e.warn(`Failed to suspend process ${r}:`,t),!1}}async function Qe(n,r){try{switch(n){case`darwin`:{let{taskResume:e}=await import(`./DarwinAPI-ZfQdpLNI.mjs`).then(e=>e.t);await Xe(r,t=>{e(t)});break}case`linux`:{let{execAsync:e}=await import(`./types-D9EiE5o9.mjs`).then(e=>e.i);await e(`kill -CONT ${r}`,{timeout:m});break}case`win32`:{let{execAsync:e}=await import(`./types-D9EiE5o9.mjs`).then(e=>e.i);await e(`powershell -NoProfile -Command "(Add-Type -MemberDefinition '[DllImport("ntdll.dll")] public static extern int NtResumeProcess(IntPtr h);' -Name W -Namespace N -PassThru)::NtResumeProcess((Get-Process -Id ${r}).Handle)"`,{timeout:t});break}}}catch(t){e.error(`CRITICAL: Failed to resume process ${r} — may need manual SIGCONT:`,t)}}function $e(e,t,n,r){return`
306
+ Add-Type @"
307
+ using System;
308
+ using System.Runtime.InteropServices;
309
+ using System.IO;
310
+ using System.ComponentModel;
311
+
312
+ public class MemoryDumper {
313
+ [DllImport("kernel32.dll", SetLastError = true)]
314
+ public static extern IntPtr OpenProcess(int access, bool inherit, int pid);
315
+
316
+ [DllImport("kernel32.dll", SetLastError = true)]
317
+ public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr addr, byte[] buffer, int size, out int read);
318
+
319
+ [DllImport("kernel32.dll", SetLastError = true)]
320
+ public static extern bool CloseHandle(IntPtr handle);
321
+
322
+ const int PROCESS_VM_READ = 0x0010;
323
+ const int PROCESS_QUERY_INFORMATION = 0x0400;
324
+
325
+ public static string DumpMemory(int pid, long address, int size, string outputPath) {
326
+ IntPtr hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, false, pid);
327
+ if (hProcess == IntPtr.Zero) {
328
+ int error = Marshal.GetLastWin32Error();
329
+ throw new Win32Exception(error, "Failed to open process. Run as Administrator.");
330
+ }
331
+
332
+ try {
333
+ byte[] buffer = new byte[size];
334
+ int bytesRead;
335
+
336
+ if (!ReadProcessMemory(hProcess, (IntPtr)address, buffer, size, out bytesRead)) {
337
+ int error = Marshal.GetLastWin32Error();
338
+ throw new Win32Exception(error, "Failed to read memory");
339
+ }
340
+
341
+ File.WriteAllBytes(outputPath, buffer);
342
+ return "Dumped " + bytesRead + " bytes to " + outputPath;
343
+ } finally {
344
+ CloseHandle(hProcess);
345
+ }
346
+ }
347
+ }
348
+ "@
349
+
350
+ try {
351
+ $result = [MemoryDumper]::DumpMemory(${e}, ${t}, ${n}, "${r.replace(/\\/g,`\\\\`).replace(/"/g,'`"').replace(/\$/g,"`$")}")
352
+ @{ success = $true; message = $result } | ConvertTo-Json -Compress
353
+ } catch {
354
+ @{ success = $false; error = $_.Exception.Message } | ConvertTo-Json -Compress
355
+ }
356
+ `.trim()}async function et(t,r,i,a,o){if(t!==`win32`&&t!==`darwin`)return{success:!1,error:`Memory dump currently only implemented for Windows and macOS`};if(t===`darwin`){let e=parseInt(i,16);if(isNaN(e))return{success:!1,error:`Invalid address format`};if(!Number.isInteger(r)||r<=0)return{success:!1,error:`Invalid pid`};if(!Number.isInteger(a)||a<=0)return{success:!1,error:`Invalid size`};let t=`0x${e.toString(16)}`;try{let{stdout:e}=await ee(`lldb`,[`--batch`,`-p`,String(r),`-o`,`memory read --outfile ${o} --binary ${t} -c ${a}`,`-o`,`process detach`],{timeout:n,maxBuffer:1024*1024});return e.includes(`bytes written`)?{success:!0}:{success:!1,error:`lldb dump failed: ${(e.split(`
357
+ `).find(e=>e.includes(`error:`))??e).trim()}`}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}}try{let e=parseInt(i,16);if(isNaN(e))return{success:!1,error:`Invalid address format`};if(!Number.isInteger(r)||r<=0)return{success:!1,error:`Invalid pid`};if(!Number.isInteger(a)||a<=0)return{success:!1,error:`Invalid size`};let{stdout:t}=await E($e(r,e,a,o),{maxBuffer:1024*1024,timeout:n}),s=t.trim();if(!s)throw Error(`PowerShell returned empty output`);let c=JSON.parse(s);return{success:c.success,error:c.error}}catch(t){return e.error(`Memory dump failed:`,t),{success:!1,error:t instanceof Error?t.message:`PowerShell execution failed`}}}function tt(e){return`
358
+ Add-Type @"
359
+ using System;
360
+ using System.Runtime.InteropServices;
361
+ using System.Collections.Generic;
362
+ using System.ComponentModel;
363
+
364
+ public class RegionEnumerator {
365
+ [DllImport("kernel32.dll", SetLastError = true)]
366
+ public static extern IntPtr OpenProcess(int access, bool inherit, int pid);
367
+
368
+ [DllImport("kernel32.dll", SetLastError = true)]
369
+ public static extern int VirtualQueryEx(IntPtr hProcess, IntPtr addr, out MEMORY_BASIC_INFORMATION info, int size);
370
+
371
+ [DllImport("kernel32.dll", SetLastError = true)]
372
+ public static extern bool CloseHandle(IntPtr handle);
373
+
374
+ const int PROCESS_QUERY_INFORMATION = 0x0400;
375
+
376
+ [StructLayout(LayoutKind.Sequential)]
377
+ public struct MEMORY_BASIC_INFORMATION {
378
+ public IntPtr BaseAddress;
379
+ public IntPtr AllocationBase;
380
+ public uint AllocationProtect;
381
+ public IntPtr RegionSize;
382
+ public uint State;
383
+ public uint Protect;
384
+ public uint Type;
385
+ }
386
+
387
+ const uint MEM_COMMIT = 0x1000;
388
+ const uint MEM_FREE = 0x10000;
389
+ const uint MEM_RESERVE = 0x2000;
390
+ const uint PAGE_READONLY = 0x02;
391
+ const uint PAGE_READWRITE = 0x04;
392
+ const uint PAGE_WRITECOPY = 0x08;
393
+ const uint PAGE_EXECUTE = 0x10;
394
+ const uint PAGE_EXECUTE_READ = 0x20;
395
+ const uint PAGE_EXECUTE_READWRITE = 0x40;
396
+
397
+ public static List<object> EnumerateRegions(int pid) {
398
+ var regions = new List<object>();
399
+ IntPtr hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, false, pid);
400
+ if (hProcess == IntPtr.Zero) {
401
+ int error = Marshal.GetLastWin32Error();
402
+ throw new Win32Exception(error, "Failed to open process. Run as Administrator.");
403
+ }
404
+
405
+ try {
406
+ IntPtr addr = IntPtr.Zero;
407
+ MEMORY_BASIC_INFORMATION info;
408
+ int infoSize = Marshal.SizeOf(typeof(MEMORY_BASIC_INFORMATION));
409
+ int scannedRegions = 0;
410
+
411
+ while (VirtualQueryEx(hProcess, addr, out info, infoSize) == infoSize) {
412
+ scannedRegions++;
413
+ string state = info.State == MEM_COMMIT ?
414
+ "COMMIT" :
415
+ (info.State == MEM_RESERVE ? "RESERVE" : (info.State == MEM_FREE ? "FREE" : "UNKNOWN"));
416
+ string protect = GetProtectionString(info.Protect);
417
+ bool isReadable = (info.State == MEM_COMMIT) && ((info.Protect & (PAGE_READONLY | PAGE_READWRITE | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE)) != 0);
418
+
419
+ regions.Add(new {
420
+ baseAddress = "0x" + info.BaseAddress.ToInt64().ToString("X"),
421
+ size = info.RegionSize.ToInt64(),
422
+ state = state,
423
+ protection = protect,
424
+ isReadable = isReadable,
425
+ type = info.Type == 0x1000000 ? "IMAGE" : (info.Type == 0x40000 ? "MAPPED" : "PRIVATE")
426
+ });
427
+
428
+ if (regions.Count >= 10000 || scannedRegions >= 50000) break;
429
+ long baseAddr = info.BaseAddress.ToInt64();
430
+ long regionSize = info.RegionSize.ToInt64();
431
+ if (regionSize <= 0) break;
432
+ long nextAddr = baseAddr + regionSize;
433
+ if (nextAddr <= baseAddr) break;
434
+ addr = new IntPtr(nextAddr);
435
+ if (addr.ToInt64() >= 0x7FFFFFFF0000) break;
436
+ }
437
+
438
+ return regions;
439
+ } finally {
440
+ CloseHandle(hProcess);
441
+ }
442
+ }
443
+
444
+ private static string GetProtectionString(uint protect) {
445
+ if (protect == 0) return "NOACCESS";
446
+ string s = "";
447
+ if ((protect & 0x100) != 0) s += "NOACCESS ";
448
+ if ((protect & PAGE_READONLY) != 0) s += "R ";
449
+ if ((protect & PAGE_READWRITE) != 0) s += "RW ";
450
+ if ((protect & PAGE_WRITECOPY) != 0) s += "W ";
451
+ if ((protect & PAGE_EXECUTE) != 0) s += "X ";
452
+ if ((protect & PAGE_EXECUTE_READ) != 0) s += "RX ";
453
+ if ((protect & PAGE_EXECUTE_READWRITE) != 0) s += "RWX ";
454
+ if ((protect & 0x100) != 0) s += "GUARD ";
455
+ return s.Trim();
456
+ }
457
+ }
458
+ "@
459
+
460
+ try {
461
+ $regions = [RegionEnumerator]::EnumerateRegions(${e})
462
+ @{ success = $true; regions = $regions; count = $regions.Count } | ConvertTo-Json -Compress -Depth 10
463
+ } catch {
464
+ @{ success = $false; error = $_.Exception.Message } | ConvertTo-Json -Compress
465
+ }
466
+ `.trim()}async function nt(t,n){if(t===`linux`)try{return{success:!0,regions:k(ne(`/proc/${n}/maps`,`utf-8`)).filter(e=>e.permissions.read).map(e=>({baseAddress:`0x${e.start.toString(16)}`,size:Number(e.end-e.start),state:`COMMIT`,protection:A(e.permissions),isReadable:!0,type:e.pathname||`anonymous`}))}}catch(t){return e.error(`Linux region enumeration failed:`,t),{success:!1,error:t instanceof Error?t.message:String(t)}}if(t!==`win32`&&t!==`darwin`)return{success:!1,error:`Region enumeration currently only implemented for Windows, Linux, and macOS`};if(t===`darwin`)try{let{stdout:e}=await D(`vmmap -v ${n}`,{timeout:S,maxBuffer:1024*1024*5}),t=[],r=/^(\S[^\t]*?)\s{2,}([0-9a-f]+)-([0-9a-f]+)\s+\[.*?\]\s+([a-z-]+)\/([a-z-]+)/;for(let n of e.split(`
467
+ `)){let e=n.match(r);if(!e)continue;let i=e[1],a=e[2],o=e[3],s=e[4],c=e[5],l=parseInt(a,16),u=parseInt(o,16);t.push({baseAddress:`0x${a}`,size:u-l,type:i.trim(),protect:s,maxProtect:c,isReadable:s.includes(`r`),isWritable:s.includes(`w`),isExecutable:s.includes(`x`)})}return{success:!0,regions:t}}catch(t){return e.error(`macOS region enumeration failed:`,t),{success:!1,error:t instanceof Error?t.message:String(t)}}if(j())try{let t=await N.enumerateRegions(n);if(t.success)return t;e.warn(`Native Windows region enumeration failed, falling back to PowerShell`,{pid:n,error:t.error,nativeAvailable:j()})}catch(t){e.warn(`Native Windows region enumeration threw, falling back to PowerShell`,{pid:n,error:t instanceof Error?t.message:String(t),nativeAvailable:j()})}try{let{stdout:e}=await E(tt(n),{maxBuffer:1024*1024*10,timeout:i}),t=e.trim();if(!t)throw Error(`PowerShell returned empty output`);let r=JSON.parse(t);return{success:r.success,regions:r.regions,error:r.error}}catch(t){return e.error(`Region enumeration failed:`,t),{success:!1,error:t instanceof Error?t.message:`PowerShell execution failed`}}}function rt(e,t){return`
468
+ Add-Type @"
469
+ using System;
470
+ using System.Runtime.InteropServices;
471
+ using System.ComponentModel;
472
+
473
+ public class ProtectionChecker {
474
+ [DllImport("kernel32.dll", SetLastError = true)]
475
+ public static extern IntPtr OpenProcess(int access, bool inherit, int pid);
476
+
477
+ [DllImport("kernel32.dll", SetLastError = true)]
478
+ public static extern int VirtualQueryEx(IntPtr hProcess, IntPtr addr, out MEMORY_BASIC_INFORMATION info, int size);
479
+
480
+ [DllImport("kernel32.dll", SetLastError = true)]
481
+ public static extern bool CloseHandle(IntPtr handle);
482
+
483
+ const int PROCESS_QUERY_INFORMATION = 0x0400;
484
+
485
+ [StructLayout(LayoutKind.Sequential)]
486
+ public struct MEMORY_BASIC_INFORMATION {
487
+ public IntPtr BaseAddress;
488
+ public IntPtr AllocationBase;
489
+ public uint AllocationProtect;
490
+ public IntPtr RegionSize;
491
+ public uint State;
492
+ public uint Protect;
493
+ public uint Type;
494
+ }
495
+
496
+ const uint MEM_COMMIT = 0x1000;
497
+ const uint PAGE_NOACCESS = 0x01;
498
+ const uint PAGE_READONLY = 0x02;
499
+ const uint PAGE_READWRITE = 0x04;
500
+ const uint PAGE_WRITECOPY = 0x08;
501
+ const uint PAGE_EXECUTE = 0x10;
502
+ const uint PAGE_EXECUTE_READ = 0x20;
503
+ const uint PAGE_EXECUTE_READWRITE = 0x40;
504
+ const uint PAGE_EXECUTE_WRITECOPY = 0x80;
505
+ const uint PAGE_GUARD = 0x100;
506
+
507
+ public static object CheckProtection(int pid, long address) {
508
+ IntPtr hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, false, pid);
509
+ if (hProcess == IntPtr.Zero) {
510
+ int error = Marshal.GetLastWin32Error();
511
+ throw new Win32Exception(error, "Failed to open process. Run as Administrator.");
512
+ }
513
+
514
+ try {
515
+ MEMORY_BASIC_INFORMATION info;
516
+ int infoSize = Marshal.SizeOf(typeof(MEMORY_BASIC_INFORMATION));
517
+ int result = VirtualQueryEx(hProcess, (IntPtr)address, out info, infoSize);
518
+
519
+ if (result != infoSize) {
520
+ return new { success = false, error = "Failed to query memory region" };
521
+ }
522
+
523
+ if (info.State != MEM_COMMIT) {
524
+ return new {
525
+ success = true,
526
+ protection = "NOT_COMMITTED",
527
+ isWritable = false,
528
+ isReadable = false,
529
+ isExecutable = false,
530
+ regionStart = "0x" + info.BaseAddress.ToInt64().ToString("X"),
531
+ regionSize = info.RegionSize.ToInt64()
532
+ };
533
+ }
534
+
535
+ uint protect = info.Protect;
536
+ string protectionStr = "";
537
+ bool isWritable = false;
538
+ bool isReadable = false;
539
+ bool isExecutable = false;
540
+
541
+ if ((protect & PAGE_NOACCESS) != 0) protectionStr += "NOACCESS ";
542
+ if ((protect & PAGE_READONLY) != 0) { protectionStr += "R "; isReadable = true; }
543
+ if ((protect & PAGE_READWRITE) != 0) { protectionStr += "RW "; isReadable = true; isWritable = true; }
544
+ if ((protect & PAGE_WRITECOPY) != 0) { protectionStr += "WC "; isReadable = true; isWritable = true; }
545
+ if ((protect & PAGE_EXECUTE) != 0) { protectionStr += "X "; isExecutable = true; }
546
+ if ((protect & PAGE_EXECUTE_READ) != 0) { protectionStr += "RX "; isReadable = true; isExecutable = true; }
547
+ if ((protect & PAGE_EXECUTE_READWRITE) != 0) {
548
+ protectionStr += "RWX ";
549
+ isReadable = true;
550
+ isWritable = true;
551
+ isExecutable = true;
552
+ ;
553
+ }
554
+ if ((protect & PAGE_EXECUTE_WRITECOPY) != 0) {
555
+ protectionStr += "RWCX ";
556
+ isReadable = true;
557
+ isWritable = true;
558
+ isExecutable = true;
559
+ ;
560
+ }
561
+ if ((protect & PAGE_GUARD) != 0) protectionStr += "GUARD ";
562
+
563
+ return new {
564
+ success = true,
565
+ protection = protectionStr.Trim(),
566
+ isWritable = isWritable,
567
+ isReadable = isReadable,
568
+ isExecutable = isExecutable,
569
+ regionStart = "0x" + info.BaseAddress.ToInt64().ToString("X"),
570
+ regionSize = info.RegionSize.ToInt64()
571
+ };
572
+ } finally {
573
+ CloseHandle(hProcess);
574
+ }
575
+ }
576
+ }
577
+ "@
578
+
579
+ try {
580
+ $result = [ProtectionChecker]::CheckProtection(${e}, ${t})
581
+ $result | ConvertTo-Json -Compress
582
+ } catch {
583
+ @{ success = $false; error = $_.Exception.Message } | ConvertTo-Json -Compress
584
+ }
585
+ `.trim()}async function Q(t,n,r){let i=BigInt(r.startsWith(`0x`)?r:`0x${r}`);if(t===`linux`)try{let e=k(await te.readFile(`/proc/${n}/maps`,`utf-8`)).find(e=>i>=e.start&&i<e.end);return e?{success:!0,protection:A(e.permissions),isReadable:e.permissions.read,isWritable:e.permissions.write,isExecutable:e.permissions.exec,regionStart:`0x${e.start.toString(16)}`,regionSize:Number(e.end-e.start)}:{success:!1,error:`Address ${r} not found in any memory region`}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}if(t===`darwin`){try{let{createPlatformProvider:e}=await import(`./factory-CKr4fAE1.mjs`).then(e=>e.n),t=e();if((await t.checkAvailability()).available){let e=t.openProcess(n,!1);try{let n=t.queryRegion(e,i);return n?{success:!0,protection:[n.isReadable?`r`:`-`,n.isWritable?`w`:`-`,n.isExecutable?`x`:`-`].join(``),isReadable:n.isReadable,isWritable:n.isWritable,isExecutable:n.isExecutable,regionStart:`0x${n.baseAddress.toString(16)}`,regionSize:n.size}:{success:!1,error:`Address ${r} not found in any memory region`}}finally{t.closeProcess(e)}}}catch{}try{let e=parseInt(r,16);if(isNaN(e))return{success:!1,error:`Invalid address format`};let{stdout:t}=await D(`vmmap -v ${n}`,{timeout:v,maxBuffer:1024*1024*5}),i=/^(\S[^\t]*?)\s{2,}([0-9a-f]+)-([0-9a-f]+)\s+\[.*?\]\s+([a-z-]+)\/([a-z-]+)/;for(let n of t.split(`
586
+ `)){let t=n.match(i);if(!t)continue;let r=parseInt(t[2],16),a=parseInt(t[3],16);if(e>=r&&e<a){let e=t[4];return{success:!0,protection:e,isReadable:e.includes(`r`),isWritable:e.includes(`w`),isExecutable:e.includes(`x`),regionStart:`0x${t[2]}`,regionSize:a-r}}}return{success:!1,error:`Address ${r} not found in any memory region`}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e)}}}if(j())try{let t=await N.checkMemoryProtection(n,r);if(t.success)return t;e.warn(`Native Windows memory protection check failed, falling back to PowerShell`,{pid:n,address:r,error:t.error,nativeAvailable:j()})}catch(t){e.warn(`Native Windows memory protection check threw, falling back to PowerShell`,{pid:n,address:r,error:t instanceof Error?t.message:String(t),nativeAvailable:j()})}try{let e=parseInt(r,16);if(isNaN(e))return{success:!1,error:`Invalid address format`};let{stdout:t}=await E(rt(n,e),{maxBuffer:1024*1024,timeout:C}),i=t.trim();if(!i)throw Error(`PowerShell returned empty output`);let a=JSON.parse(i);return{success:a.success,protection:a.protection,isWritable:a.isWritable,isReadable:a.isReadable,isExecutable:a.isExecutable,regionStart:a.regionStart,regionSize:a.regionSize,error:a.error}}catch(t){return e.error(`Memory protection check failed:`,t),{success:!1,error:t instanceof Error?t.message:`PowerShell execution failed`}}}async function it(t,n){if(t!==`win32`)return{success:!1,error:`Module enumeration currently only implemented for Windows`};try{let{stdout:e}=await E(`
587
+ Add-Type @"
588
+ using System;
589
+ using System.Runtime.InteropServices;
590
+ using System.Collections.Generic;
591
+ using System.ComponentModel;
592
+
593
+ public class ModuleEnumerator {
594
+ [DllImport("psapi.dll", SetLastError = true)]
595
+ public static extern bool EnumProcessModules(IntPtr hProcess, [Out] IntPtr[] lphModule, int cb, out int lpcbNeeded);
596
+
597
+ [DllImport("psapi.dll", SetLastError = true)]
598
+ public static extern int GetModuleBaseName(IntPtr hProcess, IntPtr hModule, [Out] System.Text.StringBuilder lpBaseName, int nSize);
599
+
600
+ [DllImport("psapi.dll", SetLastError = true)]
601
+ public static extern bool GetModuleInformation(IntPtr hProcess, IntPtr hModule, out MODULEINFO lpmodinfo, int cb);
602
+
603
+ [DllImport("kernel32.dll", SetLastError = true)]
604
+ public static extern IntPtr OpenProcess(int access, bool inherit, int pid);
605
+
606
+ [DllImport("kernel32.dll", SetLastError = true)]
607
+ public static extern bool CloseHandle(IntPtr handle);
608
+
609
+ const int PROCESS_QUERY_INFORMATION = 0x0400;
610
+ const int PROCESS_VM_READ = 0x0010;
611
+
612
+ [StructLayout(LayoutKind.Sequential)]
613
+ public struct MODULEINFO {
614
+ public IntPtr lpBaseOfDll;
615
+ public int SizeOfImage;
616
+ public IntPtr EntryPoint;
617
+ }
618
+
619
+ public static object Enumerate(int pid) {
620
+ IntPtr hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, pid);
621
+ if (hProcess == IntPtr.Zero) {
622
+ int error = Marshal.GetLastWin32Error();
623
+ throw new Win32Exception(error, "Failed to open process");
624
+ }
625
+
626
+ try {
627
+ IntPtr[] modules = new IntPtr[1024];
628
+ int cbNeeded;
629
+
630
+ if (!EnumProcessModules(hProcess, modules, modules.Length * IntPtr.Size, out cbNeeded)) {
631
+ int error = Marshal.GetLastWin32Error();
632
+ throw new Win32Exception(error, "EnumProcessModules failed");
633
+ }
634
+
635
+ int numModules = cbNeeded / IntPtr.Size;
636
+ var result = new List<object>();
637
+
638
+ for (int i = 0; i < numModules; i++) {
639
+ System.Text.StringBuilder baseName = new System.Text.StringBuilder(256);
640
+ if (GetModuleBaseName(hProcess, modules[i], baseName, baseName.Capacity) > 0) {
641
+ MODULEINFO modInfo;
642
+ if (GetModuleInformation(hProcess, modules[i], out modInfo, Marshal.SizeOf(typeof(MODULEINFO)))) {
643
+ result.Add(new {
644
+ name = baseName.ToString(),
645
+ baseAddress = "0x" + modInfo.lpBaseOfDll.ToInt64().ToString("X"),
646
+ size = modInfo.SizeOfImage
647
+ });
648
+ }
649
+ }
650
+ }
651
+
652
+ return new { success = true, modules = result };
653
+ } finally {
654
+ CloseHandle(hProcess);
655
+ }
656
+ }
657
+ }
658
+ "@
659
+
660
+ try {
661
+ $result = [ModuleEnumerator]::Enumerate(${n})
662
+ $result | ConvertTo-Json -Compress -Depth 10
663
+ } catch {
664
+ @{ success = $false; error = $_.Exception.Message } | ConvertTo-Json -Compress
665
+ }
666
+ `,{maxBuffer:1024*1024*10,timeout:i}),t=e.trim();if(!t)throw Error(`PowerShell returned empty output`);return JSON.parse(t)}catch(t){return e.error(`Module enumeration failed:`,t),{success:!1,error:t instanceof Error?t.message:`PowerShell execution failed`}}}function at(e){if(/[`$"';|<>&()\\\n\r]/.test(e))throw Error(`Path contains unsafe characters: ${e}`)}function ot(e,t){return`
667
+ Add-Type @"
668
+ using System;
669
+ using System.Runtime.InteropServices;
670
+ using System.ComponentModel;
671
+ using System.IO;
672
+
673
+ public class DllInjector {
674
+ [DllImport("kernel32.dll", SetLastError = true)]
675
+ public static extern IntPtr OpenProcess(int access, bool inherit, int pid);
676
+
677
+ [DllImport("kernel32.dll", SetLastError = true)]
678
+ public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr addr, int size, int allocType, int protect);
679
+
680
+ [DllImport("kernel32.dll", SetLastError = true)]
681
+ public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr addr, byte[] buffer, int size, out int written);
682
+
683
+ [DllImport("kernel32.dll", SetLastError = true)]
684
+ public static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr attr, int stackSize, IntPtr startAddr, IntPtr param, int flags, out int threadId);
685
+
686
+ [DllImport("kernel32.dll", SetLastError = true)]
687
+ public static extern IntPtr GetModuleHandle(string name);
688
+
689
+ [DllImport("kernel32.dll", SetLastError = true)]
690
+ public static extern IntPtr GetProcAddress(IntPtr hModule, string name);
691
+
692
+ [DllImport("kernel32.dll", SetLastError = true)]
693
+ public static extern bool CloseHandle(IntPtr handle);
694
+
695
+ [DllImport("kernel32.dll", SetLastError = true)]
696
+ public static extern bool VirtualFreeEx(IntPtr hProcess, IntPtr addr, int size, int freeType);
697
+
698
+ const int PROCESS_CREATE_THREAD = 0x0002;
699
+ const int PROCESS_QUERY_INFORMATION = 0x0400;
700
+ const int PROCESS_VM_OPERATION = 0x0008;
701
+ const int PROCESS_VM_WRITE = 0x0020;
702
+ const int MEM_COMMIT = 0x1000;
703
+ const int MEM_RESERVE = 0x2000;
704
+ const int PAGE_READWRITE = 0x04;
705
+ const int MEM_RELEASE = 0x8000;
706
+
707
+ public static object Inject(int pid, string dllPath) {
708
+ if (!File.Exists(dllPath)) {
709
+ return new { success = false, error = "DLL not found: " + dllPath };
710
+ }
711
+
712
+ IntPtr hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE, false, pid);
713
+ if (hProcess == IntPtr.Zero) {
714
+ int error = Marshal.GetLastWin32Error();
715
+ throw new Win32Exception(error, "Failed to open process. Run as Administrator.");
716
+ }
717
+
718
+ try {
719
+ byte[] dllBytes = System.Text.Encoding.ASCII.GetBytes(dllPath + "\\0");
720
+ IntPtr remoteMem = VirtualAllocEx(hProcess, IntPtr.Zero, dllBytes.Length, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
721
+ if (remoteMem == IntPtr.Zero) {
722
+ int error = Marshal.GetLastWin32Error();
723
+ throw new Win32Exception(error, "Failed to allocate memory in target");
724
+ }
725
+
726
+ try {
727
+ int written;
728
+ if (!WriteProcessMemory(hProcess, remoteMem, dllBytes, dllBytes.Length, out written)) {
729
+ int error = Marshal.GetLastWin32Error();
730
+ throw new Win32Exception(error, "Failed to write DLL path to target");
731
+ }
732
+
733
+ IntPtr hKernel32 = GetModuleHandle("kernel32.dll");
734
+ IntPtr loadLibraryAddr = GetProcAddress(hKernel32, "LoadLibraryA");
735
+ if (loadLibraryAddr == IntPtr.Zero) {
736
+ throw new Exception("Failed to get LoadLibraryA address");
737
+ }
738
+
739
+ int threadId;
740
+ IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLibraryAddr, remoteMem, 0, out threadId);
741
+ if (hThread == IntPtr.Zero) {
742
+ int error = Marshal.GetLastWin32Error();
743
+ throw new Win32Exception(error, "Failed to create remote thread");
744
+ }
745
+
746
+ CloseHandle(hThread);
747
+ return new { success = true, remoteThreadId = threadId };
748
+ } finally {
749
+ VirtualFreeEx(hProcess, remoteMem, 0, MEM_RELEASE);
750
+ }
751
+ } finally {
752
+ CloseHandle(hProcess);
753
+ }
754
+ }
755
+ }
756
+ "@
757
+
758
+ try {
759
+ $result = [DllInjector]::Inject(${e}, "${t.replace(/\\/g,`\\\\`).replace(/"/g,'`"').replace(/`/g,"``").replace(/\$/g,"`$")}")
760
+ $result | ConvertTo-Json -Compress
761
+ } catch {
762
+ @{ success = $false; error = $_.Exception.Message } | ConvertTo-Json -Compress
763
+ }
764
+ `.trim()}async function st(t,n,r){if(t===`linux`)try{at(r);let{stderr:e}=await D(`gdb -p ${n} -batch -ex "call (void*)dlopen(\\"${r}\\", 1)" -ex "quit"`,{timeout:s});if(e.includes(`Operation not permitted`)||e.includes(`ptrace:`))throw Error(`GDB injection failed (ptrace blocked): ${e}`);return{success:!0}}catch(t){return e.error(`Linux DLL injection failed:`,t),{success:!1,error:t instanceof Error?t.message:String(t)}}else if(t===`darwin`)try{at(r);let{stdout:e,stderr:t}=await D(`lldb --batch -p ${n} -o "expr (void*)dlopen(\\"${r}\\", 1)"`,{timeout:s});if(t.includes(`error:`)||e.includes(`error:`))throw Error(`LLDB injection failed: ${t||e}`);return{success:!0}}catch(t){return e.error(`macOS DLL injection failed:`,t),{success:!1,error:t instanceof Error?t.message:String(t)}}else if(t!==`win32`)return{success:!1,error:`DLL injection not supported on this platform`};try{let{stdout:e}=await E(ot(n,r),{maxBuffer:1024*1024,timeout:s}),t=e.trim();if(!t)throw Error(`PowerShell returned empty output`);let i=JSON.parse(t);return{success:i.success,remoteThreadId:i.remoteThreadId,error:i.error}}catch(t){return e.error(`DLL injection failed:`,t),{success:!1,error:t instanceof Error?t.message:`PowerShell execution failed`}}}function ct(e,t){return`
765
+ Add-Type @"
766
+ using System;
767
+ using System.Runtime.InteropServices;
768
+ using System.ComponentModel;
769
+
770
+ public class ShellcodeInjector {
771
+ [DllImport("kernel32.dll", SetLastError = true)]
772
+ public static extern IntPtr OpenProcess(int access, bool inherit, int pid);
773
+
774
+ [DllImport("kernel32.dll", SetLastError = true)]
775
+ public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr addr, int size, int allocType, int protect);
776
+
777
+ [DllImport("kernel32.dll", SetLastError = true)]
778
+ public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr addr, byte[] buffer, int size, out int written);
779
+
780
+ [DllImport("kernel32.dll", SetLastError = true)]
781
+ public static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr attr, int stackSize, IntPtr startAddr, IntPtr param, int flags, out int threadId);
782
+
783
+ [DllImport("kernel32.dll", SetLastError = true)]
784
+ public static extern bool CloseHandle(IntPtr handle);
785
+
786
+ [DllImport("kernel32.dll", SetLastError = true)]
787
+ public static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr addr, int size, int newProtect, out int oldProtect);
788
+
789
+ const int PROCESS_CREATE_THREAD = 0x0002;
790
+ const int PROCESS_QUERY_INFORMATION = 0x0400;
791
+ const int PROCESS_VM_OPERATION = 0x0008;
792
+ const int PROCESS_VM_WRITE = 0x0020;
793
+ const int MEM_COMMIT = 0x1000;
794
+ const int MEM_RESERVE = 0x2000;
795
+ const int PAGE_READWRITE = 0x04;
796
+ const int PAGE_EXECUTE_READWRITE = 0x40;
797
+
798
+ public static object Inject(int pid, byte[] shellcode) {
799
+ IntPtr hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE, false, pid);
800
+ if (hProcess == IntPtr.Zero) {
801
+ int error = Marshal.GetLastWin32Error();
802
+ throw new Win32Exception(error, "Failed to open process. Run as Administrator.");
803
+ }
804
+
805
+ try {
806
+ IntPtr remoteMem = VirtualAllocEx(hProcess, IntPtr.Zero, shellcode.Length, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
807
+ if (remoteMem == IntPtr.Zero) {
808
+ int error = Marshal.GetLastWin32Error();
809
+ throw new Win32Exception(error, "Failed to allocate memory in target");
810
+ }
811
+
812
+ try {
813
+ int written;
814
+ if (!WriteProcessMemory(hProcess, remoteMem, shellcode, shellcode.Length, out written)) {
815
+ int error = Marshal.GetLastWin32Error();
816
+ throw new Win32Exception(error, "Failed to write shellcode to target");
817
+ }
818
+
819
+ int oldProtect;
820
+ if (!VirtualProtectEx(hProcess, remoteMem, shellcode.Length, PAGE_EXECUTE_READWRITE, out oldProtect)) {
821
+ int error = Marshal.GetLastWin32Error();
822
+ throw new Win32Exception(error, "Failed to change memory protection to executable");
823
+ }
824
+
825
+ int threadId;
826
+ IntPtr hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, remoteMem, IntPtr.Zero, 0, out threadId);
827
+ if (hThread == IntPtr.Zero) {
828
+ int error = Marshal.GetLastWin32Error();
829
+ throw new Win32Exception(error, "Failed to create remote thread");
830
+ }
831
+
832
+ CloseHandle(hThread);
833
+ return new { success = true, remoteThreadId = threadId };
834
+ } finally {
835
+ // Note: Memory is not freed to allow shellcode to execute
836
+ }
837
+ } finally {
838
+ CloseHandle(hProcess);
839
+ }
840
+ }
841
+ }
842
+ "@
843
+
844
+ try {
845
+ $shellcode = @(${Array.from(t).join(`,`)})
846
+ $result = [ShellcodeInjector]::Inject(${e}, $shellcode)
847
+ $result | ConvertTo-Json -Compress
848
+ } catch {
849
+ @{ success = $false; error = $_.Exception.Message } | ConvertTo-Json -Compress
850
+ }
851
+ `.trim()}async function lt(t,n,r,i=`hex`){try{let e;if(i===`base64`)e=Buffer.from(r,`base64`);else{let t=r.replace(/\s/g,``);e=Buffer.from(t,`hex`)}if(t===`linux`){let t=Array.from(e).map(e=>`\\x${e.toString(16).padStart(2,`0`)}`).join(``),r=`
852
+ import gdb
853
+ import sys
854
+
855
+ def inject():
856
+ try:
857
+ # mmap: PROT_READ|PROT_WRITE|PROT_EXEC (7), MAP_PRIVATE|MAP_ANONYMOUS (34)
858
+ mmap_res = gdb.parse_and_eval("(void*)mmap(0, ${e.length}, 7, 34, -1, 0)")
859
+ addr = int(mmap_res)
860
+ if addr == -1 or addr == 0:
861
+ print("ERROR_INJECT: mmap failed")
862
+ return
863
+
864
+ inf = gdb.selected_inferior()
865
+ inf.write_memory(addr, b"${t}")
866
+
867
+ # Call it directly (creates a crash potentially) or via pthread_create
868
+ # Let's use pthread_create
869
+ thread_t = gdb.parse_and_eval("(void*)malloc(8)")
870
+ res = gdb.parse_and_eval(f"(int)pthread_create({int(thread_t)}, 0, {addr}, 0)")
871
+
872
+ print(f"SUCCESS_INJECT: {int(res)}")
873
+ except Exception as e:
874
+ print(f"ERROR_INJECT: {str(e)}")
875
+
876
+ inject()
877
+ `,i=L(F(),`gdb_inject_${n}_${Date.now()}.py`);await I.writeFile(i,r,`utf8`);try{let{stdout:e,stderr:t}=await D(`gdb -p ${n} -batch -x ${i}`,{timeout:s});if(e.includes(`ERROR_INJECT:`)||t.includes(`ERROR_INJECT:`))throw Error(`GDB injection failed: ${e||t}`);return{success:!0}}finally{await I.unlink(i).catch(()=>{})}}else if(t===`darwin`){let t=Array.from(e).map(e=>e.toString()).join(`,`),r=`
878
+ import lldb
879
+ import sys
880
+
881
+ def __lldb_init_module(debugger, internal_dict):
882
+ try:
883
+ target = debugger.GetSelectedTarget()
884
+ process = target.GetProcess()
885
+
886
+ # mmap: PROT_READ|PROT_WRITE|PROT_EXEC (7), MAP_PRIVATE|MAP_ANON (4098 on macOS)
887
+ res = lldb.SBCommandReturnObject()
888
+ debugger.GetCommandInterpreter().HandleCommand("expr (void*)mmap(0, ${e.length}, 7, 4098, -1, 0)", res)
889
+
890
+ if not res.Succeeded():
891
+ print("ERROR_INJECT: " + res.GetError())
892
+ return
893
+
894
+ addr_str = res.GetOutput().split()[-1]
895
+ addr = int(addr_str, 16)
896
+
897
+ err = lldb.SBError()
898
+ bytes_data = bytes([${t}])
899
+ process.WriteMemory(addr, bytes_data, err)
900
+
901
+ if not err.Success():
902
+ print("ERROR_INJECT: write failed")
903
+ return
904
+
905
+ # create thread
906
+ res2 = lldb.SBCommandReturnObject()
907
+ debugger.GetCommandInterpreter().HandleCommand(f"expr (int)pthread_create((void*)malloc(8), 0, (void*){addr}, 0)", res2)
908
+
909
+ print("SUCCESS_INJECT")
910
+ except Exception as e:
911
+ print("ERROR_INJECT: " + str(e))
912
+ `,i=L(F(),`lldb_inject_${n}_${Date.now()}.py`),a=L(F(),`lldb_inject_cmd_${n}_${Date.now()}.txt`);await I.writeFile(i,r,`utf8`),await I.writeFile(a,`command script import ${i}\\nprocess detach\\n`,`utf8`);try{let{stdout:e}=await D(`lldb --batch -p ${n} --source ${a}`,{timeout:s});if(e.includes(`ERROR_INJECT:`))throw Error(`LLDB injection failed: ${e}`);return{success:!0}}finally{await I.unlink(i).catch(()=>{}),await I.unlink(a).catch(()=>{})}}else if(t!==`win32`)return{success:!1,error:`Shellcode injection not supported on this platform`};let{stdout:a}=await E(ct(n,e),{maxBuffer:1024*1024,timeout:s}),o=a.trim();if(!o)throw Error(`PowerShell returned empty output`);let c=JSON.parse(o);return{success:c.success,remoteThreadId:c.remoteThreadId,error:c.error}}catch(t){return e.error(`Shellcode injection failed:`,t),{success:!1,error:t instanceof Error?t.message:`Execution failed`}}}var ut=class{activeMonitors=new Map;start(e,t,n=4,r=1e3,i,a){let o=`monitor_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,s=setInterval(async()=>{let r=this.activeMonitors.get(o);if(r&&!r.inFlight){r.inFlight=!0;try{let o=await i(e,t,n);o.success&&o.data&&r.lastValue!==o.data&&(a&&r.lastValue!==``&&a(r.lastValue,o.data),r.lastValue=o.data)}finally{r.inFlight=!1}}},r);return typeof s.unref==`function`&&s.unref(),this.activeMonitors.set(o,{pid:e,address:t,interval:r,lastValue:``,timer:s,inFlight:!1}),o}stop(e){let t=this.activeMonitors.get(e);return t?(clearInterval(t.timer),this.activeMonitors.delete(e),!0):!1}};const dt=b;let $=null;function ft(e,t){if(typeof e!=`object`||!e)return``;let n=e[t];return typeof n==`string`?n:``}function pt(e){let t=e instanceof Error?e.message:String(e),n=`${t}\n${ft(e,`stderr`)}`.toLowerCase();return n.includes(`enoent`)||n.includes(`command not found`)||n.includes(`is not recognized as an internal or external command`)||n.includes(`cannot find`)&&n.includes(`powershell`)?`PowerShell is unavailable. Windows memory operations require powershell.exe to verify Administrator privileges.`:`PowerShell command execution failed while checking Administrator privileges: ${t}`}async function mt(){try{let{stdout:e}=await E(`([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)`,{timeout:t}),n=e.trim().toLowerCase();return n===`true`?{available:!0}:n===`false`?{available:!1,reason:`Windows memory operations require Administrator privileges. Please run your terminal/IDE as Administrator and retry.`}:{available:!1,reason:`PowerShell command execution failed while checking Administrator privileges: unexpected output "${e.trim()} '(empty)'}".`}}catch(e){return{available:!1,reason:pt(e)}}}async function ht(){let e=Date.now();if($&&$.expiresAt>e)return $.result;let t=await mt();return $={expiresAt:e+dt,result:t},t}async function gt(e){switch(e){case`win32`:return ht();case`linux`:try{let{stdout:e}=await D(`id -u`,{timeout:m});if(e.trim()===`0`)return{available:!0};try{return await D(`capsh --print 2>/dev/null | grep -q "cap_sys_ptrace"`,{timeout:m}),{available:!0}}catch{return{available:!1,reason:`Linux memory operations require root privileges or CAP_SYS_PTRACE capability. Run with sudo.`}}}catch{return{available:!1,reason:`Requires root privileges for /proc/pid/mem access. Run with sudo.`}}case`darwin`:try{return await D(`which lldb`,{timeout:m}),{available:!0,reason:process.getuid?.()===0?void 0:`Running without root — memory access works for own processes only. Use sudo for other processes.`}}catch{return{available:!1,reason:`lldb not found. Install Xcode Command Line Tools: xcode-select --install`}}default:return{available:!1,reason:`Platform ${e} not supported for memory operations.`}}}async function _t(e,n){if(e!==`win32`)return{success:!1,error:`Debug port check currently only implemented for Windows`};try{let{stdout:e}=await E(`
913
+ Add-Type @"
914
+ using System;
915
+ using System.Runtime.InteropServices;
916
+ using System.ComponentModel;
917
+
918
+ public class DebugChecker {
919
+ [DllImport("ntdll.dll")]
920
+ public static extern int NtQueryInformationProcess(IntPtr processHandle, int processInformationClass, out IntPtr processInformation, int processInformationLength, out int returnLength);
921
+
922
+ [DllImport("kernel32.dll", SetLastError = true)]
923
+ public static extern IntPtr OpenProcess(int access, bool inherit, int pid);
924
+
925
+ [DllImport("kernel32.dll", SetLastError = true)]
926
+ public static extern bool CloseHandle(IntPtr handle);
927
+
928
+ const int PROCESS_QUERY_INFORMATION = 0x0400;
929
+ const int ProcessDebugPort = 7;
930
+
931
+ public static object Check(int pid) {
932
+ IntPtr hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, false, pid);
933
+ if (hProcess == IntPtr.Zero) {
934
+ int error = Marshal.GetLastWin32Error();
935
+ throw new Win32Exception(error, "Failed to open process");
936
+ }
937
+
938
+ try {
939
+ IntPtr debugPort;
940
+ int returnLength;
941
+ int status = NtQueryInformationProcess(hProcess, ProcessDebugPort, out debugPort, IntPtr.Size, out returnLength);
942
+
943
+ if (status != 0) {
944
+ return new { success = false, error = "NtQueryInformationProcess failed with status: 0x" + status.ToString("X") };
945
+ }
946
+
947
+ return new { success = true, isDebugged = debugPort != IntPtr.Zero };
948
+ } finally {
949
+ CloseHandle(hProcess);
950
+ }
951
+ }
952
+ }
953
+ "@
954
+
955
+ try {
956
+ $result = [DebugChecker]::Check(${n})
957
+ $result | ConvertTo-Json -Compress
958
+ } catch {
959
+ @{ success = $false; error = $_.Exception.Message } | ConvertTo-Json -Compress
960
+ }
961
+ `,{maxBuffer:1024*1024,timeout:t*2}),r=e.trim();if(!r)throw Error(`PowerShell returned empty output`);try{return JSON.parse(r)}catch{throw Error(`PowerShell returned empty output`)}}catch(e){return{success:!1,error:e instanceof Error?e.message:`PowerShell execution failed`}}}function vt(){switch(process.platform){case`win32`:return`win32`;case`linux`:return`linux`;case`darwin`:return`darwin`;default:return`unknown`}}var yt=class{platform;monitorManager=new ut;constructor(){this.platform=vt(),e.info(`MemoryManager initialized for platform: ${this.platform}`)}async readMemory(e,t,n){return ke(this.platform,e,t,n,(e,t)=>Q(this.platform,e,t))}async writeMemory(e,t,n,r=`hex`){return Ie(this.platform,e,t,n,r,(e,t)=>Q(this.platform,e,t))}async batchMemoryWrite(e,t){return Re(e,t,(e,t,n,r)=>this.writeMemory(e,t,n,r))}async scanMemory(e,t,n=`hex`,r=!1){return Je(this.platform,e,t,n,r)}async scanMemoryFiltered(e,t,n,r=`hex`){return Ye(e,t,n,r,(e,t,n)=>this.readMemory(e,t,n),(e,t,n)=>this.scanMemory(e,t,n))}async dumpMemoryRegion(e,t,n,r){return et(this.platform,e,t,n,r)}async enumerateRegions(e){return nt(this.platform,e)}async checkMemoryProtection(e,t){return Q(this.platform,e,t)}async enumerateModules(e){return it(this.platform,e)}async injectDll(e,t){return st(this.platform,e,t)}async injectShellcode(e,t,n=`hex`){return lt(this.platform,e,t,n)}async checkDebugPort(e){return _t(this.platform,e)}startMemoryMonitor(e,t,n=4,r=1e3,i){return this.monitorManager.start(e,t,n,r,(e,t,n)=>this.readMemory(e,t,n),i)}stopMemoryMonitor(e){return this.monitorManager.stop(e)}async checkAvailability(){return gt(this.platform)}};function bt(){let t=process.platform;switch(t){case`win32`:return`win32`;case`linux`:return`linux`;case`darwin`:return`darwin`;default:return e.warn(`Unsupported platform: ${t}`),`unknown`}}function xt(){let t=bt();switch(e.info(`Creating ProcessManager for platform: ${t}`),t){case`win32`:return new he;case`linux`:return new _e;case`darwin`:return new xe;default:throw Error(`Unsupported platform: ${t}. ProcessManager requires Windows, Linux, or macOS.`)}}var St=class{manager;platform;constructor(){this.platform=bt(),this.manager=xt()}getPlatform(){return this.platform}async findProcesses(e){return this.manager.findProcesses(e)}async getProcessByPid(e){return this.manager.getProcessByPid(e)}async getProcessWindows(e){return this.manager.getProcessWindows(e)}async checkDebugPort(e,t){return this.manager.checkDebugPort(e,t)}async launchWithDebug(e,t,n){return this.manager.launchWithDebug(e,t,n)}async killProcess(e){return this.manager.killProcess(e)}async getProcessCommandLine(e){return this.manager.getProcessCommandLine(e)}async findBrowserProcesses(e){return this.platform===`win32`?e?.processNamePattern||e?.windowClassPattern?this.manager.findChromiumProcesses({processNamePattern:e.processNamePattern,windowClassPattern:e.windowClassPattern}):this.manager.findChromiumAppProcesses():this.platform===`linux`||this.platform===`darwin`?this.manager.findChromeProcesses():null}};export{yt as n,St as t};