mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
String array calls transform fix (#1050)
* Fixed the wrong generation of code that has statements after `ReturnStatment` when `simplify` option is enabled * Fixed generation of reserved identifier names like `Map` or `Set` for `mangled` and `mangled-shuffled` identifier names generators
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
export const reservedIdentifierNames = [
|
||||
// reserved identifiers
|
||||
'byte', 'case', 'char', 'do', 'else', 'enum', 'eval', 'for', 'goto',
|
||||
'if', 'in', 'int', 'let', 'long', 'new', 'null', 'this', 'true', 'try',
|
||||
'var', 'void', 'with',
|
||||
|
||||
// reserved global object identifiers
|
||||
'Array', 'Attr', 'Audio', 'Blob', 'Cache', 'Date', 'Error', 'Event',
|
||||
'Feed', 'File', 'Hz', 'Image', 'Intl', 'Lock', 'Map', 'Math', 'Node',
|
||||
'Proxy', 'Range', 'Rect', 'Set', 'Table', 'Text', 'Touch'
|
||||
];
|
||||
@@ -79,7 +79,8 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public isValidIdentifierName (name: string): boolean {
|
||||
return this.notReservedName(name) && !this.preservedNamesSet.has(name);
|
||||
return !this.isReservedName(name)
|
||||
&& !this.preservedNamesSet.has(name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,12 +113,12 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam
|
||||
* @param {string} name
|
||||
* @returns {boolean}
|
||||
*/
|
||||
private notReservedName (name: string): boolean {
|
||||
private isReservedName (name: string): boolean {
|
||||
return this.options.reservedNames.length
|
||||
? !this.options.reservedNames.some((reservedName: string) =>
|
||||
? this.options.reservedNames.some((reservedName: string) =>
|
||||
new RegExp(reservedName, 'g').exec(name) !== null
|
||||
)
|
||||
: true;
|
||||
: false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,10 @@ import { IOptions } from '../../interfaces/options/IOptions';
|
||||
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
|
||||
import { ISetUtils } from '../../interfaces/utils/ISetUtils';
|
||||
|
||||
import { numbersString } from '../../constants/NumbersString';
|
||||
import { alphabetString } from '../../constants/AlphabetString';
|
||||
import { alphabetStringUppercase } from '../../constants/AlphabetStringUppercase';
|
||||
import { numbersString } from '../../constants/NumbersString';
|
||||
import { reservedIdentifierNames } from '../../constants/ReservedIdentifierNames';
|
||||
|
||||
import { AbstractIdentifierNamesGenerator } from './AbstractIdentifierNamesGenerator';
|
||||
import { NodeLexicalScopeUtils } from '../../node/NodeLexicalScopeUtils';
|
||||
@@ -40,14 +41,11 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
||||
|
||||
/**
|
||||
* Reserved JS words with length of 2-4 symbols that can be possible generated with this replacer
|
||||
* + reserved DOM names like `Set`, `Map`, `Date`, etc
|
||||
*
|
||||
* @type {Set<string>}
|
||||
*/
|
||||
private static readonly reservedNamesSet: Set<string> = new Set([
|
||||
'byte', 'case', 'char', 'do', 'else', 'enum', 'eval', 'for', 'goto',
|
||||
'if', 'in', 'int', 'let', 'long', 'new', 'null', 'this', 'true', 'try',
|
||||
'var', 'void', 'with'
|
||||
]);
|
||||
private static readonly reservedNamesSet: Set<string> = new Set(reservedIdentifierNames);
|
||||
|
||||
/**
|
||||
* @type {WeakMap<string, string>}
|
||||
|
||||
+10
-2
@@ -11,6 +11,7 @@ import {
|
||||
} from '../../types/container/node-transformers/TControlFlowStorageFactoryCreator';
|
||||
import { TNodeWithStatements } from '../../types/node/TNodeWithStatements';
|
||||
|
||||
import { IControlFlowStorage } from '../../interfaces/storages/control-flow-transformers/IControlFlowStorage';
|
||||
import { IOptions } from '../../interfaces/options/IOptions';
|
||||
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
|
||||
import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
|
||||
@@ -23,7 +24,6 @@ import { NodeTransformer } from '../../enums/node-transformers/NodeTransformer';
|
||||
|
||||
import { FunctionControlFlowTransformer } from './FunctionControlFlowTransformer';
|
||||
import { NodeGuards } from '../../node/NodeGuards';
|
||||
import { IControlFlowStorage } from '../../interfaces/storages/control-flow-transformers/IControlFlowStorage';
|
||||
|
||||
@injectable()
|
||||
export class StringArrayControlFlowTransformer extends FunctionControlFlowTransformer {
|
||||
@@ -120,12 +120,20 @@ export class StringArrayControlFlowTransformer extends FunctionControlFlowTransf
|
||||
&& this.controlFlowStorageNodes.has(node);
|
||||
|
||||
if (isControlFlowStorageNode) {
|
||||
return estraverse.VisitorOption.Break;
|
||||
return estraverse.VisitorOption.Skip;
|
||||
}
|
||||
|
||||
return super.transformFunctionBodyNode(node, parentNode, functionNode, controlFlowStorage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TNodeWithStatements} hostNode
|
||||
* @returns {TControlFlowStorage}
|
||||
*/
|
||||
protected override getControlFlowStorage (hostNode: TNodeWithStatements): IControlFlowStorage {
|
||||
return this.controlFlowStorageFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TNodeWithStatements} hostNode
|
||||
* @param {VariableDeclaration} controlFlowStorageNode
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import { IPropertyIdentifierNamesCacheStorage } from '../../../interfaces/storag
|
||||
import { IRenamePropertiesReplacer } from '../../../interfaces/node-transformers/rename-properties-transformers/replacer/IRenamePropertiesReplacer';
|
||||
|
||||
// eslint-disable-next-line import/no-internal-modules
|
||||
import ReservedDomProperties from './ReservedDomProperties.json';
|
||||
import ReservedDomProperties from '../../../constants/ReservedDomProperties.json';
|
||||
|
||||
import { NodeGuards } from '../../../node/NodeGuards';
|
||||
import { NodeFactory } from '../../../node/NodeFactory';
|
||||
|
||||
Reference in New Issue
Block a user