forked from PerimeterX/obfuscation-detector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaugmentedArrayFunctionReplacements.js
30 lines (26 loc) · 1.09 KB
/
augmentedArrayFunctionReplacements.js
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
const {
arrayIsProvidedAsArgumentToIIFE,
findArrayDeclarationCandidates,
functionHasMinimumRequiredReferences,
} = require(__dirname + '/sharedDetectionMethods');
const obfuscationName = 'augmented_array_function_replacements';
/**
* Augmented Array-Function Replacements obfuscation type has the following characteristics:
* - The same characteristics as an Array-Function Replacements obfuscation type.
* - An IIFE with a reference to Array A as one if its arguments.
* @param {ASTNode[]} flatTree
* @return {string} The obfuscation name if detected; empty string otherwise.
*/
function detectAugmentedArrayFunctionReplacements(flatTree) {
const candidates = findArrayDeclarationCandidates(flatTree);
for (const c of candidates) {
if (c.id.references.length > 2) continue;
const refs = c.id.references.map(n => n.parentNode);
if (!arrayIsProvidedAsArgumentToIIFE(refs, c.id.name)) continue;
for (const ref of c.id.references) {
if (functionHasMinimumRequiredReferences(ref, flatTree)) return obfuscationName;
}
}
return '';
}
module.exports = detectAugmentedArrayFunctionReplacements;