Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Change Log

v2.15.3
---
* Slightly improved integration between `deadCodeInjection` and `stringArrayWrappersChainedCalls` options

v2.15.2
---
* Fixed invalid behaviour of `transformObjectKeys` option when object values contains `this` references. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/937
Expand Down
2 changes: 1 addition & 1 deletion dist/index.browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.cli.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "javascript-obfuscator",
"version": "2.15.2",
"version": "2.15.3",
"description": "JavaScript obfuscator",
"keywords": [
"obfuscator",
Expand All @@ -24,7 +24,7 @@
"@javascript-obfuscator/escodegen": "2.2.0",
"@javascript-obfuscator/estraverse": "5.3.0",
"@nuxtjs/opencollective": "0.3.2",
"acorn": "8.3.0",
"acorn": "8.4.0",
"assert": "2.0.0",
"chalk": "4.1.1",
"chance": "1.1.7",
Expand All @@ -42,7 +42,7 @@
"source-map-support": "0.5.19",
"string-template": "1.0.0",
"stringz": "2.1.0",
"tslib": "2.2.0"
"tslib": "2.3.0"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "1.0.1",
Expand All @@ -62,14 +62,14 @@
"@types/sinon": "10.0.2",
"@types/string-template": "1.0.2",
"@types/webpack-env": "1.16.0",
"@typescript-eslint/eslint-plugin": "4.26.1",
"@typescript-eslint/parser": "4.26.1",
"@typescript-eslint/eslint-plugin": "4.27.0",
"@typescript-eslint/parser": "4.27.0",
"chai": "4.3.4",
"chai-exclude": "2.0.3",
"cross-env": "7.0.3",
"eslint": "7.28.0",
"eslint-plugin-import": "2.23.4",
"eslint-plugin-jsdoc": "35.1.3",
"eslint-plugin-jsdoc": "35.3.0",
"eslint-plugin-no-null": "1.0.2",
"eslint-plugin-prefer-arrow": "1.2.3",
"eslint-plugin-unicorn": "33.0.1",
Expand All @@ -85,7 +85,7 @@
"ts-loader": "9.2.3",
"ts-node": "10.0.0",
"typescript": "4.3.2",
"webpack": "5.38.1",
"webpack": "5.39.0",
"webpack-cli": "4.7.2",
"webpack-node-externals": "3.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
NodeTransformer.ScopeIdentifiersTransformer
];

/**
* @type {NodeTransformer[]}
*/
public override readonly runAfter: NodeTransformer[] = [
NodeTransformer.ScopeIdentifiersTransformer
];

/**
* @type {Set <BlockStatement>}
*/
Expand Down Expand Up @@ -237,7 +244,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
}
};

case NodeTransformationStage.Finalizing:
case NodeTransformationStage.RenameIdentifiers:
if (!this.deadCodeInjectionRootAstHostNodeSet.size) {
return null;
}
Expand Down
44 changes: 32 additions & 12 deletions test/dev/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,42 @@

let obfuscationResult = JavaScriptObfuscator.obfuscate(
`
function foo() {
global.baz = 3;
}
(function(){
if (true) {
var foo = function () {
console.log('abc');
};
var bar = function () {
console.log('def');
};
var baz = function () {
console.log('ghi');
};
var bark = function () {
console.log('jkl');
};
var hawk = function () {
console.log('mno');
};

function bar(...args) {
console.log(2);
}
foo();
bar();
baz();
bark();
hawk();
}
})();
`,
{
compact: false,
identifierNamesCache: {
globalIdentifiers: {},
propertyIdentifiers: {}
},
renameGlobals: true,
renameProperties: true
simplify: false,
stringArray: true,
stringArrayThreshold: 1,
stringArrayWrappersChainedCalls: true,
deadCodeInjection: true,
deadCodeInjectionThreshold: 1,
identifierNamesGenerator: 'mangled',
seed: 1
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -998,5 +998,46 @@ describe('DeadCodeInjectionTransformer', () => {
});
});
});

