forked from HumanSecurity/obfuscation-detector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionToArrayReplacements.js
More file actions
29 lines (26 loc) · 949 Bytes
/
functionToArrayReplacements.js
File metadata and controls
29 lines (26 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const name = 'function_to_array_replacements';
/**
* Detects the Function To Array Replacements obfuscation type.
*
* Characteristics:
* - A variable A assigned to a call expression with a function for a callee.
* - All references to variable A are objects of member expressions.
*
* @param {ASTNode[]} flatTree - The flattened AST of the code.
* @returns {string} The obfuscation name if detected; otherwise, an empty string.
*/
function detectFunctionToArrayReplacements(flatTree) {
return (flatTree[0].typeMap.VariableDeclarator || []).some(n =>
n.type === 'VariableDeclarator' &&
n?.init?.callee?.type?.indexOf('unction') > -1 &&
n?.id?.references?.length &&
!n.id.references.some(r =>
!(r.parentNode.type === 'MemberExpression' &&
r.parentKey === 'object')));
}
const detector = {
name,
prioritizeOver: [],
detect: detectFunctionToArrayReplacements,
};
export {detector, detectFunctionToArrayReplacements};