mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
Change Log
|
||||
|
||||
v2.17.1
|
||||
---
|
||||
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/959
|
||||
|
||||
v2.17.0
|
||||
---
|
||||
* **New option**: `sourceMapSourcesMode` allows to control `sources` and `sourcesContent` fields of the source map
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+4
-4
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "javascript-obfuscator",
|
||||
"version": "2.17.0",
|
||||
"version": "2.17.1",
|
||||
"description": "JavaScript obfuscator",
|
||||
"keywords": [
|
||||
"obfuscator",
|
||||
@@ -57,7 +57,7 @@
|
||||
"@types/mkdirp": "1.0.2",
|
||||
"@types/mocha": "8.2.3",
|
||||
"@types/multimatch": "4.0.0",
|
||||
"@types/node": "16.3.3",
|
||||
"@types/node": "16.4.0",
|
||||
"@types/rimraf": "3.0.1",
|
||||
"@types/sinon": "10.0.2",
|
||||
"@types/string-template": "1.0.2",
|
||||
@@ -69,7 +69,7 @@
|
||||
"cross-env": "7.0.3",
|
||||
"eslint": "7.31.0",
|
||||
"eslint-plugin-import": "2.23.4",
|
||||
"eslint-plugin-jsdoc": "35.4.5",
|
||||
"eslint-plugin-jsdoc": "35.5.0",
|
||||
"eslint-plugin-no-null": "1.0.2",
|
||||
"eslint-plugin-prefer-arrow": "1.2.3",
|
||||
"eslint-plugin-unicorn": "34.0.1",
|
||||
@@ -81,7 +81,7 @@
|
||||
"pre-commit": "1.2.2",
|
||||
"rimraf": "3.0.2",
|
||||
"sinon": "11.1.1",
|
||||
"source-map-resolve": "^0.6.0",
|
||||
"source-map-resolve": "0.6.0",
|
||||
"threads": "1.6.5",
|
||||
"ts-loader": "9.2.3",
|
||||
"ts-node": "10.1.0",
|
||||
|
||||
@@ -9,7 +9,7 @@ export function SelfDefendingNoEvalTemplate (): string {
|
||||
{globalVariableTemplate}
|
||||
|
||||
const test = function () {
|
||||
const regExp = new that.RegExp('^([^ ]+( +[^ ]+)+)+[^ ]}');
|
||||
const regExp = that.RegExp('^([^ ]+([\\\\x20\\\\x09]+[^\\\\x20\\\\x09]+)+)+[^\\\\x20\\\\x09]}');
|
||||
|
||||
return !regExp.test({selfDefendingFunctionName});
|
||||
};
|
||||
|
||||
@@ -8,8 +8,9 @@ export function SelfDefendingTemplate (): string {
|
||||
const {selfDefendingFunctionName} = {callControllerFunctionName}(this, function () {
|
||||
const test = function () {
|
||||
const regExp = test
|
||||
.constructor('return /" + this + "/')()
|
||||
.constructor('^([^ ]+( +[^ ]+)+)+[^ ]}');
|
||||
.constructor('return /" + this + "/')
|
||||
.call()
|
||||
.constructor('^([^ ]+([\\\\x20\\\\x09]+[^\\\\x20\\\\x09]+)+)+[^\\\\x20\\\\x09]}');
|
||||
|
||||
return !regExp.test({selfDefendingFunctionName});
|
||||
};
|
||||
|
||||
+59
-23
@@ -121,36 +121,72 @@ describe('SelfDefendingNoEvalTemplate', function () {
|
||||
});
|
||||
|
||||
describe('Variant #4: obfuscated code with beautified self defending code', () => {
|
||||
const expectedEvaluationResult: number = 0;
|
||||
describe('Variant #1: beautify with spaces', () => {
|
||||
const expectedEvaluationResult: number = 0;
|
||||
|
||||
let obfuscatedCode: string,
|
||||
evaluationResult: number = 0;
|
||||
let obfuscatedCode: string,
|
||||
evaluationResult: number = 0;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/input.js');
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/input.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
selfDefending: true,
|
||||
target: ObfuscationTarget.BrowserNoEval
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
obfuscatedCode = beautifyCode(obfuscatedCode);
|
||||
|
||||
return evaluateInWorker(obfuscatedCode, evaluationTimeout)
|
||||
.then((result: string | null) => {
|
||||
if (!result) {
|
||||
return;
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
selfDefending: true,
|
||||
target: ObfuscationTarget.BrowserNoEval
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
obfuscatedCode = beautifyCode(obfuscatedCode, 'space');
|
||||
|
||||
evaluationResult = parseInt(result, 10);
|
||||
});
|
||||
return evaluateInWorker(obfuscatedCode, evaluationTimeout)
|
||||
.then((result: string | null) => {
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
|
||||
evaluationResult = parseInt(result, 10);
|
||||
});
|
||||
});
|
||||
|
||||
it('should enter code in infinity loop', () => {
|
||||
assert.equal(evaluationResult, expectedEvaluationResult);
|
||||
});
|
||||
});
|
||||
|
||||
it('should enter code in infinity loop', () => {
|
||||
assert.equal(evaluationResult, expectedEvaluationResult);
|
||||
describe('Variant #2: beautify with tabs', () => {
|
||||
const expectedEvaluationResult: number = 0;
|
||||
|
||||
let obfuscatedCode: string,
|
||||
evaluationResult: number = 0;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/input.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
selfDefending: true,
|
||||
target: ObfuscationTarget.BrowserNoEval
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
obfuscatedCode = beautifyCode(obfuscatedCode, 'tab');
|
||||
|
||||
return evaluateInWorker(obfuscatedCode, evaluationTimeout)
|
||||
.then((result: string | null) => {
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
|
||||
evaluationResult = parseInt(result, 10);
|
||||
});
|
||||
});
|
||||
|
||||
it('should enter code in infinity loop', () => {
|
||||
assert.equal(evaluationResult, expectedEvaluationResult);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+57
-22
@@ -117,35 +117,70 @@ describe('SelfDefendingTemplate', function () {
|
||||
});
|
||||
|
||||
describe('Variant #4: obfuscated code with beautified self defending code', () => {
|
||||
const expectedEvaluationResult: number = 0;
|
||||
describe('Variant #1: beautify with spaces', () => {
|
||||
const expectedEvaluationResult: number = 0;
|
||||
|
||||
let obfuscatedCode: string,
|
||||
evaluationResult: number = 0;
|
||||
let obfuscatedCode: string,
|
||||
evaluationResult: number = 0;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/input.js');
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/input.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
selfDefending: true
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
obfuscatedCode = beautifyCode(obfuscatedCode);
|
||||
|
||||
return evaluateInWorker(obfuscatedCode, evaluationTimeout)
|
||||
.then((result: string | null) => {
|
||||
if (!result) {
|
||||
return;
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
selfDefending: true
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
obfuscatedCode = beautifyCode(obfuscatedCode, 'space');
|
||||
|
||||
evaluationResult = parseInt(result, 10);
|
||||
});
|
||||
return evaluateInWorker(obfuscatedCode, evaluationTimeout)
|
||||
.then((result: string | null) => {
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
|
||||
evaluationResult = parseInt(result, 10);
|
||||
});
|
||||
});
|
||||
|
||||
it('should enter code in infinity loop', () => {
|
||||
assert.equal(evaluationResult, expectedEvaluationResult);
|
||||
});
|
||||
});
|
||||
|
||||
it('should enter code in infinity loop', () => {
|
||||
assert.equal(evaluationResult, expectedEvaluationResult);
|
||||
describe('Variant #2: beautify with tabs', () => {
|
||||
const expectedEvaluationResult: number = 0;
|
||||
|
||||
let obfuscatedCode: string,
|
||||
evaluationResult: number = 0;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/input.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
selfDefending: true
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
obfuscatedCode = beautifyCode(obfuscatedCode, 'tab');
|
||||
|
||||
return evaluateInWorker(obfuscatedCode, evaluationTimeout)
|
||||
.then((result: string | null) => {
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
|
||||
evaluationResult = parseInt(result, 10);
|
||||
});
|
||||
});
|
||||
|
||||
it('should enter code in infinity loop', () => {
|
||||
assert.equal(evaluationResult, expectedEvaluationResult);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
* Adds some spaces between some language constructions
|
||||
*
|
||||
* @param {string} code
|
||||
* @param {" " | " "} character
|
||||
* @returns {string}
|
||||
*/
|
||||
export function beautifyCode (code: string): string {
|
||||
export function beautifyCode (code: string, character: 'space' | 'tab'): string {
|
||||
const spaceCharacter: string = character === 'space' ? '\x20' : '\x09';
|
||||
|
||||
return code
|
||||
.replace(/function\(\){/g, 'function () {')
|
||||
.replace(/(!?=+)/g, ' $1 ')
|
||||
.replace(/,/g, ', ')
|
||||
.replace(/;/g, '; ');
|
||||
.replace(/,/g, `,${spaceCharacter}`)
|
||||
.replace(/;/g, `;\n${spaceCharacter}`);
|
||||
}
|
||||
@@ -715,10 +715,10 @@
|
||||
resolved "https://registry.npmjs.org/@types/node/-/node-13.9.3.tgz"
|
||||
integrity sha512-01s+ac4qerwd6RHD+mVbOEsraDHSgUaefQlEdBbUolnQFjKwCr7luvAlEwW1RFojh67u0z4OUTjPn9LEl4zIkA==
|
||||
|
||||
"@types/node@16.3.3":
|
||||
version "16.3.3"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.3.3.tgz#0c30adff37bbbc7a50eb9b58fae2a504d0d88038"
|
||||
integrity sha512-8h7k1YgQKxKXWckzFCMfsIwn0Y61UK6tlD6y2lOb3hTOIMlK3t9/QwHOhc81TwU+RMf0As5fj7NPjroERCnejQ==
|
||||
"@types/node@16.4.0":
|
||||
version "16.4.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.4.0.tgz#2c219eaa3b8d1e4d04f4dd6e40bc68c7467d5272"
|
||||
integrity sha512-HrJuE7Mlqcjj+00JqMWpZ3tY8w7EUd+S0U3L1+PQSWiXZbOgyQDvi+ogoUxaHApPJq5diKxYBQwA3iIlNcPqOg==
|
||||
|
||||
"@types/normalize-package-data@^2.4.0":
|
||||
version "2.4.0"
|
||||
@@ -1927,10 +1927,10 @@ eslint-plugin-import@2.23.4:
|
||||
resolve "^1.20.0"
|
||||
tsconfig-paths "^3.9.0"
|
||||
|
||||
eslint-plugin-jsdoc@35.4.5:
|
||||
version "35.4.5"
|
||||
resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-35.4.5.tgz#20e9e52328b0e3dea1a70a965877dfe9d2b66edc"
|
||||
integrity sha512-CguI9uhIJoihCsW5WTUY9xX2w9EpovmmHCz/JzAevC7Fcop+wyJLDjzaBnTh2LlSJvG9qVfkr7OJ+9i4cv1Kzg==
|
||||
eslint-plugin-jsdoc@35.5.0:
|
||||
version "35.5.0"
|
||||
resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-35.5.0.tgz#5be39a44c0165ec0fbbe87bd905c7ad2fa1fec21"
|
||||
integrity sha512-QBtfGeKvSFjbMLl28fRVyk/V7NhdSy+/4a6nOUXNsJ+Ya4G88YwbBiHIZgU4COeMKPb+OGGnrLwxYO0tZiw+kg==
|
||||
dependencies:
|
||||
"@es-joy/jsdoccomment" "^0.9.0-alpha.1"
|
||||
comment-parser "1.1.6-beta.0"
|
||||
@@ -4101,7 +4101,7 @@ source-list-map@^2.0.1:
|
||||
resolved "https://registry.npmjs.org/source-list-map/-/source-list-map-2.0.1.tgz"
|
||||
integrity sha512-qnQ7gVMxGNxsiL4lEuJwe/To8UnK7fAnmbGEEH8RpLouuKbeEm0lhbQVFIrNSuB+G7tVrAlVsZgETT5nljf+Iw==
|
||||
|
||||
source-map-resolve@^0.6.0:
|
||||
source-map-resolve@0.6.0:
|
||||
version "0.6.0"
|
||||
resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.6.0.tgz#3d9df87e236b53f16d01e58150fc7711138e5ed2"
|
||||
integrity sha512-KXBr9d/fO/bWo97NXsPIAW1bFSBOuCnjbNTBMO7N59hsv5i9yzRDfcYwwt0l04+VqnKC+EwzvJZIP/qkuMgR/w==
|
||||
|
||||
Reference in New Issue
Block a user