unpeek 2.0.0 → 3.0.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 +30 -8
- package/README.tr.md +30 -8
- package/dist/adapters/esbuild.cjs +13 -0
- package/dist/{esbuild.d.cts → adapters/esbuild.d.cts} +2 -2
- package/dist/{esbuild.d.ts → adapters/esbuild.d.ts} +2 -2
- package/dist/adapters/esbuild.js +11 -0
- package/dist/adapters/next/adapter.cjs +42 -0
- package/dist/{next → adapters/next}/adapter.d.cts +4 -4
- package/dist/{next → adapters/next}/adapter.d.ts +4 -4
- package/dist/adapters/next/adapter.js +42 -0
- package/dist/adapters/next/index.cjs +15 -0
- package/dist/adapters/next/index.d.cts +53 -0
- package/dist/adapters/next/index.d.ts +53 -0
- package/dist/adapters/next/index.js +15 -0
- package/dist/adapters/rollup.cjs +13 -0
- package/dist/{rollup.d.cts → adapters/rollup.d.cts} +2 -2
- package/dist/{rollup.d.ts → adapters/rollup.d.ts} +2 -2
- package/dist/adapters/rollup.js +11 -0
- package/dist/adapters/rspack.cjs +12 -0
- package/dist/adapters/rspack.d.cts +13 -0
- package/dist/adapters/rspack.d.ts +11 -0
- package/dist/adapters/rspack.js +12 -0
- package/dist/adapters/vite.cjs +13 -0
- package/dist/{vite.d.cts → adapters/vite.d.cts} +2 -2
- package/dist/{vite.d.ts → adapters/vite.d.ts} +2 -2
- package/dist/adapters/vite.js +11 -0
- package/dist/adapters/webpack.cjs +13 -0
- package/dist/{webpack.d.cts → adapters/webpack.d.cts} +2 -2
- package/dist/{webpack.d.ts → adapters/webpack.d.ts} +2 -2
- package/dist/adapters/webpack.js +11 -0
- package/dist/browser.cjs +8 -5
- package/dist/browser.d.cts +41 -3
- package/dist/browser.d.ts +41 -3
- package/dist/browser.js +10 -7
- package/dist/{chunk-GAVI2C44.cjs → chunk-6TDCSIRZ.cjs} +76 -47
- package/dist/{chunk-5LCMI2TL.js → chunk-APWMNVAZ.js} +221 -32
- package/dist/{chunk-5QD6FZPB.js → chunk-BPRSCRUZ.js} +71 -42
- package/dist/{chunk-X5MKMFMX.js → chunk-DUK2SECY.js} +7 -7
- package/dist/chunk-FCF2EGPM.js +80 -0
- package/dist/{chunk-7YVEHJVM.cjs → chunk-I6GXEHFR.cjs} +241 -52
- package/dist/{chunk-LXP73HJC.cjs → chunk-IAD5DV3D.cjs} +1048 -213
- package/dist/chunk-IEBVL5BT.cjs +80 -0
- package/dist/{chunk-GZB7PFLY.js → chunk-IICVBTR2.js} +25 -62
- package/dist/{chunk-UMPUYLLZ.js → chunk-IZIWDJRF.js} +936 -101
- package/dist/chunk-L6BOM5VS.cjs +40 -0
- package/dist/{chunk-OOXSZTRV.js → chunk-LA6J3BT3.js} +26 -1
- package/dist/{chunk-24K5NDXH.cjs → chunk-ONM2CSTU.cjs} +45 -82
- package/dist/{chunk-5M6Z7ZFT.cjs → chunk-RXUY3MPH.cjs} +10 -10
- package/dist/cli/index.js +7309 -32
- package/dist/{types-BBSRUEab.d.cts → config-CfXY_iDD.d.cts} +44 -86
- package/dist/{types-BBSRUEab.d.ts → config-CfXY_iDD.d.ts} +44 -86
- package/dist/config.cjs +4 -16
- package/dist/config.d.cts +1 -12
- package/dist/config.d.ts +1 -12
- package/dist/config.js +5 -17
- package/dist/index-CjRTNPlj.d.cts +46 -0
- package/dist/index-Cm1IloVm.d.ts +46 -0
- package/dist/index.cjs +636 -9
- package/dist/index.d.cts +9 -17
- package/dist/index.d.ts +9 -17
- package/dist/index.js +638 -11
- package/dist/plugins/unplugin.cjs +20 -0
- package/dist/plugins/unplugin.d.cts +17 -0
- package/dist/plugins/unplugin.d.ts +15 -0
- package/dist/{bundler → plugins}/unplugin.js +5 -5
- package/dist/types-DYQIzGf6.d.cts +112 -0
- package/dist/types-ZHAFdOd3.d.ts +112 -0
- package/package.json +48 -52
- package/dist/ast/index.cjs +0 -17
- package/dist/ast/index.d.cts +0 -18
- package/dist/ast/index.d.ts +0 -18
- package/dist/ast/index.js +0 -17
- package/dist/bundler/unplugin.cjs +0 -20
- package/dist/bundler/unplugin.d.cts +0 -16
- package/dist/bundler/unplugin.d.ts +0 -14
- package/dist/chunk-27HR647Q.js +0 -190
- package/dist/chunk-4TDLLEEU.cjs +0 -15
- package/dist/chunk-6N6S6WTQ.cjs +0 -423
- package/dist/chunk-J5CGNZDM.cjs +0 -190
- package/dist/chunk-KQWNFKT2.js +0 -423
- package/dist/chunk-R6EBIR3T.cjs +0 -14
- package/dist/chunk-S4S2WXGC.js +0 -14
- package/dist/cli/index.cjs +0 -324
- package/dist/cli/index.d.cts +0 -22
- package/dist/cli/index.d.ts +0 -22
- package/dist/esbuild.cjs +0 -15
- package/dist/esbuild.js +0 -13
- package/dist/next/adapter.cjs +0 -31
- package/dist/next/adapter.js +0 -31
- package/dist/next/index.cjs +0 -18
- package/dist/next/index.d.cts +0 -42
- package/dist/next/index.d.ts +0 -42
- package/dist/next/index.js +0 -18
- package/dist/rollup.cjs +0 -15
- package/dist/rollup.js +0 -13
- package/dist/runtime/index.cjs +0 -17
- package/dist/runtime/index.d.cts +0 -36
- package/dist/runtime/index.d.ts +0 -36
- package/dist/runtime/index.js +0 -17
- package/dist/vite.cjs +0 -15
- package/dist/vite.js +0 -13
- package/dist/webpack.cjs +0 -15
- package/dist/webpack.js +0 -13
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
computeFnv1aHash,
|
|
3
|
-
computeIntegrityHash,
|
|
4
|
-
derivePolymorphicIdent,
|
|
5
|
-
deriveWindowKeySymbol,
|
|
6
|
-
generateCompactJs,
|
|
7
|
-
generateRuntimeShield
|
|
8
|
-
} from "./chunk-KQWNFKT2.js";
|
|
9
1
|
import {
|
|
10
2
|
UnpeekError
|
|
11
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LA6J3BT3.js";
|
|
4
|
+
|
|
5
|
+
// src/shared/hash.ts
|
|
6
|
+
function computeFnv1aHash(input, seed = 2166136261) {
|
|
7
|
+
let hash = seed >>> 0;
|
|
8
|
+
for (let i = 0; i < input.length; i++) {
|
|
9
|
+
hash ^= input.charCodeAt(i);
|
|
10
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
11
|
+
}
|
|
12
|
+
return hash >>> 0;
|
|
13
|
+
}
|
|
12
14
|
|
|
13
15
|
// src/ast/hot-path-detector.ts
|
|
14
16
|
import * as acorn from "acorn";
|
|
@@ -72,19 +74,22 @@ var FUNCTION_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
|
72
74
|
"FunctionExpression",
|
|
73
75
|
"ArrowFunctionExpression"
|
|
74
76
|
]);
|
|
75
|
-
function parseJavaScriptAst(code) {
|
|
77
|
+
function parseJavaScriptAst(code, comments) {
|
|
76
78
|
try {
|
|
77
79
|
return acorn.parse(code, {
|
|
78
80
|
ecmaVersion: "latest",
|
|
79
81
|
sourceType: "module",
|
|
80
|
-
allowReturnOutsideFunction: true
|
|
82
|
+
allowReturnOutsideFunction: true,
|
|
83
|
+
...comments ? { onComment: comments } : {}
|
|
81
84
|
});
|
|
82
85
|
} catch {
|
|
86
|
+
if (comments) comments.length = 0;
|
|
83
87
|
try {
|
|
84
88
|
return acorn.parse(code, {
|
|
85
89
|
ecmaVersion: "latest",
|
|
86
90
|
sourceType: "script",
|
|
87
|
-
allowReturnOutsideFunction: true
|
|
91
|
+
allowReturnOutsideFunction: true,
|
|
92
|
+
...comments ? { onComment: comments } : {}
|
|
88
93
|
});
|
|
89
94
|
} catch {
|
|
90
95
|
return null;
|
|
@@ -300,8 +305,10 @@ function analyzeAstHotPaths(ast, config) {
|
|
|
300
305
|
arrayHofMethods.add(m);
|
|
301
306
|
}
|
|
302
307
|
}
|
|
303
|
-
const
|
|
304
|
-
const
|
|
308
|
+
const rawEventRegex = config?.hotPath?.eventHandlerRegex;
|
|
309
|
+
const eventHandlerRegex = typeof rawEventRegex === "string" ? new RegExp(rawEventRegex) : rawEventRegex ?? DEFAULT_EVENT_HANDLER_REGEX;
|
|
310
|
+
const rawHookRegex = config?.hotPath?.hookPattern;
|
|
311
|
+
const hookRegex = typeof rawHookRegex === "string" ? new RegExp(rawHookRegex) : rawHookRegex ?? DEFAULT_HOOK_REGEX;
|
|
305
312
|
const customHooksSet = new Set(config?.hotPath?.customHooks ?? []);
|
|
306
313
|
function isHookName(name) {
|
|
307
314
|
if (!name) return false;
|
|
@@ -865,13 +872,430 @@ function detectHotPaths(code, config) {
|
|
|
865
872
|
return analyzeAstHotPaths(ast, config).report;
|
|
866
873
|
}
|
|
867
874
|
|
|
875
|
+
// src/runtime/integrity-guard.ts
|
|
876
|
+
var FNV_OFFSET_BASIS = 2166136261;
|
|
877
|
+
function computeIntegrityHash(source, seed = 0) {
|
|
878
|
+
return computeFnv1aHash(source, (FNV_OFFSET_BASIS ^ seed >>> 0) >>> 0);
|
|
879
|
+
}
|
|
880
|
+
function verifyCodeIntegrity(fnOrSource, expectedHash, seed = 0) {
|
|
881
|
+
const raw = typeof fnOrSource === "function" ? Function.prototype.toString.call(fnOrSource) : String(fnOrSource);
|
|
882
|
+
return computeIntegrityHash(raw, seed) === expectedHash >>> 0;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// src/ast/codegen.ts
|
|
886
|
+
import { generate, baseGenerator } from "astring";
|
|
887
|
+
function derivePolymorphicIdent(seed, role) {
|
|
888
|
+
let h = (2166136261 ^ seed >>> 0) >>> 0;
|
|
889
|
+
for (let i = 0; i < role.length; i++) {
|
|
890
|
+
h ^= role.charCodeAt(i);
|
|
891
|
+
h = Math.imul(h, 16777619) >>> 0;
|
|
892
|
+
}
|
|
893
|
+
const rolePrefixes = {
|
|
894
|
+
vault: "_a",
|
|
895
|
+
shield: "$b",
|
|
896
|
+
decoy: "_d",
|
|
897
|
+
shader: "_s",
|
|
898
|
+
vm: "_m",
|
|
899
|
+
wasm: "_w",
|
|
900
|
+
salted: "_k",
|
|
901
|
+
windowKey: "_z"
|
|
902
|
+
};
|
|
903
|
+
const prefix = rolePrefixes[role] ?? `_${String.fromCharCode(97 + h % 26)}`;
|
|
904
|
+
const suffix = ((h >>> 4) % 1296).toString(36).padStart(2, "0");
|
|
905
|
+
return `${prefix}${suffix}`;
|
|
906
|
+
}
|
|
907
|
+
var OPERATOR_PRECEDENCE = {
|
|
908
|
+
"||": 2,
|
|
909
|
+
"??": 3,
|
|
910
|
+
"&&": 4,
|
|
911
|
+
"|": 5,
|
|
912
|
+
"^": 6,
|
|
913
|
+
"&": 7,
|
|
914
|
+
"==": 8,
|
|
915
|
+
"!=": 8,
|
|
916
|
+
"===": 8,
|
|
917
|
+
"!==": 8,
|
|
918
|
+
"<": 9,
|
|
919
|
+
">": 9,
|
|
920
|
+
"<=": 9,
|
|
921
|
+
">=": 9,
|
|
922
|
+
"in": 9,
|
|
923
|
+
"instanceof": 9,
|
|
924
|
+
"<<": 10,
|
|
925
|
+
">>": 10,
|
|
926
|
+
">>>": 10,
|
|
927
|
+
"+": 11,
|
|
928
|
+
"-": 11,
|
|
929
|
+
"*": 12,
|
|
930
|
+
"%": 12,
|
|
931
|
+
"/": 12,
|
|
932
|
+
"**": 13
|
|
933
|
+
};
|
|
934
|
+
var NEEDS_PARENTHESES = 17;
|
|
935
|
+
function expressionNeedsParenthesis(state, node, parentNode, isRightHand) {
|
|
936
|
+
const nodePrecedence = state.expressionsPrecedence[node.type];
|
|
937
|
+
if (nodePrecedence === NEEDS_PARENTHESES) {
|
|
938
|
+
return true;
|
|
939
|
+
}
|
|
940
|
+
const parentNodePrecedence = state.expressionsPrecedence[parentNode.type];
|
|
941
|
+
if (nodePrecedence !== parentNodePrecedence) {
|
|
942
|
+
return !isRightHand && nodePrecedence === 15 && parentNodePrecedence === 14 && parentNode.operator === "**" || nodePrecedence < parentNodePrecedence;
|
|
943
|
+
}
|
|
944
|
+
if (nodePrecedence !== 13 && nodePrecedence !== 14) {
|
|
945
|
+
return false;
|
|
946
|
+
}
|
|
947
|
+
if (node.operator === "**" && parentNode.operator === "**") {
|
|
948
|
+
return !isRightHand;
|
|
949
|
+
}
|
|
950
|
+
if (nodePrecedence === 13 && parentNodePrecedence === 13 && (node.operator === "??" || parentNode.operator === "??")) {
|
|
951
|
+
return true;
|
|
952
|
+
}
|
|
953
|
+
if (isRightHand) {
|
|
954
|
+
return OPERATOR_PRECEDENCE[node.operator] <= OPERATOR_PRECEDENCE[parentNode.operator];
|
|
955
|
+
}
|
|
956
|
+
return OPERATOR_PRECEDENCE[node.operator] < OPERATOR_PRECEDENCE[parentNode.operator];
|
|
957
|
+
}
|
|
958
|
+
function formatExpression(state, node, parentNode, isRightHand) {
|
|
959
|
+
const generator = state.generator;
|
|
960
|
+
if (expressionNeedsParenthesis(state, node, parentNode, isRightHand)) {
|
|
961
|
+
state.write("(");
|
|
962
|
+
generator[node.type](node, state);
|
|
963
|
+
state.write(")");
|
|
964
|
+
} else {
|
|
965
|
+
generator[node.type](node, state);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
function formatSequence(state, expressions) {
|
|
969
|
+
const length = expressions.length;
|
|
970
|
+
if (length > 0) {
|
|
971
|
+
state.write("(");
|
|
972
|
+
state.generator[expressions[0].type](expressions[0], state);
|
|
973
|
+
for (let i = 1; i < length; i++) {
|
|
974
|
+
state.write(",");
|
|
975
|
+
state.generator[expressions[i].type](expressions[i], state);
|
|
976
|
+
}
|
|
977
|
+
state.write(")");
|
|
978
|
+
} else {
|
|
979
|
+
state.write("()");
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
function expressionStartsWith(node, char) {
|
|
983
|
+
if (!node) return false;
|
|
984
|
+
if (node.type === "UnaryExpression" && node.prefix) {
|
|
985
|
+
return node.operator === char;
|
|
986
|
+
}
|
|
987
|
+
if (node.type === "UpdateExpression" && node.prefix) {
|
|
988
|
+
return node.operator[0] === char;
|
|
989
|
+
}
|
|
990
|
+
return false;
|
|
991
|
+
}
|
|
992
|
+
function expressionEndsWith(node, char) {
|
|
993
|
+
if (!node) return false;
|
|
994
|
+
if (node.type === "UpdateExpression" && !node.prefix) {
|
|
995
|
+
return node.operator[0] === char;
|
|
996
|
+
}
|
|
997
|
+
return false;
|
|
998
|
+
}
|
|
999
|
+
function isRegExp(node) {
|
|
1000
|
+
return node && (node.type === "Literal" && !!node.regex || node.type === "RegExpLiteral");
|
|
1001
|
+
}
|
|
1002
|
+
var compactGenerator = Object.assign({}, baseGenerator, {
|
|
1003
|
+
BinaryExpression(node, state) {
|
|
1004
|
+
const isIn = node.operator === "in";
|
|
1005
|
+
if (isIn) {
|
|
1006
|
+
state.write("(");
|
|
1007
|
+
}
|
|
1008
|
+
formatExpression(state, node.left, node, false);
|
|
1009
|
+
const op = node.operator;
|
|
1010
|
+
let spaceBefore = false;
|
|
1011
|
+
let spaceAfter = false;
|
|
1012
|
+
if (op === "in" || op === "instanceof") {
|
|
1013
|
+
spaceBefore = true;
|
|
1014
|
+
spaceAfter = true;
|
|
1015
|
+
} else {
|
|
1016
|
+
if ((op === "+" || op === "-") && expressionEndsWith(node.left, op) && !expressionNeedsParenthesis(state, node.left, node, false)) {
|
|
1017
|
+
spaceBefore = true;
|
|
1018
|
+
}
|
|
1019
|
+
if ((op === "+" || op === "-") && expressionStartsWith(node.right, op) && !expressionNeedsParenthesis(state, node.right, node, true) || op === "/" && isRegExp(node.right)) {
|
|
1020
|
+
spaceAfter = true;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
if (spaceBefore) state.write(" ");
|
|
1024
|
+
state.write(op);
|
|
1025
|
+
if (spaceAfter) state.write(" ");
|
|
1026
|
+
formatExpression(state, node.right, node, true);
|
|
1027
|
+
if (isIn) {
|
|
1028
|
+
state.write(")");
|
|
1029
|
+
}
|
|
1030
|
+
},
|
|
1031
|
+
LogicalExpression(node, state) {
|
|
1032
|
+
formatExpression(state, node.left, node, false);
|
|
1033
|
+
state.write(node.operator);
|
|
1034
|
+
formatExpression(state, node.right, node, true);
|
|
1035
|
+
},
|
|
1036
|
+
AssignmentExpression(node, state) {
|
|
1037
|
+
this[node.left.type](node.left, state);
|
|
1038
|
+
const op = node.operator;
|
|
1039
|
+
if (op.endsWith("+") && expressionStartsWith(node.right, "+") || op.endsWith("-") && expressionStartsWith(node.right, "-") || op.endsWith("/") && isRegExp(node.right)) {
|
|
1040
|
+
state.write(op + " ");
|
|
1041
|
+
} else {
|
|
1042
|
+
state.write(op);
|
|
1043
|
+
}
|
|
1044
|
+
this[node.right.type](node.right, state);
|
|
1045
|
+
},
|
|
1046
|
+
ConditionalExpression(node, state) {
|
|
1047
|
+
const test = node.test;
|
|
1048
|
+
const precedence = state.expressionsPrecedence[test.type];
|
|
1049
|
+
if (precedence === NEEDS_PARENTHESES || precedence <= state.expressionsPrecedence.ConditionalExpression) {
|
|
1050
|
+
state.write("(");
|
|
1051
|
+
this[test.type](test, state);
|
|
1052
|
+
state.write(")");
|
|
1053
|
+
} else {
|
|
1054
|
+
this[test.type](test, state);
|
|
1055
|
+
}
|
|
1056
|
+
state.write("?");
|
|
1057
|
+
this[node.consequent.type](node.consequent, state);
|
|
1058
|
+
state.write(":");
|
|
1059
|
+
this[node.alternate.type](node.alternate, state);
|
|
1060
|
+
},
|
|
1061
|
+
ArrayExpression(node, state) {
|
|
1062
|
+
state.write("[");
|
|
1063
|
+
const elements = node.elements;
|
|
1064
|
+
const length = elements.length;
|
|
1065
|
+
for (let i = 0; i < length; i++) {
|
|
1066
|
+
const element = elements[i];
|
|
1067
|
+
if (element != null) {
|
|
1068
|
+
this[element.type](element, state);
|
|
1069
|
+
}
|
|
1070
|
+
if (i + 1 < length) {
|
|
1071
|
+
state.write(",");
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
state.write("]");
|
|
1075
|
+
},
|
|
1076
|
+
ObjectExpression(node, state) {
|
|
1077
|
+
state.write("{");
|
|
1078
|
+
const properties = node.properties;
|
|
1079
|
+
const length = properties.length;
|
|
1080
|
+
for (let i = 0; i < length; i++) {
|
|
1081
|
+
const property = properties[i];
|
|
1082
|
+
this[property.type](property, state);
|
|
1083
|
+
if (i + 1 < length) {
|
|
1084
|
+
state.write(",");
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
state.write("}");
|
|
1088
|
+
},
|
|
1089
|
+
Property(node, state) {
|
|
1090
|
+
if (node.method || node.kind[0] !== "i") {
|
|
1091
|
+
this.MethodDefinition(node, state);
|
|
1092
|
+
} else {
|
|
1093
|
+
if (!node.shorthand) {
|
|
1094
|
+
if (node.computed) {
|
|
1095
|
+
state.write("[");
|
|
1096
|
+
this[node.key.type](node.key, state);
|
|
1097
|
+
state.write("]");
|
|
1098
|
+
} else {
|
|
1099
|
+
this[node.key.type](node.key, state);
|
|
1100
|
+
}
|
|
1101
|
+
state.write(":");
|
|
1102
|
+
}
|
|
1103
|
+
this[node.value.type](node.value, state);
|
|
1104
|
+
}
|
|
1105
|
+
},
|
|
1106
|
+
CallExpression(node, state) {
|
|
1107
|
+
formatExpression(state, node.callee, node, false);
|
|
1108
|
+
if (node.optional) {
|
|
1109
|
+
state.write("?.");
|
|
1110
|
+
}
|
|
1111
|
+
formatSequence(state, node.arguments);
|
|
1112
|
+
},
|
|
1113
|
+
SequenceExpression(node, state) {
|
|
1114
|
+
formatSequence(state, node.expressions);
|
|
1115
|
+
},
|
|
1116
|
+
FunctionDeclaration(node, state) {
|
|
1117
|
+
state.write(
|
|
1118
|
+
(node.async ? "async " : "") + (node.generator ? "function* " : "function ") + (node.id ? node.id.name : ""),
|
|
1119
|
+
node
|
|
1120
|
+
);
|
|
1121
|
+
formatSequence(state, node.params);
|
|
1122
|
+
this[node.body.type](node.body, state);
|
|
1123
|
+
},
|
|
1124
|
+
FunctionExpression(node, state) {
|
|
1125
|
+
compactGenerator.FunctionDeclaration.call(this, node, state);
|
|
1126
|
+
},
|
|
1127
|
+
ArrowFunctionExpression(node, state) {
|
|
1128
|
+
state.write(node.async ? "async " : "", node);
|
|
1129
|
+
const params = node.params;
|
|
1130
|
+
if (params != null) {
|
|
1131
|
+
if (params.length === 0) {
|
|
1132
|
+
state.write("()");
|
|
1133
|
+
} else if (params.length === 1 && params[0].type === "Identifier") {
|
|
1134
|
+
state.write(params[0].name, params[0]);
|
|
1135
|
+
} else {
|
|
1136
|
+
formatSequence(state, node.params);
|
|
1137
|
+
}
|
|
1138
|
+
} else {
|
|
1139
|
+
state.write("()");
|
|
1140
|
+
}
|
|
1141
|
+
state.write("=>");
|
|
1142
|
+
if (node.body.type[0] === "O") {
|
|
1143
|
+
state.write("(");
|
|
1144
|
+
this.ObjectExpression(node.body, state);
|
|
1145
|
+
state.write(")");
|
|
1146
|
+
} else {
|
|
1147
|
+
this[node.body.type](node.body, state);
|
|
1148
|
+
}
|
|
1149
|
+
},
|
|
1150
|
+
ForStatement(node, state) {
|
|
1151
|
+
state.write("for(");
|
|
1152
|
+
if (node.init != null) {
|
|
1153
|
+
const init = node.init;
|
|
1154
|
+
if (init.type[0] === "V") {
|
|
1155
|
+
this.VariableDeclaration(init, state);
|
|
1156
|
+
} else {
|
|
1157
|
+
this[init.type](init, state);
|
|
1158
|
+
state.write(";");
|
|
1159
|
+
}
|
|
1160
|
+
} else {
|
|
1161
|
+
state.write(";");
|
|
1162
|
+
}
|
|
1163
|
+
if (node.test) {
|
|
1164
|
+
this[node.test.type](node.test, state);
|
|
1165
|
+
}
|
|
1166
|
+
state.write(";");
|
|
1167
|
+
if (node.update) {
|
|
1168
|
+
this[node.update.type](node.update, state);
|
|
1169
|
+
}
|
|
1170
|
+
state.write(")");
|
|
1171
|
+
this[node.body.type](node.body, state);
|
|
1172
|
+
},
|
|
1173
|
+
IfStatement(node, state) {
|
|
1174
|
+
state.write("if(");
|
|
1175
|
+
this[node.test.type](node.test, state);
|
|
1176
|
+
state.write(")");
|
|
1177
|
+
this[node.consequent.type](node.consequent, state);
|
|
1178
|
+
if (node.alternate != null) {
|
|
1179
|
+
if (node.consequent.type === "BlockStatement") {
|
|
1180
|
+
state.write("else");
|
|
1181
|
+
} else {
|
|
1182
|
+
state.write(" else");
|
|
1183
|
+
}
|
|
1184
|
+
if (node.alternate.type === "BlockStatement") {
|
|
1185
|
+
this[node.alternate.type](node.alternate, state);
|
|
1186
|
+
} else if (node.alternate.type === "IfStatement") {
|
|
1187
|
+
state.write(" ");
|
|
1188
|
+
this[node.alternate.type](node.alternate, state);
|
|
1189
|
+
} else {
|
|
1190
|
+
state.write(" ");
|
|
1191
|
+
this[node.alternate.type](node.alternate, state);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
},
|
|
1195
|
+
VariableDeclaration(node, state) {
|
|
1196
|
+
state.write(node.kind + " ");
|
|
1197
|
+
const declarations = node.declarations;
|
|
1198
|
+
const length = declarations.length;
|
|
1199
|
+
for (let i = 0; i < length; i++) {
|
|
1200
|
+
this.VariableDeclarator(declarations[i], state);
|
|
1201
|
+
if (i + 1 < length) {
|
|
1202
|
+
state.write(",");
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
state.write(";");
|
|
1206
|
+
},
|
|
1207
|
+
VariableDeclarator(node, state) {
|
|
1208
|
+
this[node.id.type](node.id, state);
|
|
1209
|
+
if (node.init != null) {
|
|
1210
|
+
state.write("=");
|
|
1211
|
+
this[node.init.type](node.init, state);
|
|
1212
|
+
}
|
|
1213
|
+
},
|
|
1214
|
+
ReturnStatement(node, state) {
|
|
1215
|
+
state.write("return");
|
|
1216
|
+
if (node.argument) {
|
|
1217
|
+
state.write(" ");
|
|
1218
|
+
this[node.argument.type](node.argument, state);
|
|
1219
|
+
}
|
|
1220
|
+
state.write(";");
|
|
1221
|
+
},
|
|
1222
|
+
ImportExpression(node, state) {
|
|
1223
|
+
state.write("import(");
|
|
1224
|
+
if (Array.isArray(node.source?.comments) && node.source.comments.length > 0) {
|
|
1225
|
+
for (const c of node.source.comments) {
|
|
1226
|
+
state.write(c.type === "Block" ? `/*${c.value}*/` : `//${c.value}
|
|
1227
|
+
`);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
this[node.source.type](node.source, state);
|
|
1231
|
+
if (node.options != null) {
|
|
1232
|
+
state.write(",");
|
|
1233
|
+
this[node.options.type](node.options, state);
|
|
1234
|
+
}
|
|
1235
|
+
state.write(")");
|
|
1236
|
+
}
|
|
1237
|
+
});
|
|
1238
|
+
function generateCompactJs(ast) {
|
|
1239
|
+
return generate(ast, {
|
|
1240
|
+
generator: compactGenerator,
|
|
1241
|
+
indent: "",
|
|
1242
|
+
lineEnd: ""
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
// src/runtime/devtools-deterrent.ts
|
|
1247
|
+
function deriveIntegrityFnName(seed) {
|
|
1248
|
+
return derivePolymorphicIdent(seed, "shield");
|
|
1249
|
+
}
|
|
1250
|
+
function deriveWindowKeySymbol(seed) {
|
|
1251
|
+
return derivePolymorphicIdent(seed, "windowKey");
|
|
1252
|
+
}
|
|
1253
|
+
function createDeterrentSnippet(config) {
|
|
1254
|
+
const seed = config.seed >>> 0;
|
|
1255
|
+
const deterrentMode = config.deterrentMode ?? "passive";
|
|
1256
|
+
const detectHeadless = config.detectHeadless ?? false;
|
|
1257
|
+
const fnName = deriveIntegrityFnName(seed);
|
|
1258
|
+
const sym = config.windowKeySymbol ?? deriveWindowKeySymbol(seed);
|
|
1259
|
+
const consoleSilence = deterrentMode === "gradual" ? "for(var k in console)console[k]=function(){return 0;};" : "";
|
|
1260
|
+
const symLit = JSON.stringify(sym);
|
|
1261
|
+
const headlessDecl = detectHeadless ? ",n=w.navigator||0" : "";
|
|
1262
|
+
const headlessCond = detectHeadless ? "||n.webdriver||/HeadlessChrome/.test(n.userAgent)" : "";
|
|
1263
|
+
return `(function ${fnName}(w){var G=typeof globalThis!=='undefined'?globalThis:w;if(w){var O=Object,P=O.getOwnPropertyDescriptor,GP=O.getPrototypeOf,T=function(o,k){try{while(o){var r=P&&P(o,k);if(r&&(r.set||!r.writable))return 1;o=GP?GP(o):0;}}catch(e){return 1;}},S=function(o,k,v){try{o[k]=v;}catch(e){}},s=Function.prototype.toString${headlessDecl},src='',t=0;try{src=s.call(${fnName});if('prototype' in s||s.name!=='toString'||s.length!==0||s.call(s).indexOf('[native code]')<0||/\\n/.test(src)${headlessCond})t=1;}catch(e){t=1;}try{s.call(0);t=1;}catch(e){}if(T(w,${symLit})||T(G,${symLit})||T(G,'__unpeek_tampered')||T(w,'__unpeek_tampered')||T(String.prototype,'_u'))t=1;for(var h=0x811c9dc5,i=0;i<src.length;i++)h=Math.imul(h^src.charCodeAt(i),0x01000193)>>>0;var d=h&0xffff;if(t){var pd=(d^(((h>>>16)^0x5a5b)||1))&0xffff;if(!T(G,${symLit}))S(G,${symLit},pd);if(!T(w,${symLit}))S(w,${symLit},pd);S(G,'__unpeek_delta',pd);S(w,'__unpeek_delta',pd);try{String.prototype._u=14;}catch(e){}var ns=((w.__unpeek_seed||${seed})^1)>>>0;S(G,'__unpeek_seed',ns);S(w,'__unpeek_seed',ns);S(G,'__unpeek_tampered',!0);S(w,'__unpeek_tampered',!0);try{${consoleSilence}if(w.dispatchEvent)w.dispatchEvent(new CustomEvent('unpeek:tamper'));}catch(e){}}else{S(G,${symLit},d);S(w,${symLit},d);}}})(typeof window!=='undefined'?window:(typeof self!=='undefined'?self:0));`;
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
// src/runtime/index.ts
|
|
1267
|
+
function generateRuntimeShield(config) {
|
|
1268
|
+
const seed = config.seed >>> 0;
|
|
1269
|
+
const windowKeySymbol = config.windowKeySymbol ?? deriveWindowKeySymbol(seed);
|
|
1270
|
+
const integrityCheckFnName = deriveIntegrityFnName(seed);
|
|
1271
|
+
const preambleCode = createDeterrentSnippet({
|
|
1272
|
+
...config,
|
|
1273
|
+
windowKeySymbol
|
|
1274
|
+
});
|
|
1275
|
+
const fnStart = preambleCode.indexOf("function");
|
|
1276
|
+
const endMarker = preambleCode.lastIndexOf("})(");
|
|
1277
|
+
const fnEnd = endMarker !== -1 ? endMarker + 1 : preambleCode.lastIndexOf("(") - 1;
|
|
1278
|
+
const fnDecl = preambleCode.slice(fnStart, fnEnd);
|
|
1279
|
+
const computedHash = computeIntegrityHash(fnDecl, 0);
|
|
1280
|
+
const expectedHash = config.expectedIntegrityHash !== void 0 ? config.expectedIntegrityHash >>> 0 : computedHash;
|
|
1281
|
+
const expectedDelta = config.expectedDelta !== void 0 ? config.expectedDelta & 65535 : computedHash >>> 0 & 65535;
|
|
1282
|
+
const payload = {
|
|
1283
|
+
preambleCode,
|
|
1284
|
+
integrityCheckFnName,
|
|
1285
|
+
expectedHash,
|
|
1286
|
+
windowKeySymbol,
|
|
1287
|
+
expectedDelta
|
|
1288
|
+
};
|
|
1289
|
+
return payload;
|
|
1290
|
+
}
|
|
1291
|
+
|
|
868
1292
|
// src/ast/string-vault.ts
|
|
869
1293
|
import * as acorn4 from "acorn";
|
|
870
|
-
import * as
|
|
1294
|
+
import * as walk4 from "acorn-walk";
|
|
871
1295
|
|
|
872
1296
|
// src/ast/salted-vault.ts
|
|
873
1297
|
import * as acorn3 from "acorn";
|
|
874
|
-
import * as
|
|
1298
|
+
import * as walk3 from "acorn-walk";
|
|
875
1299
|
|
|
876
1300
|
// src/ast/wasm-vault.ts
|
|
877
1301
|
import * as acorn2 from "acorn";
|
|
@@ -1411,6 +1835,137 @@ try {
|
|
|
1411
1835
|
};
|
|
1412
1836
|
}
|
|
1413
1837
|
|
|
1838
|
+
// src/ast/boundary-classifier.ts
|
|
1839
|
+
import * as walk2 from "acorn-walk";
|
|
1840
|
+
var GLOBAL_HOSTS = /* @__PURE__ */ new Set(["self", "window", "globalThis"]);
|
|
1841
|
+
var MAGIC_COMMENT_RE = /webpack(?:ChunkName|Mode|Prefetch|Preload|Ignore|Include|Exclude|Exports)|@?vite-ignore|viteIgnore/i;
|
|
1842
|
+
function isHostMember(node, propName) {
|
|
1843
|
+
if (!node) return false;
|
|
1844
|
+
if (node.type === "Identifier" && node.name === propName) {
|
|
1845
|
+
return true;
|
|
1846
|
+
}
|
|
1847
|
+
if (node.type === "MemberExpression" && !node.computed && node.object?.type === "Identifier" && GLOBAL_HOSTS.has(node.object.name) && node.property?.type === "Identifier" && node.property.name === propName) {
|
|
1848
|
+
return true;
|
|
1849
|
+
}
|
|
1850
|
+
return false;
|
|
1851
|
+
}
|
|
1852
|
+
function unwrapAssignedHostMember(node, propName) {
|
|
1853
|
+
if (!node) return false;
|
|
1854
|
+
if (isHostMember(node, propName)) return true;
|
|
1855
|
+
if (node.type === "AssignmentExpression" && isHostMember(node.left, propName)) {
|
|
1856
|
+
return true;
|
|
1857
|
+
}
|
|
1858
|
+
return false;
|
|
1859
|
+
}
|
|
1860
|
+
function classifyChunkBoundary(ast) {
|
|
1861
|
+
const exemptSubtreeRoots = /* @__PURE__ */ new WeakSet();
|
|
1862
|
+
const importSourceNodes = /* @__PURE__ */ new WeakSet();
|
|
1863
|
+
const importExpressions = [];
|
|
1864
|
+
let hasEntryBootstrap = false;
|
|
1865
|
+
let hasRscFlight = false;
|
|
1866
|
+
let hasPreloadManifest = false;
|
|
1867
|
+
walk2.simple(ast, {
|
|
1868
|
+
CallExpression(node) {
|
|
1869
|
+
const callee = node.callee;
|
|
1870
|
+
if (callee?.type === "MemberExpression" && !callee.computed && callee.property?.type === "Identifier" && callee.property.name === "push") {
|
|
1871
|
+
if (unwrapAssignedHostMember(callee.object, "__next_f")) {
|
|
1872
|
+
hasRscFlight = true;
|
|
1873
|
+
if (Array.isArray(node.arguments)) {
|
|
1874
|
+
for (const arg of node.arguments) {
|
|
1875
|
+
if (arg && typeof arg === "object") {
|
|
1876
|
+
exemptSubtreeRoots.add(arg);
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
} else if (unwrapAssignedHostMember(callee.object, "TURBOPACK")) {
|
|
1881
|
+
hasEntryBootstrap = true;
|
|
1882
|
+
exemptSubtreeRoots.add(node);
|
|
1883
|
+
if (Array.isArray(node.arguments)) {
|
|
1884
|
+
for (const arg of node.arguments) {
|
|
1885
|
+
if (arg && typeof arg === "object") {
|
|
1886
|
+
exemptSubtreeRoots.add(arg);
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
},
|
|
1893
|
+
AssignmentExpression(node) {
|
|
1894
|
+
if (isHostMember(node.left, "TURBOPACK")) {
|
|
1895
|
+
hasEntryBootstrap = true;
|
|
1896
|
+
exemptSubtreeRoots.add(node);
|
|
1897
|
+
} else if (node.left?.type === "Identifier" && node.left.name === "__vite__mapDeps") {
|
|
1898
|
+
hasPreloadManifest = true;
|
|
1899
|
+
exemptSubtreeRoots.add(node);
|
|
1900
|
+
}
|
|
1901
|
+
},
|
|
1902
|
+
VariableDeclarator(node) {
|
|
1903
|
+
if (node.id?.type === "Identifier") {
|
|
1904
|
+
if (node.id.name === "__vite__mapDeps") {
|
|
1905
|
+
hasPreloadManifest = true;
|
|
1906
|
+
exemptSubtreeRoots.add(node);
|
|
1907
|
+
} else if (node.id.name === "TURBOPACK") {
|
|
1908
|
+
hasEntryBootstrap = true;
|
|
1909
|
+
exemptSubtreeRoots.add(node);
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
},
|
|
1913
|
+
FunctionDeclaration(node) {
|
|
1914
|
+
if (node.id?.type === "Identifier" && node.id.name === "__vite__mapDeps") {
|
|
1915
|
+
hasPreloadManifest = true;
|
|
1916
|
+
exemptSubtreeRoots.add(node);
|
|
1917
|
+
}
|
|
1918
|
+
},
|
|
1919
|
+
ImportExpression(node) {
|
|
1920
|
+
importExpressions.push(node);
|
|
1921
|
+
if (node.source && typeof node.source === "object") {
|
|
1922
|
+
exemptSubtreeRoots.add(node.source);
|
|
1923
|
+
importSourceNodes.add(node.source);
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
});
|
|
1927
|
+
let kind = "app-chunk";
|
|
1928
|
+
if (hasEntryBootstrap) {
|
|
1929
|
+
kind = "entry-bootstrap";
|
|
1930
|
+
} else if (hasRscFlight) {
|
|
1931
|
+
kind = "rsc-flight";
|
|
1932
|
+
} else if (hasPreloadManifest) {
|
|
1933
|
+
kind = "preload-manifest";
|
|
1934
|
+
}
|
|
1935
|
+
return {
|
|
1936
|
+
kind,
|
|
1937
|
+
exemptSubtreeRoots,
|
|
1938
|
+
importSourceNodes,
|
|
1939
|
+
importExpressions
|
|
1940
|
+
};
|
|
1941
|
+
}
|
|
1942
|
+
function isNodeInExemptSubtree(ancestors, exemptRoots) {
|
|
1943
|
+
if (!exemptRoots) return false;
|
|
1944
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
1945
|
+
if (exemptRoots.has(ancestors[i])) {
|
|
1946
|
+
return true;
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
return false;
|
|
1950
|
+
}
|
|
1951
|
+
function attachMagicComments(importExpressions, comments) {
|
|
1952
|
+
if (importExpressions.length === 0 || comments.length === 0) return;
|
|
1953
|
+
const magicComments = comments.filter((c) => MAGIC_COMMENT_RE.test(c.value));
|
|
1954
|
+
if (magicComments.length === 0) return;
|
|
1955
|
+
for (const expr of importExpressions) {
|
|
1956
|
+
const src = expr?.source;
|
|
1957
|
+
if (!src || typeof expr.start !== "number" || typeof src.start !== "number") {
|
|
1958
|
+
continue;
|
|
1959
|
+
}
|
|
1960
|
+
const matched = magicComments.filter(
|
|
1961
|
+
(c) => c.start >= expr.start && c.end <= src.start
|
|
1962
|
+
);
|
|
1963
|
+
if (matched.length > 0) {
|
|
1964
|
+
src.comments = matched.map((c) => ({ type: c.type, value: c.value }));
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1414
1969
|
// src/ast/salted-vault.ts
|
|
1415
1970
|
function computeCallSiteSalt(seed, idx) {
|
|
1416
1971
|
return ((Math.imul((seed ^ idx) >>> 0, 2654435761) ^ Math.imul(idx + 1 >>> 0, 73244475)) & 31) >>> 0;
|
|
@@ -1499,7 +2054,7 @@ function replaceNodeInParent(parent, oldNode, newNode) {
|
|
|
1499
2054
|
}
|
|
1500
2055
|
return false;
|
|
1501
2056
|
}
|
|
1502
|
-
function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, config, windowKeySymbol, expectedDelta, deterrentMode, shieldCoupled = true, detectHeadless = false) {
|
|
2057
|
+
function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, config, windowKeySymbol, expectedDelta, deterrentMode, shieldCoupled = true, detectHeadless = false, exemptSubtreeRoots) {
|
|
1503
2058
|
if (isAstAlreadySalted(ast)) {
|
|
1504
2059
|
return {
|
|
1505
2060
|
encryptedStringsCount: 0,
|
|
@@ -1518,13 +2073,16 @@ function applySaltedStringVault(ast, seed = 2654435769, minStringLength = 4, hot
|
|
|
1518
2073
|
const customReserved = config?.vault?.reservedProps ? new Set(config.vault.reservedProps) : void 0;
|
|
1519
2074
|
const targetsToReplace = [];
|
|
1520
2075
|
const encryptedPayloads = [];
|
|
1521
|
-
|
|
2076
|
+
walk3.ancestor(ast, {
|
|
1522
2077
|
Literal(node, ancestors) {
|
|
1523
2078
|
if (typeof node.value !== "string") return;
|
|
1524
2079
|
if (node.value.length < minLen) return;
|
|
1525
2080
|
if (activeDirectives.has(node.value)) return;
|
|
1526
2081
|
const parent = ancestors[ancestors.length - 2];
|
|
1527
2082
|
if (!parent) return;
|
|
2083
|
+
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
1528
2086
|
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(node.value))) {
|
|
1529
2087
|
return;
|
|
1530
2088
|
}
|
|
@@ -1951,7 +2509,32 @@ function createShaderVaultAst(shaderVarName, shaderPayloads, seed) {
|
|
|
1951
2509
|
}
|
|
1952
2510
|
return createSaltedVaultHelperAst(shaderVarName, b64List, fnAst);
|
|
1953
2511
|
}
|
|
1954
|
-
function
|
|
2512
|
+
function extractScopeChain(ast, ancestors) {
|
|
2513
|
+
const chain = [ast];
|
|
2514
|
+
for (let i = 1; i < ancestors.length - 1; i++) {
|
|
2515
|
+
const a = ancestors[i];
|
|
2516
|
+
const prev = ancestors[i - 1];
|
|
2517
|
+
if (a.type === "BlockStatement" && (prev.type === "FunctionDeclaration" || prev.type === "FunctionExpression" || prev.type === "ArrowFunctionExpression")) {
|
|
2518
|
+
chain.push(a);
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
return chain;
|
|
2522
|
+
}
|
|
2523
|
+
function findLowestCommonScope(ast, chains) {
|
|
2524
|
+
if (chains.length === 0) return ast;
|
|
2525
|
+
let lca = chains[0];
|
|
2526
|
+
for (let c = 1; c < chains.length; c++) {
|
|
2527
|
+
const cur = chains[c];
|
|
2528
|
+
let matchLen = 0;
|
|
2529
|
+
const limit = Math.min(lca.length, cur.length);
|
|
2530
|
+
while (matchLen < limit && lca[matchLen] === cur[matchLen]) {
|
|
2531
|
+
matchLen++;
|
|
2532
|
+
}
|
|
2533
|
+
lca = lca.slice(0, Math.max(1, matchLen));
|
|
2534
|
+
}
|
|
2535
|
+
return lca[lca.length - 1] ?? ast;
|
|
2536
|
+
}
|
|
2537
|
+
function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExemptNodes, windowKeySymbol, expectedDelta, deterrentMode, config, shieldCoupled = true, detectHeadless = false, exemptSubtreeRoots) {
|
|
1955
2538
|
const minLen = config?.vault?.minStringLength ?? minStringLength;
|
|
1956
2539
|
const activeDirectives = new Set(DIRECTIVE_STRINGS);
|
|
1957
2540
|
if (config?.vault?.customDirectives) {
|
|
@@ -1960,7 +2543,9 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
1960
2543
|
}
|
|
1961
2544
|
}
|
|
1962
2545
|
const customReserved = config?.vault?.reservedProps ? new Set(config.vault.reservedProps) : void 0;
|
|
1963
|
-
const semanticPatterns = config?.vault?.semanticAnchors?.patterns
|
|
2546
|
+
const semanticPatterns = config?.vault?.semanticAnchors?.patterns?.map(
|
|
2547
|
+
(p) => typeof p === "string" ? new RegExp(p) : p
|
|
2548
|
+
);
|
|
1964
2549
|
const excludeUi = config?.vault?.semanticAnchors?.excludeUiClasses !== false;
|
|
1965
2550
|
const suffix = (seed >>> 0 & 65535).toString(36);
|
|
1966
2551
|
const decryptFnName = `_uD${suffix}`;
|
|
@@ -2004,19 +2589,20 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
2004
2589
|
const buildH = computeIntegrityHash(compactFnStr, 0);
|
|
2005
2590
|
const expectedKey = (buildH ^ 0 ^ (shieldCoupled ? (expDelta ?? 0) & 65535 : 0)) >>> 0;
|
|
2006
2591
|
const stringToIndex = /* @__PURE__ */ new Map();
|
|
2592
|
+
const uniqueStrings = [];
|
|
2007
2593
|
const encryptedPayloads = [];
|
|
2008
2594
|
const shaderToIndex = /* @__PURE__ */ new Map();
|
|
2009
2595
|
const shaderPayloads = [];
|
|
2010
2596
|
const targetsToReplace = [];
|
|
2011
2597
|
const hotTargetsToReplace = [];
|
|
2012
2598
|
const customWalkBase = {
|
|
2013
|
-
...
|
|
2599
|
+
...walk4.base,
|
|
2014
2600
|
Property(node, st, c) {
|
|
2015
2601
|
c(node.key, st);
|
|
2016
2602
|
if (node.value) c(node.value, st);
|
|
2017
2603
|
}
|
|
2018
2604
|
};
|
|
2019
|
-
|
|
2605
|
+
walk4.ancestor(
|
|
2020
2606
|
ast,
|
|
2021
2607
|
{
|
|
2022
2608
|
Literal(node, _state, ancestors) {
|
|
@@ -2034,6 +2620,9 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
2034
2620
|
}
|
|
2035
2621
|
const parent = ancestors[ancestors.length - 2];
|
|
2036
2622
|
if (!parent) return;
|
|
2623
|
+
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
2624
|
+
return;
|
|
2625
|
+
}
|
|
2037
2626
|
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
2038
2627
|
return;
|
|
2039
2628
|
}
|
|
@@ -2089,19 +2678,28 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
2089
2678
|
shaderToIndex.set(val, idx);
|
|
2090
2679
|
shaderPayloads.push(val);
|
|
2091
2680
|
}
|
|
2092
|
-
targetsToReplace.push({
|
|
2681
|
+
targetsToReplace.push({
|
|
2682
|
+
type: "shader",
|
|
2683
|
+
node,
|
|
2684
|
+
parent,
|
|
2685
|
+
idx,
|
|
2686
|
+
scopeChain: extractScopeChain(ast, ancestors)
|
|
2687
|
+
});
|
|
2093
2688
|
} else {
|
|
2094
2689
|
if (!shouldEncryptString(val, minLen, parent, activeDirectives, customReserved)) return;
|
|
2095
2690
|
let idx = stringToIndex.get(val);
|
|
2096
2691
|
if (idx === void 0) {
|
|
2097
|
-
idx =
|
|
2692
|
+
idx = uniqueStrings.length;
|
|
2098
2693
|
stringToIndex.set(val, idx);
|
|
2099
|
-
|
|
2100
|
-
encryptedPayloads.push(
|
|
2101
|
-
encodeStringWithSeed(val, P_CHARS, expectedKey, salt, idx)
|
|
2102
|
-
);
|
|
2694
|
+
uniqueStrings.push(val);
|
|
2103
2695
|
}
|
|
2104
|
-
targetsToReplace.push({
|
|
2696
|
+
targetsToReplace.push({
|
|
2697
|
+
type: "string",
|
|
2698
|
+
node,
|
|
2699
|
+
parent,
|
|
2700
|
+
idx,
|
|
2701
|
+
scopeChain: extractScopeChain(ast, ancestors)
|
|
2702
|
+
});
|
|
2105
2703
|
}
|
|
2106
2704
|
},
|
|
2107
2705
|
TemplateLiteral(node, _state, ancestors) {
|
|
@@ -2109,6 +2707,9 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
2109
2707
|
if (node.expressions && node.expressions.length !== 0) return;
|
|
2110
2708
|
const val = node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
2111
2709
|
if (typeof val !== "string" || activeDirectives.has(val)) return;
|
|
2710
|
+
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
2711
|
+
return;
|
|
2712
|
+
}
|
|
2112
2713
|
let isHotExempt = false;
|
|
2113
2714
|
if (hotExemptNodes) {
|
|
2114
2715
|
for (let i = ancestors.length - 2; i >= 0; i--) {
|
|
@@ -2120,6 +2721,9 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
2120
2721
|
}
|
|
2121
2722
|
const parent = ancestors[ancestors.length - 2];
|
|
2122
2723
|
if (!parent) return;
|
|
2724
|
+
if (isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
2725
|
+
return;
|
|
2726
|
+
}
|
|
2123
2727
|
if (parent.type === "ExpressionStatement" && (Boolean(parent.directive) || activeDirectives.has(val))) {
|
|
2124
2728
|
return;
|
|
2125
2729
|
}
|
|
@@ -2161,19 +2765,28 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
2161
2765
|
shaderToIndex.set(val, idx);
|
|
2162
2766
|
shaderPayloads.push(val);
|
|
2163
2767
|
}
|
|
2164
|
-
targetsToReplace.push({
|
|
2768
|
+
targetsToReplace.push({
|
|
2769
|
+
type: "shader",
|
|
2770
|
+
node,
|
|
2771
|
+
parent,
|
|
2772
|
+
idx,
|
|
2773
|
+
scopeChain: extractScopeChain(ast, ancestors)
|
|
2774
|
+
});
|
|
2165
2775
|
} else {
|
|
2166
2776
|
if (!shouldEncryptString(val, minLen, parent, activeDirectives, customReserved)) return;
|
|
2167
2777
|
let idx = stringToIndex.get(val);
|
|
2168
2778
|
if (idx === void 0) {
|
|
2169
|
-
idx =
|
|
2779
|
+
idx = uniqueStrings.length;
|
|
2170
2780
|
stringToIndex.set(val, idx);
|
|
2171
|
-
|
|
2172
|
-
encryptedPayloads.push(
|
|
2173
|
-
encodeStringWithSeed(val, P_CHARS, expectedKey, salt, idx)
|
|
2174
|
-
);
|
|
2781
|
+
uniqueStrings.push(val);
|
|
2175
2782
|
}
|
|
2176
|
-
targetsToReplace.push({
|
|
2783
|
+
targetsToReplace.push({
|
|
2784
|
+
type: "string",
|
|
2785
|
+
node,
|
|
2786
|
+
parent,
|
|
2787
|
+
idx,
|
|
2788
|
+
scopeChain: extractScopeChain(ast, ancestors)
|
|
2789
|
+
});
|
|
2177
2790
|
}
|
|
2178
2791
|
}
|
|
2179
2792
|
},
|
|
@@ -2218,65 +2831,166 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
2218
2831
|
delete node.quasis;
|
|
2219
2832
|
delete node.expressions;
|
|
2220
2833
|
}
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2834
|
+
let insertIdx = 0;
|
|
2835
|
+
while (insertIdx < ast.body.length) {
|
|
2836
|
+
const stmt = ast.body[insertIdx];
|
|
2837
|
+
const isDirective = stmt.type === "ExpressionStatement" && (Boolean(stmt.directive) || stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string" && (activeDirectives.has(stmt.expression.value) || /^(?:use\s+[a-zA-Z0-9_-]+)/.test(stmt.expression.value.trim())));
|
|
2838
|
+
if (isDirective || stmt.type === "ImportDeclaration") {
|
|
2839
|
+
insertIdx++;
|
|
2840
|
+
} else {
|
|
2841
|
+
break;
|
|
2226
2842
|
}
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2843
|
+
}
|
|
2844
|
+
const wantFragmented = Boolean(config?.vault?.fragmented);
|
|
2845
|
+
let fragCount = Math.max(2, Math.min(8, Math.floor(config?.vault?.fragmentCount ?? 3)));
|
|
2846
|
+
while (fragCount > 2 && Math.floor(uniqueStrings.length / fragCount) < 4) {
|
|
2847
|
+
fragCount--;
|
|
2848
|
+
}
|
|
2849
|
+
const useFragmented = wantFragmented && uniqueStrings.length >= 8 && Math.floor(uniqueStrings.length / fragCount) >= 4;
|
|
2850
|
+
let integrityToken = computeFnv1aHash("empty", seed);
|
|
2851
|
+
if (!useFragmented) {
|
|
2852
|
+
for (let idx = 0; idx < uniqueStrings.length; idx++) {
|
|
2853
|
+
const salt = computeCallSiteSalt(seed, idx);
|
|
2854
|
+
encryptedPayloads.push(
|
|
2855
|
+
encodeStringWithSeed(uniqueStrings[idx], P_CHARS, expectedKey, salt, idx)
|
|
2856
|
+
);
|
|
2857
|
+
}
|
|
2858
|
+
integrityToken = computeFnv1aHash(JSON.stringify(encryptedPayloads), seed);
|
|
2859
|
+
for (const { type, node, parent, idx } of targetsToReplace) {
|
|
2860
|
+
if (parent?.type === "Property" && parent.key === node) {
|
|
2861
|
+
parent.computed = true;
|
|
2862
|
+
}
|
|
2863
|
+
if (type === "shader") {
|
|
2864
|
+
node.type = "CallExpression";
|
|
2865
|
+
node.callee = { type: "Identifier", name: shaderVarName };
|
|
2866
|
+
node.arguments = [{ type: "Literal", value: idx, raw: String(idx) }];
|
|
2867
|
+
} else {
|
|
2868
|
+
const salt = computeCallSiteSalt(seed, idx);
|
|
2869
|
+
node.type = "CallExpression";
|
|
2870
|
+
node.callee = { type: "Identifier", name: decryptFnName };
|
|
2871
|
+
node.arguments = [
|
|
2872
|
+
{ type: "Literal", value: idx, raw: String(idx) },
|
|
2873
|
+
{ type: "Literal", value: salt, raw: String(salt) }
|
|
2874
|
+
];
|
|
2875
|
+
}
|
|
2240
2876
|
node.optional = false;
|
|
2241
2877
|
delete node.value;
|
|
2242
2878
|
delete node.raw;
|
|
2243
2879
|
delete node.quasis;
|
|
2244
2880
|
delete node.expressions;
|
|
2245
|
-
}
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2881
|
+
}
|
|
2882
|
+
} else {
|
|
2883
|
+
const perm = [];
|
|
2884
|
+
for (let i = 0; i < uniqueStrings.length; i++) perm.push(i);
|
|
2885
|
+
let prng = (seed || 305419896) >>> 0;
|
|
2886
|
+
for (let i = perm.length - 1; i > 0; i--) {
|
|
2887
|
+
prng ^= prng << 13;
|
|
2888
|
+
prng ^= prng >>> 17;
|
|
2889
|
+
prng ^= prng << 5;
|
|
2890
|
+
const j = (prng >>> 0) % (i + 1);
|
|
2891
|
+
const tmp = perm[i];
|
|
2892
|
+
perm[i] = perm[j];
|
|
2893
|
+
perm[j] = tmp;
|
|
2894
|
+
}
|
|
2895
|
+
const stringFragAssign = new Array(
|
|
2896
|
+
uniqueStrings.length
|
|
2897
|
+
);
|
|
2898
|
+
const fragStrings = Array.from({ length: fragCount }, () => []);
|
|
2899
|
+
for (let p = 0; p < perm.length; p++) {
|
|
2900
|
+
const strIdx = perm[p];
|
|
2901
|
+
const fragId = p % fragCount;
|
|
2902
|
+
const localIdx = fragStrings[fragId].length;
|
|
2903
|
+
fragStrings[fragId].push(uniqueStrings[strIdx]);
|
|
2904
|
+
stringFragAssign[strIdx] = { fragId, localIdx };
|
|
2905
|
+
}
|
|
2906
|
+
const fragMeta = [];
|
|
2907
|
+
const usedFnNames = /* @__PURE__ */ new Set();
|
|
2908
|
+
for (let f = 0; f < fragCount; f++) {
|
|
2909
|
+
const fragSeed = (seed ^ Math.imul(f + 1, 2654435769)) >>> 0;
|
|
2910
|
+
let fnName = `_uD${(fragSeed & 65535).toString(36)}f${f}`;
|
|
2911
|
+
while (usedFnNames.has(fnName)) {
|
|
2912
|
+
fnName += "_";
|
|
2913
|
+
}
|
|
2914
|
+
usedFnNames.add(fnName);
|
|
2915
|
+
const pCharsF = createPermutationTable(fragSeed);
|
|
2916
|
+
const fnAstF = createSaltedDecryptorFnAst(
|
|
2917
|
+
fragSeed,
|
|
2918
|
+
pCharsF,
|
|
2919
|
+
expDelta ?? 0,
|
|
2920
|
+
sym,
|
|
2921
|
+
SAFE_ALPHA,
|
|
2922
|
+
shieldCoupled,
|
|
2923
|
+
browserOnly
|
|
2924
|
+
);
|
|
2925
|
+
const buildHF = computeIntegrityHash(generateCompactJs(fnAstF), 0);
|
|
2926
|
+
const expectedKeyF = (buildHF ^ 0 ^ (shieldCoupled ? (expDelta ?? 0) & 65535 : 0)) >>> 0;
|
|
2927
|
+
const payloads = [];
|
|
2928
|
+
for (let localIdx = 0; localIdx < fragStrings[f].length; localIdx++) {
|
|
2929
|
+
const salt = computeCallSiteSalt(fragSeed, localIdx);
|
|
2930
|
+
payloads.push(
|
|
2931
|
+
encodeStringWithSeed(
|
|
2932
|
+
fragStrings[f][localIdx],
|
|
2933
|
+
pCharsF,
|
|
2934
|
+
expectedKeyF,
|
|
2935
|
+
salt,
|
|
2936
|
+
localIdx
|
|
2937
|
+
)
|
|
2938
|
+
);
|
|
2939
|
+
}
|
|
2940
|
+
fragMeta.push({
|
|
2941
|
+
fragSeed,
|
|
2942
|
+
fnName,
|
|
2943
|
+
fnAst: fnAstF,
|
|
2944
|
+
payloads,
|
|
2945
|
+
chains: []
|
|
2946
|
+
});
|
|
2947
|
+
}
|
|
2948
|
+
for (const { type, node, parent, idx, scopeChain } of targetsToReplace) {
|
|
2949
|
+
if (parent?.type === "Property" && parent.key === node) {
|
|
2950
|
+
parent.computed = true;
|
|
2951
|
+
}
|
|
2952
|
+
if (type === "shader") {
|
|
2953
|
+
node.type = "CallExpression";
|
|
2954
|
+
node.callee = { type: "Identifier", name: shaderVarName };
|
|
2955
|
+
node.arguments = [{ type: "Literal", value: idx, raw: String(idx) }];
|
|
2956
|
+
} else {
|
|
2957
|
+
const { fragId, localIdx } = stringFragAssign[idx];
|
|
2958
|
+
const meta = fragMeta[fragId];
|
|
2959
|
+
meta.chains.push(scopeChain);
|
|
2960
|
+
const salt = computeCallSiteSalt(meta.fragSeed, localIdx);
|
|
2961
|
+
node.type = "CallExpression";
|
|
2962
|
+
node.callee = { type: "Identifier", name: meta.fnName };
|
|
2963
|
+
node.arguments = [
|
|
2964
|
+
{ type: "Literal", value: localIdx, raw: String(localIdx) },
|
|
2965
|
+
{ type: "Literal", value: salt, raw: String(salt) }
|
|
2966
|
+
];
|
|
2967
|
+
}
|
|
2264
2968
|
node.optional = false;
|
|
2265
2969
|
delete node.value;
|
|
2266
2970
|
delete node.raw;
|
|
2267
2971
|
delete node.quasis;
|
|
2268
2972
|
delete node.expressions;
|
|
2269
2973
|
}
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2974
|
+
const allPayloads = [];
|
|
2975
|
+
for (const meta of fragMeta) {
|
|
2976
|
+
allPayloads.push(meta.payloads);
|
|
2977
|
+
const helperStmt = createSaltedVaultHelperAst(
|
|
2978
|
+
meta.fnName,
|
|
2979
|
+
meta.payloads,
|
|
2980
|
+
meta.fnAst
|
|
2981
|
+
);
|
|
2982
|
+
const lcaScope = findLowestCommonScope(ast, meta.chains);
|
|
2983
|
+
if (lcaScope === ast || !Array.isArray(lcaScope.body)) {
|
|
2984
|
+
ast.body.splice(insertIdx++, 0, helperStmt);
|
|
2985
|
+
} else {
|
|
2986
|
+
let blockInsertIdx = 0;
|
|
2987
|
+
while (blockInsertIdx < lcaScope.body.length && lcaScope.body[blockInsertIdx]?.type === "ExpressionStatement" && Boolean(lcaScope.body[blockInsertIdx]?.directive)) {
|
|
2988
|
+
blockInsertIdx++;
|
|
2989
|
+
}
|
|
2990
|
+
lcaScope.body.splice(blockInsertIdx, 0, helperStmt);
|
|
2991
|
+
}
|
|
2279
2992
|
}
|
|
2993
|
+
integrityToken = computeFnv1aHash(JSON.stringify(allPayloads), seed);
|
|
2280
2994
|
}
|
|
2281
2995
|
if (hotTargetsToReplace.length > 0) {
|
|
2282
2996
|
const alreadyHasHx = ast.body.some(
|
|
@@ -2290,7 +3004,7 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
2290
3004
|
ast.body.splice(insertIdx++, 0, hxAst.body[0]);
|
|
2291
3005
|
}
|
|
2292
3006
|
}
|
|
2293
|
-
if (encryptedPayloads.length > 0) {
|
|
3007
|
+
if (!useFragmented && encryptedPayloads.length > 0) {
|
|
2294
3008
|
const vaultHelperStmt = createSaltedVaultHelperAst(
|
|
2295
3009
|
decryptFnName,
|
|
2296
3010
|
encryptedPayloads,
|
|
@@ -2307,14 +3021,14 @@ function applyStringVault(ast, seed = 2654435769, minStringLength = 4, hotExempt
|
|
|
2307
3021
|
ast.body.splice(insertIdx++, 0, shaderHelperStmt);
|
|
2308
3022
|
}
|
|
2309
3023
|
return {
|
|
2310
|
-
encryptedStringsCount:
|
|
3024
|
+
encryptedStringsCount: uniqueStrings.length + hotTargetsToReplace.length,
|
|
2311
3025
|
integrityToken,
|
|
2312
3026
|
shaderBuffersCount: shaderPayloads.length
|
|
2313
3027
|
};
|
|
2314
3028
|
}
|
|
2315
3029
|
|
|
2316
3030
|
// src/ast/polymorphic-mangler.ts
|
|
2317
|
-
import * as
|
|
3031
|
+
import * as walk5 from "acorn-walk";
|
|
2318
3032
|
var RESERVED_IDENTIFIERS = /* @__PURE__ */ new Set([
|
|
2319
3033
|
"arguments",
|
|
2320
3034
|
"undefined",
|
|
@@ -2469,7 +3183,9 @@ function collectPatternTargets(pattern, out, shorthandProp) {
|
|
|
2469
3183
|
}
|
|
2470
3184
|
function isMangleableName(origName, reservedSet = RESERVED_IDENTIFIERS, manglerConfig) {
|
|
2471
3185
|
const minLength = manglerConfig?.minLength ?? 3;
|
|
2472
|
-
return origName.length >= minLength && !reservedSet.has(origName) && !JS_KEYWORDS.has(origName) && !origName.startsWith("$") && !origName.startsWith("__") && !origName.startsWith("_u") && !origName.startsWith("_0x") && (!manglerConfig?.excludePrefixes || !manglerConfig.excludePrefixes.some((p) => origName.startsWith(p))) && (!manglerConfig?.excludePatterns || !manglerConfig.excludePatterns.some(
|
|
3186
|
+
return origName.length >= minLength && !reservedSet.has(origName) && !JS_KEYWORDS.has(origName) && !origName.startsWith("$") && !origName.startsWith("__") && !origName.startsWith("_u") && !origName.startsWith("_0x") && (!manglerConfig?.excludePrefixes || !manglerConfig.excludePrefixes.some((p) => origName.startsWith(p))) && (!manglerConfig?.excludePatterns || !manglerConfig.excludePatterns.some(
|
|
3187
|
+
(re) => (typeof re === "string" ? new RegExp(re) : re).test(origName)
|
|
3188
|
+
));
|
|
2473
3189
|
}
|
|
2474
3190
|
function shuffleAlphabet(chars, seed) {
|
|
2475
3191
|
const arr = chars.split("");
|
|
@@ -2597,7 +3313,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
2597
3313
|
}
|
|
2598
3314
|
}
|
|
2599
3315
|
ensureScopeChain([ast]);
|
|
2600
|
-
|
|
3316
|
+
walk5.ancestor(ast, {
|
|
2601
3317
|
BlockStatement(_node, _state, ancestors) {
|
|
2602
3318
|
ensureScopeChain(ancestors);
|
|
2603
3319
|
},
|
|
@@ -2735,7 +3451,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
2735
3451
|
}
|
|
2736
3452
|
return false;
|
|
2737
3453
|
}
|
|
2738
|
-
|
|
3454
|
+
walk5.ancestor(ast, {
|
|
2739
3455
|
Identifier(node, _state, ancestors) {
|
|
2740
3456
|
if (renamedTargetNodes.has(node)) return;
|
|
2741
3457
|
const parent = ancestors[ancestors.length - 2];
|
|
@@ -2842,7 +3558,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
2842
3558
|
}
|
|
2843
3559
|
}
|
|
2844
3560
|
}
|
|
2845
|
-
|
|
3561
|
+
walk5.ancestor(ast, {
|
|
2846
3562
|
AssignmentExpression(node, _state, ancestors) {
|
|
2847
3563
|
renamePatternTargetsInScope(node.left, ancestors);
|
|
2848
3564
|
},
|
|
@@ -2874,7 +3590,7 @@ function applyPolymorphicMangler(ast, seed = 2654435769, serializedFunctionNodes
|
|
|
2874
3590
|
}
|
|
2875
3591
|
|
|
2876
3592
|
// src/ast/cold-flow-guard.ts
|
|
2877
|
-
import * as
|
|
3593
|
+
import * as walk6 from "acorn-walk";
|
|
2878
3594
|
function createDecoyObjectExpression(model) {
|
|
2879
3595
|
const m = Math.abs(model) % 3;
|
|
2880
3596
|
if (m === 0) {
|
|
@@ -3267,7 +3983,7 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
3267
3983
|
}
|
|
3268
3984
|
node.body.body.splice(insertIdx, 0, guardStmt);
|
|
3269
3985
|
}
|
|
3270
|
-
|
|
3986
|
+
walk6.simple(ast, {
|
|
3271
3987
|
FunctionDeclaration: maybeInjectGuard,
|
|
3272
3988
|
FunctionExpression: maybeInjectGuard,
|
|
3273
3989
|
ArrowFunctionExpression: maybeInjectGuard
|
|
@@ -3295,7 +4011,7 @@ function applyColdFlowGuard(ast, coldFunctionNodes, seed = 2654435769, hotExempt
|
|
|
3295
4011
|
|
|
3296
4012
|
// src/ast/micro-vm.ts
|
|
3297
4013
|
import * as acorn5 from "acorn";
|
|
3298
|
-
import * as
|
|
4014
|
+
import * as walk7 from "acorn-walk";
|
|
3299
4015
|
var OP_LDC = 0;
|
|
3300
4016
|
var OP_LDV = 1;
|
|
3301
4017
|
var OP_STV = 2;
|
|
@@ -3459,14 +4175,14 @@ function createInterpreterSource(vmHelperName, opMap, seed = 2654435769, windowK
|
|
|
3459
4175
|
}
|
|
3460
4176
|
function countAstNodes(node) {
|
|
3461
4177
|
let count = 0;
|
|
3462
|
-
|
|
4178
|
+
walk7.full(node, () => {
|
|
3463
4179
|
count++;
|
|
3464
4180
|
});
|
|
3465
4181
|
return count;
|
|
3466
4182
|
}
|
|
3467
4183
|
function hasForbiddenConstructs(fnNode) {
|
|
3468
4184
|
let forbidden = false;
|
|
3469
|
-
|
|
4185
|
+
walk7.full(fnNode, (node) => {
|
|
3470
4186
|
if (forbidden) return;
|
|
3471
4187
|
const type = node.type;
|
|
3472
4188
|
if (type === "JSXElement" || type === "JSXFragment" || type === "Super" || type === "YieldExpression" || type === "WithStatement") {
|
|
@@ -4066,7 +4782,7 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
4066
4782
|
return ast;
|
|
4067
4783
|
}
|
|
4068
4784
|
const candidates = [];
|
|
4069
|
-
|
|
4785
|
+
walk7.ancestor(ast, {
|
|
4070
4786
|
ImportDeclaration(node) {
|
|
4071
4787
|
for (const spec of node.specifiers || []) {
|
|
4072
4788
|
if (spec.local?.type === "Identifier") {
|
|
@@ -4336,6 +5052,103 @@ function applyMicroVm(ast, coldFunctionNodes, serializedFunctionNodes, seed = 26
|
|
|
4336
5052
|
};
|
|
4337
5053
|
}
|
|
4338
5054
|
|
|
5055
|
+
// src/ast/scrubber.ts
|
|
5056
|
+
import * as walk8 from "acorn-walk";
|
|
5057
|
+
var FILE_URI_USER_RE = /file:\/\/\/(?:[A-Za-z]:\/)?(?:Users|home)\/[^/\s"'`]+\/([^\s"'`]+)/gi;
|
|
5058
|
+
var FILE_URI_LOCAL_RE = /file:\/\/\/(?:[A-Za-z]:\/)?([^\s"'`]+)/gi;
|
|
5059
|
+
var POSIX_USER_PATH_RE = /\/?(?:Users|home)\/[^/\s"'`]+\/([^\s"'`]+)/g;
|
|
5060
|
+
var WIN_USER_PATH_RE = /[A-Za-z]:\\{1,2}Users\\{1,2}[^\\\s"'`]+\\{1,2}([^\s"'`]+)/g;
|
|
5061
|
+
var PROTECTED_URL_OR_ASSET_RE = /(?:https?:\/\/[^\s"'`]+|(?:\/assets\/|\/_next\/static\/)[^\s"'`]*)/gi;
|
|
5062
|
+
function escapeTemplateRaw(str) {
|
|
5063
|
+
return str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
5064
|
+
}
|
|
5065
|
+
function scrubStringValue(val, rootDir) {
|
|
5066
|
+
if (!val.includes("/") && !val.includes("\\") && !val.includes("file:")) {
|
|
5067
|
+
return val;
|
|
5068
|
+
}
|
|
5069
|
+
const shielded = [];
|
|
5070
|
+
let out = val.replace(PROTECTED_URL_OR_ASSET_RE, (match) => {
|
|
5071
|
+
const token = `\0_UP_SHIELD_${shielded.length}_\0`;
|
|
5072
|
+
shielded.push(match);
|
|
5073
|
+
return token;
|
|
5074
|
+
});
|
|
5075
|
+
out = out.replace(FILE_URI_USER_RE, (_m, tail) => `[src]/${tail}`);
|
|
5076
|
+
out = out.replace(FILE_URI_LOCAL_RE, (_m, tail) => `[src]/${tail}`);
|
|
5077
|
+
out = out.replace(POSIX_USER_PATH_RE, (_m, tail) => `[src]/${tail}`);
|
|
5078
|
+
out = out.replace(
|
|
5079
|
+
WIN_USER_PATH_RE,
|
|
5080
|
+
(_m, tail) => `[src]/${tail.replace(/\\+/g, "/")}`
|
|
5081
|
+
);
|
|
5082
|
+
if (rootDir && rootDir.length > 1) {
|
|
5083
|
+
const normalizedRoot = rootDir.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
5084
|
+
if (normalizedRoot.length > 1) {
|
|
5085
|
+
if (out.includes(normalizedRoot + "/")) {
|
|
5086
|
+
out = out.split(normalizedRoot + "/").join("[src]/");
|
|
5087
|
+
}
|
|
5088
|
+
const winRoot = normalizedRoot.replace(/\//g, "\\");
|
|
5089
|
+
if (out.includes(winRoot + "\\")) {
|
|
5090
|
+
out = out.split(winRoot + "\\").join("[src]/");
|
|
5091
|
+
}
|
|
5092
|
+
}
|
|
5093
|
+
}
|
|
5094
|
+
if (shielded.length > 0) {
|
|
5095
|
+
out = out.replace(
|
|
5096
|
+
/\u0000_UP_SHIELD_(\d+)_\u0000/g,
|
|
5097
|
+
(_m, idxStr) => shielded[Number(idxStr)] ?? ""
|
|
5098
|
+
);
|
|
5099
|
+
}
|
|
5100
|
+
return out;
|
|
5101
|
+
}
|
|
5102
|
+
function scrubResidualPaths(ast, options = {}, hotExemptNodes, exemptSubtreeRoots) {
|
|
5103
|
+
const exemptSet = options.exemptStrings ? new Set(options.exemptStrings) : void 0;
|
|
5104
|
+
let scrubbedCount = 0;
|
|
5105
|
+
walk8.ancestor(ast, {
|
|
5106
|
+
Literal(node, _state, ancestors) {
|
|
5107
|
+
if (node.regex || typeof node.value !== "string") return;
|
|
5108
|
+
const val = node.value;
|
|
5109
|
+
if (exemptSet?.has(val)) return;
|
|
5110
|
+
const parent = ancestors[ancestors.length - 2];
|
|
5111
|
+
if (!parent) return;
|
|
5112
|
+
if ((parent.type === "ImportDeclaration" || parent.type === "ExportNamedDeclaration" || parent.type === "ExportAllDeclaration" || parent.type === "ImportExpression") && parent.source === node) {
|
|
5113
|
+
return;
|
|
5114
|
+
}
|
|
5115
|
+
if (parent.type === "ExpressionStatement" && Boolean(parent.directive)) {
|
|
5116
|
+
return;
|
|
5117
|
+
}
|
|
5118
|
+
if (isNodeInExemptSubtree(ancestors, hotExemptNodes) || isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
5119
|
+
return;
|
|
5120
|
+
}
|
|
5121
|
+
const scrubbed = scrubStringValue(val, options.rootDir);
|
|
5122
|
+
if (scrubbed !== val) {
|
|
5123
|
+
node.value = scrubbed;
|
|
5124
|
+
node.raw = JSON.stringify(scrubbed);
|
|
5125
|
+
scrubbedCount++;
|
|
5126
|
+
}
|
|
5127
|
+
},
|
|
5128
|
+
TemplateLiteral(node, _state, ancestors) {
|
|
5129
|
+
if (!Array.isArray(node.quasis)) return;
|
|
5130
|
+
if (isNodeInExemptSubtree(ancestors, hotExemptNodes) || isNodeInExemptSubtree(ancestors, exemptSubtreeRoots)) {
|
|
5131
|
+
return;
|
|
5132
|
+
}
|
|
5133
|
+
const parent = ancestors[ancestors.length - 2];
|
|
5134
|
+
if (parent?.type === "ImportExpression" && parent.source === node) {
|
|
5135
|
+
return;
|
|
5136
|
+
}
|
|
5137
|
+
for (const quasi of node.quasis) {
|
|
5138
|
+
const val = quasi?.value?.cooked ?? quasi?.value?.raw;
|
|
5139
|
+
if (typeof val !== "string" || exemptSet?.has(val)) continue;
|
|
5140
|
+
const scrubbed = scrubStringValue(val, options.rootDir);
|
|
5141
|
+
if (scrubbed !== val) {
|
|
5142
|
+
quasi.value.cooked = scrubbed;
|
|
5143
|
+
quasi.value.raw = escapeTemplateRaw(scrubbed);
|
|
5144
|
+
scrubbedCount++;
|
|
5145
|
+
}
|
|
5146
|
+
}
|
|
5147
|
+
}
|
|
5148
|
+
});
|
|
5149
|
+
return scrubbedCount;
|
|
5150
|
+
}
|
|
5151
|
+
|
|
4339
5152
|
// src/ast/index.ts
|
|
4340
5153
|
function isAstAlreadyProtected(ast) {
|
|
4341
5154
|
if (!ast || !Array.isArray(ast.body)) return false;
|
|
@@ -4379,11 +5192,13 @@ function transformJavaScript(code, options = {}) {
|
|
|
4379
5192
|
},
|
|
4380
5193
|
integrityToken: computeFnv1aHash("", seed),
|
|
4381
5194
|
virtualizedFunctionsCount: 0,
|
|
4382
|
-
shaderBuffersCount: 0
|
|
5195
|
+
shaderBuffersCount: 0,
|
|
5196
|
+
skippedReason: "empty"
|
|
4383
5197
|
};
|
|
4384
5198
|
return emptyResult;
|
|
4385
5199
|
}
|
|
4386
|
-
const
|
|
5200
|
+
const comments = [];
|
|
5201
|
+
const ast = parseJavaScriptAst(code, comments);
|
|
4387
5202
|
if (!ast) {
|
|
4388
5203
|
if (options.strict) {
|
|
4389
5204
|
const targetLabel = options.filename ? ` "${options.filename}"` : "";
|
|
@@ -4403,7 +5218,8 @@ function transformJavaScript(code, options = {}) {
|
|
|
4403
5218
|
},
|
|
4404
5219
|
integrityToken: computeFnv1aHash(code, seed),
|
|
4405
5220
|
virtualizedFunctionsCount: 0,
|
|
4406
|
-
shaderBuffersCount: 0
|
|
5221
|
+
shaderBuffersCount: 0,
|
|
5222
|
+
skippedReason: "parse-error"
|
|
4407
5223
|
};
|
|
4408
5224
|
return unparsedResult;
|
|
4409
5225
|
}
|
|
@@ -4419,10 +5235,13 @@ function transformJavaScript(code, options = {}) {
|
|
|
4419
5235
|
},
|
|
4420
5236
|
integrityToken: computeFnv1aHash(code, seed),
|
|
4421
5237
|
virtualizedFunctionsCount: 0,
|
|
4422
|
-
shaderBuffersCount: 0
|
|
5238
|
+
shaderBuffersCount: 0,
|
|
5239
|
+
skippedReason: "already-protected"
|
|
4423
5240
|
};
|
|
4424
5241
|
return protectedResult;
|
|
4425
5242
|
}
|
|
5243
|
+
const boundary = classifyChunkBoundary(ast);
|
|
5244
|
+
attachMagicComments(boundary.importExpressions, comments);
|
|
4426
5245
|
const {
|
|
4427
5246
|
report: hotPathReport,
|
|
4428
5247
|
coldFunctionNodes,
|
|
@@ -4430,6 +5249,14 @@ function transformJavaScript(code, options = {}) {
|
|
|
4430
5249
|
hotExemptNodes,
|
|
4431
5250
|
serializedFunctionNodes
|
|
4432
5251
|
} = analyzeAstHotPaths(ast, options.config);
|
|
5252
|
+
if (options.scrubPaths || options.config?.scrubPaths) {
|
|
5253
|
+
scrubResidualPaths(
|
|
5254
|
+
ast,
|
|
5255
|
+
{ scrubPaths: true },
|
|
5256
|
+
hotExemptNodes,
|
|
5257
|
+
boundary.exemptSubtreeRoots
|
|
5258
|
+
);
|
|
5259
|
+
}
|
|
4433
5260
|
const shieldCoupled = internalOptions.shieldCoupled ?? Boolean(internalOptions.injectRuntimeShield);
|
|
4434
5261
|
const deterrentMode = internalOptions.deterrentMode ?? internalOptions.config?.shield?.deterrentMode ?? "passive";
|
|
4435
5262
|
const detectHeadless = internalOptions.detectHeadless ?? internalOptions.config?.shield?.detectHeadless ?? false;
|
|
@@ -4477,7 +5304,8 @@ function transformJavaScript(code, options = {}) {
|
|
|
4477
5304
|
shieldDelta,
|
|
4478
5305
|
deterrentMode,
|
|
4479
5306
|
shieldCoupled,
|
|
4480
|
-
detectHeadless
|
|
5307
|
+
detectHeadless,
|
|
5308
|
+
boundary.exemptSubtreeRoots
|
|
4481
5309
|
);
|
|
4482
5310
|
encryptedStringsCount = saltedRes.encryptedStringsCount;
|
|
4483
5311
|
integrityToken = saltedRes.integrityToken;
|
|
@@ -4492,7 +5320,8 @@ function transformJavaScript(code, options = {}) {
|
|
|
4492
5320
|
deterrentMode,
|
|
4493
5321
|
options.config,
|
|
4494
5322
|
shieldCoupled,
|
|
4495
|
-
detectHeadless
|
|
5323
|
+
detectHeadless,
|
|
5324
|
+
boundary.exemptSubtreeRoots
|
|
4496
5325
|
);
|
|
4497
5326
|
encryptedStringsCount = vaultRes.encryptedStringsCount;
|
|
4498
5327
|
integrityToken = vaultRes.integrityToken;
|
|
@@ -4527,6 +5356,12 @@ ${finalCode}`;
|
|
|
4527
5356
|
}
|
|
4528
5357
|
|
|
4529
5358
|
export {
|
|
5359
|
+
computeFnv1aHash,
|
|
4530
5360
|
detectHotPaths,
|
|
5361
|
+
computeIntegrityHash,
|
|
5362
|
+
verifyCodeIntegrity,
|
|
5363
|
+
deriveWindowKeySymbol,
|
|
5364
|
+
createDeterrentSnippet,
|
|
5365
|
+
generateRuntimeShield,
|
|
4531
5366
|
transformJavaScript
|
|
4532
5367
|
};
|