-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathaugmentedArrayFunctionReplacements.js
More file actions
31 lines (27 loc) · 1.33 KB
/
augmentedArrayFunctionReplacements.js
File metadata and controls
31 lines (27 loc) · 1.33 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
29
30
31
import {arrayIsProvidedAsArgumentToIIFE, findArrayDeclarationCandidates, functionHasMinimumRequiredReferences} from './sharedDetectionMethods.js';
const obfuscationName = 'augmented_array_function_replacements';
/**
* Detects the Augmented Array-Function Replacements obfuscation type.
*
* Characteristics:
* - The same characteristics as an Array-Function Replacements obfuscation type.
* - An IIFE with a reference to Array A as one of its arguments.
*
* @param {ASTNode[]} flatTree - The flattened AST of the code.
* @returns {string} The obfuscation name if detected; otherwise, an empty string.
*/
function detectAugmentedArrayFunctionReplacements(flatTree) {
const candidates = findArrayDeclarationCandidates(flatTree);
const isFound = candidates.some(c => {
if (c.id.references.length > 2) return false;
const refs = c.id.references;
const refsParents = c.id.references.map(n => n.parentNode);
const iife = arrayIsProvidedAsArgumentToIIFE(refsParents, c.id.name);
if (!iife) return false;
const iifeIdentifier = iife.arguments.find(arg => refs.includes(arg));
const arrayIdentifierInTargetFunc = refs.find(ref => ref !== iifeIdentifier);
return functionHasMinimumRequiredReferences(arrayIdentifierInTargetFunc, flatTree);
});
return isFound ? obfuscationName : '';
}
export {detectAugmentedArrayFunctionReplacements};