describe('Variant #12 - correct integration with `stringArrayWrappersChainedCalls` option', () => {
const regExp: RegExp = new RegExp(
`var ${variableMatch} *= *${variableMatch}; *` +
`if *\\(${variableMatch}\\(${hexMatch}\\) *[=|!]== *${variableMatch}\\(${hexMatch}\\)\\) *\\{`+
`(?:console|${variableMatch})\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` +
`\\} *else *\\{`+
`(?:console|${variableMatch})\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` +
`\\}`,
'g'
);
const expectedMatchesLength: number = 5;

let matchesLength: number = 0;

before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/input-1.js');

const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
deadCodeInjection: true,
deadCodeInjectionThreshold: 1,
stringArray: true,
stringArrayThreshold: 1,
stringArrayWrappersCount: 1,
stringArrayWrappersChainedCalls: true
}
).getObfuscatedCode();
const matches: RegExpMatchArray = <RegExpMatchArray>obfuscatedCode.match(regExp);

if (matches) {
matchesLength = matches.length;
}
});

it('should unwrap dead code injection root AST host node before the string array transformer', () => {
assert.equal(matchesLength, expectedMatchesLength);
});
});
});
});
114 changes: 57 additions & 57 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -738,74 +738,74 @@
resolved "https://registry.npmjs.org/@types/webpack-env/-/webpack-env-1.16.0.tgz"
integrity sha512-Fx+NpfOO0CpeYX2g9bkvX8O5qh9wrU1sOF4g8sft4Mu7z+qfe387YlyY8w8daDyDsKY5vUxM0yxkAYnbkRbZEw==

"@typescript-eslint/eslint-plugin@4.26.1":
version "4.26.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.26.1.tgz#b9c7313321cb837e2bf8bebe7acc2220659e67d3"
integrity sha512-aoIusj/8CR+xDWmZxARivZjbMBQTT9dImUtdZ8tVCVRXgBUuuZyM5Of5A9D9arQPxbi/0rlJLcuArclz/rCMJw==
"@typescript-eslint/eslint-plugin@4.27.0":
version "4.27.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.27.0.tgz#0b7fc974e8bc9b2b5eb98ed51427b0be529b4ad0"
integrity sha512-DsLqxeUfLVNp3AO7PC3JyaddmEHTtI9qTSAs+RB6ja27QvIM0TA8Cizn1qcS6vOu+WDLFJzkwkgweiyFhssDdQ==
dependencies:
"@typescript-eslint/experimental-utils" "4.26.1"
"@typescript-eslint/scope-manager" "4.26.1"
"@typescript-eslint/experimental-utils" "4.27.0"
"@typescript-eslint/scope-manager" "4.27.0"
debug "^4.3.1"
functional-red-black-tree "^1.0.1"
lodash "^4.17.21"
regexpp "^3.1.0"
semver "^7.3.5"
tsutils "^3.21.0"

"@typescript-eslint/experimental-utils@4.26.1":
version "4.26.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.26.1.tgz#a35980a2390da9232aa206b27f620eab66e94142"
integrity sha512-sQHBugRhrXzRCs9PaGg6rowie4i8s/iD/DpTB+EXte8OMDfdCG5TvO73XlO9Wc/zi0uyN4qOmX9hIjQEyhnbmQ==
"@typescript-eslint/experimental-utils@4.27.0":
version "4.27.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.27.0.tgz#78192a616472d199f084eab8f10f962c0757cd1c"
integrity sha512-n5NlbnmzT2MXlyT+Y0Jf0gsmAQzCnQSWXKy4RGSXVStjDvS5we9IWbh7qRVKdGcxT0WYlgcCYUK/HRg7xFhvjQ==
dependencies:
"@types/json-schema" "^7.0.7"
"@typescript-eslint/scope-manager" "4.26.1"
"@typescript-eslint/types" "4.26.1"
"@typescript-eslint/typescript-estree" "4.26.1"
"@typescript-eslint/scope-manager" "4.27.0"
"@typescript-eslint/types" "4.27.0"
"@typescript-eslint/typescript-estree" "4.27.0"
eslint-scope "^5.1.1"
eslint-utils "^3.0.0"

