expose-kit 0.12.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -0
- package/dist/index.js +311 -107
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -358,6 +358,46 @@ Notes:
|
|
|
358
358
|
|
|
359
359
|
---
|
|
360
360
|
|
|
361
|
+
### `expose remove-anti-tamper`
|
|
362
|
+
|
|
363
|
+
Drop the self-defending wrapper, debug guards, and console hijacks generated by anti-tamper scripts.
|
|
364
|
+
```js
|
|
365
|
+
var wrapper = (function () {
|
|
366
|
+
var guard = true;
|
|
367
|
+
return function (ctx, fn) {
|
|
368
|
+
var thunk = guard ? function () {
|
|
369
|
+
if (fn) {
|
|
370
|
+
fn.apply(ctx, arguments);
|
|
371
|
+
fn = null;
|
|
372
|
+
}
|
|
373
|
+
} : function () {};
|
|
374
|
+
guard = false;
|
|
375
|
+
return thunk;
|
|
376
|
+
};
|
|
377
|
+
})();
|
|
378
|
+
|
|
379
|
+
wrapper(this, function () {
|
|
380
|
+
console.log("tamper");
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
console.log("safe");
|
|
384
|
+
```
|
|
385
|
+
Example is [here](https://github.com/evex-dev/expose-kit/tree/main/commands/remove-anti-tamper/mocks).
|
|
386
|
+
|
|
387
|
+
```bash
|
|
388
|
+
expose remove-anti-tamper path/to/file.js --output path/to/file.remove-anti-tamper.js
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
Args:
|
|
392
|
+
- `--o, --output <file>`
|
|
393
|
+
Output file path
|
|
394
|
+
|
|
395
|
+
Notes:
|
|
396
|
+
- Targets wrappers that return guarded helper functions and removes their invocations.
|
|
397
|
+
- Cleans up debug/console helper functions before removing the wrapper.
|
|
398
|
+
|
|
399
|
+
---
|
|
400
|
+
|
|
361
401
|
### `expose control-flow-packer`
|
|
362
402
|
|
|
363
403
|
Inline control-flow flattening loops generated by string-based state machines.
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// index.ts
|
|
4
4
|
import { Command } from "commander";
|
|
5
|
-
import { dirname as
|
|
5
|
+
import { dirname as dirname14, join as join14 } from "path";
|
|
6
6
|
import { fileURLToPath } from "url";
|
|
7
7
|
import chalk4 from "chalk";
|
|
8
8
|
|
|
@@ -1107,11 +1107,35 @@ var shouldSkipReferencedIdentifier = (path) => {
|
|
|
1107
1107
|
};
|
|
1108
1108
|
var getArrayReturnExpression = (node) => {
|
|
1109
1109
|
if (node.params.length !== 0) return null;
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
const
|
|
1113
|
-
if (
|
|
1114
|
-
|
|
1110
|
+
const body = node.body;
|
|
1111
|
+
if (t4.isBlockStatement(body)) {
|
|
1112
|
+
const statements = body.body;
|
|
1113
|
+
if (statements.length === 1) {
|
|
1114
|
+
const statement = statements[0];
|
|
1115
|
+
if (!t4.isReturnStatement(statement) || !statement.argument) return null;
|
|
1116
|
+
return t4.isArrayExpression(statement.argument) ? statement.argument : null;
|
|
1117
|
+
}
|
|
1118
|
+
if (statements.length === 2) {
|
|
1119
|
+
const [first, second] = statements;
|
|
1120
|
+
const arrayExpression = (() => {
|
|
1121
|
+
if (!t4.isVariableDeclaration(first) || first.declarations.length !== 1) {
|
|
1122
|
+
return null;
|
|
1123
|
+
}
|
|
1124
|
+
const declarator = first.declarations[0];
|
|
1125
|
+
if (!(t4.isIdentifier(declarator.id) && declarator.init && t4.isArrayExpression(declarator.init))) {
|
|
1126
|
+
return null;
|
|
1127
|
+
}
|
|
1128
|
+
if (!t4.isReturnStatement(second) || !second.argument) return null;
|
|
1129
|
+
if (!t4.isIdentifier(second.argument) || second.argument.name !== declarator.id.name) {
|
|
1130
|
+
return null;
|
|
1131
|
+
}
|
|
1132
|
+
return declarator.init;
|
|
1133
|
+
})();
|
|
1134
|
+
if (arrayExpression) {
|
|
1135
|
+
return arrayExpression;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
return null;
|
|
1115
1139
|
}
|
|
1116
1140
|
return t4.isArrayExpression(node.body) ? node.body : null;
|
|
1117
1141
|
};
|
|
@@ -1561,6 +1585,7 @@ var removeReassign = (code, filename) => {
|
|
|
1561
1585
|
const binding = path.scope.getBinding(path.node.id.name);
|
|
1562
1586
|
if (!binding || !binding.constant) return;
|
|
1563
1587
|
const wrapper = getWrapperInfo(
|
|
1588
|
+
// TODO: fix this
|
|
1564
1589
|
initPath,
|
|
1565
1590
|
binding
|
|
1566
1591
|
);
|
|
@@ -1941,9 +1966,9 @@ var remove_deadcode_default = createCommand((program3) => {
|
|
|
1941
1966
|
);
|
|
1942
1967
|
});
|
|
1943
1968
|
|
|
1944
|
-
// commands/
|
|
1945
|
-
import { readFileSync as readFileSync11, writeFileSync as writeFileSync10 } from "fs";
|
|
1969
|
+
// commands/remove-anti-tamper/index.ts
|
|
1946
1970
|
import { basename as basename10, dirname as dirname10, extname as extname10, join as join10 } from "path";
|
|
1971
|
+
import { readFileSync as readFileSync11, writeFileSync as writeFileSync10 } from "fs";
|
|
1947
1972
|
import { parse as parse11 } from "@babel/parser";
|
|
1948
1973
|
import traverse10 from "@babel/traverse";
|
|
1949
1974
|
import generate10 from "@babel/generator";
|
|
@@ -1953,22 +1978,200 @@ var walk2 = patchDefault(traverse10);
|
|
|
1953
1978
|
var createDefaultOutputPath10 = (inputPath) => {
|
|
1954
1979
|
const ext = extname10(inputPath);
|
|
1955
1980
|
if (!ext) {
|
|
1956
|
-
return `${inputPath}.
|
|
1981
|
+
return `${inputPath}.remove-anti-tamper.js`;
|
|
1957
1982
|
}
|
|
1958
1983
|
const base = basename10(inputPath, ext);
|
|
1959
|
-
return join10(dirname10(inputPath), `${base}.
|
|
1984
|
+
return join10(dirname10(inputPath), `${base}.remove-anti-tamper${ext}`);
|
|
1985
|
+
};
|
|
1986
|
+
var isWrapperDeclaration = (node) => {
|
|
1987
|
+
if (!t9.isIdentifier(node.id)) return false;
|
|
1988
|
+
if (!node.init || !t9.isCallExpression(node.init)) return false;
|
|
1989
|
+
const callee = node.init.callee;
|
|
1990
|
+
if (!t9.isFunctionExpression(callee)) return false;
|
|
1991
|
+
if (callee.params.length !== 0) return false;
|
|
1992
|
+
const bodyStatements = callee.body.body;
|
|
1993
|
+
if (bodyStatements.length < 2) return false;
|
|
1994
|
+
const firstStatement = bodyStatements[0];
|
|
1995
|
+
if (!t9.isVariableDeclaration(firstStatement) || firstStatement.declarations.length !== 1) {
|
|
1996
|
+
return false;
|
|
1997
|
+
}
|
|
1998
|
+
const firstDecl = firstStatement.declarations[0];
|
|
1999
|
+
if (!t9.isIdentifier(firstDecl.id) || !t9.isBooleanLiteral(firstDecl.init, { value: true })) {
|
|
2000
|
+
return false;
|
|
2001
|
+
}
|
|
2002
|
+
const returnStatement = bodyStatements.find(
|
|
2003
|
+
(stmt) => t9.isReturnStatement(stmt)
|
|
2004
|
+
);
|
|
2005
|
+
if (!returnStatement || !t9.isFunctionExpression(returnStatement.argument)) {
|
|
2006
|
+
return false;
|
|
2007
|
+
}
|
|
2008
|
+
const innerFunction = returnStatement.argument;
|
|
2009
|
+
if (innerFunction.params.length < 2) {
|
|
2010
|
+
return false;
|
|
2011
|
+
}
|
|
2012
|
+
return true;
|
|
2013
|
+
};
|
|
2014
|
+
var removeReferencedFunctions = (callPath) => {
|
|
2015
|
+
const args = callPath.get("arguments");
|
|
2016
|
+
if (!args || args.length < 2) {
|
|
2017
|
+
return false;
|
|
2018
|
+
}
|
|
2019
|
+
const handler = args[1];
|
|
2020
|
+
if (!handler.isFunction()) {
|
|
2021
|
+
return false;
|
|
2022
|
+
}
|
|
2023
|
+
let removed = false;
|
|
2024
|
+
handler.traverse({
|
|
2025
|
+
CallExpression(innerPath) {
|
|
2026
|
+
const callee = innerPath.get("callee");
|
|
2027
|
+
if (!callee.isIdentifier()) return;
|
|
2028
|
+
const binding = callee.scope.getBinding(callee.node.name);
|
|
2029
|
+
if (!binding) return;
|
|
2030
|
+
const bindingPath = binding.path;
|
|
2031
|
+
if (bindingPath.isFunctionDeclaration() && !bindingPath.removed) {
|
|
2032
|
+
bindingPath.remove();
|
|
2033
|
+
removed = true;
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
});
|
|
2037
|
+
return removed;
|
|
2038
|
+
};
|
|
2039
|
+
var cleanEmptyVariableDeclaration = (path) => {
|
|
2040
|
+
if (path.node.declarations.length === 0) {
|
|
2041
|
+
path.remove();
|
|
2042
|
+
}
|
|
2043
|
+
};
|
|
2044
|
+
var removeAntiTamperPatterns = (code, filename) => {
|
|
2045
|
+
const ast = parse11(code, createParseOptions(filename));
|
|
2046
|
+
let changed = false;
|
|
2047
|
+
walk2(ast, {
|
|
2048
|
+
VariableDeclarator(path) {
|
|
2049
|
+
if (!isWrapperDeclaration(path.node)) return;
|
|
2050
|
+
const wrapperName = path.node.id;
|
|
2051
|
+
if (!t9.isIdentifier(wrapperName)) return;
|
|
2052
|
+
const binding = path.scope.getBinding(wrapperName.name);
|
|
2053
|
+
if (!binding) return;
|
|
2054
|
+
let removedReference = false;
|
|
2055
|
+
const references = [...binding.referencePaths];
|
|
2056
|
+
for (const reference of references) {
|
|
2057
|
+
const callPath = reference.parentPath;
|
|
2058
|
+
if (!callPath?.isCallExpression()) continue;
|
|
2059
|
+
const removedDebug = removeReferencedFunctions(callPath);
|
|
2060
|
+
if (removedDebug) {
|
|
2061
|
+
changed = true;
|
|
2062
|
+
}
|
|
2063
|
+
const declaratorPath = callPath.findParent(
|
|
2064
|
+
(p) => p.isVariableDeclarator()
|
|
2065
|
+
);
|
|
2066
|
+
if (declaratorPath && declaratorPath.isVariableDeclarator()) {
|
|
2067
|
+
const parentDecl = declaratorPath.parentPath;
|
|
2068
|
+
declaratorPath.remove();
|
|
2069
|
+
if (parentDecl?.isVariableDeclaration()) {
|
|
2070
|
+
cleanEmptyVariableDeclaration(parentDecl);
|
|
2071
|
+
}
|
|
2072
|
+
removedReference = true;
|
|
2073
|
+
changed = true;
|
|
2074
|
+
continue;
|
|
2075
|
+
}
|
|
2076
|
+
const statement = callPath.getStatementParent();
|
|
2077
|
+
if (statement) {
|
|
2078
|
+
statement.remove();
|
|
2079
|
+
removedReference = true;
|
|
2080
|
+
changed = true;
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
if (removedReference && !path.removed) {
|
|
2084
|
+
path.remove();
|
|
2085
|
+
changed = true;
|
|
2086
|
+
const parentDecl = path.parentPath;
|
|
2087
|
+
if (parentDecl?.isVariableDeclaration()) {
|
|
2088
|
+
cleanEmptyVariableDeclaration(parentDecl);
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
});
|
|
2093
|
+
return {
|
|
2094
|
+
code: patchDefault(generate10)(ast).code,
|
|
2095
|
+
changed
|
|
2096
|
+
};
|
|
2097
|
+
};
|
|
2098
|
+
var remove_anti_tamper_default = createCommand((program3) => {
|
|
2099
|
+
program3.command("remove-anti-tamper").description("Drop anti-tamper wrapper calls and helpers").argument("[file]", "The file to transform").option("--input, --file <file>", "The file to transform").option("--o, --output <file>", "Output file path").option("--unlimited", "Unlimited timeout").action(
|
|
2100
|
+
async (fileArgument, options) => {
|
|
2101
|
+
await timeout(
|
|
2102
|
+
async ({ finish }) => {
|
|
2103
|
+
const filename = fileArgument ?? options.file ?? await createPrompt("Enter the file path:");
|
|
2104
|
+
if (!filename) {
|
|
2105
|
+
showError("No file provided");
|
|
2106
|
+
return finish();
|
|
2107
|
+
}
|
|
2108
|
+
try {
|
|
2109
|
+
const fileContent = readFileSync11(filename, "utf8");
|
|
2110
|
+
const defaultOutputPath = createDefaultOutputPath10(filename);
|
|
2111
|
+
let outputPath = options.output;
|
|
2112
|
+
if (!outputPath) {
|
|
2113
|
+
const promptPath = (await createPrompt("Enter the output file path:"))?.trim();
|
|
2114
|
+
outputPath = promptPath || defaultOutputPath;
|
|
2115
|
+
}
|
|
2116
|
+
const loader = loading11("Removing anti-tamper patterns...").start();
|
|
2117
|
+
try {
|
|
2118
|
+
const { code: output, changed } = removeAntiTamperPatterns(
|
|
2119
|
+
fileContent,
|
|
2120
|
+
filename
|
|
2121
|
+
);
|
|
2122
|
+
writeFileSync10(outputPath, output, "utf8");
|
|
2123
|
+
loader.succeed(
|
|
2124
|
+
`Saved remove-anti-tamper file to: ${outputPath} (${diff(fileContent, output).length} lines changed${changed ? ", removed anti-tamper code" : ""})`
|
|
2125
|
+
);
|
|
2126
|
+
return finish();
|
|
2127
|
+
} catch (error) {
|
|
2128
|
+
loader.fail("Failed to apply remove-anti-tamper transform");
|
|
2129
|
+
showError(
|
|
2130
|
+
`Error transforming file '${filename}': ${error instanceof Error ? error.message : "Unknown error"}`
|
|
2131
|
+
);
|
|
2132
|
+
return finish();
|
|
2133
|
+
}
|
|
2134
|
+
} catch (error) {
|
|
2135
|
+
showError(
|
|
2136
|
+
`Error reading file '${filename}': ${error instanceof Error ? error.message : "Unknown error"}`
|
|
2137
|
+
);
|
|
2138
|
+
return finish();
|
|
2139
|
+
}
|
|
2140
|
+
},
|
|
2141
|
+
options.unlimited ? null : 120 * 1e3
|
|
2142
|
+
);
|
|
2143
|
+
}
|
|
2144
|
+
);
|
|
2145
|
+
});
|
|
2146
|
+
|
|
2147
|
+
// commands/control-flow-packer/index.ts
|
|
2148
|
+
import { readFileSync as readFileSync12, writeFileSync as writeFileSync11 } from "fs";
|
|
2149
|
+
import { basename as basename11, dirname as dirname11, extname as extname11, join as join11 } from "path";
|
|
2150
|
+
import { parse as parse12 } from "@babel/parser";
|
|
2151
|
+
import traverse11 from "@babel/traverse";
|
|
2152
|
+
import generate11 from "@babel/generator";
|
|
2153
|
+
import * as t10 from "@babel/types";
|
|
2154
|
+
import loading12 from "loading-cli";
|
|
2155
|
+
var walk3 = patchDefault(traverse11);
|
|
2156
|
+
var createDefaultOutputPath11 = (inputPath) => {
|
|
2157
|
+
const ext = extname11(inputPath);
|
|
2158
|
+
if (!ext) {
|
|
2159
|
+
return `${inputPath}.control-flow-packer.js`;
|
|
2160
|
+
}
|
|
2161
|
+
const base = basename11(inputPath, ext);
|
|
2162
|
+
return join11(dirname11(inputPath), `${base}.control-flow-packer${ext}`);
|
|
1960
2163
|
};
|
|
1961
2164
|
var isDeclarationOrAssignmentExpression = (node) => {
|
|
1962
|
-
if (
|
|
1963
|
-
return
|
|
2165
|
+
if (t10.isAssignmentExpression(node)) {
|
|
2166
|
+
return t10.isIdentifier(node.left) && t10.isNumericLiteral(node.right);
|
|
1964
2167
|
}
|
|
1965
|
-
if (
|
|
2168
|
+
if (t10.isVariableDeclaration(node) && node.declarations.length === 1 && t10.isIdentifier(node.declarations[0].id) && node.declarations[0].init && t10.isNumericLiteral(node.declarations[0].init)) {
|
|
1966
2169
|
return true;
|
|
1967
2170
|
}
|
|
1968
2171
|
return false;
|
|
1969
2172
|
};
|
|
1970
2173
|
var extractCounterInfo = (node) => {
|
|
1971
|
-
if (
|
|
2174
|
+
if (t10.isAssignmentExpression(node)) {
|
|
1972
2175
|
return {
|
|
1973
2176
|
counterName: node.left.name,
|
|
1974
2177
|
initialValue: node.right.value
|
|
@@ -1981,22 +2184,22 @@ var extractCounterInfo = (node) => {
|
|
|
1981
2184
|
};
|
|
1982
2185
|
};
|
|
1983
2186
|
var isStateArrayExpression = (node) => {
|
|
1984
|
-
return
|
|
2187
|
+
return t10.isCallExpression(node) && t10.isMemberExpression(node.callee) && t10.isStringLiteral(node.callee.object) && (t10.isStringLiteral(node.callee.property) && node.callee.property.value === "split" || t10.isIdentifier(node.callee.property) && node.callee.property.name === "split") && node.arguments.length === 1 && t10.isStringLiteral(node.arguments[0]);
|
|
1985
2188
|
};
|
|
1986
2189
|
var isFlatteningLoopBody = (node, statesName, counterName) => {
|
|
1987
|
-
return
|
|
1988
|
-
(c) => c.test &&
|
|
2190
|
+
return t10.isBlockStatement(node) && node.body.length === 2 && t10.isBreakStatement(node.body[1]) && t10.isSwitchStatement(node.body[0]) && t10.isMemberExpression(node.body[0].discriminant) && t10.isIdentifier(node.body[0].discriminant.object) && node.body[0].discriminant.object.name === statesName && t10.isUpdateExpression(node.body[0].discriminant.property) && t10.isIdentifier(node.body[0].discriminant.property.argument) && node.body[0].discriminant.property.argument.name === counterName && node.body[0].cases.every(
|
|
2191
|
+
(c) => c.test && t10.isStringLiteral(c.test)
|
|
1989
2192
|
);
|
|
1990
2193
|
};
|
|
1991
2194
|
var isFlatteningForLoop = (node, statesName) => {
|
|
1992
|
-
return
|
|
2195
|
+
return t10.isForStatement(node) && node.init !== null && isDeclarationOrAssignmentExpression(node.init) && isFlatteningLoopBody(
|
|
1993
2196
|
node.body,
|
|
1994
2197
|
statesName,
|
|
1995
|
-
|
|
2198
|
+
t10.isAssignmentExpression(node.init) ? node.init.left.name : node.init.declarations[0].id.name
|
|
1996
2199
|
);
|
|
1997
2200
|
};
|
|
1998
2201
|
var isFlatteningWhileLoop = (node, statesName, counterName) => {
|
|
1999
|
-
return
|
|
2202
|
+
return t10.isWhileStatement(node) && t10.isBooleanLiteral(node.test) && node.test.value === true && isFlatteningLoopBody(node.body, statesName, counterName);
|
|
2000
2203
|
};
|
|
2001
2204
|
var getStates = (expression) => {
|
|
2002
2205
|
const delimiter = expression.arguments[0].value;
|
|
@@ -2014,24 +2217,24 @@ var collectStatements = (cases, states, initialValue) => {
|
|
|
2014
2217
|
}
|
|
2015
2218
|
const blockStatements = casesMap.get(state);
|
|
2016
2219
|
for (const statement of blockStatements) {
|
|
2017
|
-
if (
|
|
2220
|
+
if (t10.isContinueStatement(statement)) {
|
|
2018
2221
|
continue;
|
|
2019
2222
|
}
|
|
2020
|
-
statements.push(
|
|
2223
|
+
statements.push(t10.cloneNode(statement, true));
|
|
2021
2224
|
}
|
|
2022
2225
|
const lastStatement = blockStatements[blockStatements.length - 1];
|
|
2023
|
-
if (lastStatement &&
|
|
2226
|
+
if (lastStatement && t10.isReturnStatement(lastStatement)) {
|
|
2024
2227
|
break;
|
|
2025
2228
|
}
|
|
2026
2229
|
}
|
|
2027
2230
|
return statements;
|
|
2028
2231
|
};
|
|
2029
2232
|
var packControlFlow = (code, filename) => {
|
|
2030
|
-
const ast =
|
|
2233
|
+
const ast = parse12(code, createParseOptions(filename));
|
|
2031
2234
|
let changedCount = 0;
|
|
2032
|
-
|
|
2235
|
+
walk3(ast, {
|
|
2033
2236
|
VariableDeclarator(path) {
|
|
2034
|
-
if (!path.node.init || !
|
|
2237
|
+
if (!path.node.init || !t10.isIdentifier(path.node.id)) {
|
|
2035
2238
|
return;
|
|
2036
2239
|
}
|
|
2037
2240
|
if (!isStateArrayExpression(path.node.init)) {
|
|
@@ -2099,7 +2302,7 @@ var packControlFlow = (code, filename) => {
|
|
|
2099
2302
|
}
|
|
2100
2303
|
});
|
|
2101
2304
|
return {
|
|
2102
|
-
code: patchDefault(
|
|
2305
|
+
code: patchDefault(generate11)(ast).code,
|
|
2103
2306
|
changedCount
|
|
2104
2307
|
};
|
|
2105
2308
|
};
|
|
@@ -2114,20 +2317,20 @@ var control_flow_packer_default = createCommand((program3) => {
|
|
|
2114
2317
|
return finish();
|
|
2115
2318
|
}
|
|
2116
2319
|
try {
|
|
2117
|
-
const fileContent =
|
|
2118
|
-
const defaultOutputPath =
|
|
2320
|
+
const fileContent = readFileSync12(filename, "utf8");
|
|
2321
|
+
const defaultOutputPath = createDefaultOutputPath11(filename);
|
|
2119
2322
|
let outputPath = options.output;
|
|
2120
2323
|
if (!outputPath) {
|
|
2121
2324
|
const promptPath = (await createPrompt("Enter the output file path:"))?.trim();
|
|
2122
2325
|
outputPath = promptPath || defaultOutputPath;
|
|
2123
2326
|
}
|
|
2124
|
-
const loader =
|
|
2327
|
+
const loader = loading12("Packing control flow...").start();
|
|
2125
2328
|
try {
|
|
2126
2329
|
const { code: output, changedCount } = packControlFlow(
|
|
2127
2330
|
fileContent,
|
|
2128
2331
|
filename
|
|
2129
2332
|
);
|
|
2130
|
-
|
|
2333
|
+
writeFileSync11(outputPath, output, "utf8");
|
|
2131
2334
|
loader.succeed(
|
|
2132
2335
|
`Saved control-flow-packer file to: ${outputPath} (${diff(fileContent, output).length} lines changed, ${changedCount} edits)`
|
|
2133
2336
|
);
|
|
@@ -2153,35 +2356,35 @@ var control_flow_packer_default = createCommand((program3) => {
|
|
|
2153
2356
|
});
|
|
2154
2357
|
|
|
2155
2358
|
// commands/fn-inliner/index.ts
|
|
2156
|
-
import { readFileSync as
|
|
2157
|
-
import { basename as
|
|
2158
|
-
import { parse as
|
|
2159
|
-
import
|
|
2160
|
-
import
|
|
2161
|
-
import * as
|
|
2162
|
-
import
|
|
2163
|
-
var
|
|
2164
|
-
var
|
|
2165
|
-
const ext =
|
|
2359
|
+
import { readFileSync as readFileSync13, writeFileSync as writeFileSync12 } from "fs";
|
|
2360
|
+
import { basename as basename12, dirname as dirname12, extname as extname12, join as join12 } from "path";
|
|
2361
|
+
import { parse as parse13 } from "@babel/parser";
|
|
2362
|
+
import traverse12 from "@babel/traverse";
|
|
2363
|
+
import generate12 from "@babel/generator";
|
|
2364
|
+
import * as t11 from "@babel/types";
|
|
2365
|
+
import loading13 from "loading-cli";
|
|
2366
|
+
var walk4 = patchDefault(traverse12);
|
|
2367
|
+
var createDefaultOutputPath12 = (inputPath) => {
|
|
2368
|
+
const ext = extname12(inputPath);
|
|
2166
2369
|
if (!ext) {
|
|
2167
2370
|
return `${inputPath}.fn-inliner.js`;
|
|
2168
2371
|
}
|
|
2169
|
-
const base =
|
|
2170
|
-
return
|
|
2372
|
+
const base = basename12(inputPath, ext);
|
|
2373
|
+
return join12(dirname12(inputPath), `${base}.fn-inliner${ext}`);
|
|
2171
2374
|
};
|
|
2172
2375
|
var isProxyFunctionExpression = (node) => {
|
|
2173
|
-
return
|
|
2376
|
+
return t11.isFunction(node) && node.params.every((param) => t11.isIdentifier(param)) && (t11.isBlockStatement(node.body) && node.body.body.length === 1 && t11.isReturnStatement(node.body.body[0]) && (node.body.body[0].argument === void 0 || t11.isExpression(node.body.body[0].argument) && isProxyValue(node.body.body[0].argument)) || t11.isArrowFunctionExpression(node) && t11.isExpression(node.body) && isProxyValue(node.body));
|
|
2174
2377
|
};
|
|
2175
2378
|
var isProxyValue = (node) => {
|
|
2176
|
-
if (
|
|
2379
|
+
if (t11.isFunction(node) || t11.isBlockStatement(node) || t11.isSequenceExpression(node) || t11.isAssignmentExpression(node)) {
|
|
2177
2380
|
return false;
|
|
2178
2381
|
}
|
|
2179
2382
|
let isValid = true;
|
|
2180
|
-
if (!
|
|
2383
|
+
if (!t11.isExpression(node)) {
|
|
2181
2384
|
return false;
|
|
2182
2385
|
}
|
|
2183
|
-
const wrapper =
|
|
2184
|
-
|
|
2386
|
+
const wrapper = t11.file(t11.program([t11.expressionStatement(node)]));
|
|
2387
|
+
walk4(wrapper, {
|
|
2185
2388
|
"SequenceExpression|BlockStatement|Function|AssignmentExpression"(path) {
|
|
2186
2389
|
isValid = false;
|
|
2187
2390
|
path.stop();
|
|
@@ -2191,7 +2394,7 @@ var isProxyValue = (node) => {
|
|
|
2191
2394
|
return isValid;
|
|
2192
2395
|
};
|
|
2193
2396
|
var copyExpression = (expression) => {
|
|
2194
|
-
return
|
|
2397
|
+
return t11.cloneNode(expression, true);
|
|
2195
2398
|
};
|
|
2196
2399
|
var ProxyFunction = class {
|
|
2197
2400
|
expression;
|
|
@@ -2199,7 +2402,7 @@ var ProxyFunction = class {
|
|
|
2199
2402
|
this.expression = expression;
|
|
2200
2403
|
}
|
|
2201
2404
|
getReplacement(args) {
|
|
2202
|
-
const expression =
|
|
2405
|
+
const expression = t11.isExpression(this.expression.body) ? copyExpression(this.expression.body) : this.expression.body.body[0].argument ? copyExpression(this.expression.body.body[0].argument) : t11.identifier("undefined");
|
|
2203
2406
|
this.replaceParameters(expression, args);
|
|
2204
2407
|
return expression;
|
|
2205
2408
|
}
|
|
@@ -2207,7 +2410,7 @@ var ProxyFunction = class {
|
|
|
2207
2410
|
const paramMap = new Map(
|
|
2208
2411
|
this.expression.params.map((param, index) => [
|
|
2209
2412
|
param.name,
|
|
2210
|
-
args[index] ??
|
|
2413
|
+
args[index] ?? t11.identifier("undefined")
|
|
2211
2414
|
])
|
|
2212
2415
|
);
|
|
2213
2416
|
const pathsToReplace = [];
|
|
@@ -2232,10 +2435,10 @@ var ProxyFunction = class {
|
|
|
2232
2435
|
}
|
|
2233
2436
|
return false;
|
|
2234
2437
|
};
|
|
2235
|
-
const wrapper =
|
|
2236
|
-
|
|
2438
|
+
const wrapper = t11.file(t11.program([t11.expressionStatement(expression)]));
|
|
2439
|
+
walk4(wrapper, {
|
|
2237
2440
|
enter(path) {
|
|
2238
|
-
if (
|
|
2441
|
+
if (t11.isIdentifier(path.node) && !shouldSkipIdentifier(path) && paramMap.has(path.node.name)) {
|
|
2239
2442
|
const replacement = paramMap.get(path.node.name);
|
|
2240
2443
|
pathsToReplace.push([path, replacement]);
|
|
2241
2444
|
}
|
|
@@ -2243,7 +2446,7 @@ var ProxyFunction = class {
|
|
|
2243
2446
|
noScope: true
|
|
2244
2447
|
});
|
|
2245
2448
|
for (const [path, replacement] of pathsToReplace) {
|
|
2246
|
-
path.replaceWith(
|
|
2449
|
+
path.replaceWith(t11.cloneNode(replacement, true));
|
|
2247
2450
|
}
|
|
2248
2451
|
}
|
|
2249
2452
|
};
|
|
@@ -2263,10 +2466,10 @@ var ProxyFunctionVariable = class extends ProxyFunction {
|
|
|
2263
2466
|
const argumentNodes = path.parentPath.node.arguments;
|
|
2264
2467
|
const args = [];
|
|
2265
2468
|
for (const argument of argumentNodes) {
|
|
2266
|
-
if (!
|
|
2469
|
+
if (!t11.isExpression(argument)) {
|
|
2267
2470
|
return false;
|
|
2268
2471
|
}
|
|
2269
|
-
args.push(
|
|
2472
|
+
args.push(t11.cloneNode(argument, true));
|
|
2270
2473
|
}
|
|
2271
2474
|
const expression = this.getReplacement(args);
|
|
2272
2475
|
path.parentPath.replaceWith(expression);
|
|
@@ -2275,7 +2478,7 @@ var ProxyFunctionVariable = class extends ProxyFunction {
|
|
|
2275
2478
|
};
|
|
2276
2479
|
var collectProxyFunctions = (ast) => {
|
|
2277
2480
|
const proxies = [];
|
|
2278
|
-
|
|
2481
|
+
walk4(ast, {
|
|
2279
2482
|
FunctionDeclaration(path) {
|
|
2280
2483
|
if (!path.node.id) return;
|
|
2281
2484
|
if (!isProxyFunctionExpression(path.node)) return;
|
|
@@ -2284,7 +2487,7 @@ var collectProxyFunctions = (ast) => {
|
|
|
2284
2487
|
proxies.push(new ProxyFunctionVariable(binding, path.node));
|
|
2285
2488
|
},
|
|
2286
2489
|
VariableDeclarator(path) {
|
|
2287
|
-
if (!
|
|
2490
|
+
if (!t11.isIdentifier(path.node.id)) return;
|
|
2288
2491
|
const init = path.node.init;
|
|
2289
2492
|
if (!init || !isProxyFunctionExpression(init)) return;
|
|
2290
2493
|
const binding = path.scope.getBinding(path.node.id.name);
|
|
@@ -2295,7 +2498,7 @@ var collectProxyFunctions = (ast) => {
|
|
|
2295
2498
|
return proxies;
|
|
2296
2499
|
};
|
|
2297
2500
|
var inlineProxyFunctions = (code, filename) => {
|
|
2298
|
-
const ast =
|
|
2501
|
+
const ast = parse13(code, createParseOptions(filename));
|
|
2299
2502
|
const proxies = collectProxyFunctions(ast);
|
|
2300
2503
|
let replacedCount = 0;
|
|
2301
2504
|
for (const proxy of proxies) {
|
|
@@ -2307,7 +2510,7 @@ var inlineProxyFunctions = (code, filename) => {
|
|
|
2307
2510
|
}
|
|
2308
2511
|
}
|
|
2309
2512
|
return {
|
|
2310
|
-
code: patchDefault(
|
|
2513
|
+
code: patchDefault(generate12)(ast).code,
|
|
2311
2514
|
replacedCount
|
|
2312
2515
|
};
|
|
2313
2516
|
};
|
|
@@ -2322,20 +2525,20 @@ var fn_inliner_default = createCommand((program3) => {
|
|
|
2322
2525
|
return finish();
|
|
2323
2526
|
}
|
|
2324
2527
|
try {
|
|
2325
|
-
const fileContent =
|
|
2326
|
-
const defaultOutputPath =
|
|
2528
|
+
const fileContent = readFileSync13(filename, "utf8");
|
|
2529
|
+
const defaultOutputPath = createDefaultOutputPath12(filename);
|
|
2327
2530
|
let outputPath = options.output;
|
|
2328
2531
|
if (!outputPath) {
|
|
2329
2532
|
const promptPath = (await createPrompt("Enter the output file path:"))?.trim();
|
|
2330
2533
|
outputPath = promptPath || defaultOutputPath;
|
|
2331
2534
|
}
|
|
2332
|
-
const loader =
|
|
2535
|
+
const loader = loading13("Inlining proxy functions...").start();
|
|
2333
2536
|
try {
|
|
2334
2537
|
const { code: output, replacedCount } = inlineProxyFunctions(
|
|
2335
2538
|
fileContent,
|
|
2336
2539
|
filename
|
|
2337
2540
|
);
|
|
2338
|
-
|
|
2541
|
+
writeFileSync12(outputPath, output, "utf8");
|
|
2339
2542
|
loader.succeed(
|
|
2340
2543
|
`Saved fn-inliner file to: ${outputPath} (${diff(fileContent, output).length} lines changed, ${replacedCount} replacements)`
|
|
2341
2544
|
);
|
|
@@ -2361,38 +2564,38 @@ var fn_inliner_default = createCommand((program3) => {
|
|
|
2361
2564
|
});
|
|
2362
2565
|
|
|
2363
2566
|
// commands/sequence-split/index.ts
|
|
2364
|
-
import { readFileSync as
|
|
2365
|
-
import { basename as
|
|
2366
|
-
import { parse as
|
|
2367
|
-
import
|
|
2368
|
-
import
|
|
2369
|
-
import * as
|
|
2370
|
-
import
|
|
2371
|
-
var
|
|
2372
|
-
var
|
|
2373
|
-
const ext =
|
|
2567
|
+
import { readFileSync as readFileSync14, writeFileSync as writeFileSync13 } from "fs";
|
|
2568
|
+
import { basename as basename13, dirname as dirname13, extname as extname13, join as join13 } from "path";
|
|
2569
|
+
import { parse as parse14 } from "@babel/parser";
|
|
2570
|
+
import traverse13 from "@babel/traverse";
|
|
2571
|
+
import generate13 from "@babel/generator";
|
|
2572
|
+
import * as t12 from "@babel/types";
|
|
2573
|
+
import loading14 from "loading-cli";
|
|
2574
|
+
var walk5 = patchDefault(traverse13);
|
|
2575
|
+
var createDefaultOutputPath13 = (inputPath) => {
|
|
2576
|
+
const ext = extname13(inputPath);
|
|
2374
2577
|
if (!ext) {
|
|
2375
2578
|
return `${inputPath}.sequence-split.js`;
|
|
2376
2579
|
}
|
|
2377
|
-
const base =
|
|
2378
|
-
return
|
|
2580
|
+
const base = basename13(inputPath, ext);
|
|
2581
|
+
return join13(dirname13(inputPath), `${base}.sequence-split${ext}`);
|
|
2379
2582
|
};
|
|
2380
2583
|
var isExcluded = (node) => {
|
|
2381
|
-
return
|
|
2584
|
+
return t12.isIdentifier(node) && node.name === "eval";
|
|
2382
2585
|
};
|
|
2383
2586
|
var sequenceSplit = (code, filename) => {
|
|
2384
|
-
const ast =
|
|
2587
|
+
const ast = parse14(code, createParseOptions(filename));
|
|
2385
2588
|
let changedCount = 0;
|
|
2386
2589
|
const markChanged = () => {
|
|
2387
2590
|
changedCount += 1;
|
|
2388
2591
|
};
|
|
2389
|
-
|
|
2592
|
+
walk5(ast, {
|
|
2390
2593
|
ConditionalExpression(path) {
|
|
2391
2594
|
if (!path.parentPath || !path.parentPath.isExpressionStatement()) return;
|
|
2392
|
-
const replacement =
|
|
2595
|
+
const replacement = t12.ifStatement(
|
|
2393
2596
|
path.node.test,
|
|
2394
|
-
|
|
2395
|
-
|
|
2597
|
+
t12.expressionStatement(path.node.consequent),
|
|
2598
|
+
t12.expressionStatement(path.node.alternate)
|
|
2396
2599
|
);
|
|
2397
2600
|
if (path.parentPath.parentPath && path.parentPath.parentPath.key === "alternate" && path.parentPath.parentPath.isBlockStatement() && path.parentPath.parentPath.node.body.length === 1) {
|
|
2398
2601
|
path.parentPath.parentPath.replaceWith(replacement);
|
|
@@ -2405,10 +2608,10 @@ var sequenceSplit = (code, filename) => {
|
|
|
2405
2608
|
LogicalExpression(path) {
|
|
2406
2609
|
if (!path.parentPath || !path.parentPath.isExpressionStatement()) return;
|
|
2407
2610
|
if (path.node.operator !== "&&" && path.node.operator !== "||") return;
|
|
2408
|
-
const test = path.node.operator === "&&" ? path.node.left :
|
|
2409
|
-
const replacement =
|
|
2611
|
+
const test = path.node.operator === "&&" ? path.node.left : t12.unaryExpression("!", path.node.left);
|
|
2612
|
+
const replacement = t12.ifStatement(
|
|
2410
2613
|
test,
|
|
2411
|
-
|
|
2614
|
+
t12.expressionStatement(path.node.right)
|
|
2412
2615
|
);
|
|
2413
2616
|
if (path.parentPath.parentPath && path.parentPath.parentPath.key === "alternate" && path.parentPath.parentPath.isBlockStatement() && path.parentPath.parentPath.node.body.length === 1) {
|
|
2414
2617
|
path.parentPath.parentPath.replaceWith(replacement);
|
|
@@ -2420,24 +2623,24 @@ var sequenceSplit = (code, filename) => {
|
|
|
2420
2623
|
},
|
|
2421
2624
|
"ForStatement|WhileStatement|DoWhileStatement"(path) {
|
|
2422
2625
|
if (!path.isForStatement() && !path.isWhileStatement() && !path.isDoWhileStatement()) return;
|
|
2423
|
-
if (
|
|
2424
|
-
path.node.body =
|
|
2626
|
+
if (t12.isBlockStatement(path.node.body)) return;
|
|
2627
|
+
path.node.body = t12.blockStatement([path.node.body]);
|
|
2425
2628
|
markChanged();
|
|
2426
2629
|
},
|
|
2427
2630
|
IfStatement(path) {
|
|
2428
|
-
if (!
|
|
2429
|
-
path.node.consequent =
|
|
2631
|
+
if (!t12.isBlockStatement(path.node.consequent)) {
|
|
2632
|
+
path.node.consequent = t12.blockStatement([path.node.consequent]);
|
|
2430
2633
|
markChanged();
|
|
2431
2634
|
}
|
|
2432
|
-
if (path.node.alternate && !
|
|
2433
|
-
path.node.alternate =
|
|
2635
|
+
if (path.node.alternate && !t12.isBlockStatement(path.node.alternate) && !t12.isIfStatement(path.node.alternate)) {
|
|
2636
|
+
path.node.alternate = t12.blockStatement([path.node.alternate]);
|
|
2434
2637
|
markChanged();
|
|
2435
2638
|
}
|
|
2436
2639
|
},
|
|
2437
2640
|
VariableDeclaration(path) {
|
|
2438
2641
|
if (path.node.declarations.length <= 1) return;
|
|
2439
2642
|
const replacements = path.node.declarations.map(
|
|
2440
|
-
(declaration) =>
|
|
2643
|
+
(declaration) => t12.variableDeclaration(path.node.kind, [declaration])
|
|
2441
2644
|
);
|
|
2442
2645
|
if (path.parentPath?.isForStatement() && path.parentKey === "init") {
|
|
2443
2646
|
const lastDeclaration = replacements.pop();
|
|
@@ -2458,7 +2661,7 @@ var sequenceSplit = (code, filename) => {
|
|
|
2458
2661
|
return;
|
|
2459
2662
|
}
|
|
2460
2663
|
let outerPath = path;
|
|
2461
|
-
while (!
|
|
2664
|
+
while (!t12.isStatement(outerPath.node)) {
|
|
2462
2665
|
const parent = outerPath.parentPath;
|
|
2463
2666
|
if (!parent) return;
|
|
2464
2667
|
if (parent.isConditionalExpression() && (outerPath.key === "consequent" || outerPath.key === "alternate") || parent.isLogicalExpression() && outerPath.key === "right" || parent.isForStatement() && (outerPath.key === "test" || outerPath.key === "update") || parent.isDoWhileStatement() && outerPath.key === "test" || parent.isArrowFunctionExpression() && outerPath.key === "body") {
|
|
@@ -2471,7 +2674,7 @@ var sequenceSplit = (code, filename) => {
|
|
|
2471
2674
|
const firstExpressions = expressions.splice(0, expressions.length - 2);
|
|
2472
2675
|
if (firstExpressions.length > 0) {
|
|
2473
2676
|
const expressionStatements = firstExpressions.map(
|
|
2474
|
-
(expression) =>
|
|
2677
|
+
(expression) => t12.expressionStatement(expression)
|
|
2475
2678
|
);
|
|
2476
2679
|
outerPath.insertBefore(expressionStatements);
|
|
2477
2680
|
markChanged();
|
|
@@ -2479,7 +2682,7 @@ var sequenceSplit = (code, filename) => {
|
|
|
2479
2682
|
} else {
|
|
2480
2683
|
const finalExpression = expressions.splice(expressions.length - 1, 1)[0];
|
|
2481
2684
|
const expressionStatements = expressions.map(
|
|
2482
|
-
(expression) =>
|
|
2685
|
+
(expression) => t12.expressionStatement(expression)
|
|
2483
2686
|
);
|
|
2484
2687
|
outerPath.insertBefore(expressionStatements);
|
|
2485
2688
|
if (finalExpression) {
|
|
@@ -2490,7 +2693,7 @@ var sequenceSplit = (code, filename) => {
|
|
|
2490
2693
|
}
|
|
2491
2694
|
});
|
|
2492
2695
|
return {
|
|
2493
|
-
code: patchDefault(
|
|
2696
|
+
code: patchDefault(generate13)(ast).code,
|
|
2494
2697
|
changedCount
|
|
2495
2698
|
};
|
|
2496
2699
|
};
|
|
@@ -2505,20 +2708,20 @@ var sequence_split_default = createCommand((program3) => {
|
|
|
2505
2708
|
return finish();
|
|
2506
2709
|
}
|
|
2507
2710
|
try {
|
|
2508
|
-
const fileContent =
|
|
2509
|
-
const defaultOutputPath =
|
|
2711
|
+
const fileContent = readFileSync14(filename, "utf8");
|
|
2712
|
+
const defaultOutputPath = createDefaultOutputPath13(filename);
|
|
2510
2713
|
let outputPath = options.output;
|
|
2511
2714
|
if (!outputPath) {
|
|
2512
2715
|
const promptPath = (await createPrompt("Enter the output file path:"))?.trim();
|
|
2513
2716
|
outputPath = promptPath || defaultOutputPath;
|
|
2514
2717
|
}
|
|
2515
|
-
const loader =
|
|
2718
|
+
const loader = loading14("Splitting sequences...").start();
|
|
2516
2719
|
try {
|
|
2517
2720
|
const { code: output, changedCount } = sequenceSplit(
|
|
2518
2721
|
fileContent,
|
|
2519
2722
|
filename
|
|
2520
2723
|
);
|
|
2521
|
-
|
|
2724
|
+
writeFileSync13(outputPath, output, "utf8");
|
|
2522
2725
|
loader.succeed(
|
|
2523
2726
|
`Saved sequence-split file to: ${outputPath} (${diff(fileContent, output).length} lines changed, ${changedCount} transforms)`
|
|
2524
2727
|
);
|
|
@@ -2567,10 +2770,10 @@ var calmGradienrain = (text) => {
|
|
|
2567
2770
|
const endHue = 300;
|
|
2568
2771
|
const saturation = 0.45;
|
|
2569
2772
|
const value = 0.8;
|
|
2570
|
-
const ease = (
|
|
2773
|
+
const ease = (t13) => t13 * t13 * (3 - 2 * t13);
|
|
2571
2774
|
return text.split("").map((char, i) => {
|
|
2572
|
-
const
|
|
2573
|
-
const hue = startHue + (endHue - startHue) *
|
|
2775
|
+
const t13 = ease(i / Math.max(text.length - 1, 1));
|
|
2776
|
+
const hue = startHue + (endHue - startHue) * t13;
|
|
2574
2777
|
const c = value * saturation;
|
|
2575
2778
|
const h = hue / 60;
|
|
2576
2779
|
const x = c * (1 - Math.abs(h % 2 - 1));
|
|
@@ -2594,11 +2797,11 @@ ${calmGradienrain(`Expose Kit v${VERSION}`)} ${update && update.latest !== VERSI
|
|
|
2594
2797
|
`;
|
|
2595
2798
|
|
|
2596
2799
|
// index.ts
|
|
2597
|
-
import { readFileSync as
|
|
2800
|
+
import { readFileSync as readFileSync15 } from "fs";
|
|
2598
2801
|
import updateNotifier from "update-notifier";
|
|
2599
2802
|
var __filename = fileURLToPath(import.meta.url);
|
|
2600
|
-
var __dirname =
|
|
2601
|
-
var pkg = JSON.parse(
|
|
2803
|
+
var __dirname = dirname14(__filename);
|
|
2804
|
+
var pkg = JSON.parse(readFileSync15(join14(__dirname, "package.json"), "utf8"));
|
|
2602
2805
|
var notifier = updateNotifier({
|
|
2603
2806
|
pkg,
|
|
2604
2807
|
updateCheckInterval: 1e3 * 60 * 60 * 24 * 3
|
|
@@ -2622,6 +2825,7 @@ var commands = [
|
|
|
2622
2825
|
remove_updater_default,
|
|
2623
2826
|
remove_reassign_default,
|
|
2624
2827
|
remove_deadcode_default,
|
|
2828
|
+
remove_anti_tamper_default,
|
|
2625
2829
|
control_flow_packer_default,
|
|
2626
2830
|
fn_inliner_default,
|
|
2627
2831
|
remove_unused_default,
|
package/dist/package.json
CHANGED