Skip to content

Commit 993cf7a

Browse files
authored
Merge pull request javascript-obfuscator#940 from javascript-obfuscator/dead-code-injection-string-array-chained-calls-integration
Dead code injection unwrap stage now runs before string array transfo…
2 parents 0f0eb27 + 899456f commit 993cf7a

9 files changed

Lines changed: 152 additions & 80 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Change Log
22

3+
v2.15.3
4+
---
5+
* Slightly improved integration between `deadCodeInjection` and `stringArrayWrappersChainedCalls` options
6+
37
v2.15.2
48
---
59
* Fixed invalid behaviour of `transformObjectKeys` option when object values contains `this` references. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/937

dist/index.browser.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.cli.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "javascript-obfuscator",
3-
"version": "2.15.2",
3+
"version": "2.15.3",
44
"description": "JavaScript obfuscator",
55
"keywords": [
66
"obfuscator",
@@ -24,7 +24,7 @@
2424
"@javascript-obfuscator/escodegen": "2.2.0",
2525
"@javascript-obfuscator/estraverse": "5.3.0",
2626
"@nuxtjs/opencollective": "0.3.2",
27-
"acorn": "8.3.0",
27+
"acorn": "8.4.0",
2828
"assert": "2.0.0",
2929
"chalk": "4.1.1",
3030
"chance": "1.1.7",
@@ -42,7 +42,7 @@
4242
"source-map-support": "0.5.19",
4343
"string-template": "1.0.0",
4444
"stringz": "2.1.0",
45-
"tslib": "2.2.0"
45+
"tslib": "2.3.0"
4646
},
4747
"devDependencies": {
4848
"@istanbuljs/nyc-config-typescript": "1.0.1",
@@ -62,14 +62,14 @@
6262
"@types/sinon": "10.0.2",
6363
"@types/string-template": "1.0.2",
6464
"@types/webpack-env": "1.16.0",
65-
"@typescript-eslint/eslint-plugin": "4.26.1",
66-
"@typescript-eslint/parser": "4.26.1",
65+
"@typescript-eslint/eslint-plugin": "4.27.0",
66+
"@typescript-eslint/parser": "4.27.0",
6767
"chai": "4.3.4",
6868
"chai-exclude": "2.0.3",
6969
"cross-env": "7.0.3",
7070
"eslint": "7.28.0",
7171
"eslint-plugin-import": "2.23.4",
72-
"eslint-plugin-jsdoc": "35.1.3",
72+
"eslint-plugin-jsdoc": "35.3.0",
7373
"eslint-plugin-no-null": "1.0.2",
7474
"eslint-plugin-prefer-arrow": "1.2.3",
7575
"eslint-plugin-unicorn": "33.0.1",
@@ -85,7 +85,7 @@
8585
"ts-loader": "9.2.3",
8686
"ts-node": "10.0.0",
8787
"typescript": "4.3.2",
88-
"webpack": "5.38.1",
88+
"webpack": "5.39.0",
8989
"webpack-cli": "4.7.2",
9090
"webpack-node-externals": "3.0.0"
9191
},

src/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
5252
NodeTransformer.ScopeIdentifiersTransformer
5353
];
5454

55+
/**
56+
* @type {NodeTransformer[]}
57+
*/
58+
public override readonly runAfter: NodeTransformer[] = [
59+
NodeTransformer.ScopeIdentifiersTransformer
60+
];
61+
5562
/**
5663
* @type {Set <BlockStatement>}
5764
*/
@@ -237,7 +244,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
237244
}
238245
};
239246

240-
case NodeTransformationStage.Finalizing:
247+
case NodeTransformationStage.RenameIdentifiers:
241248
if (!this.deadCodeInjectionRootAstHostNodeSet.size) {
242249
return null;
243250
}

test/dev/dev.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,42 @@
55

66
let obfuscationResult = JavaScriptObfuscator.obfuscate(
77
`
8-
function foo() {
9-
global.baz = 3;
10-
}
8+
(function(){
9+
if (true) {
10+
var foo = function () {
11+
console.log('abc');
12+
};
13+
var bar = function () {
14+
console.log('def');
15+
};
16+
var baz = function () {
17+
console.log('ghi');
18+
};
19+
var bark = function () {
20+
console.log('jkl');
21+
};
22+
var hawk = function () {
23+
console.log('mno');
24+
};
1125
12-
function bar(...args) {
13-
console.log(2);
14-
}
26+
foo();
27+
bar();
28+
baz();
29+
bark();
30+
hawk();
31+
}
32+
})();
1533
`,
1634
{
1735
compact: false,
18-
identifierNamesCache: {
19-
globalIdentifiers: {},
20-
propertyIdentifiers: {}
21-
},
22-
renameGlobals: true,
23-
renameProperties: true
36+
simplify: false,
37+
stringArray: true,
38+
stringArrayThreshold: 1,
39+
stringArrayWrappersChainedCalls: true,
40+
deadCodeInjection: true,
41+
deadCodeInjectionThreshold: 1,
42+
identifierNamesGenerator: 'mangled',
43+
seed: 1
2444
}
2545
);
2646

