Skip to content

Commit

Permalink
feat: add restoreSequence method
Browse files Browse the repository at this point in the history
  • Loading branch information
kuizuo committed Dec 5, 2023
1 parent 3afb34a commit b1e2b9b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
15 changes: 15 additions & 0 deletions packages/utils/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
})
})
11 changes: 9 additions & 2 deletions packages/utils/deob.js
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,11 @@ export class Deob {

/**
* 还原逗号表达式
* @example
* _0x6cbcff(), console.log('foo')
* ⬇️
* _0x6cbcff();
* console.log('foo');
*/
restoreSequence() {
traverse(this.ast, {
Expand All @@ -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()
}

/**
Expand Down
3 changes: 3 additions & 0 deletions play/obfuscator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class MyDeOb extends Deob { }

deob.removeUnusedBlock()
deob.removeUnusedVariables()

deob.splitMultipleDeclarations()
deob.restoreSequence()
deob.selfCallFnReplace()

deob.deleteExtra()
Expand Down
23 changes: 16 additions & 7 deletions play/obfuscator/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
};
}();

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down Expand Up @@ -121,7 +128,9 @@ function hi() {
}
});

_0x6cbcff(), console["log"]("Hello World!");
_0x6cbcff();

console["log"]("Hello World!");
}

hi();
2 changes: 2 additions & 0 deletions website/utils/deobfuscator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ self.addEventListener(
if (options.isRemoveUnusedVariables)
deob.removeUnusedVariables()

deob.splitMultipleDeclarations()
deob.restoreSequence()
deob.selfCallFnReplace()

if (options.deleteExtraEnable)
Expand Down

0 comments on commit b1e2b9b

Please sign in to comment.