"@typescript-eslint/parser@4.26.1":
version "4.26.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.26.1.tgz#cecfdd5eb7a5c13aabce1c1cfd7fbafb5a0f1e8e"
integrity sha512-q7F3zSo/nU6YJpPJvQveVlIIzx9/wu75lr6oDbDzoeIRWxpoc/HQ43G4rmMoCc5my/3uSj2VEpg/D83LYZF5HQ==
"@typescript-eslint/parser@4.27.0":
version "4.27.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.27.0.tgz#85447e573364bce4c46c7f64abaa4985aadf5a94"
integrity sha512-XpbxL+M+gClmJcJ5kHnUpBGmlGdgNvy6cehgR6ufyxkEJMGP25tZKCaKyC0W/JVpuhU3VU1RBn7SYUPKSMqQvQ==
dependencies:
"@typescript-eslint/scope-manager" "4.26.1"
"@typescript-eslint/types" "4.26.1"
"@typescript-eslint/typescript-estree" "4.26.1"
"@typescript-eslint/scope-manager" "4.27.0"
"@typescript-eslint/types" "4.27.0"
"@typescript-eslint/typescript-estree" "4.27.0"
debug "^4.3.1"

"@typescript-eslint/scope-manager@4.26.1":
version "4.26.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.26.1.tgz#075a74a15ff33ee3a7ed33e5fce16ee86689f662"
integrity sha512-TW1X2p62FQ8Rlne+WEShyd7ac2LA6o27S9i131W4NwDSfyeVlQWhw8ylldNNS8JG6oJB9Ha9Xyc+IUcqipvheQ==
"@typescript-eslint/scope-manager@4.27.0":
version "4.27.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.27.0.tgz#b0b1de2b35aaf7f532e89c8e81d0fa298cae327d"
integrity sha512-DY73jK6SEH6UDdzc6maF19AHQJBFVRf6fgAXHPXCGEmpqD4vYgPEzqpFz1lf/daSbOcMpPPj9tyXXDPW2XReAw==
dependencies:
"@typescript-eslint/types" "4.26.1"
"@typescript-eslint/visitor-keys" "4.26.1"
"@typescript-eslint/types" "4.27.0"
"@typescript-eslint/visitor-keys" "4.27.0"

"@typescript-eslint/types@4.26.1":
version "4.26.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.26.1.tgz#9e7c523f73c34b04a765e4167ca5650436ef1d38"
integrity sha512-STyMPxR3cS+LaNvS8yK15rb8Y0iL0tFXq0uyl6gY45glyI7w0CsyqyEXl/Fa0JlQy+pVANeK3sbwPneCbWE7yg==
"@typescript-eslint/types@4.27.0":
version "4.27.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.27.0.tgz#712b408519ed699baff69086bc59cd2fc13df8d8"
integrity sha512-I4ps3SCPFCKclRcvnsVA/7sWzh7naaM/b4pBO2hVxnM3wrU51Lveybdw5WoIktU/V4KfXrTt94V9b065b/0+wA==

"@typescript-eslint/typescript-estree@4.26.1":
version "4.26.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.26.1.tgz#b2ce2e789233d62283fae2c16baabd4f1dbc9633"
integrity sha512-l3ZXob+h0NQzz80lBGaykdScYaiEbFqznEs99uwzm8fPHhDjwaBFfQkjUC/slw6Sm7npFL8qrGEAMxcfBsBJUg==
"@typescript-eslint/typescript-estree@4.27.0":
version "4.27.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.27.0.tgz#189a7b9f1d0717d5cccdcc17247692dedf7a09da"
integrity sha512-KH03GUsUj41sRLLEy2JHstnezgpS5VNhrJouRdmh6yNdQ+yl8w5LrSwBkExM+jWwCJa7Ct2c8yl8NdtNRyQO6g==
dependencies:
"@typescript-eslint/types" "4.26.1"
"@typescript-eslint/visitor-keys" "4.26.1"
"@typescript-eslint/types" "4.27.0"
"@typescript-eslint/visitor-keys" "4.27.0"
debug "^4.3.1"
globby "^11.0.3"
is-glob "^4.0.1"
semver "^7.3.5"
tsutils "^3.21.0"

