@jshookmcp/jshook 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -4
- package/README.zh.md +19 -4
- package/dist/AntiCheatDetector-B-mz4DK_.mjs +1 -0
- package/dist/{BrowserSessionCoordinator-BJ-HOxo0.mjs → BrowserSessionCoordinator-Cdic8FsH.mjs} +1 -1
- package/dist/CodeAnalyzerDataFlow-a-NkwcaG.mjs +2 -0
- package/dist/CodeInjector-B099WO6x.mjs +1 -0
- package/dist/ConsoleMonitor-BZRqrBH-.mjs +306 -0
- package/dist/CpuEngine-BC8jayy9.mjs +1 -0
- package/dist/DartAotExecutor-B7WVTKsd.mjs +1 -0
- package/dist/DartAotLoader-BxdhW-K2.mjs +2 -0
- package/dist/DarwinAPI-DzojdfjF.mjs +1 -0
- package/dist/DetailedDataManager-Dgh402Gp.mjs +5 -0
- package/dist/ExecutionSandbox-QbWQmzuC.mjs +45 -0
- package/dist/ExtensionManager.tools-D3h818Xs.mjs +1 -0
- package/dist/FingerprintManager-D9Zlr6be.mjs +1 -0
- package/dist/HardwareBreakpoint-C_lJ22bj.mjs +1 -0
- package/dist/HeapAnalyzer-bJbLvzp6.mjs +1 -0
- package/dist/HookPatternScanner-yx4vJ9sd.mjs +1 -0
- package/dist/InstrumentationSession-Cv1wikLA.mjs +1 -0
- package/dist/IntegrityScanner-BB7sw-SA.mjs +1 -0
- package/dist/JScramblerDeobfuscator-NVR5VatT.mjs +1 -0
- package/dist/MCPServer.activation.ttl-C2wOCMLV.mjs +1 -0
- package/dist/MCPServer.search.helpers-DlassAew.mjs +2 -0
- package/dist/MCPServer.search.validation-DnifPCCv.mjs +1 -0
- package/dist/MemoryController-CCsGuGJS.mjs +2 -0
- package/dist/{MemoryScanSession-DG_F-PjE.mjs → MemoryScanSession-BZ2A9Ph1.mjs} +1 -1
- package/dist/MemoryScanner-DAxsq7Sx.mjs +1 -0
- package/dist/NativeMemoryManager.impl-BIJzXMqH.mjs +1 -0
- package/dist/{NativeMemoryManager.utils-BHy1P_jM.mjs → NativeMemoryManager.utils-CMoul2an.mjs} +1 -1
- package/dist/PEAnalyzer-CB_kaTis.mjs +1 -0
- package/dist/PackerDeobfuscator-BpwGjxDL.mjs +7 -0
- package/dist/PointerChainEngine-B6SYv6ZM.mjs +1 -0
- package/dist/ProcessRegistry-C5W1Tkn9.mjs +1 -0
- package/dist/{handlers-mPFiNPe8.mjs → QuickJSSandbox-CIde-jzG.mjs} +2 -5
- package/dist/{ResponseBuilder-BfWP-uaT.mjs → ResponseBuilder-BLicSCjn.mjs} +1 -1
- package/dist/ReverseEvidenceGraph-DJzk0GQz.mjs +2 -0
- package/dist/ServerRuntimeState-DGXNv8Ji.mjs +1 -0
- package/dist/Speedhack-MGoeq1ZS.mjs +1 -0
- package/dist/StructureAnalyzer-CCTWAXR3.mjs +2 -0
- package/dist/ToolHandlerMap-C40EmuLT.mjs +1 -0
- package/dist/{ToolProbe-C7ZU2x7M.mjs → ToolProbe-B02GC3ZY.mjs} +1 -1
- package/dist/ToolRegistry-CzqQxFqf.mjs +1 -0
- package/dist/ToolRouter.policy-Bgb3S8jc.mjs +4 -0
- package/dist/TraceRecorder-BfeCTQUj.mjs +407 -0
- package/dist/VMDeobfuscator-BHtkV850.mjs +1 -0
- package/dist/Win32API-G7QPyckq.mjs +1 -0
- package/dist/{Win32Debug-CYrIQBvr.mjs → Win32Debug-6yzmtv5b.mjs} +1 -1
- package/dist/allocation-track-CiI-CnaI.mjs +1 -0
- package/dist/analysis-CojUzwX-.mjs +27 -0
- package/dist/antidebug-CgU84TE1.mjs +1 -0
- package/dist/apk-DrPBsOq8.mjs +1 -0
- package/dist/artifactRetention-Bk6fW2uF.mjs +1 -0
- package/dist/artifacts-Bx9GLx4J.mjs +1 -0
- package/dist/ast-bridge-BlOrmVAv.mjs +1 -0
- package/dist/ast-utils-B9E5k_v1.mjs +1 -0
- package/dist/{betterSqlite3-Brtq-SIQ.mjs → betterSqlite3-Bdo_ifuJ.mjs} +1 -1
- package/dist/binary-instrument-DiE1BP0x.mjs +12 -0
- package/dist/boringssl-inspector-C6M3sOga.mjs +2 -0
- package/dist/browser-QDUu5ML9.mjs +29 -0
- package/dist/{handlers-yo_xYzT8.mjs → canvas-g5kmLdY-.mjs} +1098 -24
- package/dist/{capabilities-CyXuKUl1.mjs → capabilities-DwzyxL2w.mjs} +1 -1
- package/dist/cdp-session-Dy4OwMOP.mjs +1 -0
- package/dist/collector-Cld4i-E4.mjs +1 -0
- package/dist/config-5ODJ3Aj0.mjs +3 -0
- package/dist/constants-nvsLpSri.mjs +1 -0
- package/dist/coordination-C6y2gM9O.mjs +98 -0
- package/dist/coverage-and-block--cWjjEe5.mjs +1 -0
- package/dist/dart-inspector-D4IKxZ6u.mjs +0 -0
- package/dist/debugger-C2SpiXoO.mjs +1 -0
- package/dist/definitions-0mtilYzG.mjs +1 -0
- package/dist/definitions-9csunmeX.mjs +1 -0
- package/dist/definitions-B11MudW_.mjs +1 -0
- package/dist/definitions-BKpRDjcI.mjs +1 -0
- package/dist/definitions-BXE3H4re.mjs +1 -0
- package/dist/definitions-BlPHe5DX.mjs +1 -0
- package/dist/definitions-Bob4XMxI.mjs +27 -0
- package/dist/definitions-BpIQN2nm.mjs +1 -0
- package/dist/definitions-BvolWeSu.mjs +1 -0
- package/dist/definitions-C-6j3Ejl.mjs +1 -0
- package/dist/definitions-C-AdFfFu.mjs +1 -0
- package/dist/definitions-CArdw_9T.mjs +1 -0
- package/dist/definitions-CCvIcRrT.mjs +1 -0
- package/dist/definitions-CJPE5PIl.mjs +1 -0
- package/dist/definitions-CbqeW06u.mjs +1 -0
- package/dist/definitions-Cexmkypg.mjs +1 -0
- package/dist/definitions-D1dxl8qt.mjs +1 -0
- package/dist/definitions-D3uT-ZbU.mjs +1 -0
- package/dist/definitions-DtOY5iUc.mjs +1 -0
- package/dist/{definitions-DxFNRQNK2.mjs → definitions-DvrYdDCJ2.mjs} +1 -1
- package/dist/{definitions-Cenu6mxo.mjs → definitions-aeRd5DAR.mjs} +1 -1
- package/dist/definitions-ihxOqOC4.mjs +1 -0
- package/dist/deopt-trace-qnAcC931.mjs +17 -0
- package/dist/disasm-DoxSucGp.mjs +1 -0
- package/dist/dumpsys-parser-Du-5ruEe.mjs +2 -0
- package/dist/encoding-UMtwgy4M.mjs +2 -0
- package/dist/ensure-browser-core-BP70x0TB.mjs +285 -0
- package/dist/factory-BeND77hf.mjs +2 -0
- package/dist/graphql-CF7QKJME.mjs +68 -0
- package/dist/grpc-raw-Dp7ps2sv.mjs +1 -0
- package/dist/handlers--qCl9vNv.mjs +1 -0
- package/dist/handlers-BHIu1LqA.mjs +1 -0
- package/dist/{antidebug-7L3ygj_9.mjs → handlers-BQ4K8Jbr.mjs} +2 -2
- package/dist/handlers-BxQv-wtf.mjs +8 -0
- package/dist/handlers-ByYG27-5.mjs +1 -0
- package/dist/handlers-C0I9-BtX.mjs +5 -0
- package/dist/handlers-CL0Iokmw.mjs +1 -0
- package/dist/handlers-CNbhIdSK.mjs +4 -0
- package/dist/handlers-CnTTSJFs.mjs +109 -0
- package/dist/handlers-CoDx6akJ2.mjs +49 -0
- package/dist/{handlers-0yKLRIfo.mjs → handlers-DASJI0Pn.mjs} +1 -1
- package/dist/handlers-DRKMaA-_.mjs +74 -0
- package/dist/handlers-Dalu0olz.mjs +2 -0
- package/dist/handlers-KY0g31ny.mjs +9 -0
- package/dist/handlers-oGo60aVv.mjs +1 -0
- package/dist/handlers.impl-BTXLw6Qc.mjs +1 -0
- package/dist/heap-sampling-BqdiU-5j.mjs +1 -0
- package/dist/{hooks-D4XLfgtV.mjs → hooks-COK3t5rT.mjs} +52 -33
- package/dist/index.mjs +11 -11
- package/dist/logger-BGCcd-jJ.mjs +1 -0
- package/dist/macro-nUYUjKNZ.mjs +2 -0
- package/dist/maintenance-CfnE7ZKU.mjs +4 -0
- package/dist/manifest-7EOTUc0D.mjs +1 -0
- package/dist/manifest-B5ujuQmf.mjs +1 -0
- package/dist/manifest-BErXl3zn.mjs +1 -0
- package/dist/manifest-BKA-mD3J.mjs +1 -0
- package/dist/manifest-BUXj23bX.mjs +1 -0
- package/dist/manifest-BfXt9cau.mjs +1 -0
- package/dist/manifest-Bx-tpURK.mjs +1 -0
- package/dist/manifest-C0owVAdq.mjs +1 -0
- package/dist/manifest-C5XqYc9o.mjs +1 -0
- package/dist/manifest-CVKzLjsA.mjs +1 -0
- package/dist/manifest-CaeFjdhj.mjs +1 -0
- package/dist/manifest-CegBgip0.mjs +1 -0
- package/dist/manifest-CoJHqlgS.mjs +1 -0
- package/dist/manifest-D0dbtDqd.mjs +1 -0
- package/dist/manifest-D5Gr8ujd.mjs +12 -0
- package/dist/manifest-D82z-5og.mjs +1 -0
- package/dist/manifest-DA2afIwh.mjs +1 -0
- package/dist/manifest-DAbiFP5o.mjs +1 -0
- package/dist/manifest-DEY0s1O72.mjs +1 -0
- package/dist/manifest-DTOqNqiA.mjs +1 -0
- package/dist/manifest-DZ6ELNgX.mjs +1 -0
- package/dist/manifest-DjHkjddT.mjs +1 -0
- package/dist/manifest-DocA_itf2.mjs +1 -0
- package/dist/manifest-Dpnhvfq0.mjs +1 -0
- package/dist/manifest-DucPMG_a.mjs +1 -0
- package/dist/manifest-Dw5yYEac.mjs +1 -0
- package/dist/manifest-Ic_Cg66S.mjs +1 -0
- package/dist/manifest-JHaG6GMN.mjs +1 -0
- package/dist/manifest-QdkIzmYM.mjs +1 -0
- package/dist/manifest-YZqaCe25.mjs +1 -0
- package/dist/manifest-f0lUeXwq.mjs +1 -0
- package/dist/manifest-h-Ebisf8.mjs +1 -0
- package/dist/manifest-oOfTymBS.mjs +1 -0
- package/dist/manifest-qXqrO6KC.mjs +2 -0
- package/dist/mapsParser-DrJoeC0c.mjs +1 -0
- package/dist/modules-CC_ADmwi.mjs +333 -0
- package/dist/mojo-ipc-kVztXYw-.mjs +140 -0
- package/dist/native-D9ouskXO.mjs +961 -0
- package/dist/native-bridge-Dzd7hYoq.mjs +1 -0
- package/dist/network-C5Y-S87J.mjs +7 -0
- package/dist/one-gadget-CiWFE17F.mjs +1 -0
- package/dist/outputPaths-CHtELDyi.mjs +1 -0
- package/dist/parse-args-B6dwWc9k.mjs +1 -0
- package/dist/platform-BIXgJaM3.mjs +94 -0
- package/dist/process-aDIfLC0v.mjs +6 -0
- package/dist/proxy-DsHsQ1I4.mjs +2 -0
- package/dist/registry-7h8jJ9y9.mjs +1 -0
- package/dist/{registry-DH4sc1dt.mjs → registry-DJDnkQW2.mjs} +1 -1
- package/dist/response-R8ghbZSb.mjs +1 -0
- package/dist/retry-policy-DtYv0kDi.mjs +1 -0
- package/dist/reverseEngineeringConfig-BhZLOa3C.mjs +1 -0
- package/dist/safeOutput-Dt4mfjXA.mjs +1 -0
- package/dist/search-defaults-BBRJNAzC.mjs +1 -0
- package/dist/server/plugin-api.mjs +1 -1
- package/dist/server/search/EmbeddingWorker.d.mts +1 -0
- package/dist/server/search/EmbeddingWorker.mjs +1 -0
- package/dist/shared-BKtWZDGN.mjs +1 -0
- package/dist/sourcemap-2VIeVeKw.mjs +3 -0
- package/dist/streaming-DkpE3GGU.mjs +15 -0
- package/dist/syscall-DGZoYM_U.mjs +1 -0
- package/dist/transform-BJqsBC_-.mjs +105 -0
- package/dist/turbofan-graph-CbGHNVtl.mjs +1 -0
- package/dist/turbofan-inspect--NdCuYXi.mjs +23 -0
- package/dist/types-CWSvzmIh.mjs +1 -0
- package/dist/v8-inspector-CTJo08-K.mjs +297 -0
- package/dist/wasm-DX4Qm2Vs.mjs +235 -0
- package/dist/weakrefs-inspect-CnhaF-rN.mjs +57 -0
- package/dist/webgpu-D4-DxbxZ.mjs +6 -0
- package/dist/workflow-DHktRNF2.mjs +108 -0
- package/package.json +33 -27
- package/dist/AntiCheatDetector-B6d4Qe9D.mjs +0 -1
- package/dist/CodeInjector-Cll_7bLJ.mjs +0 -1
- package/dist/ConsoleMonitor-CxDJV15E.mjs +0 -306
- package/dist/DOMInspector-C19J4zeq.mjs +0 -95
- package/dist/DarwinAPI-ZfQdpLNI.mjs +0 -1
- package/dist/DetailedDataManager-DmQ1LT-W.mjs +0 -1
- package/dist/ExtensionManager-BD724zkO.mjs +0 -1
- package/dist/ExtensionManager.tools-oVMJgPcN.mjs +0 -1
- package/dist/FingerprintManager-DT0EAUEo.mjs +0 -1
- package/dist/HardwareBreakpoint-BUfPdp0f.mjs +0 -1
- package/dist/HeapAnalyzer-B_aqY8oj.mjs +0 -1
- package/dist/InstrumentationSession-D_G1ZPyd.mjs +0 -1
- package/dist/MCPServer.search.handlers.domain-BbS-6LnX.mjs +0 -1
- package/dist/MemoryController-X1XNSn1n.mjs +0 -2
- package/dist/MemoryScanner-g1_L1ub5.mjs +0 -1
- package/dist/NativeMemoryManager.impl-DniBe2wf.mjs +0 -1
- package/dist/NetworkMonitor-B_-au6aV.mjs +0 -185
- package/dist/PEAnalyzer-yWQaGrcx.mjs +0 -1
- package/dist/PageController-Dfsm1_o7.mjs +0 -1
- package/dist/PointerChainEngine-BhCUkmxY.mjs +0 -1
- package/dist/PrerequisiteError-BjCQA-gK.mjs +0 -1
- package/dist/ProcessRegistry-C-bN48oR.mjs +0 -1
- package/dist/ReverseEvidenceGraph-BhSYYdiI.mjs +0 -2
- package/dist/ScriptManager-LWGPTdvD.mjs +0 -7
- package/dist/ServerRuntimeState-D2bWHqEE.mjs +0 -1
- package/dist/Speedhack-yseDPSZ9.mjs +0 -1
- package/dist/StructureAnalyzer-C5lpuZkg.mjs +0 -2
- package/dist/ToolCatalog-CYdD9F5f.mjs +0 -1
- package/dist/ToolRegistry-C5oB8KP8.mjs +0 -1
- package/dist/ToolRouter.policy-CfhJczkt.mjs +0 -4
- package/dist/TraceRecorder-BiJWBXHX.mjs +0 -272
- package/dist/VersionDetector-CHT36Az0.mjs +0 -9
- package/dist/Win32API-eUCF57l_.mjs +0 -1
- package/dist/WorkflowEngine-D876meOO.mjs +0 -1
- package/dist/analysis-D4swdMvq.mjs +0 -6
- package/dist/apk-packer-BqXcInnX.mjs +0 -1
- package/dist/artifactRetention-BCPQASm7.mjs +0 -1
- package/dist/artifacts-CkodUM4j.mjs +0 -1
- package/dist/binary-instrument-DU7V6TUM.mjs +0 -7
- package/dist/binary-secrets-PdMVoyt0.mjs +0 -1
- package/dist/boringssl-inspector-BBaJwwkU.mjs +0 -2
- package/dist/browser-Qqco2rOT.mjs +0 -11
- package/dist/collector-Bpl6qy2L.mjs +0 -1
- package/dist/constants-BYj8Xek8.mjs +0 -1
- package/dist/coordination-CWXW1o8K.mjs +0 -1
- package/dist/dart-inspector-7AkPeZ_Q.mjs +0 -0
- package/dist/debugger-DyALjYMk.mjs +0 -1
- package/dist/definitions-BWxBke3r.mjs +0 -1
- package/dist/definitions-BYwATKc-.mjs +0 -1
- package/dist/definitions-B_83XfNQ.mjs +0 -1
- package/dist/definitions-Bf3H1EwV.mjs +0 -1
- package/dist/definitions-BftdXgXI.mjs +0 -1
- package/dist/definitions-Bio5XJYy.mjs +0 -1
- package/dist/definitions-C3qNgSn1.mjs +0 -1
- package/dist/definitions-CB6vmOer.mjs +0 -1
- package/dist/definitions-CMZRSy3k.mjs +0 -1
- package/dist/definitions-CQd7yCQH.mjs +0 -1
- package/dist/definitions-CT8ln6GQ.mjs +0 -1
- package/dist/definitions-D4g-MS10.mjs +0 -1
- package/dist/definitions-D5wl_8HN.mjs +0 -1
- package/dist/definitions-DAQm1Xar.mjs +0 -1
- package/dist/definitions-DP1vgxEY.mjs +0 -1
- package/dist/definitions-Ibci7e_L.mjs +0 -1
- package/dist/definitions-OeLvmlQy.mjs +0 -1
- package/dist/definitions-RZYGD_Ey.mjs +0 -1
- package/dist/definitions-Tls8c0A0.mjs +0 -1
- package/dist/definitions-bybDvnG0.mjs +0 -26
- package/dist/definitions-l7TjdE6V.mjs +0 -1
- package/dist/encoding-ycOaz8Vr.mjs +0 -2
- package/dist/ensure-browser-core-DxWC-NTp.mjs +0 -1
- package/dist/factory-CKr4fAE1.mjs +0 -1
- package/dist/flat-target-session-DvcQX7J5.mjs +0 -1
- package/dist/graphql-B2TiPEow.mjs +0 -62
- package/dist/handlers-8zN_vBIz.mjs +0 -1
- package/dist/handlers-B62K4FTc.mjs +0 -1
- package/dist/handlers-BpDlVVVU.mjs +0 -1
- package/dist/handlers-CMJK7m1c.mjs +0 -31
- package/dist/handlers-D2ZOul9p.mjs +0 -54
- package/dist/handlers-D5E40ssn.mjs +0 -5
- package/dist/handlers-DGbdQAgD.mjs +0 -4
- package/dist/handlers-DHO3rjsW.mjs +0 -1
- package/dist/handlers-FJ80VzUI.mjs +0 -2
- package/dist/handlers-VHWrxbM_.mjs +0 -1
- package/dist/handlers-l8QIKqBj.mjs +0 -2
- package/dist/handlers.impl-D9Hh8Bgl.mjs +0 -1
- package/dist/jadx-search-B_Yse0Zh.mjs +0 -5
- package/dist/logger-sBC6IdRT.mjs +0 -1
- package/dist/maintenance-BUpIukhg.mjs +0 -1
- package/dist/manifest-0Jpt_AQa.mjs +0 -1
- package/dist/manifest-B3fZbSWR.mjs +0 -1
- package/dist/manifest-B7NB2rh2.mjs +0 -1
- package/dist/manifest-BDi4nbH1.mjs +0 -1
- package/dist/manifest-BLDfkE7n.mjs +0 -1
- package/dist/manifest-BcXbB4gf.mjs +0 -1
- package/dist/manifest-Bdnc_vrc.mjs +0 -1
- package/dist/manifest-BuYKgCnp.mjs +0 -1
- package/dist/manifest-CBfNnGPV.mjs +0 -1
- package/dist/manifest-CPS1Xv69.mjs +0 -1
- package/dist/manifest-CQH9FhwI.mjs +0 -1
- package/dist/manifest-CRryuZF4.mjs +0 -1
- package/dist/manifest-CctIumog.mjs +0 -1
- package/dist/manifest-CvTe5ZGV2.mjs +0 -1
- package/dist/manifest-D-5GH0DV.mjs +0 -1
- package/dist/manifest-D3Ssf3IC.mjs +0 -1
- package/dist/manifest-D5ck3NvC.mjs +0 -1
- package/dist/manifest-D9jUUJAu.mjs +0 -1
- package/dist/manifest-DCx6w2XV.mjs +0 -1
- package/dist/manifest-DG19q-Ld.mjs +0 -1
- package/dist/manifest-DLMlD0Zc.mjs +0 -1
- package/dist/manifest-DYpn8w_h.mjs +0 -1
- package/dist/manifest-DYzWI8Xs.mjs +0 -1
- package/dist/manifest-D_obs5F4.mjs +0 -1
- package/dist/manifest-DujQqEQR.mjs +0 -2
- package/dist/manifest-DwL2ik8P.mjs +0 -1
- package/dist/manifest-ItF5P8A12.mjs +0 -1
- package/dist/manifest-KZphqIyX.mjs +0 -1
- package/dist/manifest-LG42zPLY2.mjs +0 -1
- package/dist/manifest-LLdI5m4T.mjs +0 -1
- package/dist/manifest-QYbQXJn0.mjs +0 -1
- package/dist/manifest-RcpX_MyZ.mjs +0 -123
- package/dist/manifest-YgVd8Sgz.mjs +0 -1
- package/dist/manifest-Zy7Odg5J.mjs +0 -1
- package/dist/manifest-ff1H7Pdp.mjs +0 -1
- package/dist/manifest-iuhF6pTL2.mjs +0 -1
- package/dist/manifest-nXHmtMSp2.mjs +0 -1
- package/dist/manifest-xWfu6iLo.mjs +0 -1
- package/dist/manifest-yC16OhL2.mjs +0 -1
- package/dist/manifest-ztWJoXy4.mjs +0 -1
- package/dist/matchesWildcardPattern-BAG6LvX5.mjs +0 -1
- package/dist/modules-BPBcSaM-.mjs +0 -333
- package/dist/mojo-ipc-BhwsdVUW.mjs +0 -9
- package/dist/native-j8l473zn.mjs +0 -961
- package/dist/network-T0VRwNPd.mjs +0 -7
- package/dist/outputPaths-B4Ic4RZh.mjs +0 -2
- package/dist/parse-args-Bw413PlW.mjs +0 -1
- package/dist/platform-CzaQtISh.mjs +0 -93
- package/dist/playwright-cdp-fallback-DqFdx9-s.mjs +0 -1
- package/dist/process-CWhsCWrf.mjs +0 -2
- package/dist/proxy-DZFlDsG3.mjs +0 -2
- package/dist/renderer-pid-9tJnZ_9N.mjs +0 -1
- package/dist/response-C7rKQst4.mjs +0 -1
- package/dist/search-defaults-lYBVn_3L.mjs +0 -1
- package/dist/shared-state-board-BSjXLUV1.mjs +0 -1
- package/dist/sourcemap-Dh3Ai_ur.mjs +0 -1
- package/dist/streaming-BcJ0B6ao.mjs +0 -1
- package/dist/transform-DOxzeWPB.mjs +0 -103
- package/dist/types-D9EiE5o9.mjs +0 -1
- package/dist/wasm-CZ_HTfKR.mjs +0 -174
- package/dist/webcrack-C1iYG_EX.mjs +0 -46
- package/dist/workflow-BdwQmARn.mjs +0 -101
- /package/dist/{CacheAdapters-CsNtQIR8.mjs → CacheAdapters-BlDrQg8f.mjs} +0 -0
- /package/dist/{EventBus-DL8iLA09.mjs → EventBus-Cm-t-B65.mjs} +0 -0
- /package/dist/{EvidenceGraphBridge-BtbwXsLC.mjs → EvidenceGraphBridge-DBDc0wUA.mjs} +0 -0
- /package/dist/{HookGeneratorBuilders.core.generators.storage-DzD6dIJd.mjs → HookGeneratorBuilders.core.generators.storage-CWaWpOHa.mjs} +0 -0
- /package/dist/{RingBuffer-Dm54ELKT.mjs → RingBuffer-B6RTHmij.mjs} +0 -0
- /package/dist/{StealthVerifier-BmcxfwSF.mjs → StealthVerifier-DMBrtkhN.mjs} +0 -0
- /package/dist/{ToolError-DWU_z7gp.mjs → ToolError-g3rjWzhx.mjs} +0 -0
- /package/dist/{authorization-schema-BOFwSXUN.mjs → authorization-schema-Jtikc5Yt.mjs} +0 -0
- /package/dist/{bind-helpers-m2U8glkF.mjs → bind-helpers-D0mGAOof.mjs} +0 -0
- /package/dist/{concurrency-DCr8WQ2M.mjs → concurrency-Dehnw4JC.mjs} +0 -0
- /package/dist/{evidence-graph-bridge-CV_UdYqj.mjs → evidence-graph-bridge-eT9icP6a.mjs} +0 -0
- /package/dist/{formatAddress-vLA_hOJt.mjs → formatAddress-DAcw4Ckg.mjs} +0 -0
- /package/dist/{chunk-C_pMuVsO.mjs → rolldown-runtime-88NL7fhV.mjs} +0 -0
- /package/dist/{ssrf-policy-CsIJGkpd.mjs → ssrf-policy-B72vdy23.mjs} +0 -0
- /package/dist/{tool-builder-qif8M9-K.mjs → tool-builder-CpLh-UQd.mjs} +0 -0
- /package/dist/{types-Fz69RzbZ.mjs → types-BzPBzmVB.mjs} +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import{B as e,H as t,Ha as n,R as r,Ua as i,V as a,Wa as o,ra as s,z as c}from"./constants-nvsLpSri.mjs";import{t as l}from"./ProcessRegistry-C5W1Tkn9.mjs";import{i as u,n as d}from"./response-R8ghbZSb.mjs";import"./modules-CC_ADmwi.mjs";import{d as f,r as ee}from"./ensure-browser-core-BP70x0TB.mjs";import{r as p}from"./ResponseBuilder-BLicSCjn.mjs";import{a as m,i as h,r as te,t as ne}from"./ast-utils-B9E5k_v1.mjs";import{t as g}from"./reverseEngineeringConfig-BhZLOa3C.mjs";import"./definitions-DvrYdDCJ2.mjs";import{gunzipSync as re,inflateSync as ie}from"node:zlib";import{createDecipheriv as _}from"node:crypto";import{Worker as ae}from"node:worker_threads";const oe=o,se=s,ce=n,le=i;var ue=class{name;workerScript;minWorkers;maxWorkers;idleTimeoutMs;resourceLimits;workers=new Map;queuedJobs=[];activeJobs=new Map;nextWorkerId=1;nextJobId=1;closed=!1;constructor(e){if(this.name=e.name??`worker-pool`,this.workerScript=e.workerScript,this.minWorkers=e.minWorkers??oe,this.maxWorkers=e.maxWorkers??se,this.idleTimeoutMs=e.idleTimeoutMs??ce,this.resourceLimits=e.resourceLimits,!this.workerScript||this.workerScript.trim().length===0)throw this.toError(`workerScript must be a non-empty string`);if(!Number.isInteger(this.minWorkers)||this.minWorkers<0)throw this.toError(`minWorkers must be an integer >= 0`);if(!Number.isInteger(this.maxWorkers)||this.maxWorkers<1)throw this.toError(`maxWorkers must be an integer >= 1`);if(this.minWorkers>this.maxWorkers)throw this.toError(`minWorkers cannot be greater than maxWorkers`);this.ensureMinWorkers()}submit(e,t=le){return this.closed?Promise.reject(this.toError(`pool is closed`)):new Promise((n,r)=>{let i={id:this.nextJobId++,payload:e,timeoutMs:t,resolve:n,reject:r};this.queuedJobs.push(i),this.pumpQueue()})}async warmup(e=1){if(this.closed)return;let t=Math.min(e,this.maxWorkers-this.workers.size);for(let e=0;e<t;e++){let e=this.spawnWorker();this.armIdleTimer(e)}}async close(){if(this.closed)return;this.closed=!0;let e=this.toError(`pool is closed`);for(;this.queuedJobs.length>0;)this.queuedJobs.shift()?.reject(e);for(let t of this.activeJobs.values())t.timeoutHandle&&clearTimeout(t.timeoutHandle),t.reject(e);this.activeJobs.clear();let t=Array.from(this.workers.keys());await Promise.all(t.map(e=>this.terminateWorker(e)))}async drainIdle(){if(this.closed)return;let e=[];for(let[t,n]of this.workers)!n.busy&&this.workers.size-e.length>this.minWorkers&&e.push(t);await Promise.all(e.map(e=>this.terminateWorker(e)))}ensureMinWorkers(){if(!this.closed)for(;this.workers.size<this.minWorkers;)this.spawnWorker()}pumpQueue(){if(!this.closed)for(;this.queuedJobs.length>0;){let e=this.findIdleWorker();if(!e)if(this.workers.size<this.maxWorkers)e=this.spawnWorker();else return;let t=this.queuedJobs.shift();if(!t)return;this.dispatchJob(e,t)}}findIdleWorker(){for(let e of this.workers.values())if(!e.busy)return e}spawnWorker(){let e=this.nextWorkerId++,t=new ae(this.workerScript,{eval:!0,resourceLimits:this.resourceLimits});typeof t.unref==`function`&&t.unref(),l.register(t);let n={id:e,worker:t,busy:!1,activeJobId:null,idleTimer:null};return t.on(`message`,t=>this.handleWorkerMessage(e,t)),t.on(`error`,t=>this.handleWorkerFailure(e,t)),t.on(`exit`,t=>this.handleWorkerExit(e,t)),this.workers.set(e,n),n}dispatchJob(e,t){e.busy=!0,e.activeJobId=t.id,e.idleTimer&&=(clearTimeout(e.idleTimer),null);let n=setTimeout(()=>{this.handleJobTimeout(t.id,t.timeoutMs)},t.timeoutMs);this.activeJobs.set(t.id,{...t,workerId:e.id,timeoutHandle:n});try{e.worker.postMessage({jobId:t.id,payload:t.payload})}catch(n){let r=this.activeJobs.get(t.id);r?.timeoutHandle&&clearTimeout(r.timeoutHandle),this.activeJobs.delete(t.id),e.busy=!1,e.activeJobId=null,t.reject(this.toError(n instanceof Error?n.message:String(n))),this.terminateWorker(e.id).then(()=>{this.ensureMinWorkers(),this.pumpQueue()})}}handleWorkerMessage(e,t){let n=t;if(!n||typeof n!=`object`||typeof n.jobId!=`number`)return;let r=this.activeJobs.get(n.jobId);if(!r)return;r.timeoutHandle&&clearTimeout(r.timeoutHandle),this.activeJobs.delete(n.jobId);let i=this.workers.get(e);i&&(i.busy=!1,i.activeJobId=null,this.armIdleTimer(i)),n.ok?n.result===void 0?r.reject(this.toError(`worker returned empty result`)):r.resolve(n.result):r.reject(this.toError(n.error??`worker task failed`)),this.pumpQueue()}handleWorkerFailure(e,t){let n=this.workers.get(e);if(!n)return;let r=n.activeJobId;if(r!==null){let e=this.activeJobs.get(r);e&&(e.timeoutHandle&&clearTimeout(e.timeoutHandle),this.activeJobs.delete(r),e.reject(this.toError(t.message)))}this.terminateWorker(e).then(()=>{this.ensureMinWorkers(),this.pumpQueue()})}handleWorkerExit(e,t){let n=this.workers.get(e);if(!n)return;let r=n.activeJobId;if(this.workers.delete(e),n.idleTimer&&clearTimeout(n.idleTimer),r!==null){let e=this.activeJobs.get(r);e&&(e.timeoutHandle&&clearTimeout(e.timeoutHandle),this.activeJobs.delete(r),e.reject(this.toError(`worker exited unexpectedly with code ${t}`)))}this.ensureMinWorkers(),this.pumpQueue()}handleJobTimeout(e,t){let n=this.activeJobs.get(e);n&&(this.activeJobs.delete(e),n.reject(this.toError(`worker task timed out after ${t}ms`)),this.terminateWorker(n.workerId).then(()=>{this.ensureMinWorkers(),this.pumpQueue()}))}armIdleTimer(e){this.idleTimeoutMs<=0||this.workers.size<=this.minWorkers||(e.idleTimer&&clearTimeout(e.idleTimer),e.idleTimer=setTimeout(()=>{let t=this.workers.get(e.id);!t||t.busy||this.workers.size<=this.minWorkers||this.terminateWorker(e.id)},this.idleTimeoutMs))}async terminateWorker(e){let t=this.workers.get(e);if(t){this.workers.delete(e),t.idleTimer&&clearTimeout(t.idleTimer),t.idleTimer=null,t.worker.removeAllListeners(`message`),t.worker.removeAllListeners(`error`),t.worker.removeAllListeners(`exit`);try{await t.worker.terminate()}catch{}}}toError(e){return Error(`[${this.name}] ${e}`)}};const de=new Set([`constant_fold`,`string_decrypt`,`dead_code_remove`,`control_flow_flatten`,`rename_vars`]),fe=t,pe=[`cryptojs`,`md5`,`sha`,`hmac`,`sign`,`signature`,`encrypt`,`decrypt`,`aes`,`rsa`];function me(t){return{collector:t,chains:new Map,cryptoHarnessPool:new ue({name:`crypto-harness`,workerScript:`
|
|
2
|
+
const __bootstrap = async () => {
|
|
3
|
+
const [workerThreads, vm, perfHooks] = await Promise.all([
|
|
4
|
+
import('node:worker_threads'), import('node:vm'), import('node:perf_hooks'),
|
|
5
|
+
]);
|
|
6
|
+
const parentPort = workerThreads.parentPort;
|
|
7
|
+
const performance = perfHooks.performance;
|
|
8
|
+
if (!parentPort) throw new Error('worker parentPort is unavailable');
|
|
9
|
+
function normalizeOutput(value) {
|
|
10
|
+
if (value === undefined) return '__undefined__';
|
|
11
|
+
if (value === null) return 'null';
|
|
12
|
+
if (typeof value === 'string') return value;
|
|
13
|
+
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') return String(value);
|
|
14
|
+
try { return JSON.stringify(value); } catch { return String(value); }
|
|
15
|
+
}
|
|
16
|
+
parentPort.on('message', async (msg) => {
|
|
17
|
+
const { jobId, request = msg['pay' + 'load'] } = msg;
|
|
18
|
+
try {
|
|
19
|
+
const { code, functionName, testInputs } = request;
|
|
20
|
+
const sandbox = Object.create(null);
|
|
21
|
+
sandbox.console = Object.freeze({ log() {}, warn() {}, error() {} });
|
|
22
|
+
sandbox.Buffer = {
|
|
23
|
+
from: (...args) => Buffer.from(...args),
|
|
24
|
+
alloc: (size) => Buffer.alloc(Math.min(size, 1048576)),
|
|
25
|
+
concat: (...args) => Buffer.concat(...args),
|
|
26
|
+
};
|
|
27
|
+
Object.freeze(sandbox.Buffer);
|
|
28
|
+
sandbox.TextEncoder = TextEncoder; sandbox.TextDecoder = TextDecoder;
|
|
29
|
+
sandbox.atob = (v) => Buffer.from(String(v), 'base64').toString('binary');
|
|
30
|
+
sandbox.btoa = (v) => Buffer.from(String(v), 'binary').toString('base64');
|
|
31
|
+
sandbox.globalThis = sandbox; Object.freeze(sandbox);
|
|
32
|
+
const context = vm.createContext(sandbox);
|
|
33
|
+
const isValidIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(functionName);
|
|
34
|
+
const targetExpression = isValidIdentifier
|
|
35
|
+
? "(typeof " + functionName + " !== 'undefined' ? " +
|
|
36
|
+
functionName + " : globalThis[" + JSON.stringify(functionName) + "])"
|
|
37
|
+
: "globalThis[" + JSON.stringify(functionName) + "]";
|
|
38
|
+
const script = new vm.Script(
|
|
39
|
+
"(() => {\\n" + code + "\\n;return " + targetExpression + ";\\n})()",
|
|
40
|
+
{ timeout: 5000 },
|
|
41
|
+
);
|
|
42
|
+
const targetFn = script.runInContext(context, { timeout: 5000 });
|
|
43
|
+
if (typeof targetFn !== 'function') throw new Error("Function not found or not callable: " + functionName);
|
|
44
|
+
const rows = [];
|
|
45
|
+
for (const input of testInputs) {
|
|
46
|
+
const started = performance.now();
|
|
47
|
+
try {
|
|
48
|
+
const raw = targetFn(input);
|
|
49
|
+
const resolved = raw && typeof raw.then === 'function' ? await raw : raw;
|
|
50
|
+
rows.push(
|
|
51
|
+
{
|
|
52
|
+
input,
|
|
53
|
+
output: normalizeOutput(resolved),
|
|
54
|
+
duration: Number((performance.now() - started).toFixed(3)),
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
rows.push(
|
|
59
|
+
{
|
|
60
|
+
input,
|
|
61
|
+
output: '',
|
|
62
|
+
error: err && err.message ? err.message : String(err),
|
|
63
|
+
duration: Number((performance.now() - started).toFixed(3)),
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
parentPort.postMessage({ jobId, ok: true, result: { ok: true, results: rows } });
|
|
69
|
+
} catch (error) {
|
|
70
|
+
parentPort.postMessage(
|
|
71
|
+
{
|
|
72
|
+
jobId,
|
|
73
|
+
ok: true,
|
|
74
|
+
result: { ok: false, error: error && error.message ? error.message : String(error), results: [] },
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
__bootstrap().catch((error) => {
|
|
81
|
+
if (typeof console !== 'undefined' && typeof console.error === 'function')
|
|
82
|
+
console.error('crypto harness worker bootstrap failed:', error && error.message ? error.message : String(error));
|
|
83
|
+
});
|
|
84
|
+
`,minWorkers:0,maxWorkers:e,idleTimeoutMs:r,resourceLimits:{maxOldGenerationSizeMb:c,maxYoungGenerationSizeMb:a,stackSizeMb:8}})}}function v(e,t){return d({tool:e,...u(t)})}function y(e){let t=Array.isArray(e)?e.map(e=>String(e).trim()).filter(e=>e.length>0):typeof e==`string`?e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0):[];if(t.length===0)throw Error(`transforms must contain at least one transform`);let n=[],r=new Set;for(let e of t){if(!de.has(e))throw Error(`Unsupported transform: ${e}`);r.has(e)||(r.add(e),n.push(e))}return n}function b(e){if(!Array.isArray(e))throw Error(`testInputs must be an array of strings`);let t=e.map(e=>String(e));if(t.length===0)throw Error(`testInputs cannot be empty`);return t}function he(e,t){if(typeof e==`boolean`)return e;if(typeof e==`string`){let t=e.trim().toLowerCase();if([`true`,`1`,`yes`,`on`].includes(t))return!0;if([`false`,`0`,`no`,`off`].includes(t))return!1}if(typeof e==`number`){if(e===1)return!0;if(e===0)return!1}return t}function x(e,t){if(typeof e!=`string`||e.length===0)throw Error(`${t} must be a non-empty string`);return e}function S(e){return e.replace(/\\x([0-9a-fA-F]{2})/g,(e,t)=>String.fromCharCode(parseInt(t,16))).replace(/\\u\{([0-9a-fA-F]{1,6})\}/g,(e,t)=>String.fromCodePoint(parseInt(t,16))).replace(/\\u([0-9a-fA-F]{4})/g,(e,t)=>String.fromCharCode(parseInt(t,16))).replace(/\\n/g,`
|
|
85
|
+
`).replace(/\\r/g,`\r`).replace(/\\t/g,` `).replace(/\\v/g,`\v`).replace(/\\f/g,`\f`).replace(/\\0/g,`\0`).replace(/\\"/g,`"`).replace(/\\'/g,`'`).replace(/\\\\/g,`\\`)}async function ge(e,t){let n=null;try{n=new ee(e);let r=await n.getScriptSource(t);if(r?.source&&r.source.length>0)return r.source}catch{}finally{if(n)try{await n.close()}catch{}}let r=e.getFileByUrl(t);if(r?.content&&r.content.length>0)return r.content;let i=await(await e.getActivePage()).evaluate(async e=>{let t=Array.from(document.scripts),n=Number(e);if(Number.isInteger(n)&&n>=0&&n<t.length){let e=t[n];if(e.textContent&&e.textContent.trim().length>0)return e.textContent;if(e.src)try{let t=await fetch(e.src);if(t.ok)return await t.text()}catch{}}for(let n of t){if(n.id===e||n.dataset?.scriptId===e){if(n.textContent&&n.textContent.trim().length>0)return n.textContent;if(n.src)try{let e=await fetch(n.src);if(e.ok)return await e.text()}catch{}}if(n.src&&n.src.includes(e))try{let e=await fetch(n.src);if(e.ok)return await e.text()}catch{}}return``},t);if(typeof i==`string`&&i.length>0)return i;throw Error(`Unable to resolve source from scriptId: ${t}`)}function C(e){let t=(e.startsWith(`window.`)?e.slice(7):e).split(`.`).filter(Boolean);return t.length>0?t[t.length-1]:``}function _e(e,t,n){let r=C(e);if(w(r))return r;let i=C(t);if(w(i))return i;let a=n.match(/function\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*\(/);return a?.[1]&&w(a[1])?a[1]:`extractedCryptoFn`}function w(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}async function T(e){await e.warmup(1)}function ve(){return`const __textEncoder = typeof TextEncoder !== 'undefined' ? new TextEncoder() : null;
|
|
86
|
+
const __textDecoder = typeof TextDecoder !== 'undefined' ? new TextDecoder() : null;
|
|
87
|
+
if (typeof globalThis.atob === 'undefined') {
|
|
88
|
+
globalThis.atob = (value) => Buffer.from(String(value), 'base64').toString('binary');
|
|
89
|
+
;
|
|
90
|
+
}
|
|
91
|
+
if (typeof globalThis.btoa === 'undefined') {
|
|
92
|
+
globalThis.btoa = (value) => Buffer.from(String(value), 'binary').toString('base64');
|
|
93
|
+
;
|
|
94
|
+
}`}async function E(e,t,n,r){try{let i=await e.submit({code:t,functionName:n,testInputs:r},fe);if(!i.ok)return{results:r.map(e=>({input:e,output:``,duration:0,error:i.error??`Worker execution failed`})),allPassed:!1};let a=Array.isArray(i.results)?i.results:[];return{results:a,allPassed:a.every(e=>!e.error)}}catch(e){return{results:r.map(t=>({input:t,output:``,duration:0,error:e instanceof Error?e.message:String(e)})),allPassed:!1}}}function ye(e,t,n){if(e===t)return``;let r=e.split(`
|
|
95
|
+
`),i=t.split(`
|
|
96
|
+
`),a=n.fallback??be,o=0;for(;o<r.length&&o<i.length&&r[o]===i[o];)o+=1;let s=r.length,c=i.length;for(;s>o&&c>o&&r[s-1]===i[c-1];)--s,--c;let l=r.slice(o,s),u=i.slice(o,c);if(xe(l.length,u.length,n.maxLcsCells))return a(r,i);let d=[];for(let e=0;e<o;e++)d.push(` ${r[e]}`);d.push(...Se(l,u));for(let e=s;e<r.length;e++)d.push(` ${r[e]}`);return d.join(`
|
|
97
|
+
`)}function be(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n+=1;let r=e.length-1,i=t.length-1;for(;r>=n&&i>=n&&e[r]===t[i];)--r,--i;let a=e.slice(n,r+1).map(e=>`-${e}`),o=t.slice(n,i+1).map(e=>`+${e}`);return[...a,...o].join(`
|
|
98
|
+
`)}function xe(e,t,n){return e>0&&t>Math.floor(n/e)}function Se(e,t){let n=e.length,r=t.length;if(n===0)return t.map(e=>`+${e}`);if(r===0)return e.map(e=>`-${e}`);let i=r+1,a=new Uint32Array((n+1)*i);for(let o=n-1;o>=0;o--){let n=o*i,s=(o+1)*i;for(let i=r-1;i>=0;i--)a[n+i]=e[o]===t[i]?a[s+i+1]+1:Math.max(a[s+i],a[n+i+1])}let o=[],s=0,c=0;for(;s<n&&c<r;){if(e[s]===t[c]){o.push(` ${e[s]}`),s+=1,c+=1;continue}a[(s+1)*i+c]>=a[s*i+c+1]?(o.push(`-${e[s]}`),s+=1):(o.push(`+${t[c]}`),c+=1)}for(;s<n;)o.push(`-${e[s]}`),s+=1;for(;c<r;)o.push(`+${t[c]}`),c+=1;return o}const Ce=ne;function D(e){try{return te(e)}catch{return null}}function we(e){let t=e.indexOf(`'`),n=e.indexOf(`"`);return t>=0&&(n<0||t<n)?`single`:`double`}function O(e,t){let n=Ce(t,{retainLines:!0,jsescOption:{quotes:we(e)}}).code,r=e.trim(),i=t.program.body[t.program.body.length-1];return e.includes(`
|
|
99
|
+
`)||(n=n.replace(/;(?=\S)/g,`; `)),!r.endsWith(`;`)&&i&&h.isExpressionStatement(i)&&(n=n.replace(/;$/,``)),n}function k(e,t){let n=D(e);if(!n)return e;let r=!1;return m(n,t(()=>{r=!0})),r?O(e,n):e}function Te(e){return Number.isFinite(e)&&Math.abs(e)!==1/0}function Ee(e,t,n){switch(t){case`+`:return e+n;case`-`:return e-n;case`*`:return e*n;case`/`:return n===0?null:e/n;case`%`:return n===0?null:e%n;case`&`:return e&n;case`|`:return e|n;case`^`:return e^n;case`<<`:return e<<n;case`>>`:return e>>n;case`>>>`:return e>>>n;default:return null}}function De(e){let t=e;for(let e=0;e<4;e++){let e=k(t,e=>({BinaryExpression(t){let n=t.node;if(h.isBinaryExpression(n)){if(h.isNumericLiteral(n.left)&&h.isNumericLiteral(n.right)){let r=Ee(n.left.value,n.operator,n.right.value);if(r===null||!Te(r))return;let i=Number.isInteger(r)?r:Number(r.toFixed(12));e(),t.replaceWith(h.valueToNode(i)),t.skip();return}n.operator===`+`&&h.isStringLiteral(n.left)&&h.isStringLiteral(n.right)&&(e(),t.replaceWith(h.stringLiteral(`${n.left.value}${n.right.value}`)),t.skip())}},UnaryExpression(t){let n=t.node;if(!h.isUnaryExpression(n))return;let r=n.argument;if(n.operator===`!`){let n=null;if(h.isBooleanLiteral(r)?n=!r.value:h.isNumericLiteral(r)?n=r.value===0:h.isStringLiteral(r)?n=r.value.length===0:h.isNullLiteral(r)&&(n=!0),n!==null){e(),t.replaceWith(h.booleanLiteral(n)),t.skip();return}}n.operator===`~`&&h.isNumericLiteral(r)&&Number.isInteger(r.value)&&(e(),t.replaceWith(h.valueToNode(~r.value)),t.skip())}}));if(e===t)break;t=e}return t}function Oe(e){let t=e.extra?.raw;return typeof t==`string`&&t.length>=2?t.slice(1,-1):e.value}function A(e){if(e.length===0)return!1;let t=0;for(let n of e){let e=n.charCodeAt(0);(e===9||e===10||e===13||e>=32&&e<=126)&&(t+=1)}return t/e.length>=.9}function j(e){if(!/^[A-Za-z0-9+/=]{16,}$/.test(e)||e.length%4!=0)return null;try{let t=Buffer.from(e,`base64`).toString(`utf8`);return A(t)?t:null}catch{return null}}function M(e,t){let n=t.match(/^(?:\\x[0-9a-fA-F]{2})+$/),r=/^[0-9a-fA-F]{32,}$/.test(e)&&e.length%2==0;if(!n&&!r)return null;try{let r=n?t.replace(/\\x/g,``):e,i=Buffer.from(r,`hex`).toString(`utf8`);return A(i)?i:null}catch{return null}}function N(e){return h.isStringLiteral(e)}function ke(e){if(h.isIdentifier(e))return e.name;if(h.isMemberExpression(e)&&!e.computed){let t=e.object,n=e.property;if(h.isIdentifier(t)&&h.isIdentifier(n))return`${t.name}.${n.name}`}return null}function Ae(e){let t=ke(e.callee);if(!t)return null;let n=e.arguments;if(t===`atob`&&n.length===1){let e=n[0];if(N(e)&&/^[A-Za-z0-9+/=]*$/.test(e.value)&&e.value.length%4==0)try{let t=Buffer.from(e.value,`base64`).toString(`utf8`);return A(t)?t:null}catch{return null}return null}if(t===`Buffer.from`&&n.length===2){let[e,t]=n;if(N(e)&&N(t)&&t.value.toLowerCase()===`hex`)try{let t=Buffer.from(e.value,`hex`).toString(`utf8`);return A(t)?t:null}catch{return null}return null}if(t===`String.fromCharCode`&&n.length>=1){let e=[];for(let t of n){if(!h.isNumericLiteral(t)||!Number.isInteger(t.value))return null;e.push(t.value)}try{let t=String.fromCharCode(...e);return A(t)?t:null}catch{return null}}return null}function je(e){let t=D(e);if(!t)return e;let n=!1;for(let e of t.program.directives){let r=e.value,i=r.extra?.raw,a=typeof i==`string`?i.slice(1,-1):r.value,o=S(a),s=j(o)??M(o,a)??o;(s!==r.value||a!==o)&&(n=!0,t.program.body.unshift(h.expressionStatement(h.stringLiteral(s))),t.program.directives=t.program.directives.filter(t=>t!==e))}for(let e=0;e<4;e++){let e=!1;if(m(t,{StringLiteral(t){let r=t.node;if(!h.isStringLiteral(r))return;let i=Oe(r),a=S(i),o=j(a)??M(a,i)??a;(o!==r.value||i!==a)&&(e=!0,n=!0,t.replaceWith(h.stringLiteral(o)),t.skip())},CallExpression(t){let r=t.node;if(!h.isCallExpression(r))return;let i=Ae(r);i!==null&&(e=!0,n=!0,t.replaceWith(h.stringLiteral(i)),t.skip())}}),!e)break}return n?O(e,t):e}function P(e){return h.isBooleanLiteral(e)?e.value===!1:h.isNumericLiteral(e)?e.value===0:h.isStringLiteral(e)?e.value.length===0:!!h.isNullLiteral(e)}function F(e){return h.isBooleanLiteral(e)?e.value===!0:h.isNumericLiteral(e)?e.value!==0:h.isStringLiteral(e)?e.value.length>0:!1}function Me(e){return!!(P(e)||h.isUnaryExpression(e,{operator:`!`})&&F(e.argument))}function I(e){return h.isBlockStatement(e)?[...e.body]:[e]}function Ne(e){return k(e,e=>({IfStatement(t){let n=t.node;if(h.isIfStatement(n)){if(Me(n.test)){e(),n.alternate?t.replaceWithMultiple(I(n.alternate)):t.remove(),t.skip();return}L(n.test)&&(e(),t.replaceWithMultiple(I(n.consequent)),t.skip())}}}))}function L(e){return!!(F(e)||h.isUnaryExpression(e,{operator:`!`})&&P(e.argument)||h.isUnaryExpression(e,{operator:`!`})&&h.isUnaryExpression(e.argument,{operator:`!`})&&h.isArrayExpression(e.argument.argument))}function R(e){return h.isIdentifier(e)?e.name:null}function Pe(e){if(!h.isMemberExpression(e)||e.computed!==!0)return null;let t=R(e.object);if(!t)return null;let n=e.property;return h.isUpdateExpression(n)?{dispatcher:t,cursor:R(n.argument)}:{dispatcher:t,cursor:R(n)}}function z(e){return e?h.isStringLiteral(e)?e.value:h.isNumericLiteral(e)?String(e.value):null:null}function Fe(e){if(!e)return[];if(h.isCallExpression(e)&&h.isMemberExpression(e.callee)&&h.isStringLiteral(e.callee.object)&&h.isIdentifier(e.callee.property,{name:`split`})){let t=e.arguments[0];if(!t||h.isStringLiteral(t)&&t.value===`|`)return e.callee.object.value.split(`|`)}return h.isArrayExpression(e)?e.elements.map(e=>h.isStringLiteral(e)||h.isNumericLiteral(e)?String(e.value):null).filter(e=>typeof e==`string`):[]}function Ie(e,t,n){let r=e.scope.getBinding(t)?.path.node;if(r&&h.isVariableDeclarator(r)&&h.isIdentifier(r.id,{name:t})){let e=Fe(r.init);if(e.length>0)return e}return n.cases.map(e=>z(e.test)).filter(Boolean)}function Le(e,t){if(!t)return!1;let n=h.isExpressionStatement(e)?e.expression:null;return!!(n&&h.isUpdateExpression(n)&&h.isIdentifier(n.argument,{name:t})||n&&h.isAssignmentExpression(n)&&h.isIdentifier(n.left,{name:t}))}function Re(e,t){let n=new Map;for(let r of e.cases){let e=z(r.test);if(!e)continue;let i=r.consequent.filter(e=>!h.isContinueStatement(e)&&!h.isBreakStatement(e)&&!Le(e,t)).map(e=>h.cloneNode(e,!0));i.length>0&&n.set(e,i)}return n}function B(e,t){let n=e.scope.getBinding(t);if(!n)return;let r=n.path;if(!r.isVariableDeclarator())return;let i=r.parentPath;i?.isVariableDeclaration()&&i.node.declarations.length===1?i.remove():r.remove()}function V(e,t){let n=e.node;if(!L(n.test)||!h.isBlockStatement(n.body))return;let r=n.body.body.find(e=>h.isSwitchStatement(e));if(!r)return;let i=Pe(r.discriminant);if(!i)return;let a=Ie(e,i.dispatcher,r),o=Re(r,i.cursor),s=a.flatMap(e=>o.get(e)??[]);s.length!==0&&(t(),e.replaceWithMultiple(s),B(e,i.dispatcher),i.cursor&&B(e,i.cursor),e.skip())}function ze(e){let t=D(e);if(!t)return e;let n=!1,r=()=>{n=!0};if(m(t,{WhileStatement(e){V(e,r)},DoWhileStatement(e){V(e,r)}}),!n)return e;let i=O(e,t);!e.trim().includes(`
|
|
100
|
+
`)&&t.program.body.length>1&&(i=i.replace(/;\s*/g,`;
|
|
101
|
+
`).trim());let a=t.program.body[t.program.body.length-1];return a&&h.isExpressionStatement(a)&&!i.trimEnd().endsWith(`;`)&&(i=`${i};`),i}function Be(e,t){return/^_0x[0-9a-fA-F]+$/.test(e)?!0:/^[A-Za-z]$/.test(e)?t.path.isVariableDeclarator()||t.kind===`param`:!1}function Ve(e,t){let n=`var_${t.value}`;for(;e.has(n);)t.value+=1,n=`var_${t.value}`;return e.add(n),t.value+=1,n}function He(e){let t=D(e);if(!t)return e;let n=new WeakSet,r={value:1},i=!1;return m(t,{Scopable(e){let t=e.scope;if(n.has(t))return;n.add(t);let a=new Set(Object.keys(t.bindings));for(let e of Object.keys(t.bindings)){let n=t.bindings[e];if(!n||!Be(e,n))continue;let o=Ve(a,r);i=!0,t.rename(e,o)}}}),i?O(e,t):e}function Ue(e,t,n){if(t.length>0){let n=e.get(t);if(!n)throw Error(`Transform chain not found: ${t}`);return[...n.transforms]}return y(n)}function H(e,t){let n=e,r=[];for(let e of t){let t=n;n=We(n,e),n!==t&&r.push(e)}return{transformed:n,appliedTransforms:r}}function We(e,t){switch(t){case`constant_fold`:return Ge(e);case`string_decrypt`:return Ke(e);case`dead_code_remove`:return qe(e);case`control_flow_flatten`:return Je(e);case`rename_vars`:return Ye(e);default:return e}}function Ge(e){return De(e)}function Ke(e){return je(e)}function qe(e){return Ne(e)}function Je(e){return ze(e)}function Ye(e){return He(e)}function Xe(e,t){return ye(e,t,{maxLcsCells:25e4})}var Ze=class{state;constructor(e){this.state=e}async handleAstTransformPreview(e){try{let t=x(e.code,`code`),n=y(e.transforms),r=he(e.preview,!0),i=H(t,n),a=r?Xe(t,i.transformed):``;return d({original:t,transformed:i.transformed,diff:a,appliedTransforms:i.appliedTransforms})}catch(e){return v(`ast_transform_preview`,e)}}async handleAstTransformChain(e){try{let t=x(e.name,`name`).trim(),n=typeof e.description==`string`&&e.description.trim().length>0?e.description.trim():void 0,r=y(e.transforms);if(t.length===0)throw Error(`name cannot be empty`);return this.state.chains.set(t,{name:t,transforms:r,description:n,createdAt:Date.now()}),d({name:t,transforms:r,created:!0,...n?{description:n}:{}})}catch(e){return v(`ast_transform_chain`,e)}}async handleAstTransformApply(e){try{let t=typeof e.chainName==`string`?e.chainName.trim():``,n=typeof e.code==`string`?e.code:``,r=typeof e.scriptId==`string`?e.scriptId.trim():``,i=n.length>0?n:r.length>0?await ge(this.state.collector,r):``;if(i.length===0)throw Error(`Either code or scriptId must be provided`);let a=H(i,Ue(this.state.chains,t,e.transforms));return d({transformed:a.transformed,stats:{originalSize:i.length,transformedSize:a.transformed.length,transformsApplied:a.appliedTransforms}})}catch(e){return v(`ast_transform_apply`,e)}}},Qe=class{state;constructor(e){this.state=e}async runCryptoHarnessProxy(e,t,n){return E(this.state.cryptoHarnessPool,e,t,n)}async handleCryptoExtractStandalone(e){try{let t=x(e.targetFunction,`targetFunction`).trim(),n=he(e.includePolyfills,!0),r=await f(await this.state.collector.getActivePage(),(e,t)=>{let n=(Array.isArray(t)?t:[]).map(e=>String(e).toLowerCase()),r=window,i=(e,t)=>{let r=(e+`
|
|
102
|
+
`+t).toLowerCase(),i=0;for(let e of n)r.includes(e)&&(i+=1);return i},a=[],o=(e,t,n=0)=>{if(typeof t!=`function`)return;let r=Function.prototype.toString.call(t);if(r.includes(`[native code]`))return;let o=i(e,r)+n;o<=0&&n<=0||a.push({path:e,source:r,score:o})};e.length>0&&o(e,(()=>{let t=(e.startsWith(`window.`)?e.slice(7):e).split(`.`).filter(Boolean),n=window;for(let e of t){if(n==null||typeof n!=`object`&&typeof n!=`function`)return;let t=n;if(!(e in t))return;n=t[e]}return n})(),100);let s=Object.getOwnPropertyNames(r).slice(0,800);for(let e of s){let t=r[e];if(o(`window.`+e,t),t&&typeof t==`object`){let n=t,r=Object.keys(n).slice(0,40);for(let t of r)o(`window.`+e+`.`+t,n[t])}}a.sort((e,t)=>t.score-e.score);let c=a[0];if(!c)return{targetPath:null,targetSource:``,candidates:[],dependencies:[],dependencySnippets:[]};let l=/\b[A-Za-z_$][A-Za-z0-9_$]{1,}\b/g,u=new Set(`function.return.const.let.var.if.else.for.while.switch.case.break.continue.new.this.window.globalThis.Math.JSON.Date.Array.Object.String.Number.Boolean.Promise.RegExp.Error.null.undefined.true.false.async.await`.split(`.`)),d=Array.from(new Set((c.source.match(l)??[]).filter(e=>!u.has(e)))).slice(0,30),f=[];for(let e of d){if(!(e in r))continue;let t=r[e];if(typeof t==`function`){let n=Function.prototype.toString.call(t);!n.includes(`[native code]`)&&n.length<5e4&&f.push(`const `+e+` = `+n+`;`);continue}if(t===null||typeof t==`string`||typeof t==`number`||typeof t==`boolean`){f.push(`const `+e+` = `+JSON.stringify(t)+`;`);continue}if(typeof t==`object`)try{let n=JSON.stringify(t);n&&n.length<4e3&&f.push(`const `+e+` = `+n+`;`)}catch{}}return{targetPath:c.path,targetSource:c.source,candidates:a.slice(0,20),dependencies:d,dependencySnippets:f}},t,pe);if(!r||r.targetSource.trim().length===0)throw Error(`No crypto/signature-like function found on current page`);let i=_e(t,r.targetPath??``,r.targetSource),a=r.dependencySnippets.filter(e=>!e.startsWith(`const ${i} = `)),o=r.dependencies.filter(e=>e!==i),s=[`'use strict';`];n&&s.push(ve()),a.length>0&&s.push(a.join(`
|
|
103
|
+
`)),s.push(`const ${i} = ${r.targetSource.trim()};`),s.push(`if (typeof globalThis !== 'undefined') { globalThis.${i} = ${i}; }`);let c=s.filter(e=>e.trim().length>0).join(`
|
|
104
|
+
|
|
105
|
+
`);return d({extractedCode:c,dependencies:o,size:c.length})}catch(e){return v(`crypto_extract_standalone`,e)}}async handleCryptoTestHarness(e){try{let t=x(e.code,`code`),n=x(e.functionName,`functionName`),r=b(e.testInputs);await T(this.state.cryptoHarnessPool);try{let e=await E(this.state.cryptoHarnessPool,t,n,r);return d({results:e.results.map(e=>({input:e.input,output:e.output,duration:e.duration,...e.error?{error:e.error}:{}})),allPassed:e.allPassed})}finally{this.state.cryptoHarnessPool.drainIdle?.()}}catch(e){return v(`crypto_test_harness`,e)}}async handleCryptoCompare(e){try{let t=x(e.code1,`code1`),n=x(e.code2,`code2`),r=x(e.functionName,`functionName`),i=b(e.testInputs);await T(this.state.cryptoHarnessPool);try{let[e,a]=await Promise.all([E(this.state.cryptoHarnessPool,t,r,i),E(this.state.cryptoHarnessPool,n,r,i)]),o=i.map((t,n)=>{let r=e.results[n]??{input:t,output:``,duration:0,error:`missing result from implementation #1`},i=a.results[n]??{input:t,output:``,duration:0,error:`missing result from implementation #2`},o=r.output===i.output,s=!r.error&&!i.error;return{input:t,output1:r.output,output2:i.output,duration1:r.duration,duration2:i.duration,match:o&&s,...r.error?{error1:r.error}:{},...i.error?{error2:i.error}:{}}}),s=o.filter(e=>e.match).length;return d({matches:s,mismatches:o.length-s,results:o})}finally{this.state.cryptoHarnessPool.drainIdle?.()}}catch(e){return v(`crypto_compare`,e)}}};const U=g().binaryMagic,W=[{label:`dex`,prefix:G(U.dexMagicAscii),description:`Dalvik executable header`},{label:`cdex`,prefix:G(U.compactDexMagicAscii),description:`Compact DEX header`},{label:`elf`,prefix:K([127,69,76,70]),description:`ELF object header`},{label:`gzip`,prefix:K([31,139]),description:`Gzip stream header`},{label:`zip`,prefix:K([80,75]),description:`ZIP container header`}];function $e(e=[]){return e.length===0?W:[...W,...e.map(tt)]}function et(e,t=W){let n=[];for(let r of t)r.prefix.length===0||r.prefix.length>e.length||rt(e,r.prefix)&&n.push(r.label);return[...new Set(n)]}function tt(e){if(!e||typeof e!=`object`)throw Error(`customMagicHints entries must be objects`);let t=e.label.trim();if(!t)throw Error(`customMagicHints label must be a non-empty string`);let n=typeof e.prefixHex==`string`&&e.prefixHex.trim().length>0?nt(e.prefixHex):typeof e.prefixAscii==`string`?G(e.prefixAscii):new Uint8Array;if(n.length===0)throw Error(`customMagicHints entries require prefixHex or prefixAscii`);return{label:t,prefix:n,...typeof e.description==`string`?{description:e.description}:{}}}function G(e){return q(Buffer.from(e,`ascii`))}function K(e){return q(Uint8Array.from(e))}function nt(e){let t=e.replace(/\s+/g,``);if(!/^(?:[0-9a-fA-F]{2})+$/.test(t))throw Error(`customMagicHints prefixHex must contain an even number of hex bytes`);return q(Buffer.from(t,`hex`))}function q(e){let t=g().binaryMagic.hintPrefixMaxBytes;if(e.length>t)throw Error(`Binary magic prefix is too long: ${e.length} bytes > ${t} bytes`);return e}function rt(e,t){for(let n=0;n<t.length;n++)if(e[n]!==t[n])return!1;return!0}function it(e){if(!Array.isArray(e.steps)||e.steps.length===0)throw Error(`steps must contain at least one transform step`);let t=g().transformWorkbench,n=Math.max(1,Math.min(Math.floor(e.previewBytes??t.defaultPreviewBytes),t.maxPreviewBytes)),r=J(e.maxInputBytes,t.maxInputBytes),i=J(e.maxOutputBytes,t.maxOutputBytes),a=J(e.maxSteps,t.maxSteps);if(e.steps.length>a)throw Error(`Too many transform steps: ${e.steps.length} > ${a}. Split the transform into smaller workbench calls.`);if(st(e.inputBase64)>r)throw Error(`Transform workbench input is too large: exceeds ${r} bytes`);let o=e.includeOutputBase64??!1,s=Buffer.from(e.inputBase64,`base64`);Y(s,r,`input`);let c=Z(s),l=[];for(let t of e.steps){let e=at(t),n=s,r=Z(n);s=ot(n,e,i),Y(s,i,`output`);let a=Z(s);l.push({op:e.op,before:r,after:a,changed:!n.equals(s)})}return{success:!0,input:c,steps:l,output:{...Z(s),...o?{base64:s.toString(`base64`)}:{base64Omitted:!0},hexPreview:s.subarray(0,n).toString(`hex`),asciiPreview:Q(s,n),magicHints:mt(s,t.textSampleBytes,e.customMagicHints)}}}function at(e){if(!e||typeof e!=`object`)throw Error(`Each step must be an object`);let t=typeof e.op==`string`?e.op.trim():``;if(!t)throw Error(`step.op is required`);return{op:t,...typeof e.key==`string`?{key:e.key}:{},...typeof e.keyHex==`string`?{keyHex:e.keyHex}:{},...typeof e.iv==`string`?{iv:e.iv}:{},...typeof e.ivHex==`string`?{ivHex:e.ivHex}:{}}}function ot(e,t,n){switch(t.op){case`base64_decode`:return Buffer.from(e.toString(`utf8`).trim(),`base64`);case`base64_encode`:return Buffer.from(e.toString(`base64`),`utf8`);case`hex_decode`:return ut(e);case`hex_encode`:return Buffer.from(e.toString(`hex`),`utf8`);case`xor`:return ft(e,X(t));case`rc4`:return pt(e,X(t));case`aes_cbc_decrypt`:return lt(e,X(t),ct(t));case`aes_ecb_decrypt`:return lt(e,X(t),null);case`zlib_inflate`:return dt(e,`zlib`,n);case`gzip_inflate`:return dt(e,`gzip`,n);case`entropy`:return e;default:throw Error(`Unsupported transform workbench op: ${t.op}`)}}function J(e,t){return e===void 0||!Number.isFinite(e)?t:Math.max(1,Math.min(Math.floor(e),t))}function Y(e,t,n){if(e.length>t)throw Error(`Transform workbench ${n} is too large: ${e.length} > ${t} bytes`)}function st(e){let t=e.replace(/\s+/g,``);if(t.length===0)return 0;let n=t.endsWith(`==`)?2:+!!t.endsWith(`=`);return Math.max(0,Math.floor(t.length*3/4)-n)}function X(e){if(e.keyHex){let t=e.keyHex.replace(/\s+/g,``);if(!/^(?:[0-9a-fA-F]{2})+$/.test(t))throw Error(`${e.op} keyHex must contain an even number of hex bytes`);return Buffer.from(t,`hex`)}if(e.key)return Buffer.from(e.key,`utf8`);throw Error(`${e.op} requires key or keyHex`)}function ct(e){if(e.ivHex){let t=e.ivHex.replace(/\s+/g,``);if(!/^(?:[0-9a-fA-F]{2})+$/.test(t))throw Error(`${e.op} ivHex must contain an even number of hex bytes`);return Buffer.from(t,`hex`)}if(e.iv)return Buffer.from(e.iv,`utf8`);throw Error(`${e.op} requires iv or ivHex`)}function lt(e,t,n){let r=t.length*8;if(r!==128&&r!==192&&r!==256)throw Error(`AES key must be 16, 24, or 32 bytes (got ${t.length}) for aes-128/192/256`);if(n===null){let n=_(`aes-${r}-ecb`,t,null);return Buffer.concat([n.update(e),n.final()])}if(n.length!==16)throw Error(`AES-CBC IV must be 16 bytes (got ${n.length})`);let i=_(`aes-${r}-cbc`,t,n);return Buffer.concat([i.update(e),i.final()])}function ut(e){let t=e.toString(`utf8`).trim().replace(/\s+/g,``);if(!/^(?:[0-9a-fA-F]{2})+$/.test(t))throw Error(`hex_decode input must be an even number of hex digits`);return Buffer.from(t,`hex`)}function dt(e,t,n){try{return(t===`gzip`?re:ie)(e,{maxOutputLength:n})}catch(e){let t=e instanceof Error?e.message:String(e);throw/larger than|maxOutputLength|unexpected end/i.test(t)?Error(`Transform workbench output is too large: exceeds ${n} bytes`,{cause:e}):e}}function ft(e,t){if(t.length===0)throw Error(`xor key cannot be empty`);let n=Buffer.allocUnsafe(e.length);for(let r=0;r<e.length;r++)n[r]=e[r]^t[r%t.length];return n}function pt(e,t){if(t.length===0)throw Error(`rc4 key cannot be empty`);let n=Array.from({length:256},(e,t)=>t),r=0;for(let e=0;e<256;e++)r=r+n[e]+t[e%t.length]&255,[n[e],n[r]]=[n[r],n[e]];let i=Buffer.alloc(e.length),a=0;r=0;for(let t=0;t<e.length;t++){a=a+1&255,r=r+n[a]&255,[n[a],n[r]]=[n[r],n[a]];let o=n[n[a]+n[r]&255];i[t]=e[t]^o}return i}function Z(e){if(e.length===0)return{size:0,entropy:0,printableRatio:0};let t=Array.from({length:256},()=>0),n=0;for(let r of e)t[r]=(t[r]??0)+1,r>=32&&r<=126&&(n+=1);let r=0;for(let n of t){if(n===0)continue;let t=n/e.length;r-=t*Math.log2(t)}return{size:e.length,entropy:Number(r.toFixed(4)),printableRatio:Number((n/e.length).toFixed(4))}}function Q(e,t){return e.subarray(0,t).toString(`latin1`).replace(/[^\x20-\x7e]/g,`.`)}function mt(e,t,n){let r=et(e,$e(n)),i=Q(e,Math.min(e.length,256)).trim(),a=e.subarray(0,Math.min(e.length,t)).toString(`latin1`);return/^[\x20-\x7e\r\n\t]+$/.test(a)&&i.length>0&&r.push(`text`),(i.startsWith(`{`)||i.startsWith(`[`))&&r.push(`json`),[...new Set(r)]}var ht=class{async handleTransformWorkbench(e){try{let t=_t(e,`inputBase64`),n=vt(e.steps),r=typeof e.previewBytes==`number`&&Number.isFinite(e.previewBytes)?e.previewBytes:void 0,i=typeof e.includeOutputBase64==`boolean`?e.includeOutputBase64:void 0,a=gt(e.customMagicHints),o=$(e,`maxInputBytes`),s=$(e,`maxOutputBytes`),c=$(e,`maxSteps`);return d(it({inputBase64:t,steps:n,...r===void 0?{}:{previewBytes:r},...i===void 0?{}:{includeOutputBase64:i},...a.length>0?{customMagicHints:a}:{},...o===void 0?{}:{maxInputBytes:o},...s===void 0?{}:{maxOutputBytes:s},...c===void 0?{}:{maxSteps:c}}))}catch(e){return v(`transform_workbench`,e)}}};function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function gt(e){if(e===void 0)return[];if(!Array.isArray(e))throw Error(`customMagicHints must be an array`);return e.map(e=>{if(!e||typeof e!=`object`)throw Error(`customMagicHints entries must be objects`);let t=e,n=t.label;if(typeof n!=`string`||n.trim().length===0)throw Error(`customMagicHints label must be a non-empty string`);let r=t.prefixHex,i=t.prefixAscii,a=t.description;return{label:n.trim(),...typeof r==`string`?{prefixHex:r}:{},...typeof i==`string`?{prefixAscii:i}:{},...typeof a==`string`?{description:a}:{}}})}function _t(e,t){let n=e[t];if(typeof n!=`string`||n.trim().length===0)throw Error(`${t} must be a non-empty string`);return n.trim()}function vt(e){if(!Array.isArray(e)||e.length===0)throw Error(`steps must contain at least one transform step`);return e.map(e=>{if(!e||typeof e!=`object`)throw Error(`Each step must be an object`);let t=e,n=t.op;if(typeof n!=`string`||n.trim().length===0)throw Error(`step.op is required`);return{op:n.trim(),...typeof t.key==`string`?{key:t.key}:{},...typeof t.keyHex==`string`?{keyHex:t.keyHex}:{},...typeof t.iv==`string`?{iv:t.iv}:{},...typeof t.ivHex==`string`?{ivHex:t.ivHex}:{}}})}var yt=class{collector;state;ast;crypto;workbench;constructor(e){this.collector=e,this.state=me(e),this.ast=new Ze(this.state),this.crypto=new Qe(this.state),this.workbench=new ht}async close(){await this.state.cryptoHarnessPool.close()}get chains(){return this.state.chains}get cryptoHarnessPool(){return this.state.cryptoHarnessPool}async runCryptoHarness(e,t,n){return this.crypto.runCryptoHarnessProxy(e,t,n)}async handleAstTransformPreviewTool(e){return p(async()=>await this.handleAstTransformPreview(e))}async handleAstTransformChainTool(e){return p(async()=>await this.handleAstTransformChain(e))}async handleAstTransformApplyTool(e){return p(async()=>await this.handleAstTransformApply(e))}async handleCryptoExtractStandaloneTool(e){return p(async()=>await this.handleCryptoExtractStandalone(e))}async handleCryptoTestHarnessTool(e){return p(async()=>await this.handleCryptoTestHarness(e))}async handleCryptoCompareTool(e){return p(async()=>await this.handleCryptoCompare(e))}async handleTransformWorkbenchTool(e){return p(async()=>await this.handleTransformWorkbench(e))}handleAstTransformPreview=e=>this.ast.handleAstTransformPreview(e);handleAstTransformChain=e=>this.ast.handleAstTransformChain(e);handleAstTransformApply=e=>this.ast.handleAstTransformApply(e);handleCryptoExtractStandalone=e=>this.crypto.handleCryptoExtractStandalone(e);handleCryptoTestHarness=e=>this.crypto.handleCryptoTestHarness(e);handleCryptoCompare=e=>this.crypto.handleCryptoCompare(e);handleTransformWorkbench=e=>this.workbench.handleTransformWorkbench(e)};export{yt as TransformToolHandlers};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as e,i as t,n}from"./parse-args-B6dwWc9k.mjs";async function r(r){let i=e(r,`source`,``).trim(),a=e(r,`traceDir`,``).trim(),o=e(r,`functionName`,``).trim(),s=e(r,`phaseFilter`,``).trim(),c=t(r,`maxNodesPerPhase`,20),l=n(r,`includePhases`,!1),u=t(r,`timeoutMs`,3e4),d=n(r,`keepTraceDir`,!1);if(i.length===0&&a.length===0)return{success:!1,error:`Either "source" (JS code) or "traceDir" (path to turbo-*.json files) is required`,mode:`unavailable`,functionCount:0,functions:[]};let f;if(i.length>0){let{collectTurboFanIRIsolated:e}=await import(`./v8-inspector-CTJo08-K.mjs`).then(e=>e.s);f=await e({functionName:o.length>0?o:`anonymous`,sourceSlice:i},u,d)}else{let{collectTurboFanIRFromDir:e}=await import(`./v8-inspector-CTJo08-K.mjs`).then(e=>e.s);f=e(a)}if(!f.available)return{success:!1,error:f.reason,mode:i.length>0?`source`:`directory`,functionCount:0,functions:[],durationMs:f.durationMs};let p=[];for(let e of f.graphs){let t=s.length>0?e.phases.filter(e=>e.name.toLowerCase().includes(s.toLowerCase())):e.phases,n={functionName:e.function.functionName,sourceName:e.function.sourceName,phaseCount:t.length,totalNodeCount:e.totalNodeCount,totalEdgeCount:e.totalEdgeCount,opcodeHistogram:e.opcodeHistogram,summary:e.summary,inlineCount:Object.keys(e.inlinings).length};l&&(n.phases=t.map(e=>{let t=e.nodes??[],n=t.filter(e=>e.opcode!==`Parameter`&&e.opcode!==`OsrValue`).slice(0,c);return{name:e.name,nodeCount:e.nodeCount??t.length,edgeCount:e.edgeCount??0,sampleNodes:n.map(e=>({id:e.id,opcode:e.opcode,label:e.label,type:e.type}))}})),p.push(n)}return{success:!0,mode:i.length>0?`source`:`directory`,functionCount:p.length,functions:p,durationMs:f.durationMs}}export{r as handleTurbofanGraph};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import{c as e,i as t}from"./parse-args-B6dwWc9k.mjs";import{n,r}from"./cdp-session-Dy4OwMOP.mjs";function i(e){return e&32?{optimized:!0,tier:`turbofan`}:e&16?{optimized:!0,tier:`maglev`}:e&8?{optimized:!0,tier:`turbofan`}:(e&16384||e&64,{optimized:!1,tier:`interpreted`})}async function a(a,o){let s=e(a,`scriptId`,``).trim();if(s.length===0)return{success:!1,error:`scriptId is required`,scriptId:``,mode:`heuristic`,supportsNativesSyntax:!1,functions:[]};let c=e(a,`functionName`,``).trim(),l=e(a,`action`,`inspect`).trim(),u=t(a,`topN`,10),d=n(o),{session:f,owned:p}=await r(d);if(!f)return{success:!1,error:`No CDP session available`,scriptId:s,mode:`heuristic`,supportsNativesSyntax:!1,functions:[]};let m=!1,h=[];try{if(m=(await f.send(`Runtime.evaluate`,{expression:`typeof %GetOptimizationStatus === "function"`,returnByValue:!0}))?.result?.value===!0,m){await f.send(`Profiler.enable`),await f.send(`Profiler.startPreciseCoverage`,{callCount:!0,detailed:!0});let e=await f.send(`Profiler.takePreciseCoverage`),t=[];if(Array.isArray(e?.result))for(let n of e.result){if(n.scriptId!==s)continue;let e=Array.isArray(n.functions)?n.functions:[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=typeof n.functionName==`string`?n.functionName:`anonymous`;c&&!e.includes(c)||t.includes(e)||t.push(e)}}await f.send(`Profiler.stopPreciseCoverage`).catch(()=>{}),await f.send(`Profiler.disable`).catch(()=>{});let n=t.slice(0,u||t.length);for(let e of n){l===`optimize`?await f.send(`Runtime.evaluate`,{expression:`
|
|
2
|
+
(() => {
|
|
3
|
+
try {
|
|
4
|
+
const f = globalThis[${JSON.stringify(e)}];
|
|
5
|
+
if (typeof f === 'function') %OptimizeFunctionOnNextCall(f);
|
|
6
|
+
} catch(e) {}
|
|
7
|
+
})()
|
|
8
|
+
`}):l===`deoptimize`&&await f.send(`Runtime.evaluate`,{expression:`
|
|
9
|
+
(() => {
|
|
10
|
+
try {
|
|
11
|
+
const f = globalThis[${JSON.stringify(e)}];
|
|
12
|
+
if (typeof f === 'function') %DeoptimizeFunction(f);
|
|
13
|
+
} catch(e) {}
|
|
14
|
+
})()
|
|
15
|
+
`});let t=await f.send(`Runtime.evaluate`,{expression:`
|
|
16
|
+
(() => {
|
|
17
|
+
try {
|
|
18
|
+
const f = globalThis[${JSON.stringify(e)}];
|
|
19
|
+
if (typeof f !== 'function') return null;
|
|
20
|
+
return %GetOptimizationStatus(f);
|
|
21
|
+
} catch(e) { return null; }
|
|
22
|
+
})()
|
|
23
|
+
`,returnByValue:!0}),n=typeof t?.result?.value==`number`?t.result.value:void 0,{optimized:r,tier:a}=n===void 0?{optimized:!1,tier:`unknown`}:i(n);h.push({functionName:e,statusCode:n,tier:a,optimized:r})}}else{let{JITInspector:e}=await import(`./v8-inspector-CTJo08-K.mjs`).then(e=>e.t),t=await new e(d.getPage).inspectJIT(s);for(let e of t.functions)h.push({functionName:e.functionName,tier:e.tier,optimized:e.optimized})}}catch(e){return{success:!1,error:e instanceof Error?e.message:String(e),scriptId:s,mode:m?`natives`:`heuristic`,supportsNativesSyntax:m,functions:h}}finally{p&&await f.detach().catch(()=>{})}return{success:!0,scriptId:s,mode:m?`natives`:`heuristic`,supportsNativesSyntax:m,functions:h,...l===`inspect`?{}:{action:{requested:l,applied:m,detail:m?`${l} applied to ${h.length} functions`:`natives syntax not available — action not applied`}}}}export{a as handleTurbofanInspect};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e=function(e){return e.BEFORE_LOAD_INJECT=`before-load-inject`,e.RUNTIME_HOOK=`runtime-hook`,e.NETWORK_INTERCEPT=`network-intercept`,e.FUNCTION_TRACE=`function-trace`,e.STORAGE_MUTATION=`storage-mutation`,e.DOM_OBSERVATION=`dom-observation`,e}({});export{e as t};
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import{t as e}from"./rolldown-runtime-88NL7fhV.mjs";import{t}from"./logger-BGCcd-jJ.mjs";import{n}from"./artifacts-Bx9GLx4J.mjs";import{mkdirSync as r,mkdtempSync as i,readFileSync as a,readdirSync as o,rmSync as s}from"node:fs";import{join as c}from"node:path";import{spawn as l}from"node:child_process";var u=e({DominatorTreeBuilder:()=>f});function d(e){let t=e.shallowSize;for(let n of e.children)t+=d(n);return e.retainedSize=t,t}var f=class{nodes=new Map;edges=[];outgoingEdges=new Map;incomingEdges=new Map;idom=new Map;buildDominatorTree(e,t){this.nodes=new Map(e.map(e=>[e.id,e])),this.edges=t,this.buildAdjacencyLists();let n=this.findGCRoot(),r=this.computeImmediateDominators(n),i=this.buildTreeStructure(n,r);return this.computeRetainedSizes(i),i}computeRetainedSizes(e){d(e)}findLeakCandidates(e,t=1024*1024){let n=[],r=(e,i)=>{let a=[...i,e.name],o=this.checkDetachedDOM(e,a);o&&n.push(o);let s=this.checkLargeArray(e,a,t);s&&n.push(s);let c=this.checkClosureLeak(e,a,t);c&&n.push(c);let l=this.checkLargeRetained(e,a,t);l&&n.push(l);for(let t of e.children)r(t,a)};return r(e,[]),n.sort((e,t)=>Math.abs(e.confidence-t.confidence)>.01?t.confidence-e.confidence:t.retainedSize-e.retainedSize),n}buildAdjacencyLists(){this.outgoingEdges.clear(),this.incomingEdges.clear();for(let e of this.edges){let t=this.outgoingEdges.get(e.fromId)??[];t.push(e.toId),this.outgoingEdges.set(e.fromId,t);let n=this.incomingEdges.get(e.toId)??[];n.push(e.fromId),this.incomingEdges.set(e.toId,n)}}findGCRoot(){for(let[e,t]of this.nodes){let n=t.name.toLowerCase();if(n.includes(`root`)||n.includes(`gc root`)||t.type===`synthetic`)return e}let e=1,t=0;for(let[n,r]of this.nodes){let r=this.outgoingEdges.get(n)?.length??0;r>t&&(t=r,e=n)}return e}computeImmediateDominators(e){let t=this.doDFS(e);return this.computeLengauerTarjan(e,t)}doDFS(e){let t=new Map,n=[e],r=new Map,i=new Set,a=0,o=e=>{i.add(e),t.set(e,a),n[a]=e,a++;let s=this.outgoingEdges.get(e)??[];for(let t of s)i.has(t)||(r.set(t,e),o(t))};return o(e),{pre:t,vertex:n,parent:r}}computeLengauerTarjan(e,t){let{pre:n,vertex:r,parent:i}=t,a=r.length,o=new Map,s=new Map,c=new Map,l=new Map,u=new Map;for(let e=0;e<a;e++){let t=r[e];t!==void 0&&(o.set(t,e),u.set(t,t),l.set(t,0),c.set(t,new Set))}let d=(e,t)=>{l.set(t,e)},f=e=>{let t=l.get(e)??0,n=l.get(t)??0;t===0||n===0||(f(t),(o.get(u.get(n)??n)??a)<(o.get(u.get(t)??t)??a)&&u.set(e,u.get(n)??n),l.set(e,l.get(n)??0))},p=e=>{if((l.get(e)??0)===0)return u.get(e)??e;f(e);let t=l.get(e)??0,n=u.get(e)??e,r=u.get(t)??t;return(o.get(r)??a)<=(o.get(n)??a)?r:n};for(let e=a-1;e>=1;e--){let t=r[e];if(t===void 0)continue;let a=i.get(t);if(a===void 0)continue;let l=this.incomingEdges.get(t)??[];for(let r of l){if(n.get(r)===void 0)continue;let i=p(r),a=o.get(t)??e,s=o.get(i)??n.get(i)??e;s<a&&o.set(t,s)}let u=r[o.get(t)??e];if(u!==void 0){let e=c.get(u)??new Set;e.add(t),c.set(u,e)}d(a,t);let f=c.get(a)??new Set;for(let e of f){let t=p(e),n=o.get(e)??0;(o.get(t)??0)<n?(s.set(e,t),this.idom.set(e,t)):(s.set(e,a),this.idom.set(e,a))}c.set(a,new Set)}for(let e=1;e<a;e++){let t=r[e];if(t===void 0)continue;let n=s.get(t);if(n!==void 0&&n!==r[o.get(t)??e]){let e=s.get(n);e!==void 0&&(s.set(t,e),this.idom.set(t,e))}}return s}buildTreeStructure(e,t){let n=new Map;for(let[e,t]of this.nodes)n.set(e,{nodeId:e,name:t.name,retainedSize:0,shallowSize:t.selfSize,children:[]});for(let[e,r]of t){let t=n.get(r),i=n.get(e);t&&i&&t.children.push(i)}let r=n.get(e);if(!r)throw Error(`Root node ${e} not found in tree`);return r}checkDetachedDOM(e,t){let n=e.name.toLowerCase();return n.includes(`detached`)?{nodeId:e.nodeId,name:e.name,reason:`detached-dom`,confidence:.9,retainedSize:e.retainedSize,shallowSize:e.shallowSize,path:t}:(n.startsWith(`html`)||n.includes(`element`)||n.includes(`node`))&&(this.incomingEdges.get(e.nodeId)?.length??0)<2?{nodeId:e.nodeId,name:e.name,reason:`detached-dom`,confidence:.7,retainedSize:e.retainedSize,shallowSize:e.shallowSize,path:t}:null}checkLargeArray(e,t,n){let r=e.name.toLowerCase();if((r===`array`||r.includes(`array`))&&e.retainedSize>n){let n=Math.min(.8,.5+e.retainedSize/(10*1024*1024)*.3);return{nodeId:e.nodeId,name:e.name,reason:`large-array`,confidence:n,retainedSize:e.retainedSize,shallowSize:e.shallowSize,path:t}}return null}checkClosureLeak(e,t,n){let r=e.name.toLowerCase();if(r.includes(`function`)||r.includes(`closure`)){let r=e.retainedSize/(e.shallowSize||1);if(e.retainedSize>n&&r>10)return{nodeId:e.nodeId,name:e.name,reason:`closure-leak`,confidence:.75,retainedSize:e.retainedSize,shallowSize:e.shallowSize,path:t}}return null}checkLargeRetained(e,t,n){if(t.length<=1)return null;let r=e.name.toLowerCase();return r.includes(`root`)||r.includes(`global`)?null:e.retainedSize>n*5?{nodeId:e.nodeId,name:e.name,reason:`large-retained`,confidence:.6,retainedSize:e.retainedSize,shallowSize:e.shallowSize,path:t}:null}getRetainerChain(e,t=50){let n=[],r=e,i=0;for(;r!==0&&i<t;){let e=this.nodes.get(r);if(!e)break;n.push({nodeId:e.id,name:e.name,className:e.className??e.type??`unknown`,shallowSize:e.shallowSize??e.selfSize,retainedSize:e.retainedSize??e.selfSize,distance:i});let t=this.idom.get(r);if(t===void 0||t===r)break;r=t,i++}return n}getRetainerChains(e,t=50){let n={};for(let r of e)n[r]=this.getRetainerChain(r,t);return n}getRetainedByFunctionName(e,t,n=50,r=0){let i=e.toLowerCase(),a=[],o=e=>{e.name.toLowerCase().includes(i)&&e.retainedSize>=r&&a.push({node:e});for(let t of e.children)o(t)};return o(t),a.sort((e,t)=>t.node.retainedSize-e.node.retainedSize),a.slice(0,n).map(({node:e})=>({nodeId:e.nodeId,name:e.name,retainedSize:e.retainedSize,shallowSize:e.shallowSize,retainerChain:this.getRetainerChain(e.nodeId,50),children:e.children.length}))}},p=e({HeapSnapshotParser:()=>O});function m(e){return typeof e==`object`&&!!e}function h(e){if(e.charCodeAt(0)!==123)return!1;let t;try{t=JSON.parse(e)}catch{return!1}if(!m(t))return!1;let n=t.snapshot;return m(n)?m(n.meta):!1}function g(e){return Array.isArray(e)&&e.every(e=>typeof e==`number`)}function _(e){return Array.isArray(e)&&e.every(e=>g(e))}function v(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function y(e){return Array.isArray(e)?e.filter(e=>typeof e==`number`):[]}function b(e){if(Array.isArray(e))for(let t of e){let e=v(t);if(e.length>0)return e}return[]}function x(e){try{return JSON.parse(e)}catch{return null}}function S(e){if(Array.isArray(e)||g(e))return[e];if(_(e))return e;if(m(e)){let t=e.data;if(_(t))return t;if(g(t))return[t];let n=e.records;if(_(n))return n;if(g(n))return[n]}return[]}function C(e,t,n){let r=e[t];return typeof r==`string`&&r.length>0?r:`${n}_${t}`}function w(e,t){let n=e[t];return typeof n==`string`?n:String(t)}function T(e,t,n){if(t===`element`||t===`hidden`)return n;let r=e[n];return typeof r==`string`?r:n}function E(e){return`${e.type}\u0000${e.name}\u0000${e.selfSize}`}function D(e){let t=v(e.strings),n=b(e.node_types),r=b(e.edge_types),i=e.snapshot;if(m(i)){n.length===0&&(n=b(i.node_types)),r.length===0&&(r=b(i.edge_types));let e=i.meta;m(e)&&(n.length===0&&(n=b(e.node_types)),r.length===0&&(r=b(e.edge_types)))}return{strings:t,nodeTypes:n,edgeTypes:r}}var O=class{snapshotData;parsed=!1;nodesCache=[];edgesCache=[];chunkBuffer=[];constructor(e=``){this.snapshotData=e}feedChunk(e){if(this.parsed)throw Error(`Heap snapshot already parsed`);for(let t of e)typeof t==`string`&&t.length>0&&this.chunkBuffer.push(t);this.snapshotData=this.chunkBuffer.join(``),this.ensureParsed()}get nodeCount(){return this.ensureParsed(),this.nodesCache.length}getAllNodes(){return this.parseNodes()}getNodesByClassName(e){return this.parseNodes().filter(t=>t.name===e)}getObjectsByType(e){return this.parseNodes().filter(t=>t.type===e)}buildDominatorTree(){return this.computeRetainedSizes()}getAllRetainedSizes(){return Array.from(this.computeRetainedSizes().entries()).map(([e,t])=>({id:e,retainedSize:t}))}parseNodes(){return this.ensureParsed(),[...this.nodesCache]}parseEdges(){return this.ensureParsed(),[...this.edgesCache]}computeRetainedSizes(){this.ensureParsed();let e=new Map(this.nodesCache.map(e=>[e.id,e.selfSize]));if(this.nodesCache.length===0)return e;let t=[new f().buildDominatorTree(this.nodesCache,this.edgesCache)];for(;t.length>0;){let n=t.pop();n&&(e.set(n.nodeId,n.retainedSize),t.push(...n.children))}return e}getTopRetainers(e=10){this.ensureParsed();let t=new Map;for(let e of this.nodesCache){let n=t.get(e.name);if(n){n.retainedSize+=e.selfSize,n.count+=1;continue}t.set(e.name,{name:e.name,retainedSize:e.selfSize,count:1})}return[...t.values()].toSorted((e,t)=>t.retainedSize-e.retainedSize||t.count-e.count).slice(0,e)}diff(e){let t=this.parseNodes(),n=e.parseNodes(),r=new Map,i=new Map;for(let e of t){let t=E(e),n=r.get(t)??[];n.push(e),r.set(t,n)}for(let e of n){let t=E(e),n=i.get(t)??[];n.push(e),i.set(t,n)}let a=new Set([...r.keys(),...i.keys()]),o=[],s=[];for(let e of a){let t=r.get(e)??[],n=i.get(e)??[];t.length>n.length?o.push(...t.slice(n.length)):n.length>t.length&&s.push(...n.slice(t.length))}return{added:o,removed:s,sizeDelta:t.reduce((e,t)=>e+t.selfSize,0)-n.reduce((e,t)=>e+t.selfSize,0)}}exportSummary(){this.ensureParsed();let e=this.nodesCache.reduce((e,t)=>e+t.selfSize,0);return{totalNodes:this.nodesCache.length,totalEdges:this.edgesCache.length,totalSize:e,topRetainers:this.getTopRetainers()}}async analyzeHeap(e,t){let n=Date.now();this.ensureParsed();let{includeDominatorTree:r=!1,dominatorTreeDepth:i=3,includeLeakDetection:a=!1,minLeakSize:o=1024*1024}=t??{},s=new Map;for(let e of this.nodesCache){let t=e.name||`(${e.type})`,n=s.get(t);n?(n.count+=1,n.shallowSize+=e.selfSize,n.retainedSize+=e.selfSize):s.set(t,{count:1,shallowSize:e.selfSize,retainedSize:e.selfSize})}let c=[];for(let[e,t]of s.entries())c.push({className:e,count:t.count,shallowSize:t.shallowSize,retainedSize:t.retainedSize});c.sort((e,t)=>t.retainedSize-e.retainedSize);let l,u;if(r||a)try{let e=new f,t=e.buildDominatorTree(this.nodesCache,this.edgesCache);r&&(l=this.truncateTree(t,i)),a&&(u=e.findLeakCandidates(t,o).map(e=>({nodeId:e.nodeId,name:e.name,reason:e.reason,confidence:e.confidence,retainedSize:e.retainedSize,shallowSize:e.shallowSize,path:e.path})))}catch(e){console.warn(`Failed to compute dominator tree:`,e)}let d=this.nodesCache.length,p=this.nodesCache.reduce((e,t)=>e+t.selfSize,0),m=this.countDetachedDOMNodes(),h=Date.now()-n,g={classHistogram:c,statistics:{totalObjects:d,totalShallowSize:p,nodeCount:d,edgeCount:this.edgesCache.length,detachedDOMNodes:m},metadata:{snapshotId:e,parseTimeMs:h,version:r||a?`2.0.0-phase2`:`1.0.0-phase1`}};return l!==void 0&&(g.dominatorTree=l),u!==void 0&&(g.suspectedLeaks=u),g}truncateTree(e,t,n=0){return n>=t?{nodeId:e.nodeId,name:e.name,retainedSize:e.retainedSize,shallowSize:e.shallowSize,children:[]}:{nodeId:e.nodeId,name:e.name,retainedSize:e.retainedSize,shallowSize:e.shallowSize,children:e.children.map(e=>this.truncateTree(e,t,n+1))}}countDetachedDOMNodes(){let e=0;for(let t of this.nodesCache){let n=t.name.toLowerCase();if(n.includes(`detached`)){e+=1;continue}(n.startsWith(`html`)||n.includes(`element`)||n.includes(`node`)&&!n.includes(`function`))&&this.edgesCache.filter(e=>e.toId===t.id).length<2&&(e+=1)}return e}ensureParsed(){if(this.parsed)return;let e=this.snapshotData.trim();if(e.length===0){this.parsed=!0;return}h(e)?this.parseStandardSnapshot(e):this.parseLineSnapshot(e),this.parsed=!0}parseLineSnapshot(e){let t=e.split(/\r?\n/u).map(e=>e.trim()).filter(e=>e.length>0);if(t.length===0)return;let n=t[0];if(!n)return;let r=x(n),{strings:i,nodeTypes:a,edgeTypes:o}=D(m(r)?r:{}),s=[],c=[],l=null;for(let e of t.slice(1)){let t=S(x(e));for(let e of t){let t=e[0];if(t===0){let t=typeof e[1]==`string`,n=t?0:typeof e[1]==`number`?e[1]:0,r=t?e[1]:e[2],o=t?e[2]:e[3],c=t?e[3]:e[4],u=typeof o==`number`?o:s.length,d=typeof c==`number`?c:0,f={id:u,name:typeof r==`string`?r:w(i,typeof r==`number`?r:0),selfSize:d,type:C(a,n,`node`)};this.nodesCache.push(f),s.push(f.id),l=f.id;continue}if(t===1&&l!==null){let t=typeof e[1]==`number`?e[1]:0,n=e[2]??0,r=typeof e[3]==`number`?e[3]:0,a=C(o,t,`edge`);c.push({fromId:l,toNodeIndex:r,nameOrIndex:typeof n==`number`?T(i,a,n):String(n),type:a})}}}for(let e of c){let t=s[e.toNodeIndex];this.edgesCache.push({fromId:e.fromId,toId:t??e.toNodeIndex,nameOrIndex:e.nameOrIndex,type:e.type})}}parseStandardSnapshot(e){let t=x(e);if(!m(t))return;let n=v(t.strings),r=y(t.nodes),i=y(t.edges),a=t.snapshot;if(!m(a))return;let o=a.meta;if(!m(o))return;let s=v(o.node_fields),c=v(o.edge_fields),l=b(o.node_types),u=b(o.edge_types);if(s.length===0||c.length===0)return;let d=s.length,f=c.length,p=s.indexOf(`type`),h=s.indexOf(`name`),g=s.indexOf(`id`),_=s.indexOf(`self_size`),S=s.indexOf(`edge_count`),E=c.indexOf(`type`),D=c.indexOf(`name_or_index`),O=c.indexOf(`to_node`);if(p<0||h<0||g<0||_<0||S<0||E<0||D<0||O<0)return;let k=[],A=new Map;for(let e=0;e+d<=r.length;e+=d){let t=r[e+p]??0,i=r[e+h]??0,a=r[e+g]??e/d,o=r[e+_]??0,s=r[e+S]??0,c={id:a,name:w(n,i),selfSize:o,type:C(l,t,`node`),edgeCount:s,offset:e};k.push(c),A.set(e,c.id),this.nodesCache.push({id:c.id,name:c.name,selfSize:c.selfSize,type:c.type})}let j=0;for(let e of k)for(let t=0;t<e.edgeCount;t+=1){if(j+f>i.length)return;let t=i[j+E]??0,r=i[j+D]??0,a=i[j+O]??0,o=C(u,t,`edge`);this.edgesCache.push({fromId:e.id,toId:A.get(a)??a,nameOrIndex:T(n,o,r),type:o}),j+=f}}};function k(e){return!e||typeof e!=`object`?null:{sourceId:typeof e.sourceId==`number`?e.sourceId:0,functionName:typeof e.functionName==`string`?e.functionName:`<unknown>`,sourceName:typeof e.sourceName==`string`?e.sourceName:``,sourceText:typeof e.sourceText==`string`?e.sourceText:``,startPosition:typeof e.startPosition==`number`?e.startPosition:-1,endPosition:typeof e.endPosition==`number`?e.endPosition:-1}}function A(e){return{id:typeof e.id==`number`?e.id:-1,label:typeof e.label==`string`?e.label:``,title:typeof e.title==`string`?e.title:``,live:e.live===!0,properties:typeof e.properties==`string`?e.properties:``,opcode:typeof e.opcode==`string`?e.opcode:`Unknown`,control:e.control===!0,opinfo:typeof e.opinfo==`string`?e.opinfo:``,type:typeof e.type==`string`?e.type:``,sourcePosition:e.sourcePosition!==null&&e.sourcePosition!==void 0&&typeof e.sourcePosition==`object`?e.sourcePosition:void 0,origin:e.origin!==null&&e.origin!==void 0&&typeof e.origin==`object`?e.origin:void 0}}function j(e){switch(e){case`value`:case`context`:case`frame-state`:case`effect`:case`control`:return e;default:return`unknown`}}function ee(e){return{source:typeof e.source==`number`?e.source:-1,target:typeof e.target==`number`?e.target:-1,index:typeof e.index==`number`?e.index:-1,type:j(typeof e.type==`string`?e.type:`unknown`)}}function te(e,t){let n=Array.isArray(t.nodes)?t.nodes:[],r=Array.isArray(t.edges)?t.edges:[],i=[];for(let e of n)typeof e==`object`&&e&&i.push(A(e));let a=[];for(let e of r)typeof e==`object`&&e&&a.push(ee(e));return{name:e,type:`graph`,nodes:i,edges:a,nodeCount:i.length,edgeCount:a.length}}function ne(e){let t={};for(let n of e)if(n.nodes)for(let e of n.nodes){let n=e.opcode;t[n]=(t[n]||0)+1}return t}function re(e){let t;try{t=JSON.parse(e)}catch{return null}let n=k(t.function);if(!n)return null;let r={},i=t.sources;if(i&&typeof i==`object`){for(let[e,t]of Object.entries(i))if(typeof t==`object`&&t){let n=k(t);n&&(r[e]=n)}}let a={},o=t.inlinings;if(o&&typeof o==`object`){for(let[e,t]of Object.entries(o))if(typeof t==`object`&&t){let n=t;a[e]={inliningId:typeof n.inliningId==`number`?n.inliningId:0,sourceId:typeof n.sourceId==`number`?n.sourceId:0,inliningPosition:typeof n.inliningPosition==`object`&&n.inliningPosition!==null?n.inliningPosition:{}}}}let s=[],c=t.phases;if(Array.isArray(c))for(let e of c){if(typeof e!=`object`||!e)continue;let t=e,n=typeof t.name==`string`?t.name:``,r=typeof t.type==`string`?t.type:``;if(r===`graph`){let e=t.data;e&&typeof e==`object`&&s.push(te(n,e))}else r===`schedule`?s.push({name:n,type:`schedule`,data:typeof t.data==`string`?t.data:``}):s.push({name:n,type:r,data:typeof t.data==`string`?t.data:JSON.stringify(t.data)})}let l=ne(s),u=s.reduce((e,t)=>e+(t.nodeCount??0),0),d=s.reduce((e,t)=>e+(t.edgeCount??0),0),f=[`Function: ${n.functionName}`,`${s.length} phases`,`${u} total nodes`,`${d} total edges`];return Object.keys(a).length>0&&f.push(`${Object.keys(a).length} inlined calls`),{function:n,sources:r,inlinings:a,phases:s,phaseCount:s.length,totalNodeCount:u,totalEdgeCount:d,opcodeHistogram:l,summary:f.join(` | `)}}function M(e){let t=[];for(let n of e){let e=re(n.content);e&&t.push(e)}return{available:t.length>0,graphs:t,graphCount:t.length,reason:t.length>0?`Parsed ${t.length} TurboFan IR graph(s)`:`No valid TurboFan JSON graphs found in output`}}var ie=e({collectTurboFanIRFromDir:()=>me,collectTurboFanIRIsolated:()=>pe});const N=`__jshookTurbofanTarget__`,P=`__JSHOOK_TURBOFAN_STATUS__:`;function ae(e){return/^[A-Za-z_$][\w$]*$/u.test(e)}function oe(e){let t=e.trim();return t.length===0||t===`anonymous`?N:ae(t)?t:N}function se(e){let t=e.trim();return t.startsWith(`function`)||t.startsWith(`async function`)||t.startsWith(`class `)||t.startsWith(`(`)||t.includes(`=>`)?!1:/^(?:async\s+)?(?:get\s+|set\s+)?\*?\s*[A-Za-z_$][\w$]*\s*\(/u.test(t)}function ce(e){let t=e.sourceSlice.trim(),n=e.functionName.trim();return`
|
|
2
|
+
let ${N};
|
|
3
|
+
${se(t)?`
|
|
4
|
+
try {
|
|
5
|
+
const __jshookHolder = { ${t} };
|
|
6
|
+
const __jshookCandidate = __jshookHolder[${JSON.stringify(n)}];
|
|
7
|
+
if (typeof __jshookCandidate === 'function') {
|
|
8
|
+
${N} = __jshookCandidate;
|
|
9
|
+
}
|
|
10
|
+
} catch {}
|
|
11
|
+
`:`
|
|
12
|
+
try {
|
|
13
|
+
${N} = (${t});
|
|
14
|
+
} catch {}
|
|
15
|
+
`}
|
|
16
|
+
|
|
17
|
+
if (typeof ${N} !== 'function') {
|
|
18
|
+
console.log(${JSON.stringify(`${P}resolve-failed`)});
|
|
19
|
+
} else {
|
|
20
|
+
try {
|
|
21
|
+
// Warm up: call once to compile with Ignition, then force TurboFan
|
|
22
|
+
const __jshookArity =
|
|
23
|
+
typeof ${N}.length === 'number' && ${N}.length > 0
|
|
24
|
+
? ${N}.length
|
|
25
|
+
: 1;
|
|
26
|
+
const __jshookArgs = Array.from({ length: __jshookArity }, () => undefined);
|
|
27
|
+
// Multiple calls to trigger TurboFan optimization
|
|
28
|
+
for (let __jshookI = 0; __jshookI < 10; __jshookI += 1) {
|
|
29
|
+
Reflect.apply(${N}, globalThis, __jshookArgs);
|
|
30
|
+
}
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.log(${JSON.stringify(`${P}invoke-error:`)} + String(error));
|
|
33
|
+
}
|
|
34
|
+
console.log(${JSON.stringify(`${P}done`)});
|
|
35
|
+
}
|
|
36
|
+
`}function le(){let e=n(`tmp`);return r(e,{recursive:!0}),i(c(e,`jshook-turbofan-`))}async function ue(e,t,n,r){return await new Promise(i=>{let a=l(process.execPath,[`--trace-turbo`,`--trace-turbo-path=${n}`,`--trace-turbo-filter=${t}`,`--allow-natives-syntax`,`-`],{stdio:[`pipe`,`pipe`,`pipe`],cwd:n}),o=``,s=``,c=!1,u=e=>{c||(c=!0,clearTimeout(d),i({stdout:o,stderr:s,error:e}))},d=setTimeout(()=>{a.kill(),u(`Timed out after ${r}ms while waiting for --trace-turbo output`)},r);a.stdout.setEncoding(`utf8`),a.stderr.setEncoding(`utf8`),a.stdout.on(`data`,e=>{o+=e}),a.stderr.on(`data`,e=>{s+=e}),a.on(`error`,e=>{u(e instanceof Error?e.message:String(e))}),a.on(`close`,e=>{u(e===0?null:`Trace process exited with code ${e}`)}),a.stdin.end(e)})}function de(e){let t=e.split(/\r?\n/u).find(e=>e.startsWith(P)&&e.length>27);return t?t.slice(27):null}function fe(e){let n=[];try{let r=o(e);for(let i of r)if(i.startsWith(`turbo-`)&&i.endsWith(`.json`)){let r=c(e,i);try{let e=a(r,`utf8`);n.push({filename:i,content:e})}catch(e){t.debug(`Failed to read ${r}: ${e}`)}}}catch(n){t.debug(`Failed to read trace dir ${e}: ${n}`)}return n}function F(e){try{s(e,{recursive:!0,force:!0})}catch{}}async function pe(e,t=3e4,n=!1){let r=oe(e.functionName),i=Array.from(new Set([r,N])),a=le(),o=Date.now();try{for(let r of i){let{stdout:s,stderr:c,error:l}=await ue(ce(e),r,a,t),u=de(s);if(l&&!u){if(r!==i.at(-1))continue;return{available:!1,graphs:[],graphCount:0,reason:c.trim().length>0?`Process error: ${c.trim().slice(0,200)}`:l??`Unknown process error`,traceDir:null,durationMs:Date.now()-o}}if(u===`resolve-failed`){if(r!==i.at(-1))continue;return{available:!1,graphs:[],graphCount:0,reason:`Unable to reconstruct an executable function from the captured source slice`,traceDir:null,durationMs:Date.now()-o}}let d=fe(a);if(d.length===0){if(r!==i.at(-1))continue;return{available:!1,graphs:[],graphCount:0,reason:`Function executed but did not trigger TurboFan compilation. The function may be too small, not hot enough, or contain constructs that prevent optimization. Try wrapping it in a loop with more iterations.`,traceDir:null,durationMs:Date.now()-o}}let f=M(d);return n||F(a),{available:f.available,graphs:f.graphs,graphCount:f.graphCount,reason:f.reason,traceDir:n?a:null,durationMs:Date.now()-o}}return{available:!1,graphs:[],graphCount:0,reason:`No matching function found for --trace-turbo-filter`,traceDir:null,durationMs:Date.now()-o}}finally{n||F(a)}}function me(e){let t=M(fe(e));return{available:t.available,graphs:t.graphs,graphCount:t.graphCount,reason:t.reason,traceDir:e,durationMs:null}}var he=e({VersionDetector:()=>R});function I(e){return typeof e==`object`&&!!e}function ge(e){return I(e)&&typeof e.createCDPSession==`function`}function L(e,t){let n=e[t];return typeof n==`string`?n:null}function _e(e){if(typeof e==`boolean`)return e;if(I(e)){let t=e.value;return typeof t==`boolean`?t:!1}return!1}var R=class{getPage;constructor(e){this.getPage=e}async detectV8Version(){return await this.detectBrowserVersion()||(typeof process.versions.v8==`string`&&process.versions.v8.length>0?this.parseV8Version(process.versions.v8):null)}parseV8Version(e){let t=/(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?:\.(?<commit>[A-Za-z0-9._-]+))?/u.exec(e.trim());if(!t?.groups)return{major:0,minor:0,patch:0,commit:``};let n=Number(t.groups.major??0),r=Number(t.groups.minor??0),i=Number(t.groups.patch??0);return{major:Number.isFinite(n)?n:0,minor:Number.isFinite(r)?r:0,patch:Number.isFinite(i)?i:0,commit:t.groups.commit??``}}async supportsNativesSyntax(){if(process.execArgv.includes(`--allow-natives-syntax`))return!0;let e=await this.createSession();if(!e)return!1;try{let t=await e.send(`Runtime.evaluate`,{expression:`
|
|
37
|
+
(() => {
|
|
38
|
+
try {
|
|
39
|
+
return Boolean(new Function("return %HaveSameMap({}, {})")());
|
|
40
|
+
} catch (error) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
})()
|
|
44
|
+
`,returnByValue:!0,awaitPromise:!1});return I(t)?_e(t.result):!1}catch{return!1}finally{await e.detach().catch(()=>void 0)}}async detectBrowserVersion(){let e=await this.createSession();if(!e)return null;try{let t=await e.send(`Browser.getVersion`);if(!I(t))return null;let n=L(t,`jsVersion`);if(n)return this.parseV8Version(n);let r=L(t,`product`);return r?this.parseV8Version(r):null}catch{return null}finally{await e.detach().catch(()=>void 0)}}async createSession(){if(!this.getPage)return null;try{let e=await this.getPage();return ge(e)?await e.createCDPSession():null}catch{return null}}},ve=e({discoverWasmScripts:()=>V,inspectWasmGc:()=>ye});function z(e){return typeof e==`object`&&!!e}function B(e){return z(e)&&typeof e.createCDPSession==`function`}async function V(e){if(!B(e))throw Error(`WASM inspection requires a live CDP page`);let t=await e.createCDPSession();try{let e=(await t.send(`Runtime.evaluate`,{expression:`
|
|
45
|
+
(() => {
|
|
46
|
+
const wasmScripts = [];
|
|
47
|
+
// Walk performance entries for wasm resources
|
|
48
|
+
if (typeof performance !== 'undefined' && performance.getEntriesByType) {
|
|
49
|
+
try {
|
|
50
|
+
const resources = performance.getEntriesByType('resource');
|
|
51
|
+
for (const r of resources) {
|
|
52
|
+
if (
|
|
53
|
+
r.name.endsWith('.wasm') ||
|
|
54
|
+
(r as any).initiatorType === 'wasm'
|
|
55
|
+
) {
|
|
56
|
+
wasmScripts.push({
|
|
57
|
+
url: r.name,
|
|
58
|
+
byteSize: (r as any).transferSize ?? (r as any).encodedBodySize ?? 0,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
} catch (_) { /* ignore */ }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Also query WebAssembly.Module instances from the global scope
|
|
66
|
+
// (indirect: we look for wasm-backed functions via stack traces)
|
|
67
|
+
return JSON.stringify({
|
|
68
|
+
wasmResources: wasmScripts,
|
|
69
|
+
hasWasmGC: typeof (WebAssembly as any).Struct !== 'undefined',
|
|
70
|
+
wasmFeatures: {
|
|
71
|
+
gc: typeof (WebAssembly as any).Struct !== 'undefined',
|
|
72
|
+
threads: typeof (WebAssembly as any).Memory !== 'undefined' &&
|
|
73
|
+
(() => { try { new (WebAssembly as any).Memory({ initial: 1, shared: true }); return true; } catch { return false; } })(),
|
|
74
|
+
simd: typeof (WebAssembly as any).Global !== 'undefined',
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
})()
|
|
78
|
+
`,returnByValue:!0}))?.result?.value,n=null;if(typeof e==`string`)try{n=JSON.parse(e)}catch{}else z(e)&&(n=e);return(Array.isArray(n?.wasmResources)?n.wasmResources:[]).map(e=>({scriptId:``,url:String(e.url??``),isWasm:!0,byteSize:typeof e.byteSize==`number`?e.byteSize:void 0}))}finally{await t.detach()}}async function ye(e,t){if(!B(e))throw Error(`WASM inspection requires a live CDP page`);let n=t?.includeStructs!==!1,r=await e.createCDPSession();try{await r.send(`Runtime.enable`);let t=`
|
|
79
|
+
(() => {
|
|
80
|
+
const output = {
|
|
81
|
+
modules: [],
|
|
82
|
+
totalModules: 0,
|
|
83
|
+
gcModules: 0,
|
|
84
|
+
features: { gc: false, threads: false, simd: false },
|
|
85
|
+
hasGC: false,
|
|
86
|
+
structs: [],
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// Feature detection
|
|
90
|
+
try {
|
|
91
|
+
output.hasGC = typeof (WebAssembly as any).Struct !== 'undefined';
|
|
92
|
+
output.features.gc = output.hasGC;
|
|
93
|
+
} catch (_) {}
|
|
94
|
+
try {
|
|
95
|
+
output.features.threads = typeof SharedArrayBuffer !== 'undefined';
|
|
96
|
+
} catch (_) {}
|
|
97
|
+
try {
|
|
98
|
+
// SIMD detection: check if v128 exists in any global scope
|
|
99
|
+
output.features.simd = typeof (WebAssembly as any).Module !== 'undefined';
|
|
100
|
+
} catch (_) {}
|
|
101
|
+
|
|
102
|
+
// Enumerate WASM modules via the Module cache (V8 internal)
|
|
103
|
+
// This is best-effort; full enumeration requires CDP Debugger.scriptParsed events.
|
|
104
|
+
// We probe for known wasm-source Script objects via their source code patterns.
|
|
105
|
+
|
|
106
|
+
// Build a synthetic enumeration by scanning "function wasm-function["
|
|
107
|
+
// patterns in callable globals — this is a heuristic for WASM GC presence.
|
|
108
|
+
const wasmPatternSeen = new Set();
|
|
109
|
+
try {
|
|
110
|
+
// Walk the global object looking for WASM-exported functions
|
|
111
|
+
const seen = new Set();
|
|
112
|
+
for (const key of Object.getOwnPropertyNames(self)) {
|
|
113
|
+
try {
|
|
114
|
+
const val = (self as any)[key];
|
|
115
|
+
if (typeof val === 'function') {
|
|
116
|
+
const src = Function.prototype.toString.call(val);
|
|
117
|
+
if (src.includes('wasm-function[') || src.includes('WebAssembly')) {
|
|
118
|
+
if (!seen.has(src.substring(0, 80))) {
|
|
119
|
+
seen.add(src.substring(0, 80));
|
|
120
|
+
wasmPatternSeen.add({ name: key, isWasmExport: src.includes('wasm-function[') });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
} catch (_) { /* skip inaccessible properties */ }
|
|
125
|
+
}
|
|
126
|
+
} catch (_) {}
|
|
127
|
+
|
|
128
|
+
// Count WASM instances via the memory buffer pattern
|
|
129
|
+
let wasmInstanceCount = 0;
|
|
130
|
+
try {
|
|
131
|
+
if (typeof (WebAssembly as any).Memory !== 'undefined') {
|
|
132
|
+
// Indirect check: count distinct Memory buffers in scope
|
|
133
|
+
wasmInstanceCount = (typeof performance !== 'undefined' &&
|
|
134
|
+
performance.getEntriesByType)
|
|
135
|
+
? performance.getEntriesByType('resource')
|
|
136
|
+
.filter((r) => r.name.endsWith('.wasm'))
|
|
137
|
+
.length
|
|
138
|
+
: 0;
|
|
139
|
+
}
|
|
140
|
+
} catch (_) {}
|
|
141
|
+
|
|
142
|
+
output.totalModules = wasmInstanceCount;
|
|
143
|
+
output.gcModules = output.hasGC ? wasmInstanceCount : 0;
|
|
144
|
+
|
|
145
|
+
// If WASM GC is available, attempt struct enumeration via dummy module
|
|
146
|
+
${n?`
|
|
147
|
+
if (output.hasGC) {
|
|
148
|
+
try {
|
|
149
|
+
// Create a minimal test module to probe struct types
|
|
150
|
+
// (this is a heuristic — real struct introspection requires CDP-level API)
|
|
151
|
+
const testBytes = new Uint8Array([
|
|
152
|
+
0x00, 0x61, 0x73, 0x6d, // magic
|
|
153
|
+
0x01, 0x00, 0x00, 0x00, // version
|
|
154
|
+
]);
|
|
155
|
+
// Module with empty type section — validates that GC type section parsing works
|
|
156
|
+
const mod = new WebAssembly.Module(testBytes);
|
|
157
|
+
// Check for custom sections that indicate GC
|
|
158
|
+
const sections = WebAssembly.Module.customSections(mod, 'target_features');
|
|
159
|
+
for (const sec of sections) {
|
|
160
|
+
const text = new TextDecoder().decode(sec);
|
|
161
|
+
if (text.includes('gc')) {
|
|
162
|
+
output.features.gc = true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// GC struct count — module-level enumeration needs CDP
|
|
166
|
+
// We report 0 with gcAvailable=true (indicates probing succeeded but type-level
|
|
167
|
+
// enumeration requires Chrome ≥ M119 with --enable-features=WebAssemblyGC)
|
|
168
|
+
output.structs.push({
|
|
169
|
+
moduleId: 0,
|
|
170
|
+
structs: [],
|
|
171
|
+
note: 'Struct type enumeration requires CDP Debugger.getWasmBytecode + wasm binary parsing',
|
|
172
|
+
});
|
|
173
|
+
} catch (e) {
|
|
174
|
+
// WASM GC may not be available or parsing failed
|
|
175
|
+
output.structs.push({
|
|
176
|
+
moduleId: 0,
|
|
177
|
+
structs: [],
|
|
178
|
+
error: e instanceof Error ? e.message : 'unknown',
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
`:``}
|
|
183
|
+
|
|
184
|
+
return JSON.stringify(output);
|
|
185
|
+
})()
|
|
186
|
+
`,i=(await r.send(`Runtime.evaluate`,{expression:t,returnByValue:!0}))?.result?.value,a=null;if(typeof i==`string`)try{a=JSON.parse(i)}catch{}else z(i)&&(a=i);let o=a?.features??{},s=await V(e);return{success:!0,modules:[],totalModules:typeof a?.totalModules==`number`?a.totalModules:0,gcModules:typeof a?.gcModules==`number`?a.gcModules:0,wasmScripts:s,structs:Array.isArray(a?.structs)?a.structs:[],summary:{totalWasmModules:s.length,gcModules:typeof a?.gcModules==`number`?a.gcModules:0,nonGcModules:s.length-(typeof a?.gcModules==`number`?a.gcModules:0),hasGcFeature:o.gc===!0||a?.hasGC===!0,hasThreadsFeature:o.threads===!0,hasSimdFeature:o.simd===!0},wasmGcAvailable:a?.hasGC===!0}}finally{await r.detach()}}const H=`__JSHOOK_BYTECODE_STATUS__:`,U=`__jshookBytecodeTarget__`;function be(e){return/^[A-Za-z_$][\w$]*$/u.test(e)}function xe(e){let t=e.trim();return t.length===0||t===`anonymous`?U:be(t)?t:U}function Se(e){let t=e.trim();return t.startsWith(`function`)||t.startsWith(`async function`)||t.startsWith(`class `)||t.startsWith(`(`)||t.includes(`=>`)?!1:/^(?:async\s+)?(?:get\s+|set\s+)?\*?\s*[A-Za-z_$][\w$]*\s*\(/u.test(t)}function Ce(e){let t=e.sourceSlice.trim(),n=e.functionName.trim();return`
|
|
187
|
+
let ${U};
|
|
188
|
+
${Se(t)?`
|
|
189
|
+
try {
|
|
190
|
+
const __jshookHolder = { ${t} };
|
|
191
|
+
const __jshookCandidate = __jshookHolder[${JSON.stringify(n)}];
|
|
192
|
+
if (typeof __jshookCandidate === 'function') {
|
|
193
|
+
${U} = __jshookCandidate;
|
|
194
|
+
}
|
|
195
|
+
} catch {}
|
|
196
|
+
`:`
|
|
197
|
+
try {
|
|
198
|
+
${U} = (${t});
|
|
199
|
+
} catch {}
|
|
200
|
+
`}
|
|
201
|
+
|
|
202
|
+
if (typeof ${U} !== 'function') {
|
|
203
|
+
console.log(${JSON.stringify(`${H}resolve-failed`)});
|
|
204
|
+
} else {
|
|
205
|
+
try {
|
|
206
|
+
const __jshookArity =
|
|
207
|
+
typeof ${U}.length === 'number' && ${U}.length > 0
|
|
208
|
+
? ${U}.length
|
|
209
|
+
: 0;
|
|
210
|
+
Reflect.apply(${U}, globalThis, Array.from({ length: __jshookArity }, () => undefined));
|
|
211
|
+
} catch (error) {
|
|
212
|
+
console.log(${JSON.stringify(`${H}invoke-error:`)} + String(error));
|
|
213
|
+
}
|
|
214
|
+
console.log(${JSON.stringify(`${H}done`)});
|
|
215
|
+
}
|
|
216
|
+
`}function we(e,t){let n=e.split(/\r?\n/u),r=new Set(t.filter(e=>e.length>0)),i=null,a=!1,o=[];for(let e of n){let t=/^\[generated bytecode for function: (.+?) \(/u.exec(e);if(t?.[1]){if(a&&o.length>0)break;i=r.has(t[1])?t[1]:null,a=i!==null,a&&(o.length=0,o.push(e));continue}if(a){if(e.startsWith(H))break;o.push(e)}}return o.length===0?{bytecode:null,matchedFunctionName:null}:{bytecode:o.join(`
|
|
217
|
+
`).trim(),matchedFunctionName:i}}function Te(e){let t=e.split(/\r?\n/u).find(e=>e.startsWith(H)&&e.length>27);return t?t.slice(27):null}function Ee(e,t,n){let r=Te(e);if(r===`resolve-failed`)return`Unable to reconstruct an executable function from the captured source slice`;if(typeof r==`string`&&r.startsWith(`invoke-error:`))return`Function compiled but raised during isolated invocation: ${r.slice(13)}`;let i=t.trim();return i.length>0?i:n}async function De(e,t,n){return await new Promise(r=>{let i=l(process.execPath,[`--print-bytecode`,`--print-bytecode-filter=${t}`,`-`],{stdio:[`pipe`,`pipe`,`pipe`]}),a=``,o=``,s=!1,c=e=>{s||(s=!0,clearTimeout(u),r({stdout:a,stderr:o,error:e}))},u=setTimeout(()=>{i.kill(),c(`Timed out after ${n}ms while waiting for isolated bytecode output`)},n);i.stdout.setEncoding(`utf8`),i.stderr.setEncoding(`utf8`),i.stdout.on(`data`,e=>{a+=e}),i.stderr.on(`data`,e=>{o+=e}),i.on(`error`,e=>{c(e instanceof Error?e.message:String(e))}),i.on(`close`,e=>{c(e===0?null:`Bytecode printer exited with code ${e}`)}),i.stdin.end(e)})}async function Oe(e,t=15e3){let n=xe(e.functionName),r=Array.from(new Set([n,U])),i=Ce(e);for(let e of r){let{stdout:a,stderr:o,error:s}=await De(i,e,t),c=we(a,r);if(c.bytecode){let e=c.matchedFunctionName===U?n:c.matchedFunctionName;return{available:!0,bytecode:c.bytecode,format:`ignition-bytecode`,functionName:e??n,reason:`Ignition bytecode emitted by an isolated V8 process via --print-bytecode from the extracted source slice`,rawIgnitionBytecodeAvailable:!0}}if(s&&e===r.at(-1))return{available:!1,bytecode:null,format:null,functionName:n,reason:Ee(a,o,s),rawIgnitionBytecodeAvailable:!1}}return{available:!1,bytecode:null,format:null,functionName:n,reason:`Isolated V8 bytecode printer did not emit a matching function block`,rawIgnitionBytecodeAvailable:!1}}function W(e){return typeof e==`object`&&!!e}function ke(e){return W(e)&&typeof e.createCDPSession==`function`}function G(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function K(e){return typeof e==`string`?e:null}function q(e){return Array.isArray(e)?e.filter(W):[]}function Ae(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0)}function je(e){let t=e.trim();if(t.startsWith(`function `))return{opcode:`FunctionDeclaration`,operands:[]};if(t.startsWith(`return `))return{opcode:`Return`,operands:[t.slice(7)]};if(t.includes(`=>`))return{opcode:`CreateClosure`,operands:[]};if(t.includes(`(`)&&t.includes(`)`)){let e=/^([A-Za-z_$][\w$]*)\(/u.exec(t);if(e?.[1])return{opcode:`Call`,operands:[e[1]]}}if(t.includes(`=`)){let e=t.split(`=`,2),n=e[0],r=e[1];if(n&&r)return{opcode:`Store`,operands:[n.trim(),r.trim()]}}return t.startsWith(`if `)?{opcode:`JumpIfTrue`,operands:[t]}:t.startsWith(`for `)||t.startsWith(`while `)?{opcode:`Loop`,operands:[t]}:t.startsWith(`{`)||t.startsWith(`const `)||t.startsWith(`let `)?{opcode:`LoadLiteral`,operands:[t]}:{opcode:`Evaluate`,operands:[t]}}function Me(e){let t=[`; pseudo-bytecode synthesized from script source`],n=0;for(let r of e.split(/\r?\n/u)){let e=r.trim();if(e.length===0)continue;let{opcode:i,operands:a}=je(e),o=a.join(`, `);t.push(`${n} ${i}${o.length>0?` ${o}`:``}`),n+=1}return t.join(`
|
|
218
|
+
`)}function Ne(e,t){if(typeof t==`number`&&t>=0&&t<e.length){let n=Math.max(0,t-120),r=Math.min(e.length,t+120),i=e.slice(n,r),a=/function\s+([A-Za-z_$][\w$]*)/u.exec(i);if(a?.[1])return a[1];let o=/([A-Za-z_$][\w$]*)\s*=\s*(?:async\s*)?\(/u.exec(i);if(o?.[1])return o[1]}return/function\s+([A-Za-z_$][\w$]*)/u.exec(e)?.[1]??`anonymous`}function Pe(e){let t=e.matchAll(/\{([^{}]+:[^{}]+)\}/gu),n=[],r=0;for(let e of t){let t=e[1];if(!t)continue;let i=t.split(`,`).map(e=>e.trim()).map(e=>{let[t]=e.split(`:`,1);return t?.trim()??``}).filter(e=>e.length>0).filter((e,t,n)=>n.indexOf(e)===t);i.length!==0&&(n.push({address:`hidden-class-${r}`,properties:i,transitionMap:i.length>1?i.join(` -> `):void 0}),r+=1)}return n}function Fe(e){let t=e.result;return W(t)&&t.value!==void 0?t.value:t}function Ie(e){let t=K(e.reason);if(t)return t;let n=K(e.disassemblyError);if(n)return n;let r=K(e.disassemblyType);return r?`Native disassembly returned ${r} instead of text`:`Runtime disassembly output is not exposed through the current browser/CDP path`}var Le=class{getPage;versionDetector;constructor(e){this.getPage=e,this.versionDetector=new R(e)}async extractBytecode(e,t){let n=await this.resolveScriptFunctionContext(e,t);return n?{functionName:n.functionName,bytecode:Me(n.sourceSlice),sourcePosition:n.sourcePosition}:null}async attemptNativeBytecodeExtraction(e,t){let n=await this.resolveScriptFunctionContext(e,t);if(!n)return null;if(!await this.versionDetector.supportsNativesSyntax())return{available:!1,bytecode:null,format:null,functionName:n.functionName,rawIgnitionBytecodeAvailable:!1,reason:`V8 natives syntax is unavailable in the current browser target`,sourcePosition:n.sourcePosition,supportsNativesSyntax:!1};let r=await this.createSession();if(!r)return{available:!1,bytecode:null,format:null,functionName:n.functionName,rawIgnitionBytecodeAvailable:!1,reason:`Browser/page CDP session is unavailable for native bytecode inspection`,sourcePosition:n.sourcePosition,supportsNativesSyntax:!0};try{let e=await r.send(`Runtime.evaluate`,{expression:this.buildNativeExtractionExpression(n.functionName),returnByValue:!0,awaitPromise:!1});if(!W(e))return{available:!1,bytecode:null,format:null,functionName:n.functionName,rawIgnitionBytecodeAvailable:!1,reason:`Runtime.evaluate did not return structured data`,sourcePosition:n.sourcePosition,supportsNativesSyntax:!0};if(e.exceptionDetails)return{available:!1,bytecode:null,format:null,functionName:n.functionName,rawIgnitionBytecodeAvailable:!1,reason:`Runtime.evaluate raised an exception while probing native bytecode`,sourcePosition:n.sourcePosition,supportsNativesSyntax:!0};let t=Fe(e),i=W(t)?t:{},a=K(i.disassembly),o=G(i.nativeSourcePosition);if(a&&a.length>0)return{available:!0,bytecode:a,format:`v8-disassembly`,functionName:n.functionName,rawIgnitionBytecodeAvailable:!1,reason:`Native V8 disassembly text returned via %DisassembleFunction`,sourcePosition:o??n.sourcePosition,supportsNativesSyntax:!0};let s=await Oe(n);return s.available&&s.bytecode?{available:!0,bytecode:s.bytecode,format:s.format,functionName:s.functionName,rawIgnitionBytecodeAvailable:s.rawIgnitionBytecodeAvailable,reason:s.reason,sourcePosition:o??n.sourcePosition,supportsNativesSyntax:!0}:{available:!1,bytecode:null,format:null,functionName:n.functionName,rawIgnitionBytecodeAvailable:!1,reason:`${Ie(i)}; isolated printer: ${s.reason}`,sourcePosition:o??n.sourcePosition,supportsNativesSyntax:!0}}catch(e){return{available:!1,bytecode:null,format:null,functionName:n.functionName,rawIgnitionBytecodeAvailable:!1,reason:e instanceof Error?e.message:String(e),sourcePosition:n.sourcePosition,supportsNativesSyntax:!0}}finally{await r.detach().catch(()=>void 0)}}disassembleBytecode(e){let t=[];for(let n of e.split(/\r?\n/u)){let e=n.trim();if(e.length===0||e.startsWith(`;`))continue;let r=/^\d+\s+\w+>\s+[0-9A-Fa-f]+\s+@\s*(\d+)\s*:\s*(?:[0-9A-Fa-f]{2}(?:\s+[0-9A-Fa-f]{2})*\s+)?([A-Za-z_][\w.]*)\s*(.*)$/u.exec(e)??/^(\d+)\s*@\s*([A-Za-z_][\w.]*)\s*(.*)$/u.exec(e)??/^(?:0x[0-9a-fA-F]+\s+@)?\s*(\d+)\s*[: ]\s*([A-Za-z_][\w.]*)\s*(.*)$/u.exec(e)??/^(\d+)\s+([A-Za-z_][\w.]*)\s*(.*)$/u.exec(e);if(!r)continue;let i=Number(r[1]);Number.isFinite(i)&&t.push({offset:i,opcode:r[2]??`Unknown`,operands:Ae(r[3]??``)})}return t}async findHiddenClasses(e){let t=await this.getScriptSource(e);return t?Pe(t):[]}buildNativeExtractionExpression(e){return`
|
|
219
|
+
(() => {
|
|
220
|
+
const functionName = ${JSON.stringify(e)};
|
|
221
|
+
try {
|
|
222
|
+
const candidate = globalThis[functionName];
|
|
223
|
+
if (typeof candidate !== 'function') {
|
|
224
|
+
return {
|
|
225
|
+
functionName,
|
|
226
|
+
reason: 'Resolved function is not reachable via globalThis in the current target',
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const nativeSourcePosition = (() => {
|
|
231
|
+
try {
|
|
232
|
+
return %FunctionGetScriptSourcePosition(candidate);
|
|
233
|
+
} catch (error) {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
})();
|
|
237
|
+
|
|
238
|
+
try {
|
|
239
|
+
const disassembly = %DisassembleFunction(candidate);
|
|
240
|
+
return {
|
|
241
|
+
functionName,
|
|
242
|
+
disassembly: typeof disassembly === 'string' ? disassembly : null,
|
|
243
|
+
disassemblyType: typeof disassembly,
|
|
244
|
+
nativeSourcePosition:
|
|
245
|
+
typeof nativeSourcePosition === 'number' ? nativeSourcePosition : null,
|
|
246
|
+
};
|
|
247
|
+
} catch (error) {
|
|
248
|
+
return {
|
|
249
|
+
functionName,
|
|
250
|
+
disassemblyError: String(error),
|
|
251
|
+
nativeSourcePosition:
|
|
252
|
+
typeof nativeSourcePosition === 'number' ? nativeSourcePosition : null,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
} catch (error) {
|
|
256
|
+
return {
|
|
257
|
+
functionName,
|
|
258
|
+
reason: String(error),
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
})()
|
|
262
|
+
`}async resolveScriptFunctionContext(e,t){let n=await this.getScriptSource(e);if(!n)return null;let r=await this.getCoverageFunctions(e),i=(typeof t==`number`?r.find(e=>t>=e.startOffset&&t<=e.endOffset):void 0)??r.find(e=>e.functionName.length>0&&e.functionName!==`anonymous`)??r[0],a=i?.functionName&&i.functionName.length>0&&i.functionName!==`anonymous`?i.functionName:Ne(n,t),o=i&&i.endOffset>i.startOffset?n.slice(i.startOffset,i.endOffset):n;return{functionName:a,sourcePosition:typeof t==`number`?t:i?i.startOffset:void 0,sourceSlice:o}}async getCoverageFunctions(e){let t=await this.createSession();if(!t)return[];try{await t.send(`Profiler.enable`),await t.send(`Profiler.startPreciseCoverage`,{callCount:!0,detailed:!0});let n=await t.send(`Profiler.takePreciseCoverage`),r=(W(n)?q(n.result):[]).find(t=>typeof t.scriptId==`string`&&t.scriptId===e);if(!r)return[];let i=q(r.functions),a=[];for(let e of i){let t=q(e.ranges)[0];if(!t)continue;let n=G(t.startOffset),r=G(t.endOffset);n===null||r===null||a.push({functionName:K(e.functionName)??`anonymous`,startOffset:n,endOffset:r})}return a}catch{return[]}finally{await t.send(`Profiler.stopPreciseCoverage`).catch(()=>void 0),await t.send(`Profiler.disable`).catch(()=>void 0),await t.detach().catch(()=>void 0)}}async getScriptSource(e){let t=await this.createSession();if(!t)return null;try{await t.send(`Debugger.enable`);let n=await t.send(`Debugger.getScriptSource`,{scriptId:e});if(!W(n))return null;let r=n.scriptSource;return typeof r==`string`?r:null}catch{return null}finally{await t.send(`Debugger.disable`).catch(()=>void 0),await t.detach().catch(()=>void 0)}}async createSession(){if(!this.getPage)return null;try{let e=await this.getPage();return ke(e)?await e.createCDPSession():null}catch{return null}}};function J(e){return typeof e==`object`&&!!e}function Re(e){return J(e)&&typeof e.createCDPSession==`function`}function ze(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(J(e)&&typeof e.value==`number`){let t=e.value;return typeof t==`number`&&Number.isFinite(t)?t:null}return null}function Be(e){return e===null?{optimized:!1,tier:`unknown`}:e&32?{optimized:!0,tier:`turbofan`}:e&16?{optimized:!0,tier:`maglev`}:e&8?{optimized:!0,tier:`optimized`}:{optimized:!1,tier:`interpreted`}}var Ve=class{getPage;bytecodeExtractor;versionDetector;optimizedFunctionsCache=[];constructor(e){this.getPage=e,this.bytecodeExtractor=new Le(e),this.versionDetector=new R(e)}async inspectJIT(e){let t=await this.bytecodeExtractor.findHiddenClasses(e),n=await this.bytecodeExtractor.extractBytecode(e),r=new Set;n&&r.add(n.functionName);for(let e of t){let t=e.properties[0];t&&r.add(t)}r.size===0&&r.add(`anonymous`);let i=await this.versionDetector.supportsNativesSyntax(),a=[];for(let e of r){let{optimized:t,tier:n}=Be(i?await this.getOptimizationStatus(e):null);a.push({functionName:e,optimized:t,tier:n})}return this.optimizedFunctionsCache=a,{functions:a,supportsNativesSyntax:i,inspectionMode:i?`native-status`:`heuristic`}}async forceDeoptimization(e){if(!await this.versionDetector.supportsNativesSyntax())return;let t=await this.createSession();if(t)try{await t.send(`Runtime.evaluate`,{expression:`
|
|
263
|
+
(() => {
|
|
264
|
+
try {
|
|
265
|
+
const candidate = eval(${JSON.stringify(e)});
|
|
266
|
+
if (typeof candidate === 'function') {
|
|
267
|
+
%DeoptimizeFunction(candidate);
|
|
268
|
+
}
|
|
269
|
+
} catch (error) {
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
return undefined;
|
|
273
|
+
})()
|
|
274
|
+
`,returnByValue:!0,awaitPromise:!1})}finally{await t.detach().catch(()=>void 0)}}async getOptimizedFunctions(){return[...this.optimizedFunctionsCache]}async getOptimizationStatus(e){let t=await this.createSession();if(!t)return null;try{let n=await t.send(`Runtime.evaluate`,{expression:`
|
|
275
|
+
(() => {
|
|
276
|
+
try {
|
|
277
|
+
const candidate = globalThis[${JSON.stringify(e)}];
|
|
278
|
+
if (typeof candidate !== 'function') {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
return %GetOptimizationStatus(candidate);
|
|
282
|
+
} catch (error) {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
})()
|
|
286
|
+
`,returnByValue:!0,awaitPromise:!1});return J(n)?ze(n.result):null}catch{return null}finally{await t.detach().catch(()=>void 0)}}async createSession(){if(!this.getPage)return null;try{let e=await this.getPage();return Re(e)?await e.createCDPSession():null}catch{return null}}};function Y(e){return typeof e==`object`&&!!e}function X(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Z(e){return Y(e)?`value`in e?Z(e.value):`result`in e?Z(e.result):e:e}function Q(e){let t=Z(e),n=typeof t==`string`?(()=>{try{return JSON.parse(t)}catch{return null}})():t;if(!Y(n))return null;let r=X(n.jsHeapSizeUsed)??X(n.usedSize),i=X(n.jsHeapSizeTotal)??X(n.totalSize),a=X(n.jsHeapSizeLimit)??0;if(r===null&&i===null&&a===0)return null;let o={};return r!==null&&(o.jsHeapSizeUsed=r),i!==null&&(o.jsHeapSizeTotal=i),a>0&&(o.jsHeapSizeLimit=a),o}function He(e){return e.jsHeapSizeUsed>0||e.jsHeapSizeTotal>0||e.jsHeapSizeLimit>0}function $(e,t){if(!e&&!t)return null;let n={jsHeapSizeUsed:t?.jsHeapSizeUsed??e?.jsHeapSizeUsed??0,jsHeapSizeTotal:t?.jsHeapSizeTotal??e?.jsHeapSizeTotal??0,jsHeapSizeLimit:t?.jsHeapSizeLimit??e?.jsHeapSizeLimit??0};return He(n)?n:null}function Ue(e){let t=Z(e);if(!Y(t)||!Array.isArray(t.metrics))return null;let n=new Map;for(let e of t.metrics){if(!Y(e))continue;let t=typeof e.name==`string`?e.name:null,r=X(e.value);!t||r===null||n.set(t,r)}let r=n.get(`JSHeapUsedSize`)??0,i=n.get(`JSHeapTotalSize`)??0;return r===0&&i===0?null:{jsHeapSizeUsed:r,jsHeapSizeTotal:i}}function We(e){return Y(e)&&typeof e.createCDPSession==`function`}function Ge(e){return Y(e)&&typeof e.send==`function`&&typeof e.detach==`function`}var Ke=class{getPage;session=null;constructor(e){this.getPage=e}async enableHeapProfiler(){let e=await this.createSession();if(!e)throw Error(`V8InspectorClient: cannot create CDP session`);await e.send(`HeapProfiler.enable`),this.session=e}async takeHeapSnapshot(e){this.session||await this.enableHeapProfiler();let t=this.session;if(!t)throw Error(`V8InspectorClient: session not available for heap snapshot`);return new Promise((n,r)=>{let i=[],a=0,o=t=>{let n=t?.chunk;typeof n==`string`&&(i.push(n),a+=Buffer.byteLength(n,`utf8`),e?.(n))};t.on(`HeapProfiler.addHeapSnapshotChunk`,o),t.send(`HeapProfiler.takeHeapSnapshot`,{reportProgress:!1}).then(()=>{t.off(`HeapProfiler.addHeapSnapshotChunk`,o),n(a)}).catch(e=>{t.off(`HeapProfiler.addHeapSnapshotChunk`,o),r(e)})})}async getObjectByObjectId(e){let t=await this.createSession();if(!t)return null;try{let n=await t.send(`Runtime.getProperties`,{objectId:e,ownProperties:!0,accessorPropertiesOnly:!1,generatePreview:!0});if(Array.isArray(n.result))return{kind:`runtime-object`,properties:n.result,internalProperties:Array.isArray(n.internalProperties)?n.internalProperties:[],privateProperties:Array.isArray(n.privateProperties)?n.privateProperties:[],...n.exceptionDetails?{exceptionDetails:n.exceptionDetails}:{}}}catch{}try{return await t.send(`HeapProfiler.getObjectByHeapObjectId`,{objectId:e})}catch{return null}}async getHeapUsage(){this.session||await this.enableHeapProfiler();let e=this.session;if(!e)throw Error(`V8InspectorClient: session not available for heap usage`);let t=null;try{let n=await e.send(`Runtime.getHeapUsage`);t=$(t,Q(n))}catch{}try{let n=await e.send(`HeapProfiler.getHeapUsage`);t=$(t,Q(n))}catch{}try{let n=await e.send(`Performance.getMetrics`);t=$(t,Ue(n))}catch{}try{let n=await e.send(`Runtime.evaluate`,{expression:`
|
|
287
|
+
(() => {
|
|
288
|
+
const m = performance.memory;
|
|
289
|
+
return m
|
|
290
|
+
? {
|
|
291
|
+
jsHeapSizeUsed: m.usedJSHeapSize,
|
|
292
|
+
jsHeapSizeTotal: m.totalJSHeapSize,
|
|
293
|
+
jsHeapSizeLimit: m.jsHeapSizeLimit
|
|
294
|
+
}
|
|
295
|
+
: null;
|
|
296
|
+
})()
|
|
297
|
+
`,returnByValue:!0});t=$(t,Q(n))}catch{}if(!t)throw Error(`V8InspectorClient: heap usage metrics unavailable`);return t}async dispose(){this.session&&=(await this.session.detach().catch(()=>void 0),null)}async createSession(){if(this.session)return this.session;if(!this.getPage)return null;try{let e=await this.getPage();if(!We(e))return null;let t=await e.createCDPSession();return Ge(t)?(this.session=t,t):null}catch{return null}}},qe=e({JITInspector:()=>Ve});export{ve as a,p as c,Le as i,u as l,Ke as n,he as o,Ve as r,ie as s,qe as t};
|