-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy patharrayFunctionReplacements.js
More file actions
28 lines (24 loc) · 1.13 KB
/
arrayFunctionReplacements.js
File metadata and controls
28 lines (24 loc) · 1.13 KB
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
import {findArrayDeclarationCandidates, functionHasMinimumRequiredReferences} from './sharedDetectionMethods.js';
const obfuscationName = 'array_function_replacements';
/**
* Detects the Array-Function Replacements obfuscation type.
*
* Characteristics:
* - An array (A) with many strings is defined.
* - A function (B) that returns a single value from the array A, based on provided arguments is present.
* - There are many call expressions to function B, with only literals as arguments.
* - There are no more than 2 references to array A.
*
* @param {ASTNode[]} flatTree - The flattened AST of the code.
* @returns {string} The obfuscation name if detected; otherwise, an empty string.
*/
function detectArrayFunctionReplacements(flatTree) {
const candidates = findArrayDeclarationCandidates(flatTree);
const isFound = candidates.some(c => {
// A matching array would not have more than two reference to it
if (c.id.references.length > 2) return false;
return c.id.references.some(ref => functionHasMinimumRequiredReferences(ref, flatTree));
});
return isFound ? obfuscationName : '';
}
export {detectArrayFunctionReplacements};