Skip to content

Commit

Permalink
kept unpacking arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-sb committed Jul 30, 2022
1 parent 9281e9a commit 97fbf22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "javascript-deobfuscator",
"version": "1.0.13",
"version": "1.0.14",
"description": "",
"main": "dist/index.js",
"scripts": {
Expand Down
23 changes: 16 additions & 7 deletions src/modifications/arrays/arrayUnpacker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import TraversalHelper from "../../helpers/traversalHelper";

export default class ArrayUnpacker extends Modification {
private readonly scopeTypes = new Set(['Block', 'FunctionBody']);
private shouldRemoveArrays: boolean;
private globalScope: Scope;
private readonly shouldRemoveArrays: boolean;
private readonly globalScope: Scope;
private readonly arrayNodes: Set<Shift.Node>;

/**
* Creates a new modification.
Expand All @@ -19,15 +20,17 @@ export default class ArrayUnpacker extends Modification {
super('Unpack Arrays', ast);
this.shouldRemoveArrays = removeArrays;
this.globalScope = new Scope(this.ast);
this.arrayNodes = new Set<Shift.Node>();
}

/**
* Executes the modification.
*/
execute(): void {
this.findArrays();
this.unpackArrays();

while (this.findArrays()) {
this.unpackArrays();
}

if (this.shouldRemoveArrays) {
this.removeArrays(this.globalScope);
}
Expand All @@ -36,21 +39,25 @@ export default class ArrayUnpacker extends Modification {
/**
* Finds all literal arrays and stores them in the according scope.
*/
private findArrays(): void {
private findArrays(): boolean {
const self = this;
let scope = this.globalScope;
let foundArrays = false;

traverse(this.ast, {
enter(node: Shift.Node, parent: Shift.Node) {
if (self.scopeTypes.has(node.type)) {
scope = new Scope(node, scope);
}
else if (self.isLiteralArrayDeclaration(node)) {
else if (self.isLiteralArrayDeclaration(node) && !self.arrayNodes.has(node)) {
const name = (node as any).binding.name;
const elements = (node as any).init.elements;

const array = new Array(node, parent, name, elements);
scope.addArray(array);

self.arrayNodes.add(node);
foundArrays = true;
}
},
leave(node: Shift.Node) {
Expand All @@ -59,6 +66,8 @@ export default class ArrayUnpacker extends Modification {
}
}
});

return foundArrays;
}

/**
Expand Down

0 comments on commit 97fbf22

Please sign in to comment.