"@typescript-eslint/visitor-keys@4.26.1":
version "4.26.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.26.1.tgz#0d55ea735cb0d8903b198017d6d4f518fdaac546"
integrity sha512-IGouNSSd+6x/fHtYRyLOM6/C+QxMDzWlDtN41ea+flWuSF9g02iqcIlX8wM53JkfljoIjP0U+yp7SiTS1onEkw==
"@typescript-eslint/visitor-keys@4.27.0":
version "4.27.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.27.0.tgz#f56138b993ec822793e7ebcfac6ffdce0a60cb81"
integrity sha512-es0GRYNZp0ieckZ938cEANfEhsfHrzuLrePukLKtY3/KPXcq1Xd555Mno9/GOgXhKzn0QfkDLVgqWO3dGY80bg==
dependencies:
"@typescript-eslint/types" "4.26.1"
"@typescript-eslint/types" "4.27.0"
eslint-visitor-keys "^2.0.0"

"@ungap/[email protected]":
Expand Down Expand Up @@ -971,10 +971,10 @@ acorn-jsx@^5.3.1:
resolved "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.1.tgz"
integrity sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng==

acorn@8.3.0:
version "8.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.3.0.tgz#1193f9b96c4e8232f00b11a9edff81b2c8b98b88"
integrity sha512-tqPKHZ5CaBJw0Xmy0ZZvLs1qTV+BNFSyvn77ASXkpBNfIRk8ev26fKrD9iLGwGA9zedPao52GSHzq8lyZG0NUw==
acorn@8.4.0:
version "8.4.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.4.0.tgz#af53266e698d7cffa416714b503066a82221be60"
integrity sha512-ULr0LDaEqQrMFGyQ3bhJkLsbtrQ8QibAseGZeaSUiT/6zb9IvIkomWHJIvgvwad+hinRAgsI51JcWk2yvwyL+w==

acorn@^7.4.0:
version "7.4.0"
Expand Down Expand Up @@ -1886,10 +1886,10 @@ [email protected]:
resolve "^1.20.0"
tsconfig-paths "^3.9.0"

eslint-plugin-jsdoc@35.1.3:
version "35.1.3"
resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-35.1.3.tgz#ee9f8566eeb87a0e96fc52ec55897a2cb93ceea5"
integrity sha512-9AVpCssb7+cfEx3GJtnhJ8yLOVsHDKGMgngcfvwFBxdcOVPFhLENReL5aX1R2gNiG3psqIWFVBpSPnPQTrMZUA==
eslint-plugin-jsdoc@35.3.0:
version "35.3.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-35.3.0.tgz#375410bc990b54d1a394b545b9faa92d8e05a065"
integrity sha512-caPF26GcTqU8e83kj6Zp5RLCNgf9ya8rGNxtk1aDAiUCF5KMqTKmOt28sjcejL99b0py3EC0ds8dOXsoFDVahA==
dependencies:
"@es-joy/jsdoccomment" "^0.8.0-alpha.2"
comment-parser "1.1.5"
Expand Down Expand Up @@ -4409,10 +4409,10 @@ tsconfig-paths@^3.9.0:
minimist "^1.2.0"
strip-bom "^3.0.0"

tslib@2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.2.0.tgz#fb2c475977e35e241311ede2693cee1ec6698f5c"
integrity sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w==
tslib@2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.0.tgz#803b8cdab3e12ba581a4ca41c8839bbb0dacb09e"
integrity sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==

tslib@^1.8.1, tslib@^1.9.0:
version "1.11.1"
Expand Down Expand Up @@ -4592,10 +4592,10 @@ webpack-sources@^2.3.0:
source-list-map "^2.0.1"
source-map "^0.6.1"

webpack@5.38.1:
version "5.38.1"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.38.1.tgz#5224c7f24c18e729268d3e3bc97240d6e880258e"
integrity sha512-OqRmYD1OJbHZph6RUMD93GcCZy4Z4wC0ele4FXyYF0J6AxO1vOSuIlU1hkS/lDlR9CDYBz64MZRmdbdnFFoT2g==
webpack@5.39.0:
version "5.39.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.39.0.tgz#37d6899f1f40c31d5901abc0f39bc8cc7224138c"
integrity sha512-25CHmuDj+oOTyteI13sUqNlCnjCnySuhiKWE/cRYPQYeoQ3ijHgyWX27CiyUKLNGq27v8S0mrksyTreT/xo7pg==
dependencies:
"@types/eslint-scope" "^3.7.0"
"@types/estree" "^0.0.47"
Expand Down