From b1e2b9b17df08d7503158b693ee574816df521a4 Mon Sep 17 00:00:00 2001 From: Kuizuo Date: Tue, 5 Dec 2023 08:02:54 +0800 Subject: [PATCH] feat: add restoreSequence method --- packages/utils/__tests__/index.test.ts | 15 +++++++++++++++ packages/utils/deob.js | 11 +++++++++-- play/obfuscator/index.js | 3 +++ play/obfuscator/output.js | 23 ++++++++++++++++------- website/utils/deobfuscator.ts | 2 ++ 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/packages/utils/__tests__/index.test.ts b/packages/utils/__tests__/index.test.ts index 1d7acc8..d7f9d1b 100644 --- a/packages/utils/__tests__/index.test.ts +++ b/packages/utils/__tests__/index.test.ts @@ -305,4 +305,19 @@ _0x4547db(); a + b;`.trim(), ) }) + + it('restoreSequence', () => { + const rawCode = `_0x6cbcff(), console.log('foo')` + const deob = new Deob(rawCode) + + deob.restoreSequence() + const code = deob.getCode() + + expect(code).toBe( + ` +_0x6cbcff(); + +console.log('foo');`.trim(), + ) + }) }) diff --git a/packages/utils/deob.js b/packages/utils/deob.js index d335b8b..600d9bf 100644 --- a/packages/utils/deob.js +++ b/packages/utils/deob.js @@ -1145,6 +1145,11 @@ export class Deob { /** * 还原逗号表达式 + * @example + * _0x6cbcff(), console.log('foo') + * ⬇️ + * _0x6cbcff(); + * console.log('foo'); */ restoreSequence() { traverse(this.ast, { @@ -1154,13 +1159,15 @@ export class Deob { const finalExpression = exporessions[exporessions.length - 1] const statement = path.getStatementParent() - this.expression.forEach((e) => { - statemente.insertBefore(t.ExpressionStatement(e)) + exporessions.slice(0, -1).forEach((e) => { + statement.insertBefore(t.ExpressionStatement(e)) }) path.replaceInline(finalExpression) }, }, }) + + this.reParse() } /** diff --git a/play/obfuscator/index.js b/play/obfuscator/index.js index ea4bb6b..084bbf5 100644 --- a/play/obfuscator/index.js +++ b/play/obfuscator/index.js @@ -56,6 +56,9 @@ class MyDeOb extends Deob { } deob.removeUnusedBlock() deob.removeUnusedVariables() + + deob.splitMultipleDeclarations() + deob.restoreSequence() deob.selfCallFnReplace() deob.deleteExtra() diff --git a/play/obfuscator/output.js b/play/obfuscator/output.js index 616d190..9a20532 100644 --- a/play/obfuscator/output.js +++ b/play/obfuscator/output.js @@ -15,7 +15,8 @@ function hi() { return _0x4b57(_0x38aa9b - 582 - 243, _0x237d6c); } - _0x5601ab["UywnN"] = _0x31a68e["zoWtj"], _0x5601ab["AjDZu"] = _0x31a68e["SGFdI"]; + _0x5601ab["UywnN"] = _0x31a68e["zoWtj"]; + _0x5601ab["AjDZu"] = _0x31a68e["SGFdI"]; function _0x294cfa(_0x95d0a4, _0x2b4d9c, _0x1a5bbe, _0x54c4d3) { return _0x4b57(_0x1a5bbe - -1624 - 841, _0x54c4d3); @@ -36,12 +37,14 @@ function hi() { if (_0x46a7b3) { var _0x3d6c1e = _0x46a7b3["apply"](_0x330efc, arguments); - return _0x46a7b3 = null, _0x3d6c1e; + _0x46a7b3 = null; + return _0x3d6c1e; } } else _0x22db6b = _0x4bbd53; } : function () {}; - return _0x7159b6 = false, _0x7fa39c; + _0x7159b6 = false; + return _0x7fa39c; }; }(); @@ -71,11 +74,13 @@ function hi() { if (_0x24e3b2) { var _0x3f7b59 = _0x237167["apply"](_0x4b4d1b, arguments); - return _0x269724 = null, _0x3f7b59; + _0x269724 = null; + return _0x3f7b59; } } : function () {}; - return _0x542fef = false, _0x5a6f56; + _0x542fef = false; + return _0x5a6f56; } } catch (_0x10880c) { if (false) { @@ -85,7 +90,9 @@ function hi() { var _0x4982de = _0x3457ce[_0xc56e0] || _0x5f7acf; - _0x5f7acf["__proto__"] = _0x25f351["bind"](_0x592499), _0x5f7acf["toString"] = _0x4982de["toString"]["bind"](_0x4982de), _0x2b5296[_0xc56e0] = _0x5f7acf; + _0x5f7acf["__proto__"] = _0x25f351["bind"](_0x592499); + _0x5f7acf["toString"] = _0x4982de["toString"]["bind"](_0x4982de); + _0x2b5296[_0xc56e0] = _0x5f7acf; } else _0x6f0388 = window; } @@ -121,7 +128,9 @@ function hi() { } }); - _0x6cbcff(), console["log"]("Hello World!"); + _0x6cbcff(); + + console["log"]("Hello World!"); } hi(); \ No newline at end of file diff --git a/website/utils/deobfuscator.ts b/website/utils/deobfuscator.ts index 3e600a1..6a9e9a1 100644 --- a/website/utils/deobfuscator.ts +++ b/website/utils/deobfuscator.ts @@ -52,6 +52,8 @@ self.addEventListener( if (options.isRemoveUnusedVariables) deob.removeUnusedVariables() + deob.splitMultipleDeclarations() + deob.restoreSequence() deob.selfCallFnReplace() if (options.deleteExtraEnable)