obscura-js 2.0.2 → 2.0.3
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/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "obscura-js",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "JavaScript code protection tool — obfuscation & anti-debugging inspired by Google reCAPTCHA",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -65,13 +65,13 @@
|
|
|
65
65
|
"commander": "^12.0.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@types/jest": "^
|
|
69
|
-
"@types/node": "^
|
|
68
|
+
"@types/jest": "^30.0.0",
|
|
69
|
+
"@types/node": "^24.0.0",
|
|
70
70
|
"@typescript-eslint/eslint-plugin": "^8.59.4",
|
|
71
71
|
"@typescript-eslint/parser": "^8.59.4",
|
|
72
|
-
"eslint": "^
|
|
72
|
+
"eslint": "^10.0.0",
|
|
73
73
|
"eslint-config-prettier": "^10.1.8",
|
|
74
|
-
"jest": "^
|
|
74
|
+
"jest": "^30.0.0",
|
|
75
75
|
"prettier": "^3.8.3",
|
|
76
76
|
"ts-jest": "^29.1.2",
|
|
77
77
|
"ts-node": "^10.9.2",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functionTable.d.ts","sourceRoot":"","sources":["../../../src/obfuscation/functionTable.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGrD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,GAAE,oBAAyB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"functionTable.d.ts","sourceRoot":"","sources":["../../../src/obfuscation/functionTable.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGrD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,GAAE,oBAAyB,GAAG,IAAI,CAsH5F"}
|
|
@@ -31,10 +31,9 @@ function applyFunctionTable(ast, options = {}) {
|
|
|
31
31
|
if (path.node.source)
|
|
32
32
|
return; // re-export from another file — no local binding // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
33
33
|
for (const spec of path.node.specifiers ?? []) {
|
|
34
|
-
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
35
34
|
if (swc_utils_1.t.isExportSpecifier(spec)) {
|
|
36
35
|
// SWC ExportSpecifier uses .orig (not .local)
|
|
37
|
-
const orig = spec.orig;
|
|
36
|
+
const orig = spec.orig;
|
|
38
37
|
if (orig && orig.type === "Identifier") {
|
|
39
38
|
leakedNames.add(orig.value);
|
|
40
39
|
}
|
|
@@ -44,7 +43,7 @@ function applyFunctionTable(ast, options = {}) {
|
|
|
44
43
|
// ESM: export default foo (identifier, not an inline declaration)
|
|
45
44
|
ExportDefaultExpression(path) {
|
|
46
45
|
// SWC uses ExportDefaultExpression.expression for identifier exports
|
|
47
|
-
const expr = path.node.expression ?? path.node.decl;
|
|
46
|
+
const expr = path.node.expression ?? path.node.decl;
|
|
48
47
|
if (expr && expr.type === "Identifier") {
|
|
49
48
|
leakedNames.add(expr.value);
|
|
50
49
|
}
|
|
@@ -56,32 +55,28 @@ function applyFunctionTable(ast, options = {}) {
|
|
|
56
55
|
if (!isExportsTarget(left))
|
|
57
56
|
return;
|
|
58
57
|
if (swc_utils_1.t.isIdentifier(right)) {
|
|
59
|
-
leakedNames.add(right.value);
|
|
58
|
+
leakedNames.add(right.value);
|
|
60
59
|
}
|
|
61
60
|
else if (swc_utils_1.t.isObjectExpression(right)) {
|
|
62
61
|
for (const prop of right.properties ?? []) {
|
|
63
|
-
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
64
62
|
// SWC shorthand { foo } → Identifier node directly in properties[]
|
|
65
63
|
if (swc_utils_1.t.isIdentifier(prop)) {
|
|
66
|
-
leakedNames.add(prop.value);
|
|
64
|
+
leakedNames.add(prop.value);
|
|
67
65
|
}
|
|
68
66
|
else if (swc_utils_1.t.isObjectProperty(prop) && swc_utils_1.t.isIdentifier(prop.value)) {
|
|
69
|
-
|
|
70
|
-
leakedNames.add(prop.value.value); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
67
|
+
leakedNames.add(prop.value.value);
|
|
71
68
|
}
|
|
72
69
|
}
|
|
73
70
|
}
|
|
74
71
|
},
|
|
75
72
|
});
|
|
76
73
|
// Collect top-level named function declarations first, then remove only if threshold is met
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
74
|
const functions = [];
|
|
79
75
|
const nameToIndex = new Map();
|
|
80
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
76
|
const functionPaths = [];
|
|
82
77
|
(0, swc_utils_1.traverse)(ast, {
|
|
83
78
|
FunctionDeclaration(path) {
|
|
84
|
-
const node = path.node;
|
|
79
|
+
const node = path.node;
|
|
85
80
|
// SWC FunctionDeclaration uses .identifier (not .id)
|
|
86
81
|
if (!node.identifier)
|
|
87
82
|
return;
|
|
@@ -96,7 +91,7 @@ function applyFunctionTable(ast, options = {}) {
|
|
|
96
91
|
return;
|
|
97
92
|
// Build the index map before touching the AST
|
|
98
93
|
for (let i = 0; i < functionPaths.length; i++) {
|
|
99
|
-
nameToIndex.set(functionPaths[i].node.identifier.value, i);
|
|
94
|
+
nameToIndex.set(functionPaths[i].node.identifier.value, i);
|
|
100
95
|
}
|
|
101
96
|
// Replace call sites FIRST (while function bodies are still in the AST)
|
|
102
97
|
// so calls inside one function to another are also rewritten.
|
|
@@ -104,7 +99,7 @@ function applyFunctionTable(ast, options = {}) {
|
|
|
104
99
|
CallExpression(path) {
|
|
105
100
|
if (!swc_utils_1.t.isIdentifier(path.node.callee))
|
|
106
101
|
return;
|
|
107
|
-
const idx = nameToIndex.get(path.node.callee.value);
|
|
102
|
+
const idx = nameToIndex.get(path.node.callee.value);
|
|
108
103
|
if (idx === undefined)
|
|
109
104
|
return;
|
|
110
105
|
path.node.callee = swc_utils_1.t.memberExpression(swc_utils_1.t.identifier(tableId), swc_utils_1.t.numericLiteral(idx), true // computed
|
|
@@ -114,7 +109,7 @@ function applyFunctionTable(ast, options = {}) {
|
|
|
114
109
|
// Now extract function expressions and remove declarations from the AST
|
|
115
110
|
// Extract in original order first, then remove in reverse order to preserve indices
|
|
116
111
|
for (const path of functionPaths) {
|
|
117
|
-
const node = path.node;
|
|
112
|
+
const node = path.node;
|
|
118
113
|
functions.push({
|
|
119
114
|
id: node.identifier.value,
|
|
120
115
|
fn: swc_utils_1.t.functionExpression(null, node.params, // already Parameter[] in SWC
|
|
@@ -129,22 +124,21 @@ function applyFunctionTable(ast, options = {}) {
|
|
|
129
124
|
const tableDeclaration = swc_utils_1.t.variableDeclaration("const", [
|
|
130
125
|
swc_utils_1.t.variableDeclarator(swc_utils_1.t.identifier(tableId), swc_utils_1.t.arrayExpression(functions.map((f) => f.fn))),
|
|
131
126
|
]);
|
|
132
|
-
ast.body.unshift(tableDeclaration);
|
|
127
|
+
ast.body.unshift(tableDeclaration);
|
|
133
128
|
}
|
|
134
129
|
/**
|
|
135
130
|
* Returns true if `node` is an assignment target that exposes a value as a
|
|
136
131
|
* CJS export: `exports`, `module.exports`, or any member of `module.exports`.
|
|
137
132
|
*/
|
|
138
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
139
133
|
function isExportsTarget(node) {
|
|
140
134
|
// bare `exports`
|
|
141
135
|
if (swc_utils_1.t.isIdentifier(node) && node.value === "exports")
|
|
142
|
-
return true;
|
|
136
|
+
return true;
|
|
143
137
|
// must be a MemberExpression and not computed
|
|
144
138
|
if (!swc_utils_1.t.isMemberExpression(node) || node.property?.type === "Computed")
|
|
145
|
-
return false;
|
|
146
|
-
const obj = node.object;
|
|
147
|
-
const prop = node.property;
|
|
139
|
+
return false;
|
|
140
|
+
const obj = node.object;
|
|
141
|
+
const prop = node.property;
|
|
148
142
|
// `exports.foo`
|
|
149
143
|
if (swc_utils_1.t.isIdentifier(obj) && obj.value === "exports")
|
|
150
144
|
return true;
|
|
@@ -156,12 +150,11 @@ function isExportsTarget(node) {
|
|
|
156
150
|
return true;
|
|
157
151
|
// `module.exports.foo`
|
|
158
152
|
if (swc_utils_1.t.isMemberExpression(obj) &&
|
|
159
|
-
obj.property?.type !== "Computed" &&
|
|
160
|
-
swc_utils_1.t.isIdentifier(obj.object) &&
|
|
161
|
-
obj.object.value === "module" &&
|
|
162
|
-
swc_utils_1.t.isIdentifier(obj.property) &&
|
|
163
|
-
obj.property.value === "exports"
|
|
164
|
-
)
|
|
153
|
+
obj.property?.type !== "Computed" &&
|
|
154
|
+
swc_utils_1.t.isIdentifier(obj.object) &&
|
|
155
|
+
obj.object.value === "module" &&
|
|
156
|
+
swc_utils_1.t.isIdentifier(obj.property) &&
|
|
157
|
+
obj.property.value === "exports")
|
|
165
158
|
return true;
|
|
166
159
|
return false;
|
|
167
160
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functionTable.js","sourceRoot":"","sources":["../../../src/obfuscation/functionTable.ts"],"names":[],"mappings":";;AAoBA,
|
|
1
|
+
{"version":3,"file":"functionTable.js","sourceRoot":"","sources":["../../../src/obfuscation/functionTable.ts"],"names":[],"mappings":";;AAoBA,gDAsHC;AA1ID,uDAAuD;AACvD,4CAA0D;AAG1D,oCAAiC;AAEjC;;;;;;;;;;;;;GAaG;AACH,SAAgB,kBAAkB,CAAC,GAAe,EAAE,UAAgC,EAAE;IACpF,MAAM,YAAY,GAAG,OAAO,CAAC,YA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AAC,IAAI,CAAC;QACpB,IAAI,CAAC,KAAK,KAAK,SAAS;QAExB,OAAO,IAAI,CAAC;IACd,uBAAuB;IACvB,IACE,aAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC;QACxB,GAAW,CAAC,QAAQ,EAAE,IAAI,KAAK,UAAU;QAC1C,aAAC,CAAC,YAAY,CAAE,GAAW,CAAC,MAAM,CAAC;QAClC,GAAW,CAAC,MAAM,CAAC,KAAK,KAAK,QAAQ;QACtC,aAAC,CAAC,YAAY,CAAE,GAAW,CAAC,QAAQ,CAAC;QACpC,GAAW,CAAC,QAAQ,CAAC,KAAK,KAAK,SAAS;QAEzC,OAAO,IAAI,CAAC;IACd,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "obscura-js",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "JavaScript code protection tool — obfuscation & anti-debugging inspired by Google reCAPTCHA",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -65,13 +65,13 @@
|
|
|
65
65
|
"commander": "^12.0.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@types/jest": "^
|
|
69
|
-
"@types/node": "^
|
|
68
|
+
"@types/jest": "^30.0.0",
|
|
69
|
+
"@types/node": "^24.0.0",
|
|
70
70
|
"@typescript-eslint/eslint-plugin": "^8.59.4",
|
|
71
71
|
"@typescript-eslint/parser": "^8.59.4",
|
|
72
|
-
"eslint": "^
|
|
72
|
+
"eslint": "^10.0.0",
|
|
73
73
|
"eslint-config-prettier": "^10.1.8",
|
|
74
|
-
"jest": "^
|
|
74
|
+
"jest": "^30.0.0",
|
|
75
75
|
"prettier": "^3.8.3",
|
|
76
76
|
"ts-jest": "^29.1.2",
|
|
77
77
|
"ts-node": "^10.9.2",
|