@jshookmcp/jshook 0.2.9 → 0.3.0
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 +2 -2
- package/README.zh.md +2 -2
- package/dist/{AntiCheatDetector-BNk-EoBt.mjs → AntiCheatDetector-CqGDXmfc.mjs} +159 -53
- package/dist/{CodeInjector-Cq8q01kp.mjs → CodeInjector-BdjRfNx7.mjs} +5 -5
- package/dist/{ConsoleMonitor-CPVQW1Y-.mjs → ConsoleMonitor-DykL3IAw.mjs} +85 -17
- package/dist/{DetailedDataManager-BQQcxh64.mjs → DetailedDataManager-HT49OrvF.mjs} +1 -1
- package/dist/{ExtensionManager-CWYgw0YW.mjs → ExtensionManager-BDMsY2Dz.mjs} +15 -8
- package/dist/{HardwareBreakpoint-B9gZCdFP.mjs → HardwareBreakpoint-Cc2AFq1Y.mjs} +3 -3
- package/dist/{HeapAnalyzer-BLDH0dCv.mjs → HeapAnalyzer-DruMgsgj.mjs} +20 -20
- package/dist/{HookGeneratorBuilders.core.generators.storage-CtcdK78Q.mjs → HookGeneratorBuilders.core.generators.storage-CTbB4Lcx.mjs} +1 -74
- package/dist/{InstrumentationSession-CvPC7Jwy.mjs → InstrumentationSession-DLH0vd-z.mjs} +2 -2
- package/dist/{MemoryController-CbVdCIJF.mjs → MemoryController-CMtviNW_.mjs} +3 -3
- package/dist/{MemoryScanSession-BsDZbLYm.mjs → MemoryScanSession-ITgb_NMi.mjs} +2 -2
- package/dist/{MemoryScanner-Bcpml6II.mjs → MemoryScanner-CiL7Z3ey.mjs} +12 -9
- package/dist/{NativeMemoryManager.impl-dZtA1ZGn.mjs → NativeMemoryManager.impl-D9Lkovvn.mjs} +13 -10
- package/dist/{NativeMemoryManager.utils-B-FjA2mJ.mjs → NativeMemoryManager.utils-BBlAixF5.mjs} +1 -1
- package/dist/{PEAnalyzer-D1lzJ_VG.mjs → PEAnalyzer-DMQ44gen.mjs} +15 -15
- package/dist/{PageController-Bqm2kZ_X.mjs → PageController-BPJNqqBN.mjs} +18 -4
- package/dist/{PointerChainEngine-BOhyVsjx.mjs → PointerChainEngine-K7wN8Z-w.mjs} +10 -7
- package/dist/ProcessRegistry-zGg12QbE.mjs +74 -0
- package/dist/{ResponseBuilder-D3iFYx2N.mjs → ResponseBuilder-CJXWmWNw.mjs} +10 -10
- package/dist/{ScriptManager-aHHq0X7U.mjs → ScriptManager-ZuWD-0Jg.mjs} +195 -192
- package/dist/{Speedhack-CqdIFlQl.mjs → Speedhack-D-z0umeT.mjs} +2 -2
- package/dist/{StructureAnalyzer-DhFaPvRO.mjs → StructureAnalyzer-Cav5AVSL.mjs} +9 -6
- package/dist/{ToolCatalog-C0JGZoOm.mjs → ToolCatalog-5OJdMiF0.mjs} +81 -81
- package/dist/{ToolProbe-oC7aPrkv.mjs → ToolProbe-DbCFGyrg.mjs} +1 -1
- package/dist/{ToolRegistry-BjaF4oNz.mjs → ToolRegistry-B9krbTtI.mjs} +51 -2
- package/dist/{ToolRouter.policy-BWV67ZK-.mjs → ToolRouter.policy-BGDAGyeH.mjs} +60 -20
- package/dist/TraceRecorder-B41Z5XBj.mjs +1286 -0
- package/dist/{Win32API-CePkipZY.mjs → Win32API-C2kjj0ze.mjs} +18 -12
- package/dist/{Win32Debug-BvKs-gxc.mjs → Win32Debug-CKrGOTpo.mjs} +2 -2
- package/dist/{WorkflowEngine-CuvkZtWu.mjs → WorkflowEngine-DJ6M4opp.mjs} +226 -255
- package/dist/analysis-BHeJW2Nb.mjs +1234 -0
- package/dist/{antidebug-CqDTB_uk.mjs → antidebug-BRKeyt27.mjs} +3 -3
- package/dist/{artifactRetention-CFEprwPw.mjs → artifactRetention-CPXkUJXp.mjs} +13 -6
- package/dist/{artifacts-Bk2-_uPq.mjs → artifacts-DkfosXH3.mjs} +1 -1
- package/dist/authorization-schema-DRqyJMSk.mjs +31 -0
- package/dist/{binary-instrument-CXfpx6fT.mjs → binary-instrument--V3MAhJ4.mjs} +19 -27
- package/dist/bind-helpers-ClV34xdn.mjs +42 -0
- package/dist/{boringssl-inspector-BH2D3VKc.mjs → boringssl-inspector-Bo_LOLaS.mjs} +1 -1
- package/dist/{browser-BpOr5PEx.mjs → browser-Dx3_S2cG.mjs} +324 -37
- package/dist/capabilities-CcHlvWgK.mjs +33 -0
- package/dist/{constants-B0OANIBL.mjs → constants-CDZLOoVv.mjs} +18 -3
- package/dist/{coordination-qUbyF8KU.mjs → coordination-DgItD9DL.mjs} +2 -2
- package/dist/{debugger-gnKxRSN0.mjs → debugger-RS3RSAqs.mjs} +30 -13
- package/dist/definitions-BEoYofW5.mjs +47 -0
- package/dist/{definitions-bAhHQJq9.mjs → definitions-BRaefg3u.mjs} +11 -5
- package/dist/{definitions-DVGfrn7y.mjs → definitions-BbkvZkiv.mjs} +2 -2
- package/dist/definitions-BtWSHJ3o.mjs +17 -0
- package/dist/{definitions-BMfYXoNC.mjs → definitions-C1gCHO0i.mjs} +1 -1
- package/dist/{definitions-C1UvM5Iy.mjs → definitions-CDOg_b-l.mjs} +14 -2
- package/dist/definitions-CVPD9hzZ.mjs +54 -0
- package/dist/{definitions-Cke7zEb8.mjs → definitions-Cea8Lgl7.mjs} +1 -1
- package/dist/definitions-DAgIyjxM.mjs +10 -0
- package/dist/{definitions-B4rAvHNZ.mjs → definitions-DJA27nsL.mjs} +12 -9
- package/dist/{definitions-ClJLzsJQ.mjs → definitions-DKPFU3LW.mjs} +1 -1
- package/dist/{definitions-D3VsGcvz.mjs → definitions-DPRpZQ96.mjs} +7 -7
- package/dist/{definitions-B18eyf0B.mjs → definitions-DUE5gmdn.mjs} +1 -1
- package/dist/definitions-DYVjOtxa.mjs +26 -0
- package/dist/{definitions-BB_4jnmy.mjs → definitions-DcYLVLCo.mjs} +1 -1
- package/dist/{definitions-Beid2EB3.mjs → definitions-Pp5LI2H4.mjs} +1 -1
- package/dist/definitions-j9KdHVNR.mjs +14 -0
- package/dist/definitions-uzkjBwa7.mjs +258 -0
- package/dist/{definitions-Cq-zroAU.mjs → definitions-va-AnLuQ.mjs} +4 -4
- package/dist/{encoding-Bvz5jLRv.mjs → encoding-DJeqHmpd.mjs} +18 -4
- package/dist/{evidence-graph-bridge-C_fv9PuC.mjs → evidence-graph-bridge-DcYizFk2.mjs} +1 -0
- package/dist/{factory-DxlGh9Xf.mjs → factory-C90tBff6.mjs} +6 -6
- package/dist/flat-target-session-Dgax2Cy3.mjs +29 -0
- package/dist/{graphql-DYWzJ29s.mjs → graphql-CoHrhweh.mjs} +205 -34
- package/dist/{handlers-C67ktuRN.mjs → handlers-4jmR0nMs.mjs} +220 -32
- package/dist/{handlers-DlCJN4Td.mjs → handlers-BAHPxcch.mjs} +122 -90
- package/dist/{handlers-9sAbfIg-.mjs → handlers-BOs9b907.mjs} +849 -801
- package/dist/{handlers-DxGIq15_2.mjs → handlers-BWXEy6ef.mjs} +16 -16
- package/dist/{handlers-tB9Mp9ZK.mjs → handlers-Bndn6QvE.mjs} +31 -4
- package/dist/{handlers-CTsDAO6p.mjs → handlers-BqC4bD4s.mjs} +1 -1
- package/dist/{handlers-C87g8oCe.mjs → handlers-BtYq60bM2.mjs} +1 -1
- package/dist/{handlers-DeLOCd5m.mjs → handlers-BzgcB4iv.mjs} +17 -17
- package/dist/{handlers-Cgyg6c0U.mjs → handlers-CRyRWj2b.mjs} +237 -23
- package/dist/{handlers-U6L4xhuF.mjs → handlers-CVv2H1uq.mjs} +24 -17
- package/dist/{handlers-tiy7EIBp.mjs → handlers-Dl5a7JS4.mjs} +3 -3
- package/dist/{handlers-D6j6yka7.mjs → handlers-Dx2d7jt7.mjs} +1893 -1480
- package/dist/{handlers-Bl8zkwz1.mjs → handlers-Dz9PYsCa.mjs} +95 -6
- package/dist/handlers-HujRKC3b.mjs +661 -0
- package/dist/{handlers.impl-DS0d9fUw.mjs → handlers.impl-XWXkQfyi.mjs} +70 -24
- package/dist/{hooks-CzCWByww.mjs → hooks-B1B8NRHL.mjs} +3 -3
- package/dist/index.mjs +154 -144
- package/dist/{maintenance-P7ePRXQC.mjs → maintenance-PRMkLVRW.mjs} +35 -30
- package/dist/manifest-67Bok-Si.mjs +58 -0
- package/dist/{manifest-B3QVVeBS.mjs → manifest-6lNTMZAB2.mjs} +33 -28
- package/dist/manifest-B2duEHiH.mjs +90 -0
- package/dist/manifest-B6EY9Vm8.mjs +57 -0
- package/dist/{manifest-gZ4s_UtG.mjs → manifest-B6nKSbyY.mjs} +32 -33
- package/dist/{manifest-2ToTpjv8.mjs → manifest-BL8AQNPF.mjs} +31 -31
- package/dist/{manifest-DzwvxPJX.mjs → manifest-BSZvJJmV.mjs} +23 -14
- package/dist/{manifest-Sc_0JQ13.mjs → manifest-BU7qzUyX.mjs} +23 -23
- package/dist/{manifest-CT7zZBV1.mjs → manifest-Bl62e8WK.mjs} +24 -23
- package/dist/manifest-Bo5cXjdt.mjs +82 -0
- package/dist/manifest-BpS4gtUK.mjs +1347 -0
- package/dist/manifest-Bv65_e2W.mjs +101 -0
- package/dist/manifest-BytNIF4Z.mjs +117 -0
- package/dist/{manifest-BqrQ4Tpj.mjs → manifest-C-xtsjS3.mjs} +23 -23
- package/dist/{manifest-NXctwWQq.mjs → manifest-CDYl7OhA.mjs} +36 -38
- package/dist/manifest-CRZ3xmkD.mjs +61 -0
- package/dist/manifest-CoW6u4Tp.mjs +132 -0
- package/dist/manifest-Cq5zN_8A.mjs +50 -0
- package/dist/{manifest-CAhOuvSl.mjs → manifest-D7YZM_2e.mjs} +75 -85
- package/dist/{manifest-DCyjf4n2.mjs → manifest-DE_VrAeQ.mjs} +27 -7
- package/dist/manifest-DGsXSCpT.mjs +39 -0
- package/dist/{manifest-BB2J8IMJ.mjs → manifest-DJ2vfEuW.mjs} +48 -41
- package/dist/{manifest-3g71z6Bg.mjs → manifest-DPXDYhEu.mjs} +26 -25
- package/dist/manifest-Dd4fQb0a.mjs +322 -0
- package/dist/{manifest-CXsRWjjI.mjs → manifest-Deq6opGg.mjs} +95 -96
- package/dist/{manifest-C9RT5nk32.mjs → manifest-DfJTafJK.mjs} +14 -11
- package/dist/manifest-DgOdgN_j.mjs +50 -0
- package/dist/{manifest-BmtZzQiQ2.mjs → manifest-DlbMW4v4.mjs} +17 -15
- package/dist/{manifest-DrbmZcFl2.mjs → manifest-DmVfbH0w.mjs} +212 -91
- package/dist/manifest-Dog6Ddjr.mjs +109 -0
- package/dist/manifest-DvgU5FWb.mjs +58 -0
- package/dist/manifest-HsfDBs7j.mjs +50 -0
- package/dist/manifest-I8oQHvCG.mjs +186 -0
- package/dist/manifest-NvH_a-av.mjs +786 -0
- package/dist/{manifest-Dh8WBmEW.mjs → manifest-cEJU1v0Z.mjs} +24 -24
- package/dist/manifest-wOl5XLB12.mjs +112 -0
- package/dist/{modules-C184v-S9.mjs → modules-tZozf0LQ.mjs} +130 -860
- package/dist/{mojo-ipc-B_H61Afw.mjs → mojo-ipc-DXNEXEqb.mjs} +141 -26
- package/dist/{network-671Cw6hV.mjs → network-CPVvwvFg.mjs} +1329 -823
- package/dist/{outputPaths-B1uGmrWZ.mjs → outputPaths-um7lCRY3.mjs} +4 -8
- package/dist/{platform-WmNn8Sxb.mjs → platform-CYeFoTWp.mjs} +101 -10
- package/dist/{process-QcbIy5Zq.mjs → process-BTbgcVc6.mjs} +251 -346
- package/dist/{proxy-DqNs0bAd.mjs → proxy-r8YN6nP1.mjs} +30 -8
- package/dist/{registry-D-6e18lB.mjs → registry-Bl8ZQW61.mjs} +3 -3
- package/dist/{response-BQVP-xUn.mjs → response-CWhh2aLo.mjs} +7 -1
- package/dist/{shared-state-board-DV-dpHFJ.mjs → shared-state-board-BoZnSoj-.mjs} +2 -2
- package/dist/{sourcemap-Dq8ez8vS.mjs → sourcemap-BIDHUVXy.mjs} +350 -66
- package/dist/{streaming-BUQ0VJsg.mjs → streaming-Dal6utPp.mjs} +13 -13
- package/dist/{tool-builder-DCbIC5Eo.mjs → tool-builder-BHJp32mV.mjs} +1 -1
- package/dist/{transform-CiYJfNX0.mjs → transform-DRVgGG90.mjs} +18 -14
- package/dist/wasm-BYx5UOeG.mjs +1044 -0
- package/dist/webcrack-Be0_FccV.mjs +747 -0
- package/dist/{workflow-f3xJOcjx.mjs → workflow-BpuKEtvn.mjs} +8 -8
- package/package.json +76 -43
- package/dist/TraceRecorder-DgxyVbdQ.mjs +0 -519
- package/dist/analysis-CL9uACt9.mjs +0 -463
- package/dist/bind-helpers-xFfRF-qm.mjs +0 -22
- package/dist/definitions-6M-eejaT.mjs +0 -53
- package/dist/definitions-B3QdlrHv.mjs +0 -34
- 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-Cy3Sl6gV.mjs +0 -34
- package/dist/definitions-LKpC3-nL.mjs +0 -9
- package/dist/handlers-DdFzXLvF.mjs +0 -446
- package/dist/manifest-82baTv4U.mjs +0 -45
- package/dist/manifest-BKbgbSiY.mjs +0 -60
- package/dist/manifest-Bcf-TJzH.mjs +0 -848
- package/dist/manifest-Bnd7kqEY.mjs +0 -55
- package/dist/manifest-BqQX6OQC2.mjs +0 -65
- package/dist/manifest-Br4RPFt5.mjs +0 -370
- package/dist/manifest-C5qDjysN.mjs +0 -107
- package/dist/manifest-CBYWCUBJ.mjs +0 -51
- package/dist/manifest-CFADCRa1.mjs +0 -37
- package/dist/manifest-CQVhavRF.mjs +0 -114
- package/dist/manifest-CV12bcrF.mjs +0 -121
- package/dist/manifest-CZLUCfG02.mjs +0 -95
- package/dist/manifest-D6phHKFd.mjs +0 -131
- package/dist/manifest-DHsnKgP6.mjs +0 -60
- package/dist/manifest-Df_dliIe.mjs +0 -55
- package/dist/manifest-DhKRAT8_.mjs +0 -92
- package/dist/manifest-DlpTj4ic2.mjs +0 -193
- package/dist/manifest-DuwHjUa5.mjs +0 -70
- package/dist/manifest-qSleDqdO.mjs +0 -1023
- package/dist/wasm-DQTnHDs4.mjs +0 -531
- /package/dist/{CacheAdapters-CDe5WPSV.mjs → CacheAdapters-jJFy20G-.mjs} +0 -0
- /package/dist/{DarwinAPI-BNPxu0RH.mjs → DarwinAPI-ETyy0xyo.mjs} +0 -0
- /package/dist/{EventBus-DgPmwpeu.mjs → EventBus-DFKvADm3.mjs} +0 -0
- /package/dist/{EvidenceGraphBridge-SFesNera.mjs → EvidenceGraphBridge-318Oi0Lf.mjs} +0 -0
- /package/dist/{FingerprintManager-gzWtkKuf.mjs → FingerprintManager-BN4UQWnX.mjs} +0 -0
- /package/dist/{PrerequisiteError-Dl33Svkz.mjs → PrerequisiteError-TuyZIs6n.mjs} +0 -0
- /package/dist/{ReverseEvidenceGraph-Dlsk94LC.mjs → ReverseEvidenceGraph-C02-gXOh.mjs} +0 -0
- /package/dist/{StealthVerifier-Bo4T3bz8.mjs → StealthVerifier-BWmPgQsv.mjs} +0 -0
- /package/dist/{VersionDetector-CwVLVdDM.mjs → VersionDetector-K3V4vGsw.mjs} +0 -0
- /package/dist/{betterSqlite3-0pqusHHH.mjs → betterSqlite3-DLSBZodi.mjs} +0 -0
- /package/dist/{concurrency-Bt0yv1kJ.mjs → concurrency-Drev_Vz9.mjs} +0 -0
- /package/dist/{formatAddress-DVkj9kpI.mjs → formatAddress-nnMvEohD.mjs} +0 -0
- /package/dist/{parse-args-BlRjqlkL.mjs → parse-args-B4cY5Vx5.mjs} +0 -0
- /package/dist/{ssrf-policy-ZaUfvhq7.mjs → ssrf-policy-Dsqd-DTX.mjs} +0 -0
- /package/dist/{types-CPhOReNX.mjs → types-DDBWs9UP.mjs} +0 -0
|
@@ -0,0 +1,1234 @@
|
|
|
1
|
+
import { t as logger } from "./logger-Dh_xb7_2.mjs";
|
|
2
|
+
import { d as ANALYSIS_MAX_SAFE_RESPONSE_BYTES, f as ANALYSIS_MAX_SUMMARY_FILES, u as ANALYSIS_MAX_SAFE_COLLECTED_BYTES } from "./constants-CDZLOoVv.mjs";
|
|
3
|
+
import { a as serializeError, n as asJsonResponse, r as asTextResponse, t as asErrorResponse } from "./response-CWhh2aLo.mjs";
|
|
4
|
+
import { a as argString, i as argObject, n as argEnum, r as argNumber, s as argStringRequired, t as argBool } from "./parse-args-B4cY5Vx5.mjs";
|
|
5
|
+
import { s as evaluateWithTimeout } from "./PageController-BPJNqqBN.mjs";
|
|
6
|
+
import "./definitions-CDOg_b-l.mjs";
|
|
7
|
+
import { n as JSVMPDeobfuscator, t as runWebcrack } from "./webcrack-Be0_FccV.mjs";
|
|
8
|
+
import * as parser from "@babel/parser";
|
|
9
|
+
import traverse from "@babel/traverse";
|
|
10
|
+
import * as t from "@babel/types";
|
|
11
|
+
//#region src/server/domains/analysis/handlers/ast-safe-replace.ts
|
|
12
|
+
const REGEX_OPENER_PREV = new Set([
|
|
13
|
+
"=",
|
|
14
|
+
"(",
|
|
15
|
+
"[",
|
|
16
|
+
",",
|
|
17
|
+
";",
|
|
18
|
+
"{",
|
|
19
|
+
"!",
|
|
20
|
+
"&",
|
|
21
|
+
"|",
|
|
22
|
+
"?",
|
|
23
|
+
":",
|
|
24
|
+
"~",
|
|
25
|
+
"^",
|
|
26
|
+
"+",
|
|
27
|
+
"-",
|
|
28
|
+
"*",
|
|
29
|
+
"%",
|
|
30
|
+
"<",
|
|
31
|
+
">",
|
|
32
|
+
"\n"
|
|
33
|
+
]);
|
|
34
|
+
function cloneRegex(pattern) {
|
|
35
|
+
return new RegExp(pattern.source, pattern.flags);
|
|
36
|
+
}
|
|
37
|
+
function mergeProtectedRanges(ranges) {
|
|
38
|
+
if (ranges.length === 0) return [];
|
|
39
|
+
const merged = [];
|
|
40
|
+
const sorted = ranges.toSorted((a, b) => a.start - b.start || a.end - b.end);
|
|
41
|
+
for (const range of sorted) {
|
|
42
|
+
const last = merged[merged.length - 1];
|
|
43
|
+
if (!last || range.start > last.end) {
|
|
44
|
+
merged.push({ ...range });
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
last.end = Math.max(last.end, range.end);
|
|
48
|
+
}
|
|
49
|
+
return merged;
|
|
50
|
+
}
|
|
51
|
+
function collectProtectedRangesWithAst(code) {
|
|
52
|
+
try {
|
|
53
|
+
const ast = parser.parse(code, {
|
|
54
|
+
sourceType: "unambiguous",
|
|
55
|
+
plugins: ["jsx", "typescript"],
|
|
56
|
+
errorRecovery: true
|
|
57
|
+
});
|
|
58
|
+
const ranges = [];
|
|
59
|
+
const pushRange = (start, end) => {
|
|
60
|
+
if (typeof start === "number" && typeof end === "number" && end > start) ranges.push({
|
|
61
|
+
start,
|
|
62
|
+
end
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const comments = Array.isArray(ast.comments) ? ast.comments : [];
|
|
66
|
+
for (const comment of comments) pushRange(comment.start, comment.end);
|
|
67
|
+
traverse(ast, {
|
|
68
|
+
StringLiteral(path) {
|
|
69
|
+
pushRange(path.node.start, path.node.end);
|
|
70
|
+
path.skip();
|
|
71
|
+
},
|
|
72
|
+
TemplateElement(path) {
|
|
73
|
+
pushRange(path.node.start, path.node.end);
|
|
74
|
+
path.skip();
|
|
75
|
+
},
|
|
76
|
+
RegExpLiteral(path) {
|
|
77
|
+
pushRange(path.node.start, path.node.end);
|
|
78
|
+
path.skip();
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return mergeProtectedRanges(ranges);
|
|
82
|
+
} catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function getReplaceCallbackOffset(args) {
|
|
87
|
+
const maybeOffset = args[args.length - 2];
|
|
88
|
+
if (typeof maybeOffset === "number") return maybeOffset;
|
|
89
|
+
const fallbackOffset = args[args.length - 3];
|
|
90
|
+
return typeof fallbackOffset === "number" ? fallbackOffset : null;
|
|
91
|
+
}
|
|
92
|
+
function isRegexOpener(code, pos) {
|
|
93
|
+
let prevIndex = pos - 1;
|
|
94
|
+
while (prevIndex >= 0 && (code[prevIndex] === " " || code[prevIndex] === " " || code[prevIndex] === "\r")) prevIndex--;
|
|
95
|
+
if (prevIndex < 0) return true;
|
|
96
|
+
const prev = code[prevIndex];
|
|
97
|
+
if (REGEX_OPENER_PREV.has(prev)) return true;
|
|
98
|
+
if (prev !== ")") return false;
|
|
99
|
+
let depth = 1;
|
|
100
|
+
let keywordIndex = prevIndex - 1;
|
|
101
|
+
while (keywordIndex >= 0 && depth > 0) {
|
|
102
|
+
if (code[keywordIndex] === ")") depth++;
|
|
103
|
+
if (code[keywordIndex] === "(") depth--;
|
|
104
|
+
keywordIndex--;
|
|
105
|
+
}
|
|
106
|
+
keywordIndex--;
|
|
107
|
+
while (keywordIndex >= 0 && (code[keywordIndex] === " " || code[keywordIndex] === " ")) keywordIndex--;
|
|
108
|
+
let keyword = "";
|
|
109
|
+
while (keywordIndex >= 0 && /[a-z]/.test(code[keywordIndex])) {
|
|
110
|
+
keyword = code[keywordIndex] + keyword;
|
|
111
|
+
keywordIndex--;
|
|
112
|
+
}
|
|
113
|
+
return [
|
|
114
|
+
"if",
|
|
115
|
+
"while",
|
|
116
|
+
"for",
|
|
117
|
+
"switch",
|
|
118
|
+
"return",
|
|
119
|
+
"typeof",
|
|
120
|
+
"void",
|
|
121
|
+
"in",
|
|
122
|
+
"of",
|
|
123
|
+
"case"
|
|
124
|
+
].includes(keyword);
|
|
125
|
+
}
|
|
126
|
+
function insideStringLiteralOrComment(code, offset) {
|
|
127
|
+
let inStr = null;
|
|
128
|
+
let inBlockComment = false;
|
|
129
|
+
let inLineComment = false;
|
|
130
|
+
let inRegex = false;
|
|
131
|
+
for (let index = 0; index < offset; index++) {
|
|
132
|
+
const char = code[index];
|
|
133
|
+
if (inBlockComment) {
|
|
134
|
+
if (char === "*" && code[index + 1] === "/") {
|
|
135
|
+
inBlockComment = false;
|
|
136
|
+
index++;
|
|
137
|
+
}
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (inLineComment) {
|
|
141
|
+
if (char === "\n") inLineComment = false;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (inRegex) {
|
|
145
|
+
if (char === "\\") {
|
|
146
|
+
index++;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (char === "/") {
|
|
150
|
+
inRegex = false;
|
|
151
|
+
index++;
|
|
152
|
+
while (index < offset && /[gimsuy]/.test(code[index])) index++;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (char === "[") {
|
|
156
|
+
index++;
|
|
157
|
+
while (index < offset && code[index] !== "]") {
|
|
158
|
+
if (code[index] === "\\") index++;
|
|
159
|
+
index++;
|
|
160
|
+
}
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (inStr) {
|
|
166
|
+
if (char === "\\") {
|
|
167
|
+
index++;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (char === inStr) inStr = null;
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (char === "/" && code[index + 1] === "/") {
|
|
174
|
+
inLineComment = true;
|
|
175
|
+
index++;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (char === "/" && code[index + 1] === "*") {
|
|
179
|
+
inBlockComment = true;
|
|
180
|
+
index++;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (char === "/" && isRegexOpener(code, index)) {
|
|
184
|
+
inRegex = true;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (char === "'" || char === "\"" || char === "`") inStr = char;
|
|
188
|
+
}
|
|
189
|
+
return inStr !== null || inBlockComment || inLineComment || inRegex;
|
|
190
|
+
}
|
|
191
|
+
function replaceOutsideProtectedRanges(code, pattern, replacement) {
|
|
192
|
+
const applyReplacement = (input) => typeof replacement === "string" ? input.replace(cloneRegex(pattern), replacement) : input.replace(cloneRegex(pattern), replacement);
|
|
193
|
+
const protectedRanges = collectProtectedRangesWithAst(code);
|
|
194
|
+
if (protectedRanges === null) return code.replace(cloneRegex(pattern), (...args) => {
|
|
195
|
+
const fullMatch = typeof args[0] === "string" ? args[0] : "";
|
|
196
|
+
const offset = getReplaceCallbackOffset(args);
|
|
197
|
+
if (offset !== null && insideStringLiteralOrComment(code, offset)) return fullMatch;
|
|
198
|
+
return typeof replacement === "string" ? replacement : replacement(fullMatch, ...args.slice(1));
|
|
199
|
+
});
|
|
200
|
+
if (protectedRanges.length === 0) return applyReplacement(code);
|
|
201
|
+
let rewritten = "";
|
|
202
|
+
let cursor = 0;
|
|
203
|
+
for (const range of protectedRanges) {
|
|
204
|
+
if (cursor < range.start) rewritten += applyReplacement(code.slice(cursor, range.start));
|
|
205
|
+
rewritten += code.slice(range.start, range.end);
|
|
206
|
+
cursor = range.end;
|
|
207
|
+
}
|
|
208
|
+
if (cursor < code.length) rewritten += applyReplacement(code.slice(cursor));
|
|
209
|
+
return rewritten;
|
|
210
|
+
}
|
|
211
|
+
//#endregion
|
|
212
|
+
//#region src/server/domains/analysis/handlers/inline-deobfuscation.ts
|
|
213
|
+
const NUMERIC_BINARY_EXPR = /\b(-?\d+(?:\.\d+)?)\s*([+\-%*/])\s*(-?\d+(?:\.\d+)?)\b/g;
|
|
214
|
+
const DEAD_CODE_IF_FALSE = /if\s*\(\s*false\s*\)\s*\{[^}]*\}\s*/g;
|
|
215
|
+
const DEAD_CODE_IF_FALSE_WITH_ELSE = /if\s*\(\s*false\s*\)\s*\{[^}]*\}\s*else\s*\{([^}]*)\}/g;
|
|
216
|
+
const DEAD_CODE_IF_TRUE = /if\s*\(\s*true\s*\)\s*\{([^}]*)\}\s*(?:else\s*\{[^}]*\}\s*)?/g;
|
|
217
|
+
const CFF_PATTERN = /var\s+([A-Za-z_$]\w*)\s*=\s*['"]([^'"]+)['"]\.split\(['"]\|['"]\)\s*;\s*var\s+(\w+)\s*=\s*0\s*;\s*while\s*\(\s*!!\[\]\s*\)\s*\{\s*switch\s*\(\s*\1\[\s*\3\+\+\s*\]\s*\)\s*\{([\s\S]*?)\}\s*break;\s*\}/g;
|
|
218
|
+
const CFF_PATTERN_VAR2 = /var\s+([A-Za-z_$]\w*)\s*=\s*\[(['"][^'"]*['"]\s*(?:,\s*['"][^'"]*['"]\s*)*)\];\s*var\s+(\w+)\s*=\s*(\d+);\s*while\s*\(\s*!!\[\]\s*\)\s*\{\s*switch\s*\(\s*\1\[\s*\3\+\+\]\s*\)\s*\{([\s\S]*?)\}\s*break;\s*\}/g;
|
|
219
|
+
const STRING_CONCAT = /['"]([^'"]*)['"]\s*\+\s*['"]([^'"]*)['"]/g;
|
|
220
|
+
function findNonWhitespace(input, start, step) {
|
|
221
|
+
for (let index = start; index >= 0 && index < input.length; index += step) {
|
|
222
|
+
const char = input[index];
|
|
223
|
+
if (char && !/\s/.test(char)) return char;
|
|
224
|
+
}
|
|
225
|
+
return "";
|
|
226
|
+
}
|
|
227
|
+
function applyTextReplacements(code, replacements) {
|
|
228
|
+
const sorted = replacements.toSorted((a, b) => b.start - a.start || b.end - a.end);
|
|
229
|
+
let next = code;
|
|
230
|
+
for (const replacement of sorted) next = `${next.slice(0, replacement.start)}${replacement.text}${next.slice(replacement.end)}`;
|
|
231
|
+
return next;
|
|
232
|
+
}
|
|
233
|
+
function getBindingReplacement(path, renameMap) {
|
|
234
|
+
const replacement = renameMap.get(path.node.name);
|
|
235
|
+
if (!replacement) return null;
|
|
236
|
+
const binding = path.scope.getBinding(path.node.name);
|
|
237
|
+
if (!binding || !t.isVariableDeclarator(binding.path.node) || !t.isIdentifier(binding.path.node.id) || !renameMap.has(binding.path.node.id.name)) return null;
|
|
238
|
+
const isBindingId = binding.identifier === path.node;
|
|
239
|
+
const isReference = path.isReferencedIdentifier();
|
|
240
|
+
const isAssignmentTarget = path.key === "left" && path.parentPath.isAssignmentExpression();
|
|
241
|
+
const isForLoopTarget = path.key === "left" && (path.parentPath.isForInStatement() || path.parentPath.isForOfStatement());
|
|
242
|
+
const isUpdateTarget = path.key === "argument" && path.parentPath.isUpdateExpression();
|
|
243
|
+
if (!isBindingId && !isReference && !isAssignmentTarget && !isForLoopTarget && !isUpdateTarget) return null;
|
|
244
|
+
return replacement;
|
|
245
|
+
}
|
|
246
|
+
function applyRenameVarsWithAst(code, renameMap) {
|
|
247
|
+
try {
|
|
248
|
+
const ast = parser.parse(code, {
|
|
249
|
+
sourceType: "unambiguous",
|
|
250
|
+
plugins: ["jsx", "typescript"],
|
|
251
|
+
errorRecovery: true
|
|
252
|
+
});
|
|
253
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
254
|
+
traverse(ast, {
|
|
255
|
+
ObjectProperty(path) {
|
|
256
|
+
if (!path.node.shorthand || !t.isIdentifier(path.node.key) || !t.isIdentifier(path.node.value)) return;
|
|
257
|
+
const valuePath = path.get("value");
|
|
258
|
+
if (!valuePath.isIdentifier()) return;
|
|
259
|
+
const replacement = getBindingReplacement(valuePath, renameMap);
|
|
260
|
+
const { start, end } = path.node;
|
|
261
|
+
if (!replacement || start === null || start === void 0) return;
|
|
262
|
+
if (end === null || end === void 0) return;
|
|
263
|
+
replacements.set(`${start}:${end}`, {
|
|
264
|
+
start,
|
|
265
|
+
end,
|
|
266
|
+
text: `${path.node.key.name}: ${replacement}`
|
|
267
|
+
});
|
|
268
|
+
path.skip();
|
|
269
|
+
},
|
|
270
|
+
Identifier(path) {
|
|
271
|
+
const replacement = getBindingReplacement(path, renameMap);
|
|
272
|
+
const { start, end } = path.node;
|
|
273
|
+
if (!replacement || start === null || start === void 0) return;
|
|
274
|
+
if (end === null || end === void 0) return;
|
|
275
|
+
replacements.set(`${start}:${end}`, {
|
|
276
|
+
start,
|
|
277
|
+
end,
|
|
278
|
+
text: replacement
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
if (replacements.size === 0) return code;
|
|
283
|
+
return applyTextReplacements(code, [...replacements.values()]);
|
|
284
|
+
} catch {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function applyConstantFold(code) {
|
|
289
|
+
let result = code;
|
|
290
|
+
result = replaceOutsideProtectedRanges(result, NUMERIC_BINARY_EXPR, (_full, leftRaw, op, rightRaw) => {
|
|
291
|
+
const left = Number(leftRaw);
|
|
292
|
+
const right = Number(rightRaw);
|
|
293
|
+
if (!Number.isFinite(left) || !Number.isFinite(right)) return _full;
|
|
294
|
+
let value = null;
|
|
295
|
+
if (op === "+") value = left + right;
|
|
296
|
+
else if (op === "-") value = left - right;
|
|
297
|
+
else if (op === "*") value = left * right;
|
|
298
|
+
else if (op === "/" && right !== 0) value = left / right;
|
|
299
|
+
else if (op === "%" && right !== 0) value = left % right;
|
|
300
|
+
if (value === null || !Number.isFinite(value)) return _full;
|
|
301
|
+
return Number.isInteger(value) ? String(value) : String(Number(value.toFixed(12)));
|
|
302
|
+
});
|
|
303
|
+
result = replaceOutsideProtectedRanges(result, STRING_CONCAT, (_full, left, right) => JSON.stringify(`${left}${right}`));
|
|
304
|
+
result = replaceOutsideProtectedRanges(result, /--(\d)/g, (_full, digit) => digit);
|
|
305
|
+
result = replaceOutsideProtectedRanges(result, /\+\s*(\d+(?:\.\d+)?)/g, (_full, num) => num);
|
|
306
|
+
result = replaceOutsideProtectedRanges(result, /\b0x([0-9a-fA-F]{2,8})\b/g, (_full, hex) => {
|
|
307
|
+
const value = Number.parseInt(hex, 16);
|
|
308
|
+
return Number.isFinite(value) ? String(value) : _full;
|
|
309
|
+
});
|
|
310
|
+
return result;
|
|
311
|
+
}
|
|
312
|
+
function applyDeadCodeRemove(code) {
|
|
313
|
+
let result = code;
|
|
314
|
+
result = replaceOutsideProtectedRanges(result, DEAD_CODE_IF_FALSE_WITH_ELSE, (_full, elseBody) => elseBody);
|
|
315
|
+
result = replaceOutsideProtectedRanges(result, DEAD_CODE_IF_FALSE, "");
|
|
316
|
+
result = replaceOutsideProtectedRanges(result, DEAD_CODE_IF_TRUE, (_full, trueBody) => trueBody);
|
|
317
|
+
result = replaceOutsideProtectedRanges(result, /\btrue\s*\?\s*([^:]+)\s*:\s*([^,;)\]}]+)/g, (_full, ifVal) => ifVal);
|
|
318
|
+
result = replaceOutsideProtectedRanges(result, /\bfalse\s*\?\s*[^:]+\s*:\s*([^,;)}\]]+)/g, (_full, elseVal) => elseVal);
|
|
319
|
+
result = replaceOutsideProtectedRanges(result, /if\s*\([^)]*\)\s*\{\s*\}\s*/g, "");
|
|
320
|
+
return result;
|
|
321
|
+
}
|
|
322
|
+
function applyControlFlowFlatten(code) {
|
|
323
|
+
let result = code;
|
|
324
|
+
result = replaceOutsideProtectedRanges(result, CFF_PATTERN, (_full, _dispatcher, orderRaw, _cursor, switchBody) => {
|
|
325
|
+
const caseRegex = /case\s*['"]([^'"]+)['"]\s*:\s*([\s\S]*?)(?=case\s*['"]|default\s*:|$)/g;
|
|
326
|
+
const caseMap = /* @__PURE__ */ new Map();
|
|
327
|
+
let match;
|
|
328
|
+
while ((match = caseRegex.exec(switchBody)) !== null) {
|
|
329
|
+
const key = match[1];
|
|
330
|
+
const body = (match[2] ?? "").replace(/\bcontinue\s*;?/g, "").replace(/\bbreak\s*;?/g, "").trim();
|
|
331
|
+
if (key && body.length > 0) caseMap.set(key, body);
|
|
332
|
+
}
|
|
333
|
+
const rebuilt = orderRaw.split("|").map((value) => value.trim()).map((token) => caseMap.get(token)).filter((value) => !!value).join("\n");
|
|
334
|
+
return rebuilt.length > 0 ? rebuilt : _full;
|
|
335
|
+
});
|
|
336
|
+
result = replaceOutsideProtectedRanges(result, CFF_PATTERN_VAR2, (_full, _dispatcher, arrContent, _cursor, _startIdx, switchBody) => {
|
|
337
|
+
const caseRegex = /case\s*['"]([^'"]+)['"]\s*:\s*([\s\S]*?)(?=case\s*['"]|default\s*:|$)/g;
|
|
338
|
+
const caseMap = /* @__PURE__ */ new Map();
|
|
339
|
+
let match;
|
|
340
|
+
while ((match = caseRegex.exec(switchBody)) !== null) {
|
|
341
|
+
const key = match[1];
|
|
342
|
+
const body = (match[2] ?? "").replace(/\bcontinue\s*;?/g, "").replace(/\bbreak\s*;?/g, "").trim();
|
|
343
|
+
if (key && body.length > 0) caseMap.set(key, body);
|
|
344
|
+
}
|
|
345
|
+
const rebuilt = arrContent.split(/,\s*/).map((value) => value.replace(/^['"]|['"]$/g, "").trim()).map((token) => caseMap.get(token)).filter((value) => !!value).join("\n");
|
|
346
|
+
return rebuilt.length > 0 ? rebuilt : _full;
|
|
347
|
+
});
|
|
348
|
+
return result;
|
|
349
|
+
}
|
|
350
|
+
function applyRenameVars(code) {
|
|
351
|
+
const declared = /* @__PURE__ */ new Set();
|
|
352
|
+
const re = /\b(?:var|let|const)\s+([A-Za-z_$]\w{0,3})\b/g;
|
|
353
|
+
let match;
|
|
354
|
+
while ((match = re.exec(code)) !== null) {
|
|
355
|
+
const name = match[1];
|
|
356
|
+
if (name && (name.length <= 2 || name.startsWith("_0x") || name.startsWith("_"))) declared.add(name);
|
|
357
|
+
}
|
|
358
|
+
if (declared.size === 0) return {
|
|
359
|
+
code,
|
|
360
|
+
count: 0
|
|
361
|
+
};
|
|
362
|
+
const renameMap = /* @__PURE__ */ new Map();
|
|
363
|
+
let counter = 1;
|
|
364
|
+
for (const name of declared) {
|
|
365
|
+
renameMap.set(name, `var_${counter}`);
|
|
366
|
+
counter++;
|
|
367
|
+
}
|
|
368
|
+
const astRenamed = applyRenameVarsWithAst(code, renameMap);
|
|
369
|
+
if (astRenamed !== null) return {
|
|
370
|
+
code: astRenamed,
|
|
371
|
+
count: astRenamed === code ? 0 : renameMap.size
|
|
372
|
+
};
|
|
373
|
+
const newCode = code.replace(new RegExp(`\\b(${[...declared].map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})\\b`, "g"), (token, id, offset, full) => {
|
|
374
|
+
const replacement = renameMap.get(id);
|
|
375
|
+
if (!replacement) return token;
|
|
376
|
+
const prev = offset > 0 ? full[offset - 1] : "";
|
|
377
|
+
const prevNonWhitespace = findNonWhitespace(full, offset - 1, -1);
|
|
378
|
+
const nextNonWhitespace = findNonWhitespace(full, offset + token.length, 1);
|
|
379
|
+
if (prev === "." || prev === "'" || prev === "\"" || prev === "`" || prev === "$") return token;
|
|
380
|
+
if ((prevNonWhitespace === "{" || prevNonWhitespace === ",") && (nextNonWhitespace === ":" || nextNonWhitespace === "(")) return token;
|
|
381
|
+
return replacement;
|
|
382
|
+
});
|
|
383
|
+
return {
|
|
384
|
+
code: newCode,
|
|
385
|
+
count: newCode === code ? 0 : renameMap.size
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
//#endregion
|
|
389
|
+
//#region src/server/domains/analysis/handlers/solve-constraints.ts
|
|
390
|
+
const NUMERIC_COMPARATORS = {
|
|
391
|
+
"<": (left, right) => left < right,
|
|
392
|
+
">": (left, right) => left > right,
|
|
393
|
+
"<=": (left, right) => left <= right,
|
|
394
|
+
"<==": (left, right) => left <= right,
|
|
395
|
+
">=": (left, right) => left >= right,
|
|
396
|
+
">==": (left, right) => left >= right,
|
|
397
|
+
"==": (left, right) => left === right,
|
|
398
|
+
"===": (left, right) => left === right,
|
|
399
|
+
"!=": (left, right) => left !== right,
|
|
400
|
+
"!==": (left, right) => left !== right
|
|
401
|
+
};
|
|
402
|
+
const JS_FUCK_RULES = [
|
|
403
|
+
{
|
|
404
|
+
pattern: "jsfuck",
|
|
405
|
+
regex: /\[!\[\]\]\[\(['"]\)constructor['"]\)\]\(!!\[\]\+\[\]\)\(\)/g,
|
|
406
|
+
replacement: "\"function Boolean() { [native code] }\""
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
pattern: "jsfuck",
|
|
410
|
+
regex: /!!\[\]\+\[\]/g,
|
|
411
|
+
replacement: "\"true\""
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
pattern: "jsfuck",
|
|
415
|
+
regex: /!\[\]\+\[\]/g,
|
|
416
|
+
replacement: "\"false\""
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
pattern: "jsfuck",
|
|
420
|
+
regex: /\+!!\[\]/g,
|
|
421
|
+
replacement: "1"
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
pattern: "jsfuck",
|
|
425
|
+
regex: /\[\]\+\[\]/g,
|
|
426
|
+
replacement: "\"\""
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
pattern: "jsfuck",
|
|
430
|
+
regex: /\+\[\]/g,
|
|
431
|
+
replacement: "0"
|
|
432
|
+
}
|
|
433
|
+
];
|
|
434
|
+
const BOOLEAN_LITERAL_RULES = [
|
|
435
|
+
{
|
|
436
|
+
pattern: "boolean-literal",
|
|
437
|
+
regex: /!!\[\]/g,
|
|
438
|
+
replacement: "true"
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
pattern: "boolean-literal",
|
|
442
|
+
regex: /!\[\]/g,
|
|
443
|
+
replacement: "false"
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
pattern: "undefined-literal",
|
|
447
|
+
regex: /void\s+0/g,
|
|
448
|
+
replacement: "undefined"
|
|
449
|
+
}
|
|
450
|
+
];
|
|
451
|
+
const OPAQUE_TRUTHY_RULE = {
|
|
452
|
+
pattern: "opaque-truthy",
|
|
453
|
+
regex: /!0x0\b|!\b0(?![.\d])/g,
|
|
454
|
+
replacement: "true"
|
|
455
|
+
};
|
|
456
|
+
const TYPE_COERCION_RULES = [
|
|
457
|
+
{
|
|
458
|
+
pattern: "type-coercion",
|
|
459
|
+
regex: /typeof\s+undefined\s*===?\s*["']undefined["']/g,
|
|
460
|
+
replacement: "true"
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
pattern: "type-coercion",
|
|
464
|
+
regex: /typeof\s+null\s*===?\s*["']object["']/g,
|
|
465
|
+
replacement: "true"
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
pattern: "type-coercion",
|
|
469
|
+
regex: /typeof\s+NaN\s*===?\s*["']number["']/g,
|
|
470
|
+
replacement: "true"
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
pattern: "type-coercion",
|
|
474
|
+
regex: /null\s*==\s*undefined/g,
|
|
475
|
+
replacement: "true"
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
pattern: "type-coercion",
|
|
479
|
+
regex: /null\s*===\s*undefined/g,
|
|
480
|
+
replacement: "false"
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
pattern: "type-coercion",
|
|
484
|
+
regex: /NaN\s*===?\s*NaN/g,
|
|
485
|
+
replacement: "false"
|
|
486
|
+
}
|
|
487
|
+
];
|
|
488
|
+
const CONSTANT_COMPARISON_PATTERN = /if\s*\(\s*(-?\d+(?:\.\d+)?)\s*([<>!=]+)\s*(-?\d+(?:\.\d+)?)\s*\)/g;
|
|
489
|
+
const OPAQUE_FALSY_PATTERN = /!\s*(-?\d+(?:\.\d+)?)(?![.\d\s\w])/g;
|
|
490
|
+
const STRING_ARRAY_DECLARATION_PATTERN = /(?:var|let|const)\s+(\w+)\s*=\s*\[(['"][^'"]*['"]\s*(?:,\s*['"][^'"]*['"]\s*)*)\]/g;
|
|
491
|
+
function recordSolve(state, pattern, original, result) {
|
|
492
|
+
state.solved.push({
|
|
493
|
+
pattern,
|
|
494
|
+
original,
|
|
495
|
+
result
|
|
496
|
+
});
|
|
497
|
+
return result;
|
|
498
|
+
}
|
|
499
|
+
function applyStaticRules(state, rules) {
|
|
500
|
+
for (const rule of rules) state.output = replaceOutsideProtectedRanges(state.output, rule.regex, (fullMatch) => recordSolve(state, rule.pattern, fullMatch, rule.replacement));
|
|
501
|
+
}
|
|
502
|
+
function applyConstantComparisons(state) {
|
|
503
|
+
state.output = replaceOutsideProtectedRanges(state.output, CONSTANT_COMPARISON_PATTERN, (fullMatch, leftRaw, operator, rightRaw) => {
|
|
504
|
+
if (state.iterations >= state.maxIterations) return fullMatch;
|
|
505
|
+
const compare = NUMERIC_COMPARATORS[operator];
|
|
506
|
+
if (!compare) return fullMatch;
|
|
507
|
+
state.iterations += 1;
|
|
508
|
+
const result = compare(Number(leftRaw), Number(rightRaw));
|
|
509
|
+
recordSolve(state, "constant-comparison", fullMatch, String(result));
|
|
510
|
+
return state.replaceInPlace ? `/* ${fullMatch} => ${result} */ if (${result})` : `if (${result})`;
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
function applyOpaqueFalsyRules(state) {
|
|
514
|
+
state.output = replaceOutsideProtectedRanges(state.output, OPAQUE_FALSY_PATTERN, (fullMatch, numericRaw) => {
|
|
515
|
+
const numericValue = Number(numericRaw);
|
|
516
|
+
if (numericValue === 0 || !Number.isFinite(numericValue)) return fullMatch;
|
|
517
|
+
return recordSolve(state, "opaque-falsy", fullMatch, "false");
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
function escapeRegExp(value) {
|
|
521
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
522
|
+
}
|
|
523
|
+
function collectStringArrays(output) {
|
|
524
|
+
const stringArrays = /* @__PURE__ */ new Map();
|
|
525
|
+
replaceOutsideProtectedRanges(output, STRING_ARRAY_DECLARATION_PATTERN, (fullMatch, name, arrayContent) => {
|
|
526
|
+
const items = arrayContent.split(/,\s*/).map((item) => item.replace(/^['"]|['"]$/g, ""));
|
|
527
|
+
stringArrays.set(name, items);
|
|
528
|
+
return fullMatch;
|
|
529
|
+
});
|
|
530
|
+
return stringArrays;
|
|
531
|
+
}
|
|
532
|
+
function applyStringArrayAccesses(state) {
|
|
533
|
+
const stringArrays = collectStringArrays(state.output);
|
|
534
|
+
if (stringArrays.size === 0) return;
|
|
535
|
+
for (const [name, items] of stringArrays) {
|
|
536
|
+
const accessPattern = new RegExp(`${escapeRegExp(name)}\\(['"]?(0x[0-9a-fA-F]+|\\d+)['"]?\\)`, "g");
|
|
537
|
+
state.output = replaceOutsideProtectedRanges(state.output, accessPattern, (fullMatch, rawIndex) => {
|
|
538
|
+
if (state.iterations >= state.maxIterations) return fullMatch;
|
|
539
|
+
const index = rawIndex.startsWith("0x") ? Number.parseInt(rawIndex, 16) : Number(rawIndex);
|
|
540
|
+
if (index < 0 || index >= items.length) return fullMatch;
|
|
541
|
+
state.iterations += 1;
|
|
542
|
+
return recordSolve(state, "string-array-access", fullMatch, JSON.stringify(items[index]));
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
function solveConstraints(options) {
|
|
547
|
+
const state = {
|
|
548
|
+
output: options.code,
|
|
549
|
+
solved: [],
|
|
550
|
+
replaceInPlace: options.replaceInPlace,
|
|
551
|
+
maxIterations: options.maxIterations,
|
|
552
|
+
iterations: 0
|
|
553
|
+
};
|
|
554
|
+
applyConstantComparisons(state);
|
|
555
|
+
applyStaticRules(state, JS_FUCK_RULES);
|
|
556
|
+
applyStaticRules(state, BOOLEAN_LITERAL_RULES);
|
|
557
|
+
applyStaticRules(state, [OPAQUE_TRUTHY_RULE]);
|
|
558
|
+
applyOpaqueFalsyRules(state);
|
|
559
|
+
applyStringArrayAccesses(state);
|
|
560
|
+
applyStaticRules(state, TYPE_COERCION_RULES);
|
|
561
|
+
return {
|
|
562
|
+
success: true,
|
|
563
|
+
solvedCount: state.solved.length,
|
|
564
|
+
solved: state.solved,
|
|
565
|
+
transformedCode: options.replaceInPlace ? state.output : void 0
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
//#endregion
|
|
569
|
+
//#region src/server/domains/analysis/handlers/vm-analysis.ts
|
|
570
|
+
const VM_DISPATCH_PATTERNS = [
|
|
571
|
+
{
|
|
572
|
+
type: "for-switch",
|
|
573
|
+
test: /for.*switch/s
|
|
574
|
+
},
|
|
575
|
+
{
|
|
576
|
+
type: "while-switch",
|
|
577
|
+
test: /while.*switch/s
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
type: "if-else-chain",
|
|
581
|
+
test: /if\s*\(\s*\w+\s*===?\s*\w+/
|
|
582
|
+
}
|
|
583
|
+
];
|
|
584
|
+
function detectVmDispatchType(code) {
|
|
585
|
+
for (const pattern of VM_DISPATCH_PATTERNS) if (pattern.test.test(code)) return pattern.type;
|
|
586
|
+
return "switch";
|
|
587
|
+
}
|
|
588
|
+
function buildOpcodeDistribution(instructions) {
|
|
589
|
+
const distribution = /* @__PURE__ */ new Map();
|
|
590
|
+
for (const instruction of instructions) {
|
|
591
|
+
const type = instruction.type || "unknown";
|
|
592
|
+
distribution.set(type, (distribution.get(type) || 0) + 1);
|
|
593
|
+
}
|
|
594
|
+
return Object.fromEntries(distribution);
|
|
595
|
+
}
|
|
596
|
+
function buildVmAnalysisResponse(options) {
|
|
597
|
+
const { code, extractBytecode, mapOpcodes, vmResult } = options;
|
|
598
|
+
if (!vmResult.isJSVMP) return {
|
|
599
|
+
success: true,
|
|
600
|
+
isVM: false,
|
|
601
|
+
message: "No VM/JSVMP patterns detected."
|
|
602
|
+
};
|
|
603
|
+
const analysis = {
|
|
604
|
+
isVM: true,
|
|
605
|
+
vmType: vmResult.vmType,
|
|
606
|
+
dispatchType: detectVmDispatchType(code),
|
|
607
|
+
complexity: vmResult.vmFeatures?.complexity,
|
|
608
|
+
instructionCount: vmResult.vmFeatures?.instructionCount,
|
|
609
|
+
interpreterLocation: vmResult.vmFeatures?.interpreterLocation
|
|
610
|
+
};
|
|
611
|
+
if (extractBytecode && vmResult.instructions) analysis.bytecode = vmResult.instructions;
|
|
612
|
+
if (mapOpcodes && vmResult.instructions) {
|
|
613
|
+
analysis.opcodeDistribution = buildOpcodeDistribution(vmResult.instructions);
|
|
614
|
+
analysis.suggestedStrategy = vmResult.vmFeatures?.complexity === "high" ? "Use symbolic execution (js_deobfuscate_jsvmp with aggressive=true) for high-complexity VMs" : "Use standard deobfuscation pipeline (js_deobfuscate_pipeline)";
|
|
615
|
+
}
|
|
616
|
+
return {
|
|
617
|
+
success: true,
|
|
618
|
+
analysis
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/server/domains/analysis/handlers.web-tools.ts
|
|
623
|
+
const MAX_WEBPACK_MODULES = 100;
|
|
624
|
+
async function runWebpackEnumerate(collector, args) {
|
|
625
|
+
const searchKeyword = argString(args, "searchKeyword", "");
|
|
626
|
+
const forceRequireAll = argBool(args, "forceRequireAll", !!searchKeyword);
|
|
627
|
+
const maxResults = Math.min(argNumber(args, "maxResults", 20), MAX_WEBPACK_MODULES);
|
|
628
|
+
try {
|
|
629
|
+
const result = await evaluateWithTimeout(await collector.getActivePage(), async (opts) => {
|
|
630
|
+
const w = window;
|
|
631
|
+
let requireFn = null;
|
|
632
|
+
if (typeof w["__webpack_require__"] === "function") requireFn = w["__webpack_require__"];
|
|
633
|
+
const chunkKeys = Object.keys(w).filter((k) => k.startsWith("webpackChunk") || k.startsWith("webpackJsonp"));
|
|
634
|
+
const moduleIdSet = /* @__PURE__ */ new Set();
|
|
635
|
+
for (const key of chunkKeys) {
|
|
636
|
+
const arr = w[key];
|
|
637
|
+
if (!Array.isArray(arr)) continue;
|
|
638
|
+
const arrWithM = arr;
|
|
639
|
+
if (arrWithM.m && typeof arrWithM.m === "object") for (const id of Object.keys(arrWithM.m)) moduleIdSet.add(id);
|
|
640
|
+
for (const chunk of arr) if (Array.isArray(chunk) && chunk[1] && typeof chunk[1] === "object") for (const id of Object.keys(chunk[1])) moduleIdSet.add(id);
|
|
641
|
+
}
|
|
642
|
+
if (typeof w["__webpack_modules__"] === "object" && w["__webpack_modules__"]) for (const id of Object.keys(w["__webpack_modules__"])) moduleIdSet.add(id);
|
|
643
|
+
if (!requireFn) for (const key of chunkKeys) {
|
|
644
|
+
const arr = w[key];
|
|
645
|
+
if (arr?.m && typeof arr.m === "object") {
|
|
646
|
+
const mods = arr.m;
|
|
647
|
+
requireFn = (id) => {
|
|
648
|
+
try {
|
|
649
|
+
const fn = mods[id];
|
|
650
|
+
return typeof fn === "function" ? fn() : fn;
|
|
651
|
+
} catch {
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
break;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
const allIds = Array.from(moduleIdSet);
|
|
659
|
+
if (!opts.forceRequireAll || !requireFn) return {
|
|
660
|
+
total: allIds.length,
|
|
661
|
+
requireFound: !!requireFn,
|
|
662
|
+
chunkKeys,
|
|
663
|
+
moduleIds: allIds.slice(0, 200),
|
|
664
|
+
matches: []
|
|
665
|
+
};
|
|
666
|
+
const fn = requireFn;
|
|
667
|
+
const matches = [];
|
|
668
|
+
for (const id of allIds) {
|
|
669
|
+
if (matches.length >= opts.maxResults) break;
|
|
670
|
+
try {
|
|
671
|
+
const mod = fn(id);
|
|
672
|
+
if (mod === void 0 || mod === null) continue;
|
|
673
|
+
let str;
|
|
674
|
+
try {
|
|
675
|
+
str = JSON.stringify(mod);
|
|
676
|
+
} catch {
|
|
677
|
+
str = String(mod);
|
|
678
|
+
}
|
|
679
|
+
if (!opts.searchKeyword || str.toLowerCase().includes(opts.searchKeyword.toLowerCase())) matches.push({
|
|
680
|
+
id,
|
|
681
|
+
preview: str.slice(0, 600)
|
|
682
|
+
});
|
|
683
|
+
} catch {}
|
|
684
|
+
}
|
|
685
|
+
return {
|
|
686
|
+
total: allIds.length,
|
|
687
|
+
requireFound: true,
|
|
688
|
+
chunkKeys,
|
|
689
|
+
moduleIds: allIds.slice(0, 200),
|
|
690
|
+
matches
|
|
691
|
+
};
|
|
692
|
+
}, {
|
|
693
|
+
searchKeyword,
|
|
694
|
+
forceRequireAll,
|
|
695
|
+
maxResults
|
|
696
|
+
});
|
|
697
|
+
logger.info(`webpack_enumerate: found ${result.total} modules, ${result.matches.length} matches`);
|
|
698
|
+
return asJsonResponse(result);
|
|
699
|
+
} catch (error) {
|
|
700
|
+
return asErrorResponse(error);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
//#endregion
|
|
704
|
+
//#region src/server/domains/analysis/handlers.impl.ts
|
|
705
|
+
const SMART_MODES = new Set([
|
|
706
|
+
"summary",
|
|
707
|
+
"priority",
|
|
708
|
+
"incremental",
|
|
709
|
+
"full"
|
|
710
|
+
]);
|
|
711
|
+
const FOCUS_MODES = new Set([
|
|
712
|
+
"structure",
|
|
713
|
+
"business",
|
|
714
|
+
"security",
|
|
715
|
+
"all"
|
|
716
|
+
]);
|
|
717
|
+
const HOOK_TYPES = new Set([
|
|
718
|
+
"function",
|
|
719
|
+
"xhr",
|
|
720
|
+
"fetch",
|
|
721
|
+
"websocket",
|
|
722
|
+
"localstorage",
|
|
723
|
+
"cookie"
|
|
724
|
+
]);
|
|
725
|
+
const HOOK_ACTIONS = new Set([
|
|
726
|
+
"log",
|
|
727
|
+
"block",
|
|
728
|
+
"modify"
|
|
729
|
+
]);
|
|
730
|
+
var CoreAnalysisHandlers = class {
|
|
731
|
+
collector;
|
|
732
|
+
scriptManager;
|
|
733
|
+
deobfuscator;
|
|
734
|
+
advancedDeobfuscator;
|
|
735
|
+
obfuscationDetector;
|
|
736
|
+
analyzer;
|
|
737
|
+
cryptoDetector;
|
|
738
|
+
hookManager;
|
|
739
|
+
jsvmpDeobfuscator;
|
|
740
|
+
constructor(deps) {
|
|
741
|
+
this.collector = deps.collector;
|
|
742
|
+
this.scriptManager = deps.scriptManager;
|
|
743
|
+
this.deobfuscator = deps.deobfuscator;
|
|
744
|
+
this.advancedDeobfuscator = deps.advancedDeobfuscator;
|
|
745
|
+
this.obfuscationDetector = deps.obfuscationDetector;
|
|
746
|
+
this.analyzer = deps.analyzer;
|
|
747
|
+
this.cryptoDetector = deps.cryptoDetector;
|
|
748
|
+
this.hookManager = deps.hookManager;
|
|
749
|
+
this.jsvmpDeobfuscator = new JSVMPDeobfuscator();
|
|
750
|
+
}
|
|
751
|
+
requireCodeArg(args, toolName) {
|
|
752
|
+
const code = args.code;
|
|
753
|
+
if (typeof code !== "string" || code.trim().length === 0) {
|
|
754
|
+
logger.warn(`${toolName} called without valid code argument`);
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
757
|
+
return code;
|
|
758
|
+
}
|
|
759
|
+
extractWebcrackArgs(args) {
|
|
760
|
+
const extracted = {};
|
|
761
|
+
const unpack = argBool(args, "unpack");
|
|
762
|
+
const unminify = argBool(args, "unminify");
|
|
763
|
+
const jsx = argBool(args, "jsx");
|
|
764
|
+
const mangle = argBool(args, "mangle");
|
|
765
|
+
const forceOutput = argBool(args, "forceOutput");
|
|
766
|
+
const includeModuleCode = argBool(args, "includeModuleCode");
|
|
767
|
+
const outputDir = argString(args, "outputDir");
|
|
768
|
+
const maxBundleModules = argNumber(args, "maxBundleModules");
|
|
769
|
+
if (unpack !== void 0) extracted.unpack = unpack;
|
|
770
|
+
if (unminify !== void 0) extracted.unminify = unminify;
|
|
771
|
+
if (jsx !== void 0) extracted.jsx = jsx;
|
|
772
|
+
if (mangle !== void 0) extracted.mangle = mangle;
|
|
773
|
+
if (forceOutput !== void 0) extracted.forceOutput = forceOutput;
|
|
774
|
+
if (includeModuleCode !== void 0) extracted.includeModuleCode = includeModuleCode;
|
|
775
|
+
if (outputDir?.trim()) extracted.outputDir = outputDir;
|
|
776
|
+
if (maxBundleModules !== void 0) extracted.maxBundleModules = maxBundleModules;
|
|
777
|
+
if (Array.isArray(args.mappings)) extracted.mappings = args.mappings.filter((item) => typeof item === "object" && item !== null && typeof item.path === "string" && typeof item.pattern === "string");
|
|
778
|
+
return extracted;
|
|
779
|
+
}
|
|
780
|
+
async handleCollectCode(args) {
|
|
781
|
+
const returnSummaryOnly = argBool(args, "returnSummaryOnly", false);
|
|
782
|
+
let smartMode = argEnum(args, "smartMode", SMART_MODES);
|
|
783
|
+
const maxSummaryFiles = ANALYSIS_MAX_SUMMARY_FILES;
|
|
784
|
+
const summarizeFiles = (files) => files.slice(0, maxSummaryFiles).map((file) => ({
|
|
785
|
+
url: file.url,
|
|
786
|
+
type: file.type,
|
|
787
|
+
size: file.size,
|
|
788
|
+
sizeKB: (file.size / 1024).toFixed(2),
|
|
789
|
+
truncated: file.metadata?.truncated || false,
|
|
790
|
+
preview: `${file.content.substring(0, 200)}...`
|
|
791
|
+
}));
|
|
792
|
+
const summarizeResult = (result) => {
|
|
793
|
+
const entries = (Array.isArray(result.summaries) && result.summaries.length > 0 ? result.summaries : summarizeFiles(result.files)).slice(0, maxSummaryFiles);
|
|
794
|
+
const filesCount = Array.isArray(result.summaries) ? result.summaries.length : result.files.length;
|
|
795
|
+
const totalSize = result.totalSize > 0 ? result.totalSize : Array.isArray(result.summaries) ? result.summaries.reduce((sum, entry) => sum + (typeof entry.size === "number" ? entry.size : 0), 0) : result.files.reduce((sum, file) => sum + file.size, 0);
|
|
796
|
+
return {
|
|
797
|
+
totalSize,
|
|
798
|
+
totalSizeKB: (totalSize / 1024).toFixed(2),
|
|
799
|
+
filesCount,
|
|
800
|
+
summarizedFiles: entries.length,
|
|
801
|
+
omittedFiles: Math.max(0, filesCount - entries.length),
|
|
802
|
+
collectTime: result.collectTime,
|
|
803
|
+
summary: entries
|
|
804
|
+
};
|
|
805
|
+
};
|
|
806
|
+
if (!smartMode) smartMode = returnSummaryOnly ? "summary" : "summary";
|
|
807
|
+
const result = await this.collector.collect({
|
|
808
|
+
url: argStringRequired(args, "url"),
|
|
809
|
+
includeInline: argBool(args, "includeInline"),
|
|
810
|
+
includeExternal: argBool(args, "includeExternal"),
|
|
811
|
+
includeDynamic: argBool(args, "includeDynamic"),
|
|
812
|
+
smartMode,
|
|
813
|
+
compress: argBool(args, "compress"),
|
|
814
|
+
maxTotalSize: argNumber(args, "maxTotalSize"),
|
|
815
|
+
maxFileSize: args.maxFileSize ? argNumber(args, "maxFileSize", 0) * 1024 : void 0,
|
|
816
|
+
priorities: args.priorities
|
|
817
|
+
});
|
|
818
|
+
if (returnSummaryOnly) return asJsonResponse({
|
|
819
|
+
mode: "summary",
|
|
820
|
+
...summarizeResult(result),
|
|
821
|
+
hint: "Use get_script_source for specific files."
|
|
822
|
+
});
|
|
823
|
+
const maxSafeCollectedSize = ANALYSIS_MAX_SAFE_COLLECTED_BYTES;
|
|
824
|
+
const maxSafeResponseSize = ANALYSIS_MAX_SAFE_RESPONSE_BYTES;
|
|
825
|
+
const estimatedResponseSize = Buffer.byteLength(JSON.stringify(result), "utf8");
|
|
826
|
+
if (result.totalSize > maxSafeCollectedSize || estimatedResponseSize > maxSafeResponseSize) {
|
|
827
|
+
logger.warn(`Collected code is too large (collected=${(result.totalSize / 1024).toFixed(2)}KB, response=${(estimatedResponseSize / 1024).toFixed(2)}KB), returning summary mode.`);
|
|
828
|
+
return asJsonResponse({
|
|
829
|
+
warning: "Code size exceeds safe response threshold; summary returned.",
|
|
830
|
+
...summarizeResult(result),
|
|
831
|
+
estimatedResponseSize,
|
|
832
|
+
estimatedResponseSizeKB: (estimatedResponseSize / 1024).toFixed(2),
|
|
833
|
+
recommendations: [
|
|
834
|
+
"Use get_script_source for targeted files.",
|
|
835
|
+
"Use more specific priority filters.",
|
|
836
|
+
"Use smartMode=summary for initial reconnaissance."
|
|
837
|
+
]
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
return asJsonResponse(result);
|
|
841
|
+
}
|
|
842
|
+
async handleSearchInScripts(args) {
|
|
843
|
+
await this.scriptManager.init();
|
|
844
|
+
const keyword = argString(args, "keyword");
|
|
845
|
+
if (!keyword) return asJsonResponse({
|
|
846
|
+
success: false,
|
|
847
|
+
error: "keyword is required"
|
|
848
|
+
});
|
|
849
|
+
const maxMatches = argNumber(args, "maxMatches", 100);
|
|
850
|
+
const returnSummary = argBool(args, "returnSummary", false);
|
|
851
|
+
const maxContextSize = argNumber(args, "maxContextSize", 5e4);
|
|
852
|
+
const result = await this.scriptManager.searchInScripts(keyword, {
|
|
853
|
+
isRegex: argBool(args, "isRegex"),
|
|
854
|
+
caseSensitive: argBool(args, "caseSensitive"),
|
|
855
|
+
contextLines: argNumber(args, "contextLines"),
|
|
856
|
+
maxMatches
|
|
857
|
+
});
|
|
858
|
+
const resultSize = JSON.stringify(result).length;
|
|
859
|
+
if (returnSummary || resultSize > maxContextSize) {
|
|
860
|
+
const matches = result.matches ?? [];
|
|
861
|
+
return asJsonResponse({
|
|
862
|
+
success: true,
|
|
863
|
+
keyword: args.keyword,
|
|
864
|
+
totalMatches: matches.length,
|
|
865
|
+
resultSize,
|
|
866
|
+
resultSizeKB: (resultSize / 1024).toFixed(2),
|
|
867
|
+
truncated: resultSize > maxContextSize,
|
|
868
|
+
reason: resultSize > maxContextSize ? `Result too large (${(resultSize / 1024).toFixed(2)}KB > ${(maxContextSize / 1024).toFixed(2)}KB)` : "Summary mode enabled",
|
|
869
|
+
matchesSummary: matches.slice(0, 10).map((match) => ({
|
|
870
|
+
scriptId: match.scriptId,
|
|
871
|
+
url: match.url,
|
|
872
|
+
line: match.line,
|
|
873
|
+
preview: `${(match.context ?? "").substring(0, 100)}...`
|
|
874
|
+
})),
|
|
875
|
+
recommendations: [
|
|
876
|
+
"Use more specific keywords.",
|
|
877
|
+
`Reduce maxMatches (current: ${maxMatches}).`,
|
|
878
|
+
"Use get_script_source for targeted file retrieval."
|
|
879
|
+
]
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
return asJsonResponse(result);
|
|
883
|
+
}
|
|
884
|
+
async handleExtractFunctionTree(args) {
|
|
885
|
+
const scriptId = argString(args, "scriptId");
|
|
886
|
+
const functionName = argString(args, "functionName");
|
|
887
|
+
if (!scriptId) return asJsonResponse({
|
|
888
|
+
success: false,
|
|
889
|
+
error: "scriptId is required",
|
|
890
|
+
hint: "Use get_all_scripts() to list available scripts and their scriptIds"
|
|
891
|
+
});
|
|
892
|
+
if (!functionName) return asJsonResponse({
|
|
893
|
+
success: false,
|
|
894
|
+
error: "functionName is required",
|
|
895
|
+
hint: "Specify the name of the function to extract"
|
|
896
|
+
});
|
|
897
|
+
await this.scriptManager.init();
|
|
898
|
+
const scripts = await this.scriptManager.getAllScripts();
|
|
899
|
+
if (!scripts.some((s) => String(s.scriptId) === String(scriptId))) {
|
|
900
|
+
const availableScripts = scripts.slice(0, 10).map((s) => ({
|
|
901
|
+
scriptId: s.scriptId,
|
|
902
|
+
url: s.url?.substring(0, 80)
|
|
903
|
+
}));
|
|
904
|
+
return asJsonResponse({
|
|
905
|
+
success: false,
|
|
906
|
+
error: `Script not found: ${scriptId}`,
|
|
907
|
+
hint: "The specified scriptId does not exist. Use get_all_scripts() to list available scripts.",
|
|
908
|
+
availableScripts: availableScripts.length > 0 ? availableScripts : "No scripts loaded. Navigate to a page first.",
|
|
909
|
+
totalScripts: scripts.length
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
try {
|
|
913
|
+
return asJsonResponse({
|
|
914
|
+
success: true,
|
|
915
|
+
...await this.scriptManager.extractFunctionTree(scriptId, functionName, {
|
|
916
|
+
maxDepth: argNumber(args, "maxDepth"),
|
|
917
|
+
maxSize: argNumber(args, "maxSize"),
|
|
918
|
+
includeComments: argBool(args, "includeComments")
|
|
919
|
+
})
|
|
920
|
+
});
|
|
921
|
+
} catch (error) {
|
|
922
|
+
return asJsonResponse({
|
|
923
|
+
success: false,
|
|
924
|
+
error: error instanceof Error ? error.message : String(error),
|
|
925
|
+
hint: "Make sure the function name exists in the specified script"
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
async handleDeobfuscate(args) {
|
|
930
|
+
const code = this.requireCodeArg(args, "deobfuscate");
|
|
931
|
+
if (!code) return asJsonResponse({
|
|
932
|
+
success: false,
|
|
933
|
+
error: "code is required and must be a non-empty string"
|
|
934
|
+
});
|
|
935
|
+
if (argEnum(args, "engine", new Set(["auto", "webcrack"]), "auto") === "webcrack") return asJsonResponse(await this.advancedDeobfuscator.deobfuscate({
|
|
936
|
+
code,
|
|
937
|
+
...this.extractWebcrackArgs(args),
|
|
938
|
+
...typeof args.detectOnly === "boolean" ? { detectOnly: args.detectOnly } : {},
|
|
939
|
+
...typeof args.aggressiveVM === "boolean" ? { aggressiveVM: args.aggressiveVM } : {},
|
|
940
|
+
...typeof args.useASTOptimization === "boolean" ? { useASTOptimization: args.useASTOptimization } : {},
|
|
941
|
+
...typeof args.timeout === "number" ? { timeout: args.timeout } : {}
|
|
942
|
+
}));
|
|
943
|
+
const result = await this.deobfuscator.deobfuscate({
|
|
944
|
+
code,
|
|
945
|
+
aggressive: argBool(args, "aggressive"),
|
|
946
|
+
...this.extractWebcrackArgs(args)
|
|
947
|
+
});
|
|
948
|
+
if (result && typeof result === "object" && "success" in result && result.success === false && !("error" in result)) return asJsonResponse({
|
|
949
|
+
...result,
|
|
950
|
+
error: result.reason || "deobfuscation failed"
|
|
951
|
+
});
|
|
952
|
+
return asJsonResponse(result);
|
|
953
|
+
}
|
|
954
|
+
async handleUnderstandCode(args) {
|
|
955
|
+
const code = this.requireCodeArg(args, "understand_code");
|
|
956
|
+
if (!code) return asJsonResponse({
|
|
957
|
+
success: false,
|
|
958
|
+
error: "code is required and must be a non-empty string"
|
|
959
|
+
});
|
|
960
|
+
return asJsonResponse(await this.analyzer.understand({
|
|
961
|
+
code,
|
|
962
|
+
context: argObject(args, "context"),
|
|
963
|
+
focus: argEnum(args, "focus", FOCUS_MODES, "all")
|
|
964
|
+
}));
|
|
965
|
+
}
|
|
966
|
+
async handleDetectCrypto(args) {
|
|
967
|
+
const code = this.requireCodeArg(args, "detect_crypto");
|
|
968
|
+
if (!code) return asJsonResponse({
|
|
969
|
+
success: false,
|
|
970
|
+
error: "code is required and must be a non-empty string"
|
|
971
|
+
});
|
|
972
|
+
return asJsonResponse(await this.cryptoDetector.detect({ code }));
|
|
973
|
+
}
|
|
974
|
+
async handleManageHooks(args) {
|
|
975
|
+
const action = argStringRequired(args, "action");
|
|
976
|
+
switch (action) {
|
|
977
|
+
case "create": return asJsonResponse(await this.hookManager.createHook({
|
|
978
|
+
target: argStringRequired(args, "target"),
|
|
979
|
+
type: argEnum(args, "type", HOOK_TYPES) ?? "function",
|
|
980
|
+
action: argEnum(args, "hookAction", HOOK_ACTIONS, "log"),
|
|
981
|
+
customCode: argString(args, "customCode")
|
|
982
|
+
}));
|
|
983
|
+
case "list": return asJsonResponse({ hooks: this.hookManager.getAllHooks() });
|
|
984
|
+
case "records": return asJsonResponse({ records: this.hookManager.getHookRecords(argStringRequired(args, "hookId")) });
|
|
985
|
+
case "clear":
|
|
986
|
+
this.hookManager.clearHookRecords(argString(args, "hookId"));
|
|
987
|
+
return asJsonResponse({
|
|
988
|
+
success: true,
|
|
989
|
+
message: "Hook records cleared"
|
|
990
|
+
});
|
|
991
|
+
default: return asJsonResponse({
|
|
992
|
+
success: false,
|
|
993
|
+
message: `Unknown hook action: ${action}. Valid actions: create, list, records, clear`
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
async handleDetectObfuscation(args) {
|
|
998
|
+
const code = this.requireCodeArg(args, "detect_obfuscation");
|
|
999
|
+
if (!code) return asJsonResponse({
|
|
1000
|
+
success: false,
|
|
1001
|
+
error: "code is required and must be a non-empty string"
|
|
1002
|
+
});
|
|
1003
|
+
const generateReport = argBool(args, "generateReport", true);
|
|
1004
|
+
const result = this.obfuscationDetector.detect(code);
|
|
1005
|
+
if (!generateReport) return asJsonResponse(result);
|
|
1006
|
+
const report = this.obfuscationDetector.generateReport(result);
|
|
1007
|
+
return asTextResponse(`${JSON.stringify(result, null, 2)}\n\n${report}`);
|
|
1008
|
+
}
|
|
1009
|
+
async handleWebcrackUnpack(args) {
|
|
1010
|
+
const code = this.requireCodeArg(args, "webcrack_unpack");
|
|
1011
|
+
if (!code) return asJsonResponse({
|
|
1012
|
+
success: false,
|
|
1013
|
+
error: "code is required and must be a non-empty string"
|
|
1014
|
+
});
|
|
1015
|
+
const result = await runWebcrack(code, {
|
|
1016
|
+
unpack: argBool(args, "unpack", true),
|
|
1017
|
+
unminify: argBool(args, "unminify", true),
|
|
1018
|
+
jsx: argBool(args, "jsx", true),
|
|
1019
|
+
mangle: argBool(args, "mangle", false),
|
|
1020
|
+
...this.extractWebcrackArgs(args)
|
|
1021
|
+
});
|
|
1022
|
+
if (!result.applied) return asJsonResponse({
|
|
1023
|
+
success: false,
|
|
1024
|
+
error: result.reason || "webcrack execution failed",
|
|
1025
|
+
optionsUsed: result.optionsUsed,
|
|
1026
|
+
engine: "webcrack"
|
|
1027
|
+
});
|
|
1028
|
+
return asJsonResponse({
|
|
1029
|
+
success: true,
|
|
1030
|
+
code: result.code,
|
|
1031
|
+
bundle: result.bundle,
|
|
1032
|
+
savedTo: result.savedTo,
|
|
1033
|
+
savedArtifacts: result.savedArtifacts,
|
|
1034
|
+
optionsUsed: result.optionsUsed,
|
|
1035
|
+
engine: "webcrack"
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
async handleWebpackEnumerate(args) {
|
|
1039
|
+
return runWebpackEnumerate(this.collector, args);
|
|
1040
|
+
}
|
|
1041
|
+
async handleClearCollectedData() {
|
|
1042
|
+
try {
|
|
1043
|
+
await this.collector.clearAllData();
|
|
1044
|
+
this.scriptManager.clear();
|
|
1045
|
+
return asJsonResponse({
|
|
1046
|
+
success: true,
|
|
1047
|
+
message: "All collected data cleared.",
|
|
1048
|
+
cleared: {
|
|
1049
|
+
fileCache: true,
|
|
1050
|
+
compressionCache: true,
|
|
1051
|
+
collectedUrls: true,
|
|
1052
|
+
scriptManager: true
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
} catch (error) {
|
|
1056
|
+
logger.error("Failed to clear collected data:", error);
|
|
1057
|
+
return asJsonResponse(serializeError(error));
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
async handleGetCollectionStats() {
|
|
1061
|
+
try {
|
|
1062
|
+
const stats = await this.collector.getAllStats();
|
|
1063
|
+
return asJsonResponse({
|
|
1064
|
+
success: true,
|
|
1065
|
+
stats,
|
|
1066
|
+
summary: {
|
|
1067
|
+
totalCachedFiles: stats.cache.memoryEntries + stats.cache.diskEntries,
|
|
1068
|
+
totalCacheSize: `${(stats.cache.totalSize / 1024).toFixed(2)} KB`,
|
|
1069
|
+
compressionRatio: `${stats.compression.averageRatio.toFixed(1)}%`,
|
|
1070
|
+
cacheHitRate: stats.compression.cacheHits > 0 ? `${(stats.compression.cacheHits / (stats.compression.cacheHits + stats.compression.cacheMisses) * 100).toFixed(1)}%` : "0%",
|
|
1071
|
+
collectedUrls: stats.collector.collectedUrls
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
1074
|
+
} catch (error) {
|
|
1075
|
+
logger.error("Failed to get collection stats:", error);
|
|
1076
|
+
return asJsonResponse(serializeError(error));
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
async handleJsDeobfuscateJsvmp(args) {
|
|
1080
|
+
const code = this.requireCodeArg(args, "js_deobfuscate_jsvmp");
|
|
1081
|
+
if (!code) return asJsonResponse({
|
|
1082
|
+
success: false,
|
|
1083
|
+
error: "code is required and must be a non-empty string"
|
|
1084
|
+
});
|
|
1085
|
+
const detectOnly = argBool(args, "detectOnly", false);
|
|
1086
|
+
const result = await this.jsvmpDeobfuscator.deobfuscate({
|
|
1087
|
+
code,
|
|
1088
|
+
aggressive: argBool(args, "aggressive", false),
|
|
1089
|
+
extractInstructions: argBool(args, "extractInstructions", true),
|
|
1090
|
+
timeout: argNumber(args, "timeout", 3e4)
|
|
1091
|
+
});
|
|
1092
|
+
if (detectOnly) return asJsonResponse({
|
|
1093
|
+
success: true,
|
|
1094
|
+
isJSVMP: result.isJSVMP,
|
|
1095
|
+
vmType: result.vmType,
|
|
1096
|
+
vmFeatures: result.vmFeatures,
|
|
1097
|
+
confidence: result.confidence,
|
|
1098
|
+
instructionCount: result.instructions?.length
|
|
1099
|
+
});
|
|
1100
|
+
return asJsonResponse({
|
|
1101
|
+
success: result.isJSVMP,
|
|
1102
|
+
isJSVMP: result.isJSVMP,
|
|
1103
|
+
vmType: result.vmType,
|
|
1104
|
+
vmFeatures: result.vmFeatures,
|
|
1105
|
+
instructions: result.instructions,
|
|
1106
|
+
deobfuscatedCode: result.deobfuscatedCode,
|
|
1107
|
+
confidence: result.confidence,
|
|
1108
|
+
warnings: result.warnings,
|
|
1109
|
+
unresolvedParts: result.unresolvedParts,
|
|
1110
|
+
stats: result.stats
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
async handleJsDeobfuscatePipeline(args) {
|
|
1114
|
+
const code = this.requireCodeArg(args, "js_deobfuscate_pipeline");
|
|
1115
|
+
if (!code) return asJsonResponse({
|
|
1116
|
+
success: false,
|
|
1117
|
+
error: "code is required"
|
|
1118
|
+
});
|
|
1119
|
+
const useWebcrack = argBool(args, "useWebcrack", true);
|
|
1120
|
+
const aggressive = argBool(args, "aggressive", false);
|
|
1121
|
+
const humanize = argBool(args, "humanize", true);
|
|
1122
|
+
const returnStageDetails = argBool(args, "returnStageDetails", false);
|
|
1123
|
+
const startTime = Date.now();
|
|
1124
|
+
let preprocessed = code;
|
|
1125
|
+
const ppTransforms = [];
|
|
1126
|
+
const afterFold = applyConstantFold(preprocessed);
|
|
1127
|
+
if (afterFold !== preprocessed) {
|
|
1128
|
+
preprocessed = afterFold;
|
|
1129
|
+
ppTransforms.push("constant_fold");
|
|
1130
|
+
}
|
|
1131
|
+
const afterDeadCode = applyDeadCodeRemove(preprocessed);
|
|
1132
|
+
if (afterDeadCode !== preprocessed) {
|
|
1133
|
+
preprocessed = afterDeadCode;
|
|
1134
|
+
ppTransforms.push("dead_code_remove");
|
|
1135
|
+
}
|
|
1136
|
+
let deobfuscated = preprocessed;
|
|
1137
|
+
let webcrackApplied = false;
|
|
1138
|
+
let webcrackWarning;
|
|
1139
|
+
let webcrackError;
|
|
1140
|
+
if (useWebcrack) try {
|
|
1141
|
+
const result = await runWebcrack(preprocessed, {
|
|
1142
|
+
unminify: true,
|
|
1143
|
+
unpack: true
|
|
1144
|
+
});
|
|
1145
|
+
if (result.applied) {
|
|
1146
|
+
deobfuscated = result.code;
|
|
1147
|
+
webcrackApplied = true;
|
|
1148
|
+
} else webcrackWarning = result.reason ? `webcrack stage did not apply: ${result.reason}` : "webcrack stage did not apply any transformation.";
|
|
1149
|
+
} catch (error) {
|
|
1150
|
+
webcrackError = error instanceof Error ? error.message : String(error);
|
|
1151
|
+
}
|
|
1152
|
+
if (aggressive) {
|
|
1153
|
+
const afterCFF = applyControlFlowFlatten(deobfuscated);
|
|
1154
|
+
if (afterCFF !== deobfuscated) deobfuscated = afterCFF;
|
|
1155
|
+
}
|
|
1156
|
+
let humanized = deobfuscated;
|
|
1157
|
+
let renameCount = 0;
|
|
1158
|
+
if (humanize) {
|
|
1159
|
+
const result = applyRenameVars(humanized);
|
|
1160
|
+
if (result.code !== humanized) {
|
|
1161
|
+
humanized = result.code;
|
|
1162
|
+
renameCount = result.count;
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
const totalMs = Date.now() - startTime;
|
|
1166
|
+
const reductionRate = code.length > 0 ? 1 - humanized.length / code.length : 0;
|
|
1167
|
+
const response = {
|
|
1168
|
+
success: !webcrackWarning && !webcrackError,
|
|
1169
|
+
deobfuscatedCode: humanized,
|
|
1170
|
+
...webcrackWarning ? { warning: webcrackWarning } : {},
|
|
1171
|
+
...webcrackError ? { error: `webcrack stage failed: ${webcrackError}` } : {},
|
|
1172
|
+
stats: {
|
|
1173
|
+
originalSize: code.length,
|
|
1174
|
+
finalSize: humanized.length,
|
|
1175
|
+
reductionRate: Math.round(reductionRate * 1e3) / 10,
|
|
1176
|
+
processingTimeMs: totalMs,
|
|
1177
|
+
stages: {
|
|
1178
|
+
preprocessor: {
|
|
1179
|
+
transforms: ppTransforms,
|
|
1180
|
+
sizeAfter: preprocessed.length
|
|
1181
|
+
},
|
|
1182
|
+
deobfuscator: {
|
|
1183
|
+
webcrackApplied,
|
|
1184
|
+
sizeAfter: deobfuscated.length,
|
|
1185
|
+
...webcrackWarning ? { warning: webcrackWarning } : {},
|
|
1186
|
+
...webcrackError ? { error: webcrackError } : {}
|
|
1187
|
+
},
|
|
1188
|
+
humanizer: {
|
|
1189
|
+
renameCount,
|
|
1190
|
+
sizeAfter: humanized.length
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
if (returnStageDetails) response.stageDetails = {
|
|
1196
|
+
preprocessed: preprocessed.substring(0, 5e3),
|
|
1197
|
+
deobfuscated: deobfuscated.substring(0, 5e3)
|
|
1198
|
+
};
|
|
1199
|
+
return asJsonResponse(response);
|
|
1200
|
+
}
|
|
1201
|
+
async handleJsAnalyzeVm(args) {
|
|
1202
|
+
const code = this.requireCodeArg(args, "js_analyze_vm");
|
|
1203
|
+
if (!code) return asJsonResponse({
|
|
1204
|
+
success: false,
|
|
1205
|
+
error: "code is required"
|
|
1206
|
+
});
|
|
1207
|
+
const extractBytecode = argBool(args, "extractBytecode", true);
|
|
1208
|
+
return asJsonResponse(buildVmAnalysisResponse({
|
|
1209
|
+
code,
|
|
1210
|
+
extractBytecode,
|
|
1211
|
+
mapOpcodes: argBool(args, "mapOpcodes", true),
|
|
1212
|
+
vmResult: await this.jsvmpDeobfuscator.deobfuscate({
|
|
1213
|
+
code,
|
|
1214
|
+
aggressive: false,
|
|
1215
|
+
extractInstructions: extractBytecode,
|
|
1216
|
+
timeout: 15e3
|
|
1217
|
+
})
|
|
1218
|
+
}));
|
|
1219
|
+
}
|
|
1220
|
+
async handleJsSolveConstraints(args) {
|
|
1221
|
+
const code = this.requireCodeArg(args, "js_solve_constraints");
|
|
1222
|
+
if (!code) return asJsonResponse({
|
|
1223
|
+
success: false,
|
|
1224
|
+
error: "code is required"
|
|
1225
|
+
});
|
|
1226
|
+
return asJsonResponse(solveConstraints({
|
|
1227
|
+
code,
|
|
1228
|
+
replaceInPlace: argBool(args, "replaceInPlace", true),
|
|
1229
|
+
maxIterations: argNumber(args, "maxIterations", 100)
|
|
1230
|
+
}));
|
|
1231
|
+
}
|
|
1232
|
+
};
|
|
1233
|
+
//#endregion
|
|
1234
|
+
export { CoreAnalysisHandlers };
|