@jshookmcp/jshook 0.2.9 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -50
- package/README.zh.md +25 -48
- package/dist/AntiCheatDetector-CGVGNfy5.mjs +1 -0
- package/dist/CacheAdapters-CdAxBmVW.mjs +1 -0
- package/dist/CodeInjector-BlgyqTOk.mjs +1 -0
- package/dist/ConsoleMonitor-Dkqc0HNi.mjs +490 -0
- package/dist/DOMInspector-BYY_EJ0C.mjs +95 -0
- package/dist/DarwinAPI-DC4HGGLl.mjs +1 -0
- package/dist/DetailedDataManager-BniBJlVv.mjs +1 -0
- package/dist/EventBus-DgciURGg.mjs +1 -0
- package/dist/EvidenceGraphBridge-BIfgB7HP.mjs +1 -0
- package/dist/ExtensionManager-erMpqcLk.mjs +1 -0
- package/dist/FingerprintManager-N7BZqjxP.mjs +1 -0
- package/dist/HardwareBreakpoint-OcJqNFVc.mjs +1 -0
- package/dist/HeapAnalyzer-CqAxZzeS.mjs +1 -0
- package/dist/{HookGeneratorBuilders.core.generators.storage-CtcdK78Q.mjs → HookGeneratorBuilders.core.generators.storage-Bf1fbrNK.mjs} +66 -174
- package/dist/InstrumentationSession-DxXs0sCp.mjs +1 -0
- package/dist/MCPServer.search.handlers.domain-DVbWL1bT.mjs +1 -0
- package/dist/MemoryController-BaqstM5w.mjs +2 -0
- package/dist/MemoryScanSession-CaxAjZJf.mjs +1 -0
- package/dist/MemoryScanner-BLYnMJy6.mjs +1 -0
- package/dist/NativeMemoryManager.impl-CI554XbY.mjs +1 -0
- package/dist/NativeMemoryManager.utils-DM4NC3FE.mjs +1 -0
- package/dist/PEAnalyzer-DJyaJTQJ.mjs +1 -0
- package/dist/PageController-D9jVkH0i.mjs +1 -0
- package/dist/PointerChainEngine-5nF9eNlu.mjs +1 -0
- package/dist/PrerequisiteError-Bl3dK8XA.mjs +1 -0
- package/dist/ProcessRegistry-Hf12LlR9.mjs +1 -0
- package/dist/ResponseBuilder-B2lu4KEl.mjs +1 -0
- package/dist/ReverseEvidenceGraph-B931HeoW.mjs +2 -0
- package/dist/ScriptManager-fgqiALgj.mjs +7 -0
- package/dist/Speedhack-l6s8L2Qw.mjs +1 -0
- package/dist/StealthVerifier-Dhbj4B4P.mjs +1 -0
- package/dist/StructureAnalyzer-A-WamfYE.mjs +2 -0
- package/dist/ToolCatalog-D_IKl1Hu.mjs +1 -0
- package/dist/ToolError-DWU_z7gp.mjs +1 -0
- package/dist/ToolProbe-xsfALmN3.mjs +1 -0
- package/dist/ToolRegistry-B0Zs-phN.mjs +1 -0
- package/dist/ToolRouter.policy-CFHoN_Lw.mjs +4 -0
- package/dist/TraceRecorder-Dd8jLXpi.mjs +272 -0
- package/dist/VersionDetector-DMoUWyNm.mjs +9 -0
- package/dist/Win32API-Bhi5xFBe.mjs +1 -0
- package/dist/Win32Debug-CQteFL4F.mjs +1 -0
- package/dist/WorkflowEngine-CxEp2WXH.mjs +1 -0
- package/dist/analysis-BuR-NgX8.mjs +5 -0
- package/dist/{antidebug-CqDTB_uk.mjs → antidebug-BOTZH6-0.mjs} +8 -259
- package/dist/artifactRetention-NBdncOEW.mjs +1 -0
- package/dist/artifacts-B5xQuEa_.mjs +1 -0
- package/dist/authorization-schema-B40obG1A.mjs +1 -0
- package/dist/betterSqlite3-CGaxz4AX.mjs +1 -0
- package/dist/binary-instrument-Cf9qqLlM.mjs +7 -0
- package/dist/bind-helpers-BlAOQrFQ.mjs +1 -0
- package/dist/boringssl-inspector-BST5vtKx.mjs +2 -0
- package/dist/browser-C4Le3xqA.mjs +11 -0
- package/dist/capabilities-DbYCv-HF.mjs +1 -0
- package/dist/chunk-C_pMuVsO.mjs +1 -0
- package/dist/collector-CKO8RPK8.mjs +1 -0
- package/dist/concurrency-CcK46d0h.mjs +1 -0
- package/dist/constants-Cp6hBrrx.mjs +1 -0
- package/dist/coordination-BbijHEHH.mjs +1 -0
- package/dist/debugger-CRJq_krh.mjs +1 -0
- package/dist/definitions-BGobEDQa.mjs +1 -0
- package/dist/definitions-BGwNSkVm.mjs +1 -0
- package/dist/definitions-BbxOUiP-.mjs +1 -0
- package/dist/definitions-CCP9gphV.mjs +1 -0
- package/dist/definitions-CIO9O-Sw.mjs +1 -0
- package/dist/definitions-CYFbewnd.mjs +1 -0
- package/dist/definitions-CdWEuIkI.mjs +1 -0
- package/dist/definitions-CoQFbggH.mjs +1 -0
- package/dist/definitions-CuJRsJ6N.mjs +1 -0
- package/dist/definitions-DI9YXsJk.mjs +1 -0
- package/dist/definitions-DJklW2sS.mjs +1 -0
- package/dist/definitions-DZ8uKusP.mjs +1 -0
- package/dist/definitions-Dds_zrWx.mjs +1 -0
- package/dist/definitions-Dgrg7f3D.mjs +1 -0
- package/dist/definitions-DtE0XLrT.mjs +1 -0
- package/dist/definitions-LaYTuwQd.mjs +26 -0
- package/dist/definitions-NoVp_9Pm.mjs +1 -0
- package/dist/definitions-OvGsfxdt.mjs +1 -0
- package/dist/definitions-jXPaVy4P.mjs +1 -0
- package/dist/encoding-DGcr6Aj_.mjs +2 -0
- package/dist/ensure-browser-core-Buls24LQ.mjs +1 -0
- package/dist/evidence-graph-bridge-B0yhGPcs.mjs +1 -0
- package/dist/factory-Cx_1LorX.mjs +1 -0
- package/dist/flat-target-session-CO5g78k3.mjs +1 -0
- package/dist/formatAddress-C7j2fDlM.mjs +1 -0
- package/dist/graphql-HLf3MS8H.mjs +62 -0
- package/dist/handlers-BLMa4X7l.mjs +54 -0
- package/dist/handlers-BP12ZsWc.mjs +4 -0
- package/dist/handlers-BZoPla6E.mjs +1 -0
- package/dist/handlers-BggKiVx9.mjs +2 -0
- package/dist/handlers-D3iev8g1.mjs +1 -0
- package/dist/handlers-D49r1-1P.mjs +1 -0
- package/dist/handlers-DCE45Ww8.mjs +2 -0
- package/dist/handlers-DW5AbYs5.mjs +5 -0
- package/dist/handlers-De5u62Ga2.mjs +1 -0
- package/dist/handlers-DmQzIc44.mjs +31 -0
- package/dist/handlers-DnJRGp7t.mjs +302 -0
- package/dist/handlers-Dv_runVv.mjs +2 -0
- package/dist/handlers-S9Ws0IGy.mjs +2 -0
- package/dist/{handlers-Bl8zkwz1.mjs → handlers-pVNpaw4A.mjs} +144 -841
- package/dist/handlers.impl-CD2_kOcC.mjs +1 -0
- package/dist/hooks-DDKppogd.mjs +600 -0
- package/dist/index.mjs +12 -5225
- package/dist/logger-sBC6IdRT.mjs +1 -0
- package/dist/maintenance-CutEO84j.mjs +1 -0
- package/dist/manifest-BFGxlDRh.mjs +123 -0
- package/dist/manifest-BPuE6oH2.mjs +1 -0
- package/dist/manifest-BXry5N09.mjs +1 -0
- package/dist/manifest-BeP_zJGb2.mjs +1 -0
- package/dist/manifest-C0g67k6U.mjs +1 -0
- package/dist/manifest-C1nZkTkO.mjs +1 -0
- package/dist/manifest-C7qV1z7F.mjs +1 -0
- package/dist/manifest-CDeUZGUZ.mjs +1 -0
- package/dist/manifest-CDiCtaQT.mjs +1 -0
- package/dist/manifest-CFn0359q2.mjs +1 -0
- package/dist/manifest-CGq4NpqH2.mjs +1 -0
- package/dist/manifest-CJMGt7Qy.mjs +1 -0
- package/dist/manifest-CRIJq4Hs.mjs +1 -0
- package/dist/manifest-C_hEIjSx.mjs +1 -0
- package/dist/manifest-CeQmtQOY.mjs +1 -0
- package/dist/manifest-Cq0j7GZt.mjs +1 -0
- package/dist/manifest-CtPmHAdn.mjs +1 -0
- package/dist/manifest-Cx2IVMUY.mjs +1 -0
- package/dist/manifest-D16xPXro.mjs +1 -0
- package/dist/manifest-D44TaRJU.mjs +1 -0
- package/dist/manifest-D610kxZr.mjs +2 -0
- package/dist/manifest-DC-SMF6b.mjs +1 -0
- package/dist/manifest-DD3rtxvV.mjs +1 -0
- package/dist/manifest-DKUorv5M.mjs +1 -0
- package/dist/manifest-DMJlcsTR.mjs +1 -0
- package/dist/manifest-DWUUWBz0.mjs +1 -0
- package/dist/manifest-De-6Wf2R.mjs +1 -0
- package/dist/manifest-Dgh0uDW-.mjs +1 -0
- package/dist/manifest-Dm0o3i2U.mjs +1 -0
- package/dist/manifest-DsVh7Y4U.mjs +1 -0
- package/dist/manifest-DtEFSRaq.mjs +1 -0
- package/dist/manifest-H-EpAyZQ.mjs +1 -0
- package/dist/manifest-ais9Afrw.mjs +1 -0
- package/dist/manifest-tmb54wmA.mjs +1 -0
- package/dist/manifest-yu2xiQqe.mjs +1 -0
- package/dist/manifest-zrbrpKCC.mjs +1 -0
- package/dist/matchesWildcardPattern-BGqLSmEs.mjs +1 -0
- package/dist/modules-p-PUNv9r.mjs +332 -0
- package/dist/mojo-ipc-VGlv3Qyp.mjs +9 -0
- package/dist/network-BjZ1Y-GB.mjs +7 -0
- package/dist/outputPaths-BonGThuc.mjs +2 -0
- package/dist/parse-args-Cuk7-xUt.mjs +1 -0
- package/dist/platform-C446Lf97.mjs +93 -0
- package/dist/playwright-cdp-fallback-BwVR-_T3.mjs +1 -0
- package/dist/process-C9f2A5zk.mjs +962 -0
- package/dist/proxy-CvRepxgV.mjs +1 -0
- package/dist/registry-DUHIPE-v.mjs +1 -0
- package/dist/response-C7rKQst4.mjs +1 -0
- package/dist/search-defaults-D2bY-rzH.mjs +1 -0
- package/dist/server/plugin-api.mjs +1 -293
- package/dist/shared-state-board-Cyg-xh_k.mjs +1 -0
- package/dist/sourcemap-D6Q1UuAp.mjs +1 -0
- package/dist/ssrf-policy-T96MR3r6.mjs +1 -0
- package/dist/streaming-CTX58tbb.mjs +1 -0
- package/dist/tool-builder-CI9914Tf.mjs +1 -0
- package/dist/transform-Cv9P2vVD.mjs +103 -0
- package/dist/types-CuyefmGT.mjs +1 -0
- package/dist/types-DtThH00r.mjs +1 -0
- package/dist/wasm-DaJa8J0V.mjs +174 -0
- package/dist/webcrack-CsLLJIs9.mjs +46 -0
- package/dist/workflow-CYIXtrWD.mjs +101 -0
- package/package.json +12 -7
- package/dist/AntiCheatDetector-BNk-EoBt.mjs +0 -244
- package/dist/CacheAdapters-CDe5WPSV.mjs +0 -80
- package/dist/CodeInjector-Cq8q01kp.mjs +0 -150
- package/dist/ConsoleMonitor-CPVQW1Y-.mjs +0 -2201
- package/dist/DarwinAPI-BNPxu0RH.mjs +0 -363
- package/dist/DetailedDataManager-BQQcxh64.mjs +0 -217
- package/dist/EventBus-DgPmwpeu.mjs +0 -141
- package/dist/EvidenceGraphBridge-SFesNera.mjs +0 -153
- package/dist/ExtensionManager-CWYgw0YW.mjs +0 -714
- package/dist/FingerprintManager-gzWtkKuf.mjs +0 -96
- package/dist/HardwareBreakpoint-B9gZCdFP.mjs +0 -239
- package/dist/HeapAnalyzer-BLDH0dCv.mjs +0 -284
- package/dist/InstrumentationSession-CvPC7Jwy.mjs +0 -244
- package/dist/MemoryController-CbVdCIJF.mjs +0 -167
- package/dist/MemoryScanSession-BsDZbLYm.mjs +0 -278
- package/dist/MemoryScanner-Bcpml6II.mjs +0 -425
- package/dist/NativeMemoryManager.impl-dZtA1ZGn.mjs +0 -482
- package/dist/NativeMemoryManager.utils-B-FjA2mJ.mjs +0 -165
- package/dist/PEAnalyzer-D1lzJ_VG.mjs +0 -385
- package/dist/PageController-Bqm2kZ_X.mjs +0 -417
- package/dist/PointerChainEngine-BOhyVsjx.mjs +0 -322
- package/dist/PrerequisiteError-Dl33Svkz.mjs +0 -20
- package/dist/ResponseBuilder-D3iFYx2N.mjs +0 -143
- package/dist/ReverseEvidenceGraph-Dlsk94LC.mjs +0 -269
- package/dist/ScriptManager-aHHq0X7U.mjs +0 -3000
- package/dist/Speedhack-CqdIFlQl.mjs +0 -156
- package/dist/StealthVerifier-Bo4T3bz8.mjs +0 -135
- package/dist/StructureAnalyzer-DhFaPvRO.mjs +0 -426
- package/dist/ToolCatalog-C0JGZoOm.mjs +0 -582
- package/dist/ToolError-jh9whhMd.mjs +0 -15
- package/dist/ToolProbe-oC7aPrkv.mjs +0 -45
- package/dist/ToolRegistry-BjaF4oNz.mjs +0 -131
- package/dist/ToolRouter.policy-BWV67ZK-.mjs +0 -304
- package/dist/TraceRecorder-DgxyVbdQ.mjs +0 -519
- package/dist/VersionDetector-CwVLVdDM.mjs +0 -104
- package/dist/Win32API-CePkipZY.mjs +0 -340
- package/dist/Win32Debug-BvKs-gxc.mjs +0 -274
- package/dist/WorkflowEngine-CuvkZtWu.mjs +0 -598
- package/dist/analysis-CL9uACt9.mjs +0 -463
- package/dist/artifactRetention-CFEprwPw.mjs +0 -591
- package/dist/artifacts-Bk2-_uPq.mjs +0 -59
- package/dist/betterSqlite3-0pqusHHH.mjs +0 -74
- package/dist/binary-instrument-CXfpx6fT.mjs +0 -979
- package/dist/bind-helpers-xFfRF-qm.mjs +0 -22
- package/dist/boringssl-inspector-BH2D3VKc.mjs +0 -180
- package/dist/browser-BpOr5PEx.mjs +0 -4082
- package/dist/chunk-CjcI7cDX.mjs +0 -15
- package/dist/concurrency-Bt0yv1kJ.mjs +0 -41
- package/dist/constants-B0OANIBL.mjs +0 -519
- package/dist/coordination-qUbyF8KU.mjs +0 -259
- package/dist/debugger-gnKxRSN0.mjs +0 -1271
- package/dist/definitions-6M-eejaT.mjs +0 -53
- package/dist/definitions-B18eyf0B.mjs +0 -18
- package/dist/definitions-B3QdlrHv.mjs +0 -34
- package/dist/definitions-B4rAvHNZ.mjs +0 -63
- package/dist/definitions-BB_4jnmy.mjs +0 -37
- package/dist/definitions-BMfYXoNC.mjs +0 -43
- package/dist/definitions-Beid2EB3.mjs +0 -27
- package/dist/definitions-C1UvM5Iy.mjs +0 -126
- package/dist/definitions-CXEI7QC72.mjs +0 -216
- package/dist/definitions-C_4r7Fo-2.mjs +0 -14
- package/dist/definitions-CkFDALoa.mjs +0 -26
- package/dist/definitions-Cke7zEb8.mjs +0 -94
- package/dist/definitions-ClJLzsJQ.mjs +0 -25
- package/dist/definitions-Cq-zroAU.mjs +0 -28
- package/dist/definitions-Cy3Sl6gV.mjs +0 -34
- package/dist/definitions-D3VsGcvz.mjs +0 -47
- package/dist/definitions-DVGfrn7y.mjs +0 -96
- package/dist/definitions-LKpC3-nL.mjs +0 -9
- package/dist/definitions-bAhHQJq9.mjs +0 -359
- package/dist/encoding-Bvz5jLRv.mjs +0 -1065
- package/dist/evidence-graph-bridge-C_fv9PuC.mjs +0 -135
- package/dist/factory-DxlGh9Xf.mjs +0 -575
- package/dist/formatAddress-DVkj9kpI.mjs +0 -17
- package/dist/graphql-DYWzJ29s.mjs +0 -1026
- package/dist/handlers-9sAbfIg-.mjs +0 -2552
- package/dist/handlers-C67ktuRN.mjs +0 -710
- package/dist/handlers-C87g8oCe.mjs +0 -276
- package/dist/handlers-CTsDAO6p.mjs +0 -681
- package/dist/handlers-Cgyg6c0U.mjs +0 -645
- package/dist/handlers-D6j6yka7.mjs +0 -2124
- package/dist/handlers-DdFzXLvF.mjs +0 -446
- package/dist/handlers-DeLOCd5m.mjs +0 -799
- package/dist/handlers-DlCJN4Td.mjs +0 -757
- package/dist/handlers-DxGIq15_2.mjs +0 -917
- package/dist/handlers-U6L4xhuF.mjs +0 -585
- package/dist/handlers-tB9Mp9ZK.mjs +0 -84
- package/dist/handlers-tiy7EIBp.mjs +0 -572
- package/dist/handlers.impl-DS0d9fUw.mjs +0 -761
- package/dist/hooks-CzCWByww.mjs +0 -898
- package/dist/logger-Dh_xb7_2.mjs +0 -93
- package/dist/maintenance-P7ePRXQC.mjs +0 -830
- package/dist/manifest-2ToTpjv8.mjs +0 -106
- package/dist/manifest-3g71z6Bg.mjs +0 -79
- package/dist/manifest-82baTv4U.mjs +0 -45
- package/dist/manifest-B3QVVeBS.mjs +0 -82
- package/dist/manifest-BB2J8IMJ.mjs +0 -149
- package/dist/manifest-BKbgbSiY.mjs +0 -60
- package/dist/manifest-Bcf-TJzH.mjs +0 -848
- package/dist/manifest-BmtZzQiQ2.mjs +0 -45
- package/dist/manifest-Bnd7kqEY.mjs +0 -55
- package/dist/manifest-BqQX6OQC2.mjs +0 -65
- package/dist/manifest-BqrQ4Tpj.mjs +0 -81
- package/dist/manifest-Br4RPFt5.mjs +0 -370
- package/dist/manifest-C5qDjysN.mjs +0 -107
- package/dist/manifest-C9RT5nk32.mjs +0 -34
- package/dist/manifest-CAhOuvSl.mjs +0 -204
- package/dist/manifest-CBYWCUBJ.mjs +0 -51
- package/dist/manifest-CFADCRa1.mjs +0 -37
- package/dist/manifest-CQVhavRF.mjs +0 -114
- package/dist/manifest-CT7zZBV1.mjs +0 -48
- package/dist/manifest-CV12bcrF.mjs +0 -121
- package/dist/manifest-CXsRWjjI.mjs +0 -224
- package/dist/manifest-CZLUCfG02.mjs +0 -95
- package/dist/manifest-D6phHKFd.mjs +0 -131
- package/dist/manifest-DCyjf4n2.mjs +0 -294
- package/dist/manifest-DHsnKgP6.mjs +0 -60
- package/dist/manifest-Df_dliIe.mjs +0 -55
- package/dist/manifest-Dh8WBmEW.mjs +0 -129
- package/dist/manifest-DhKRAT8_.mjs +0 -92
- package/dist/manifest-DlpTj4ic2.mjs +0 -193
- package/dist/manifest-DrbmZcFl2.mjs +0 -253
- package/dist/manifest-DuwHjUa5.mjs +0 -70
- package/dist/manifest-DzwvxPJX.mjs +0 -38
- package/dist/manifest-NXctwWQq.mjs +0 -68
- package/dist/manifest-Sc_0JQ13.mjs +0 -418
- package/dist/manifest-gZ4s_UtG.mjs +0 -96
- package/dist/manifest-qSleDqdO.mjs +0 -1023
- package/dist/modules-C184v-S9.mjs +0 -11365
- package/dist/mojo-ipc-B_H61Afw.mjs +0 -525
- package/dist/network-671Cw6hV.mjs +0 -3346
- package/dist/outputPaths-B1uGmrWZ.mjs +0 -1145
- package/dist/parse-args-BlRjqlkL.mjs +0 -39
- package/dist/platform-WmNn8Sxb.mjs +0 -2070
- package/dist/process-QcbIy5Zq.mjs +0 -1401
- package/dist/proxy-DqNs0bAd.mjs +0 -170
- package/dist/registry-D-6e18lB.mjs +0 -34
- package/dist/response-BQVP-xUn.mjs +0 -28
- package/dist/shared-state-board-DV-dpHFJ.mjs +0 -586
- package/dist/sourcemap-Dq8ez8vS.mjs +0 -650
- package/dist/ssrf-policy-ZaUfvhq7.mjs +0 -166
- package/dist/streaming-BUQ0VJsg.mjs +0 -725
- package/dist/tool-builder-DCbIC5Eo.mjs +0 -186
- package/dist/transform-CiYJfNX0.mjs +0 -1007
- package/dist/types-Bx92KJfT.mjs +0 -4
- package/dist/types-CPhOReNX.mjs +0 -37
- package/dist/wasm-DQTnHDs4.mjs +0 -531
- package/dist/workflow-f3xJOcjx.mjs +0 -725
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./chunk-CjcI7cDX.mjs";
|
|
2
|
-
import { t as logger } from "./logger-Dh_xb7_2.mjs";
|
|
3
|
-
import koffi from "koffi";
|
|
4
|
-
//#region src/native/Win32API.ts
|
|
5
|
-
/**
|
|
6
|
-
* Win32 API Bindings using koffi FFI
|
|
7
|
-
* Direct native calls to Windows kernel32.dll, ntdll.dll, psapi.dll
|
|
8
|
-
*
|
|
9
|
-
* This replaces PowerShell-based P/Invoke with direct FFI calls,
|
|
10
|
-
* providing 10-100x performance improvement for memory operations.
|
|
11
|
-
*
|
|
12
|
-
* Note: We use inline types in function signatures to avoid
|
|
13
|
-
* "Duplicate type name" errors in test environments where modules
|
|
14
|
-
* may be loaded multiple times.
|
|
15
|
-
*
|
|
16
|
-
* @module Win32API
|
|
17
|
-
*/
|
|
18
|
-
var Win32API_exports = /* @__PURE__ */ __exportAll({
|
|
19
|
-
CloseHandle: () => CloseHandle,
|
|
20
|
-
CreateRemoteThread: () => CreateRemoteThread,
|
|
21
|
-
EnumProcessModules: () => EnumProcessModules,
|
|
22
|
-
GetLastError: () => GetLastError,
|
|
23
|
-
GetModuleBaseName: () => GetModuleBaseName,
|
|
24
|
-
GetModuleFileNameEx: () => GetModuleFileNameEx,
|
|
25
|
-
GetModuleHandle: () => GetModuleHandle,
|
|
26
|
-
GetModuleInformation: () => GetModuleInformation,
|
|
27
|
-
GetProcAddress: () => GetProcAddress,
|
|
28
|
-
MEM: () => MEM,
|
|
29
|
-
NtQueryInformationProcess: () => NtQueryInformationProcess,
|
|
30
|
-
OpenProcess: () => OpenProcess,
|
|
31
|
-
PAGE: () => PAGE,
|
|
32
|
-
PROCESS_ACCESS: () => PROCESS_ACCESS,
|
|
33
|
-
ReadProcessMemory: () => ReadProcessMemory,
|
|
34
|
-
VirtualAllocEx: () => VirtualAllocEx,
|
|
35
|
-
VirtualFreeEx: () => VirtualFreeEx,
|
|
36
|
-
VirtualProtectEx: () => VirtualProtectEx,
|
|
37
|
-
VirtualQueryEx: () => VirtualQueryEx,
|
|
38
|
-
WriteProcessMemory: () => WriteProcessMemory,
|
|
39
|
-
isKoffiAvailable: () => isKoffiAvailable,
|
|
40
|
-
isWindows: () => isWindows,
|
|
41
|
-
openProcessForMemory: () => openProcessForMemory
|
|
42
|
-
});
|
|
43
|
-
const PROCESS_ACCESS = {
|
|
44
|
-
TERMINATE: 1,
|
|
45
|
-
CREATE_THREAD: 2,
|
|
46
|
-
SET_SESSIONID: 4,
|
|
47
|
-
VM_OPERATION: 8,
|
|
48
|
-
VM_READ: 16,
|
|
49
|
-
VM_WRITE: 32,
|
|
50
|
-
DUP_HANDLE: 64,
|
|
51
|
-
CREATE_PROCESS: 128,
|
|
52
|
-
SET_QUOTA: 256,
|
|
53
|
-
SET_INFORMATION: 512,
|
|
54
|
-
QUERY_INFORMATION: 1024,
|
|
55
|
-
SUSPEND_RESUME: 2048,
|
|
56
|
-
QUERY_LIMITED_INFORMATION: 4096,
|
|
57
|
-
ALL_ACCESS: 2035711
|
|
58
|
-
};
|
|
59
|
-
const MEM = {
|
|
60
|
-
COMMIT: 4096,
|
|
61
|
-
RESERVE: 8192,
|
|
62
|
-
DECOMMIT: 16384,
|
|
63
|
-
RELEASE: 32768,
|
|
64
|
-
FREE: 65536,
|
|
65
|
-
PRIVATE: 131072,
|
|
66
|
-
MAPPED: 262144,
|
|
67
|
-
RESET: 524288,
|
|
68
|
-
TOP_DOWN: 1048576,
|
|
69
|
-
WRITE_WATCH: 2097152,
|
|
70
|
-
PHYSICAL: 4194304,
|
|
71
|
-
LARGE_PAGES: 536870912
|
|
72
|
-
};
|
|
73
|
-
const PAGE = {
|
|
74
|
-
NOACCESS: 1,
|
|
75
|
-
READONLY: 2,
|
|
76
|
-
READWRITE: 4,
|
|
77
|
-
WRITECOPY: 8,
|
|
78
|
-
EXECUTE: 16,
|
|
79
|
-
EXECUTE_READ: 32,
|
|
80
|
-
EXECUTE_READWRITE: 64,
|
|
81
|
-
EXECUTE_WRITECOPY: 128,
|
|
82
|
-
GUARD: 256,
|
|
83
|
-
NOCACHE: 512,
|
|
84
|
-
WRITECOMBINE: 1024
|
|
85
|
-
};
|
|
86
|
-
let kernel32 = null;
|
|
87
|
-
let ntdll = null;
|
|
88
|
-
let psapi = null;
|
|
89
|
-
let koffiAvailable = null;
|
|
90
|
-
/**
|
|
91
|
-
* Check if koffi is available
|
|
92
|
-
*/
|
|
93
|
-
function isKoffiAvailable() {
|
|
94
|
-
if (koffiAvailable !== null) return koffiAvailable;
|
|
95
|
-
try {
|
|
96
|
-
koffi.load("kernel32.dll").unload();
|
|
97
|
-
koffiAvailable = true;
|
|
98
|
-
return true;
|
|
99
|
-
} catch {
|
|
100
|
-
/* istanbul ignore next */
|
|
101
|
-
koffiAvailable = false;
|
|
102
|
-
/* istanbul ignore next */
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Check if running on Windows
|
|
108
|
-
*/
|
|
109
|
-
function isWindows() {
|
|
110
|
-
return process.platform === "win32";
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Get or load kernel32.dll
|
|
114
|
-
*/
|
|
115
|
-
function getKernel32() {
|
|
116
|
-
if (!kernel32) {
|
|
117
|
-
kernel32 = koffi.load("kernel32.dll");
|
|
118
|
-
logger.debug("Loaded kernel32.dll via koffi");
|
|
119
|
-
}
|
|
120
|
-
return kernel32;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Get or load ntdll.dll
|
|
124
|
-
*/
|
|
125
|
-
function getNtdll() {
|
|
126
|
-
if (!ntdll) {
|
|
127
|
-
ntdll = koffi.load("ntdll.dll");
|
|
128
|
-
logger.debug("Loaded ntdll.dll via koffi");
|
|
129
|
-
}
|
|
130
|
-
return ntdll;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Get or load psapi.dll
|
|
134
|
-
*/
|
|
135
|
-
function getPsapi() {
|
|
136
|
-
if (!psapi) {
|
|
137
|
-
psapi = koffi.load("psapi.dll");
|
|
138
|
-
logger.debug("Loaded psapi.dll via koffi");
|
|
139
|
-
}
|
|
140
|
-
return psapi;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Open a process handle
|
|
144
|
-
*/
|
|
145
|
-
function OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId) {
|
|
146
|
-
return getKernel32().func("void * OpenProcess(uint32, int, uint32)")(dwDesiredAccess, bInheritHandle ? 1 : 0, dwProcessId);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Close a handle
|
|
150
|
-
*/
|
|
151
|
-
function CloseHandle(hObject) {
|
|
152
|
-
return getKernel32().func("int CloseHandle(void *)")(hObject) !== 0;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Read process memory - returns buffer directly
|
|
156
|
-
*/
|
|
157
|
-
function ReadProcessMemory(hProcess, lpBaseAddress, size) {
|
|
158
|
-
const fn = getKernel32().func("int ReadProcessMemory(void *, void *, _Out_ uint8_t[len], size_t len, _Out_ size_t *bytesRead)");
|
|
159
|
-
const buffer = Buffer.alloc(size);
|
|
160
|
-
const bytesReadBuf = Buffer.alloc(8);
|
|
161
|
-
if (fn(hProcess, lpBaseAddress, buffer, BigInt(size), bytesReadBuf) === 0) {
|
|
162
|
-
const error = GetLastError();
|
|
163
|
-
throw new Error(`ReadProcessMemory failed. Error: 0x${error.toString(16)}`);
|
|
164
|
-
}
|
|
165
|
-
return buffer;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Write process memory
|
|
169
|
-
*/
|
|
170
|
-
function WriteProcessMemory(hProcess, lpBaseAddress, data) {
|
|
171
|
-
const fn = getKernel32().func("int WriteProcessMemory(void *, void *, uint8_t[len], size_t len, _Out_ size_t *bytesWritten)");
|
|
172
|
-
const bytesWrittenBuf = Buffer.alloc(8);
|
|
173
|
-
if (fn(hProcess, lpBaseAddress, data, BigInt(data.length), bytesWrittenBuf) === 0) {
|
|
174
|
-
const error = GetLastError();
|
|
175
|
-
throw new Error(`WriteProcessMemory failed. Error: 0x${error.toString(16)}`);
|
|
176
|
-
}
|
|
177
|
-
return Number(bytesWrittenBuf.readBigUInt64LE());
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Query memory region information
|
|
181
|
-
* Uses Buffer parsing to avoid koffi struct registration issues
|
|
182
|
-
*/
|
|
183
|
-
function VirtualQueryEx(hProcess, lpAddress) {
|
|
184
|
-
const fn = getKernel32().func("size_t VirtualQueryEx(void *, void *, _Out_ uint8_t[48], size_t)");
|
|
185
|
-
const structSize = 48;
|
|
186
|
-
const buffer = Buffer.alloc(structSize);
|
|
187
|
-
const result = fn(hProcess, lpAddress, buffer, BigInt(structSize));
|
|
188
|
-
if (Number(result) !== structSize) return {
|
|
189
|
-
success: false,
|
|
190
|
-
info: {}
|
|
191
|
-
};
|
|
192
|
-
return {
|
|
193
|
-
success: true,
|
|
194
|
-
info: {
|
|
195
|
-
BaseAddress: buffer.readBigUInt64LE(0),
|
|
196
|
-
AllocationBase: buffer.readBigUInt64LE(8),
|
|
197
|
-
AllocationProtect: buffer.readUInt32LE(16),
|
|
198
|
-
RegionSize: buffer.readBigUInt64LE(24),
|
|
199
|
-
State: buffer.readUInt32LE(32),
|
|
200
|
-
Protect: buffer.readUInt32LE(36),
|
|
201
|
-
Type: buffer.readUInt32LE(40)
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Change memory protection
|
|
207
|
-
*/
|
|
208
|
-
function VirtualProtectEx(hProcess, lpAddress, dwSize, flNewProtect) {
|
|
209
|
-
const fn = getKernel32().func("int VirtualProtectEx(void *, void *, size_t, uint32, _Out_ uint32 *)");
|
|
210
|
-
const oldProtectBuf = Buffer.alloc(4);
|
|
211
|
-
return {
|
|
212
|
-
success: fn(hProcess, lpAddress, BigInt(dwSize), flNewProtect, oldProtectBuf) !== 0,
|
|
213
|
-
oldProtect: oldProtectBuf.readUInt32LE(0)
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Allocate memory in another process
|
|
218
|
-
*/
|
|
219
|
-
function VirtualAllocEx(hProcess, lpAddress, dwSize, flAllocationType, flProtect) {
|
|
220
|
-
return getKernel32().func("void * VirtualAllocEx(void *, void *, size_t, uint32, uint32)")(hProcess, lpAddress, BigInt(dwSize), flAllocationType, flProtect);
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Free memory in another process
|
|
224
|
-
*/
|
|
225
|
-
function VirtualFreeEx(hProcess, lpAddress, dwSize, dwFreeType) {
|
|
226
|
-
return getKernel32().func("int VirtualFreeEx(void *, void *, size_t, uint32)")(hProcess, lpAddress, BigInt(dwSize), dwFreeType) !== 0;
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Create a remote thread in another process
|
|
230
|
-
*/
|
|
231
|
-
function CreateRemoteThread(hProcess, lpStartAddress, lpParameter) {
|
|
232
|
-
const fn = getKernel32().func("void * CreateRemoteThread(void *, void *, size_t, void *, void *, uint32, _Out_ uint32 *)");
|
|
233
|
-
const threadIdBuf = Buffer.alloc(4);
|
|
234
|
-
return {
|
|
235
|
-
handle: fn(hProcess, null, 0n, lpStartAddress, lpParameter, 0, threadIdBuf),
|
|
236
|
-
threadId: threadIdBuf.readUInt32LE(0)
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Get module handle by name
|
|
241
|
-
*/
|
|
242
|
-
function GetModuleHandle(lpModuleName) {
|
|
243
|
-
return getKernel32().func("void * GetModuleHandleA(char *)")(lpModuleName);
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Get function address from module
|
|
247
|
-
*/
|
|
248
|
-
function GetProcAddress(hModule, lpProcName) {
|
|
249
|
-
return getKernel32().func("void * GetProcAddress(void *, char *)")(hModule, lpProcName);
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Get last error code
|
|
253
|
-
*/
|
|
254
|
-
function GetLastError() {
|
|
255
|
-
return getKernel32().func("uint32 GetLastError()")();
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* NtQueryInformationProcess for anti-debug detection
|
|
259
|
-
*/
|
|
260
|
-
function NtQueryInformationProcess(hProcess, processInformationClass) {
|
|
261
|
-
const fn = getNtdll().func("int32 NtQueryInformationProcess(void *, uint32, _Out_ void *, uint32, void *)");
|
|
262
|
-
const debugPortBuf = Buffer.alloc(8);
|
|
263
|
-
return {
|
|
264
|
-
status: fn(hProcess, processInformationClass, debugPortBuf, 8, null),
|
|
265
|
-
debugPort: Number(debugPortBuf.readBigUInt64LE())
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Enumerate process modules
|
|
270
|
-
*/
|
|
271
|
-
function EnumProcessModules(hProcess, maxModules = 1024) {
|
|
272
|
-
const fn = getPsapi().func("int EnumProcessModules(void *, _Out_ void *[], uint32, _Out_ uint32 *)");
|
|
273
|
-
const moduleBuf = Buffer.alloc(maxModules * 8);
|
|
274
|
-
const neededBuf = Buffer.alloc(4);
|
|
275
|
-
const result = fn(hProcess, moduleBuf, maxModules * 8, neededBuf);
|
|
276
|
-
const needed = neededBuf.readUInt32LE(0);
|
|
277
|
-
const count = Math.floor(needed / 8);
|
|
278
|
-
const modules = [];
|
|
279
|
-
for (let i = 0; i < count; i++) modules.push(moduleBuf.readBigUInt64LE(i * 8));
|
|
280
|
-
return {
|
|
281
|
-
success: result !== 0,
|
|
282
|
-
modules,
|
|
283
|
-
count
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Get module base name
|
|
288
|
-
*/
|
|
289
|
-
function GetModuleBaseName(hProcess, hModule, maxSize = 260) {
|
|
290
|
-
const fn = getPsapi().func("uint32 GetModuleBaseNameA(void *, void *, _Out_ char[], uint32)");
|
|
291
|
-
const buffer = Buffer.alloc(maxSize);
|
|
292
|
-
fn(hProcess, hModule, buffer, maxSize);
|
|
293
|
-
let len = 0;
|
|
294
|
-
while (len < maxSize && buffer[len] !== 0) len++;
|
|
295
|
-
return buffer.toString("utf8", 0, len);
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Get full module path from a remote process.
|
|
299
|
-
* Returns null when the API is unavailable or the module path cannot be resolved.
|
|
300
|
-
*/
|
|
301
|
-
function GetModuleFileNameEx(hProcess, hModule, maxSize = 32768) {
|
|
302
|
-
const fn = getPsapi().func("uint32 GetModuleFileNameExA(void *, void *, _Out_ char[], uint32)");
|
|
303
|
-
const buffer = Buffer.alloc(maxSize);
|
|
304
|
-
const result = fn(hProcess, hModule, buffer, maxSize);
|
|
305
|
-
if (typeof result !== "number" || result <= 0) return null;
|
|
306
|
-
let len = 0;
|
|
307
|
-
while (len < maxSize && buffer[len] !== 0) len++;
|
|
308
|
-
return len > 0 ? buffer.toString("utf8", 0, len) : null;
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Get module information
|
|
312
|
-
* Uses Buffer parsing to avoid koffi struct registration issues
|
|
313
|
-
*/
|
|
314
|
-
function GetModuleInformation(hProcess, hModule) {
|
|
315
|
-
const fn = getPsapi().func("int GetModuleInformation(void *, void *, _Out_ uint8_t[24], uint32)");
|
|
316
|
-
const buffer = Buffer.alloc(24);
|
|
317
|
-
const result = fn(hProcess, hModule, buffer, 24);
|
|
318
|
-
const info = {
|
|
319
|
-
lpBaseOfDll: buffer.readBigUInt64LE(0),
|
|
320
|
-
SizeOfImage: buffer.readUInt32LE(8),
|
|
321
|
-
EntryPoint: buffer.readBigUInt64LE(16)
|
|
322
|
-
};
|
|
323
|
-
return {
|
|
324
|
-
success: result !== 0,
|
|
325
|
-
info
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Open a process with standard memory access rights
|
|
330
|
-
*/
|
|
331
|
-
function openProcessForMemory(pid, writeAccess = false) {
|
|
332
|
-
const handle = OpenProcess(writeAccess ? PROCESS_ACCESS.VM_READ | PROCESS_ACCESS.VM_WRITE | PROCESS_ACCESS.VM_OPERATION | PROCESS_ACCESS.QUERY_INFORMATION : PROCESS_ACCESS.VM_READ | PROCESS_ACCESS.QUERY_INFORMATION, false, pid);
|
|
333
|
-
if (handle === 0n) {
|
|
334
|
-
const error = GetLastError();
|
|
335
|
-
throw new Error(`Failed to open process ${pid}. Error: 0x${error.toString(16)}. Run as Administrator.`);
|
|
336
|
-
}
|
|
337
|
-
return handle;
|
|
338
|
-
}
|
|
339
|
-
//#endregion
|
|
340
|
-
export { WriteProcessMemory as _, GetModuleFileNameEx as a, openProcessForMemory as b, GetProcAddress as c, ReadProcessMemory as d, VirtualAllocEx as f, Win32API_exports as g, VirtualQueryEx as h, GetModuleBaseName as i, MEM as l, VirtualProtectEx as m, EnumProcessModules as n, GetModuleHandle as o, VirtualFreeEx as p, GetLastError as r, GetModuleInformation as s, CloseHandle as t, PAGE as u, isKoffiAvailable as v, isWindows as y };
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
import { t as logger } from "./logger-Dh_xb7_2.mjs";
|
|
2
|
-
import { r as GetLastError, t as CloseHandle } from "./Win32API-CePkipZY.mjs";
|
|
3
|
-
import koffi from "koffi";
|
|
4
|
-
//#region src/native/Win32Debug.ts
|
|
5
|
-
/**
|
|
6
|
-
* Win32 Debug API Bindings using koffi FFI.
|
|
7
|
-
*
|
|
8
|
-
* Thread management, debug registers, debug events, and instruction cache.
|
|
9
|
-
* These extend Win32API.ts with debug-specific functionality needed for
|
|
10
|
-
* hardware breakpoints and code injection.
|
|
11
|
-
*
|
|
12
|
-
* @module Win32Debug
|
|
13
|
-
*/
|
|
14
|
-
const THREAD_ACCESS = {
|
|
15
|
-
TERMINATE: 1,
|
|
16
|
-
SUSPEND_RESUME: 2,
|
|
17
|
-
GET_CONTEXT: 8,
|
|
18
|
-
SET_CONTEXT: 16,
|
|
19
|
-
SET_INFORMATION: 32,
|
|
20
|
-
QUERY_INFORMATION: 64,
|
|
21
|
-
SET_THREAD_TOKEN: 128,
|
|
22
|
-
IMPERSONATE: 256,
|
|
23
|
-
DIRECT_IMPERSONATION: 512,
|
|
24
|
-
ALL_ACCESS: 2032639
|
|
25
|
-
};
|
|
26
|
-
/** CONTEXT flags for GetThreadContext / SetThreadContext */
|
|
27
|
-
const CONTEXT_FLAGS = {
|
|
28
|
-
AMD64: 1048576,
|
|
29
|
-
CONTROL: 1048577,
|
|
30
|
-
INTEGER: 1048578,
|
|
31
|
-
SEGMENTS: 1048580,
|
|
32
|
-
FLOATING_POINT: 1048584,
|
|
33
|
-
DEBUG_REGISTERS: 1048592,
|
|
34
|
-
FULL: 1048587,
|
|
35
|
-
ALL: 1048607
|
|
36
|
-
};
|
|
37
|
-
/** Debug event codes */
|
|
38
|
-
const DEBUG_EVENT_CODE = {
|
|
39
|
-
EXCEPTION_DEBUG_EVENT: 1,
|
|
40
|
-
CREATE_THREAD_DEBUG_EVENT: 2,
|
|
41
|
-
CREATE_PROCESS_DEBUG_EVENT: 3,
|
|
42
|
-
EXIT_THREAD_DEBUG_EVENT: 4,
|
|
43
|
-
EXIT_PROCESS_DEBUG_EVENT: 5,
|
|
44
|
-
LOAD_DLL_DEBUG_EVENT: 6,
|
|
45
|
-
UNLOAD_DLL_DEBUG_EVENT: 7,
|
|
46
|
-
OUTPUT_DEBUG_STRING_EVENT: 8,
|
|
47
|
-
RIP_EVENT: 9
|
|
48
|
-
};
|
|
49
|
-
/** Exception codes */
|
|
50
|
-
const EXCEPTION_CODE = {
|
|
51
|
-
SINGLE_STEP: 2147483652,
|
|
52
|
-
BREAKPOINT: 2147483651,
|
|
53
|
-
ACCESS_VIOLATION: 3221225477
|
|
54
|
-
};
|
|
55
|
-
/** Continue status for ContinueDebugEvent */
|
|
56
|
-
const DBG = {
|
|
57
|
-
CONTINUE: 65538,
|
|
58
|
-
EXCEPTION_NOT_HANDLED: 2147549185,
|
|
59
|
-
REPLY_LATER: 1073807361
|
|
60
|
-
};
|
|
61
|
-
/** TH32CS flags for CreateToolhelp32Snapshot */
|
|
62
|
-
const TH32CS = {
|
|
63
|
-
SNAPHEAPLIST: 1,
|
|
64
|
-
SNAPTHREAD: 4,
|
|
65
|
-
SNAPMODULE: 8
|
|
66
|
-
};
|
|
67
|
-
const CONTEXT_SIZE = 1232;
|
|
68
|
-
/** Parse x64 CONTEXT from raw buffer */
|
|
69
|
-
function parseContext(buf) {
|
|
70
|
-
return {
|
|
71
|
-
contextFlags: buf.readUInt32LE(48),
|
|
72
|
-
eflags: buf.readUInt32LE(68),
|
|
73
|
-
dr0: buf.readBigUInt64LE(72),
|
|
74
|
-
dr1: buf.readBigUInt64LE(80),
|
|
75
|
-
dr2: buf.readBigUInt64LE(88),
|
|
76
|
-
dr3: buf.readBigUInt64LE(96),
|
|
77
|
-
dr6: buf.readBigUInt64LE(104),
|
|
78
|
-
dr7: buf.readBigUInt64LE(112),
|
|
79
|
-
rax: buf.readBigUInt64LE(120),
|
|
80
|
-
rcx: buf.readBigUInt64LE(128),
|
|
81
|
-
rdx: buf.readBigUInt64LE(136),
|
|
82
|
-
rbx: buf.readBigUInt64LE(144),
|
|
83
|
-
rsp: buf.readBigUInt64LE(152),
|
|
84
|
-
rbp: buf.readBigUInt64LE(160),
|
|
85
|
-
rsi: buf.readBigUInt64LE(168),
|
|
86
|
-
rdi: buf.readBigUInt64LE(176),
|
|
87
|
-
r8: buf.readBigUInt64LE(184),
|
|
88
|
-
r9: buf.readBigUInt64LE(192),
|
|
89
|
-
r10: buf.readBigUInt64LE(200),
|
|
90
|
-
r11: buf.readBigUInt64LE(208),
|
|
91
|
-
r12: buf.readBigUInt64LE(216),
|
|
92
|
-
r13: buf.readBigUInt64LE(224),
|
|
93
|
-
r14: buf.readBigUInt64LE(232),
|
|
94
|
-
r15: buf.readBigUInt64LE(240),
|
|
95
|
-
rip: buf.readBigUInt64LE(248)
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
/** Write x64 CONTEXT fields into a raw buffer */
|
|
99
|
-
function writeContext(buf, ctx) {
|
|
100
|
-
if (ctx.contextFlags !== void 0) buf.writeUInt32LE(ctx.contextFlags, 48);
|
|
101
|
-
if (ctx.eflags !== void 0) buf.writeUInt32LE(ctx.eflags, 68);
|
|
102
|
-
if (ctx.dr0 !== void 0) buf.writeBigUInt64LE(ctx.dr0, 72);
|
|
103
|
-
if (ctx.dr1 !== void 0) buf.writeBigUInt64LE(ctx.dr1, 80);
|
|
104
|
-
if (ctx.dr2 !== void 0) buf.writeBigUInt64LE(ctx.dr2, 88);
|
|
105
|
-
if (ctx.dr3 !== void 0) buf.writeBigUInt64LE(ctx.dr3, 96);
|
|
106
|
-
if (ctx.dr6 !== void 0) buf.writeBigUInt64LE(ctx.dr6, 104);
|
|
107
|
-
if (ctx.dr7 !== void 0) buf.writeBigUInt64LE(ctx.dr7, 112);
|
|
108
|
-
if (ctx.rip !== void 0) buf.writeBigUInt64LE(ctx.rip, 248);
|
|
109
|
-
}
|
|
110
|
-
let kernel32Debug = null;
|
|
111
|
-
function getKernel32() {
|
|
112
|
-
if (!kernel32Debug) {
|
|
113
|
-
kernel32Debug = koffi.load("kernel32.dll");
|
|
114
|
-
logger.debug("Loaded kernel32.dll for debug APIs");
|
|
115
|
-
}
|
|
116
|
-
return kernel32Debug;
|
|
117
|
-
}
|
|
118
|
-
/** Open a thread handle */
|
|
119
|
-
function OpenThread(dwDesiredAccess, bInheritHandle, dwThreadId) {
|
|
120
|
-
return getKernel32().func("void * OpenThread(uint32, int, uint32)")(dwDesiredAccess, bInheritHandle ? 1 : 0, dwThreadId);
|
|
121
|
-
}
|
|
122
|
-
/** Suspend a thread, returns previous suspend count */
|
|
123
|
-
function SuspendThread(hThread) {
|
|
124
|
-
const result = getKernel32().func("uint32 SuspendThread(void *)")(hThread);
|
|
125
|
-
if (result === 4294967295) throw new Error(`SuspendThread failed. Error: 0x${GetLastError().toString(16)}`);
|
|
126
|
-
return result;
|
|
127
|
-
}
|
|
128
|
-
/** Resume a thread, returns previous suspend count */
|
|
129
|
-
function ResumeThread(hThread) {
|
|
130
|
-
const result = getKernel32().func("uint32 ResumeThread(void *)")(hThread);
|
|
131
|
-
if (result === 4294967295) throw new Error(`ResumeThread failed. Error: 0x${GetLastError().toString(16)}`);
|
|
132
|
-
return result;
|
|
133
|
-
}
|
|
134
|
-
/** Get thread context (CPU registers including debug registers) */
|
|
135
|
-
function GetThreadContext(hThread, contextFlags) {
|
|
136
|
-
const fn = getKernel32().func("int GetThreadContext(void *, _Inout_ uint8_t[1232])");
|
|
137
|
-
const buf = Buffer.alloc(CONTEXT_SIZE);
|
|
138
|
-
buf.writeUInt32LE(contextFlags, 48);
|
|
139
|
-
if (fn(hThread, buf) === 0) throw new Error(`GetThreadContext failed. Error: 0x${GetLastError().toString(16)}`);
|
|
140
|
-
return buf;
|
|
141
|
-
}
|
|
142
|
-
/** Set thread context (CPU registers including debug registers) */
|
|
143
|
-
function SetThreadContext(hThread, contextBuf) {
|
|
144
|
-
if (getKernel32().func("int SetThreadContext(void *, uint8_t[1232])")(hThread, contextBuf) === 0) throw new Error(`SetThreadContext failed. Error: 0x${GetLastError().toString(16)}`);
|
|
145
|
-
}
|
|
146
|
-
/** Attach as debugger to a process */
|
|
147
|
-
function DebugActiveProcess(dwProcessId) {
|
|
148
|
-
if (getKernel32().func("int DebugActiveProcess(uint32)")(dwProcessId) === 0) throw new Error(`DebugActiveProcess failed for pid ${dwProcessId}. Error: 0x${GetLastError().toString(16)}`);
|
|
149
|
-
}
|
|
150
|
-
/** Detach debugger from process */
|
|
151
|
-
function DebugActiveProcessStop(dwProcessId) {
|
|
152
|
-
if (getKernel32().func("int DebugActiveProcessStop(uint32)")(dwProcessId) === 0) throw new Error(`DebugActiveProcessStop failed. Error: 0x${GetLastError().toString(16)}`);
|
|
153
|
-
}
|
|
154
|
-
/** Don't kill the process when debugger detaches */
|
|
155
|
-
function DebugSetProcessKillOnExit(killOnExit) {
|
|
156
|
-
getKernel32().func("int DebugSetProcessKillOnExit(int)")(killOnExit ? 1 : 0);
|
|
157
|
-
}
|
|
158
|
-
function WaitForDebugEvent(timeoutMs) {
|
|
159
|
-
const fn = getKernel32().func("int WaitForDebugEvent(_Out_ uint8_t[176], uint32)");
|
|
160
|
-
const buf = Buffer.alloc(176);
|
|
161
|
-
if (fn(buf, timeoutMs) === 0) return null;
|
|
162
|
-
const info = {
|
|
163
|
-
debugEventCode: buf.readUInt32LE(0),
|
|
164
|
-
processId: buf.readUInt32LE(4),
|
|
165
|
-
threadId: buf.readUInt32LE(8)
|
|
166
|
-
};
|
|
167
|
-
if (info.debugEventCode === DEBUG_EVENT_CODE.EXCEPTION_DEBUG_EVENT) {
|
|
168
|
-
info.exceptionCode = buf.readUInt32LE(16);
|
|
169
|
-
info.exceptionAddress = buf.readBigUInt64LE(32);
|
|
170
|
-
info.firstChance = buf.readUInt32LE(20) === 0;
|
|
171
|
-
}
|
|
172
|
-
return info;
|
|
173
|
-
}
|
|
174
|
-
/** Continue after handling a debug event */
|
|
175
|
-
function ContinueDebugEvent(dwProcessId, dwThreadId, dwContinueStatus) {
|
|
176
|
-
if (getKernel32().func("int ContinueDebugEvent(uint32, uint32, uint32)")(dwProcessId, dwThreadId, dwContinueStatus) === 0) throw new Error(`ContinueDebugEvent failed. Error: 0x${GetLastError().toString(16)}`);
|
|
177
|
-
}
|
|
178
|
-
/** Flush instruction cache after writing code */
|
|
179
|
-
function FlushInstructionCache(hProcess, lpBaseAddress, dwSize) {
|
|
180
|
-
getKernel32().func("int FlushInstructionCache(void *, void *, size_t)")(hProcess, lpBaseAddress, BigInt(dwSize));
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Enumerate all thread IDs of a process using CreateToolhelp32Snapshot.
|
|
184
|
-
*
|
|
185
|
-
* THREADENTRY32 layout (28 bytes):
|
|
186
|
-
* +0x00: dwSize (uint32)
|
|
187
|
-
* +0x04: cntUsage (uint32)
|
|
188
|
-
* +0x08: th32ThreadID (uint32)
|
|
189
|
-
* +0x0C: th32OwnerProcessID (uint32)
|
|
190
|
-
* +0x10: tpBasePri (int32)
|
|
191
|
-
* +0x14: tpDeltaPri (int32)
|
|
192
|
-
* +0x18: dwFlags (uint32)
|
|
193
|
-
*/
|
|
194
|
-
function EnumerateProcessThreads(pid) {
|
|
195
|
-
const fnSnapshot = getKernel32().func("void * CreateToolhelp32Snapshot(uint32, uint32)");
|
|
196
|
-
const fnFirst = getKernel32().func("int Thread32First(void *, _Inout_ uint8_t[28])");
|
|
197
|
-
const fnNext = getKernel32().func("int Thread32Next(void *, _Inout_ uint8_t[28])");
|
|
198
|
-
const snapshot = fnSnapshot(TH32CS.SNAPTHREAD, 0);
|
|
199
|
-
if (snapshot === 0n || snapshot === BigInt("0xFFFFFFFFFFFFFFFF")) throw new Error(`CreateToolhelp32Snapshot failed. Error: 0x${GetLastError().toString(16)}`);
|
|
200
|
-
const threads = [];
|
|
201
|
-
const entry = Buffer.alloc(28);
|
|
202
|
-
entry.writeUInt32LE(28, 0);
|
|
203
|
-
try {
|
|
204
|
-
if (fnFirst(snapshot, entry) !== 0) do {
|
|
205
|
-
if (entry.readUInt32LE(12) === pid) threads.push(entry.readUInt32LE(8));
|
|
206
|
-
entry.writeUInt32LE(28, 0);
|
|
207
|
-
} while (fnNext(snapshot, entry) !== 0);
|
|
208
|
-
CloseHandle(snapshot);
|
|
209
|
-
} catch (e) {
|
|
210
|
-
console.error("[EnumerateProcessThreads] cleanup error:", e);
|
|
211
|
-
}
|
|
212
|
-
return threads;
|
|
213
|
-
}
|
|
214
|
-
/** Open a thread with debug-appropriate access rights */
|
|
215
|
-
function openThreadForDebug(threadId) {
|
|
216
|
-
const handle = OpenThread(THREAD_ACCESS.SUSPEND_RESUME | THREAD_ACCESS.GET_CONTEXT | THREAD_ACCESS.SET_CONTEXT | THREAD_ACCESS.QUERY_INFORMATION, false, threadId);
|
|
217
|
-
if (handle === 0n) throw new Error(`Failed to open thread ${threadId}. Error: 0x${GetLastError().toString(16)}`);
|
|
218
|
-
return handle;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Encode DR7 breakpoint configuration.
|
|
222
|
-
*
|
|
223
|
-
* DR7 layout (x64):
|
|
224
|
-
* Bits 0-7: Local/Global enable for DR0-DR3 (L0, G0, L1, G1, ...)
|
|
225
|
-
* Bits 16-17: DR0 condition (00=exec, 01=write, 11=readwrite)
|
|
226
|
-
* Bits 18-19: DR0 size (00=1byte, 01=2byte, 11=4byte, 10=8byte)
|
|
227
|
-
* Bits 20-21: DR1 condition
|
|
228
|
-
* Bits 22-23: DR1 size
|
|
229
|
-
* Bits 24-25: DR2 condition
|
|
230
|
-
* Bits 26-27: DR2 size
|
|
231
|
-
* Bits 28-29: DR3 condition
|
|
232
|
-
* Bits 30-31: DR3 size
|
|
233
|
-
*/
|
|
234
|
-
function encodeDR7(entries) {
|
|
235
|
-
let dr7 = 0n;
|
|
236
|
-
for (const entry of entries) {
|
|
237
|
-
if (!entry.enabled) continue;
|
|
238
|
-
const { drIndex, access, size } = entry;
|
|
239
|
-
dr7 |= 1n << BigInt(drIndex * 2);
|
|
240
|
-
let condition = 0;
|
|
241
|
-
switch (access) {
|
|
242
|
-
case "execute":
|
|
243
|
-
condition = 0;
|
|
244
|
-
break;
|
|
245
|
-
case "write":
|
|
246
|
-
condition = 1;
|
|
247
|
-
break;
|
|
248
|
-
case "readwrite":
|
|
249
|
-
case "read":
|
|
250
|
-
condition = 3;
|
|
251
|
-
break;
|
|
252
|
-
}
|
|
253
|
-
dr7 |= BigInt(condition) << BigInt(16 + drIndex * 4);
|
|
254
|
-
let sizeCode = 0;
|
|
255
|
-
switch (size) {
|
|
256
|
-
case 1:
|
|
257
|
-
sizeCode = 0;
|
|
258
|
-
break;
|
|
259
|
-
case 2:
|
|
260
|
-
sizeCode = 1;
|
|
261
|
-
break;
|
|
262
|
-
case 4:
|
|
263
|
-
sizeCode = 3;
|
|
264
|
-
break;
|
|
265
|
-
case 8:
|
|
266
|
-
sizeCode = 2;
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
dr7 |= BigInt(sizeCode) << BigInt(18 + drIndex * 4);
|
|
270
|
-
}
|
|
271
|
-
return dr7;
|
|
272
|
-
}
|
|
273
|
-
//#endregion
|
|
274
|
-
export { openThreadForDebug as _, DebugActiveProcessStop as a, EnumerateProcessThreads as c, ResumeThread as d, SetThreadContext as f, encodeDR7 as g, WaitForDebugEvent as h, DebugActiveProcess as i, FlushInstructionCache as l, TH32CS as m, ContinueDebugEvent as n, DebugSetProcessKillOnExit as o, SuspendThread as p, DBG as r, EXCEPTION_CODE as s, CONTEXT_FLAGS as t, GetThreadContext as u, parseContext as v, writeContext as y };
|