Skip to content

Commit

Permalink
Use typeMap (#16)
Browse files Browse the repository at this point in the history
* Update dependencies

* Use typeMap
  • Loading branch information
BenBaryoPX authored Nov 12, 2024
1 parent 44501f2 commit da8d36e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
28 changes: 14 additions & 14 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obfuscation-detector",
"version": "2.0.2",
"version": "2.0.3",
"description": "Javascript obfuscation detector",
"main": "src/index.js",
"type": "module",
Expand Down Expand Up @@ -34,10 +34,10 @@
},
"homepage": "https://github.com/PerimeterX/obfuscation-detector#readme",
"devDependencies": {
"eslint": "^9.12.0",
"eslint": "^9.14.0",
"husky": "^9.1.6"
},
"dependencies": {
"flast": "^2.0.3"
"flast": "^2.1.0"
}
}
2 changes: 1 addition & 1 deletion src/detectors/caesarp.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function isNodeInScope(targetNode, targetScopeBlock) {
*/
function detectCaesarPlus(flatTree) {
// Verify the main function's name is 3 letters long and has maximum 1 reference;
const candidates = flatTree.filter(n =>
const candidates = (flatTree[0].typeMap.FunctionExpression || []).filter(n =>
n.type === 'FunctionExpression' &&
n?.id?.name?.length === 3 &&
n?.parentNode?.type === 'CallExpression' && !n.parentNode.arguments.length);
Expand Down
6 changes: 3 additions & 3 deletions src/detectors/functionToArrayReplacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const obfuscationName = 'function_to_array_replacements';
* @param {ASTNode[]} flatTree
* @return {string} The obfuscation name if detected; empty string otherwise.
*/
function detectFunctionToArrayReplacemets(flatTree) {
return flatTree.some(n =>
function detectFunctionToArrayReplacements(flatTree) {
return (flatTree[0].typeMap.VariableDeclarator || []).some(n =>
n.type === 'VariableDeclarator' &&
n?.init?.callee?.type?.indexOf('unction') > -1 &&
n?.id?.references?.length &&
Expand All @@ -18,4 +18,4 @@ function detectFunctionToArrayReplacemets(flatTree) {
r.parentKey === 'object'))) ? obfuscationName : '';
}

export {detectFunctionToArrayReplacemets};
export {detectFunctionToArrayReplacements};
4 changes: 2 additions & 2 deletions src/detectors/obfuscator-io.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const obfuscationName = 'obfuscator.io';

function setCookieIndicator(flatTree) {
const candidate = flatTree.find(n =>
const candidate = (flatTree[0].typeMap.ObjectExpression || []).find(n =>
n.type === 'ObjectExpression' &&
n.properties.length &&
n.properties.some(p =>
Expand All @@ -19,7 +19,7 @@ function setCookieIndicator(flatTree) {
}

function notBooleanTilde(flatTree) {
const candidates = flatTree.filter(n =>
const candidates = (flatTree[0].typeMap.BlockStatement || []).filter(n =>
n.type === 'BlockStatement' &&
n.body.length === 2 &&
n.body[0].type === 'IfStatement' &&
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/sharedDetectionMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function arrayHasMeaningfulContentLength(targetArray, flatTree) {
* @return {ASTNode[]} Candidates matching the target profile of an array with more than a few items, all literals.
*/
function findArrayDeclarationCandidates(flatTree) {
return flatTree.filter(n =>
return (flatTree[0].typeMap.VariableDeclarator || []).filter(n =>
n.type === 'VariableDeclarator' &&
n?.init?.type === 'ArrayExpression' &&
arrayHasMeaningfulContentLength(n.init.elements, flatTree) &&
Expand Down

0 comments on commit da8d36e

Please sign in to comment.