Skip to content

Commit da8d36e

Browse files
authored
Use typeMap (#16)
* Update dependencies * Use typeMap
1 parent 44501f2 commit da8d36e

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

package-lock.json

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obfuscation-detector",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"description": "Javascript obfuscation detector",
55
"main": "src/index.js",
66
"type": "module",
@@ -34,10 +34,10 @@
3434
},
3535
"homepage": "https://github.com/PerimeterX/obfuscation-detector#readme",
3636
"devDependencies": {
37-
"eslint": "^9.12.0",
37+
"eslint": "^9.14.0",
3838
"husky": "^9.1.6"
3939
},
4040
"dependencies": {
41-
"flast": "^2.0.3"
41+
"flast": "^2.1.0"
4242
}
4343
}

src/detectors/caesarp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function isNodeInScope(targetNode, targetScopeBlock) {
2929
*/
3030
function detectCaesarPlus(flatTree) {
3131
// Verify the main function's name is 3 letters long and has maximum 1 reference;
32-
const candidates = flatTree.filter(n =>
32+
const candidates = (flatTree[0].typeMap.FunctionExpression || []).filter(n =>
3333
n.type === 'FunctionExpression' &&
3434
n?.id?.name?.length === 3 &&
3535
n?.parentNode?.type === 'CallExpression' && !n.parentNode.arguments.length);

src/detectors/functionToArrayReplacements.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const obfuscationName = 'function_to_array_replacements';
88
* @param {ASTNode[]} flatTree
99
* @return {string} The obfuscation name if detected; empty string otherwise.
1010
*/
11-
function detectFunctionToArrayReplacemets(flatTree) {
12-
return flatTree.some(n =>
11+
function detectFunctionToArrayReplacements(flatTree) {
12+
return (flatTree[0].typeMap.VariableDeclarator || []).some(n =>
1313
n.type === 'VariableDeclarator' &&
1414
n?.init?.callee?.type?.indexOf('unction') > -1 &&
1515
n?.id?.references?.length &&
@@ -18,4 +18,4 @@ function detectFunctionToArrayReplacemets(flatTree) {
1818
r.parentKey === 'object'))) ? obfuscationName : '';
1919
}
2020

21-
export {detectFunctionToArrayReplacemets};
21+
export {detectFunctionToArrayReplacements};

src/detectors/obfuscator-io.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const obfuscationName = 'obfuscator.io';
22

33
function setCookieIndicator(flatTree) {
4-
const candidate = flatTree.find(n =>
4+
const candidate = (flatTree[0].typeMap.ObjectExpression || []).find(n =>
55
n.type === 'ObjectExpression' &&
66
n.properties.length &&
77
n.properties.some(p =>
@@ -19,7 +19,7 @@ function setCookieIndicator(flatTree) {
1919
}
2020

2121
function notBooleanTilde(flatTree) {
22-
const candidates = flatTree.filter(n =>
22+
const candidates = (flatTree[0].typeMap.BlockStatement || []).filter(n =>
2323
n.type === 'BlockStatement' &&
2424
n.body.length === 2 &&
2525
n.body[0].type === 'IfStatement' &&

src/detectors/sharedDetectionMethods.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function arrayHasMeaningfulContentLength(targetArray, flatTree) {
1919
* @return {ASTNode[]} Candidates matching the target profile of an array with more than a few items, all literals.
2020
*/
2121
function findArrayDeclarationCandidates(flatTree) {
22-
return flatTree.filter(n =>
22+
return (flatTree[0].typeMap.VariableDeclarator || []).filter(n =>
2323
n.type === 'VariableDeclarator' &&
2424
n?.init?.type === 'ArrayExpression' &&
2525
arrayHasMeaningfulContentLength(n.init.elements, flatTree) &&

0 commit comments

Comments
 (0)