test/functional-tests/node-transformers/dead-code-injection-transformers/DeadCodeInjectionTransformer.spec.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,5 +998,46 @@ describe('DeadCodeInjectionTransformer', () => {
998998
});
999999
});
10001000
});
1001+
1002+
describe('Variant #12 - correct integration with `stringArrayWrappersChainedCalls` option', () => {
1003+
const regExp: RegExp = new RegExp(
1004+
`var ${variableMatch} *= *${variableMatch}; *` +
1005+
`if *\\(${variableMatch}\\(${hexMatch}\\) *[=|!]== *${variableMatch}\\(${hexMatch}\\)\\) *\\{`+
1006+
`(?:console|${variableMatch})\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` +
1007+
`\\} *else *\\{`+
1008+
`(?:console|${variableMatch})\\[${variableMatch}\\(${hexMatch}\\)\\]\\(${variableMatch}\\(${hexMatch}\\)\\);` +
1009+
`\\}`,
1010+
'g'
1011+
);
1012+
const expectedMatchesLength: number = 5;
1013+
1014+
let matchesLength: number = 0;
1015+
1016+
before(() => {
1017+
const code: string = readFileAsString(__dirname + '/fixtures/input-1.js');
1018+
1019+
const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
1020+
code,
1021+
{
1022+
...NO_ADDITIONAL_NODES_PRESET,
1023+
deadCodeInjection: true,
1024+
deadCodeInjectionThreshold: 1,
1025+
stringArray: true,
1026+
stringArrayThreshold: 1,
1027+
stringArrayWrappersCount: 1,
1028+
stringArrayWrappersChainedCalls: true
1029+
}
1030+
).getObfuscatedCode();
1031+
const matches: RegExpMatchArray = <RegExpMatchArray>obfuscatedCode.match(regExp);
1032+
1033+
if (matches) {
1034+
matchesLength = matches.length;
1035+
}
1036+
});
1037+
1038+
it('should unwrap dead code injection root AST host node before the string array transformer', () => {
1039+
assert.equal(matchesLength, expectedMatchesLength);
1040+
});
1041+
});
10011042
});
10021043
});

yarn.lock

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -738,74 +738,74 @@
738738
resolved "https://registry.npmjs.org/@types/webpack-env/-/webpack-env-1.16.0.tgz"
739739
integrity sha512-Fx+NpfOO0CpeYX2g9bkvX8O5qh9wrU1sOF4g8sft4Mu7z+qfe387YlyY8w8daDyDsKY5vUxM0yxkAYnbkRbZEw==
740740

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

755-
"@typescript-eslint/experimental-utils@4.26.1":
756-
version "4.26.1"
757-
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.26.1.tgz#a35980a2390da9232aa206b27f620eab66e94142"
758-
integrity sha512-sQHBugRhrXzRCs9PaGg6rowie4i8s/iD/DpTB+EXte8OMDfdCG5TvO73XlO9Wc/zi0uyN4qOmX9hIjQEyhnbmQ==
755+
"@typescript-eslint/experimental-utils@4.27.0":
756+
version "4.27.0"
757+
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.27.0.tgz#78192a616472d199f084eab8f10f962c0757cd1c"
758+
integrity sha512-n5NlbnmzT2MXlyT+Y0Jf0gsmAQzCnQSWXKy4RGSXVStjDvS5we9IWbh7qRVKdGcxT0WYlgcCYUK/HRg7xFhvjQ==
759759
dependencies:
760760
"@types/json-schema" "^7.0.7"
761-
"@typescript-eslint/scope-manager" "4.26.1"
762-
"@typescript-eslint/types" "4.26.1"
763-
"@typescript-eslint/typescript-estree" "4.26.1"
761+
"@typescript-eslint/scope-manager" "4.27.0"
762+
"@typescript-eslint/types" "4.27.0"
763+
"@typescript-eslint/typescript-estree" "4.27.0"
764764
eslint-scope "^5.1.1"
765765
eslint-utils "^3.0.0"
766766

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

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

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

790-
"@typescript-eslint/typescript-estree@4.26.1":
791-
version "4.26.1"
792-
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.26.1.tgz#b2ce2e789233d62283fae2c16baabd4f1dbc9633"
793-
integrity sha512-l3ZXob+h0NQzz80lBGaykdScYaiEbFqznEs99uwzm8fPHhDjwaBFfQkjUC/slw6Sm7npFL8qrGEAMxcfBsBJUg==
790+
"@typescript-eslint/typescript-estree@4.27.0":
791+
version "4.27.0"
792+
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.27.0.tgz#189a7b9f1d0717d5cccdcc17247692dedf7a09da"
793+
integrity sha512-KH03GUsUj41sRLLEy2JHstnezgpS5VNhrJouRdmh6yNdQ+yl8w5LrSwBkExM+jWwCJa7Ct2c8yl8NdtNRyQO6g==
794794
dependencies:
795-
"@typescript-eslint/types" "4.26.1"
796-
"@typescript-eslint/visitor-keys" "4.26.1"
795+
"@typescript-eslint/types" "4.27.0"
796+
"@typescript-eslint/visitor-keys" "4.27.0"
797797
debug "^4.3.1"
798798
globby "^11.0.3"
799799
is-glob "^4.0.1"
800800
semver "^7.3.5"
801801
tsutils "^3.21.0"
802802

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

811811
@@ -971,10 +971,10 @@ acorn-jsx@^5.3.1:
971971
resolved "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.1.tgz"
972972
integrity sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng==
973973

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

979979
acorn@^7.4.0:
980980
version "7.4.0"
@@ -1886,10 +1886,10 @@ [email protected]:
18861886
resolve "^1.20.0"
18871887
tsconfig-paths "^3.9.0"
18881888

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

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

44174417
tslib@^1.8.1, tslib@^1.9.0:
44184418
version "1.11.1"
@@ -4592,10 +4592,10 @@ webpack-sources@^2.3.0:
45924592
source-list-map "^2.0.1"
45934593
source-map "^0.6.1"
45944594

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

0 commit comments

Comments
 (0)