Skip to content

Commit

Permalink
Avoid anti debugging trap (#69)
Browse files Browse the repository at this point in the history
* Prevent resolving a function's toString as it might be an anti-debugging mechanism which will spring if the code is beautified

* Improve comparison between eval results

* 1.6.5
  • Loading branch information
BenBaryoPX authored Jan 29, 2023
1 parent 09ebbb0 commit 521907f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "restringer",
"version": "1.6.4",
"version": "1.6.5",
"description": "Deobfuscate Javascript with emphasis on reconstructing strings",
"main": "index.js",
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/unsafe/evalInVm.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function evalInVm(stringToEval) {
else {
// To exclude results based on randomness or timing, eval again and compare results
const res2 = (new VM(vmOptions)).run(stringToEval);
assert.deepEqual(res, res2);
assert.deepEqual(res.toString(), res2.toString());
cache[cacheName] = createNewNode(res);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/modules/unsafe/resolveLocalCalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ function resolveLocalCalls(arb, candidateFilter = () => true) {
const src = context ? `${context}\n${nodeSrc}` : nodeSrc;
const newNode = evalInVm(src);
if (newNode !== badValue && newNode.type !== 'FunctionDeclaration' && newNode.name !== 'undefined') {
// Prevent resolving a function's toString as it might be an anti-debugging mechanism
// which will spring if the code is beautified
if (c.callee.type === 'MemberExpression' && (c.callee.property?.name || c.callee.property?.value) === 'toString' &&
(new RegExp('^function ')).test(newNode?.value)) continue;
arb.markNode(c, newNode);
modifiedRanges.push(c.range);
}
Expand Down

0 comments on commit 521907f

Please sign in to comment.