Skip to content

Commit

Permalink
Fix edge cases (#68)
Browse files Browse the repository at this point in the history
* Add optional chaining where script broke in some cases

* Verify arguments are in the form of an array

* Prevent resolving builtin member expression calls where the object is 'this' or the property is a constructor.

* 1.6.4
  • Loading branch information
BenBaryoPX authored Jan 17, 2023
1 parent 792cfa6 commit 09ebbb0
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 6 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.3",
"version": "1.6.4",
"description": "Deobfuscate Javascript with emphasis on reconstructing strings",
"main": "index.js",
"bin": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function replaceCallExpressionsWithUnwrappedIdentifier(arb, candidateFilter = ()
}
} else if (declBody.type === 'BlockStatement' && declBody.body.length === 1 && declBody.body[0].type === 'ReturnStatement') {
const arg = declBody.body[0].argument;
if (arg.type === 'Identifier' || (arg.type === 'CallExpression' && !arg.arguments.length)) {
if (arg.type === 'Identifier' || (arg.type === 'CallExpression' && !arg.arguments?.length)) {
arb.markNode(c, arg);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/safe/resolveProxyCalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function resolveProxyCalls(arb, candidateFilter = () => true) {
n.body?.body?.length === 1 &&
n.body.body[0].type === 'ReturnStatement' &&
n.body.body[0].argument?.type === 'CallExpression' &&
n.body.body[0].argument.arguments.length === n.params.length &&
n.body.body[0].argument.arguments?.length === n.params?.length &&
n.body.body[0].argument.callee.type === 'Identifier' &&
candidateFilter(n));

Expand Down
3 changes: 2 additions & 1 deletion src/modules/safe/simplifyCalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ function simplifyCalls(arb, candidateFilter = () => true) {
candidateFilter(n));

for (const c of candidates) {
const args = (c.callee.property?.name || c.callee.property?.value) === 'apply' ? c.arguments[1].elements : c.arguments.slice(1);
arb.markNode(c, {
type: 'CallExpression',
callee: c.callee.object,
arguments: (c.callee.property?.name || c.callee.property?.value) === 'apply' ? c.arguments[1].elements : c.arguments.slice(1),
arguments: Array.isArray(args) ? args : (args ? [args] : []),
});
}
return arb;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/unsafe/resolveBuiltinCalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ function resolveBuiltinCalls(arb, candidateFilter = () => true) {
try {
const callee = c.callee;
if (callee?.declNode || callee?.object?.declNode) continue;
if ((callee?.object?.type || callee.type ) === 'ThisExpression' ||
(callee?.property?.name || callee?.property?.value) === 'constructor') continue;
const safeImplementation = safeImplementations[callee.name];
if (safeImplementation) {
const args = c.arguments.map(a => a.value);
Expand Down

0 comments on commit 09ebbb0

Please sign in to comment.