javascript-obfuscator
Advanced tools
Comparing version
Change Log | ||
v2.14.0 | ||
--- | ||
* Added `identifierNamesCache` option for reading and writing identifier names cache. See `README.md`. | ||
* **CLI**: Added `--identifier-names-cache-path` option for reading and writing identifier names cache. See `README.md`. | ||
v2.13.0 | ||
@@ -4,0 +9,0 @@ --- |
@@ -6,7 +6,7 @@ import { TDictionary } from './src/types/TDictionary'; | ||
import { IObfuscatedCode } from './src/interfaces/source-code/IObfuscatedCode'; | ||
import { IObfuscationResult } from './src/interfaces/source-code/IObfuscationResult'; | ||
export type ObfuscatorOptions = TInputOptions; | ||
export interface ObfuscatedCode extends IObfuscatedCode {} | ||
export interface ObfuscationResult extends IObfuscationResult {} | ||
@@ -18,3 +18,3 @@ /** | ||
*/ | ||
export function obfuscate (sourceCode: string, inputOptions?: ObfuscatorOptions): ObfuscatedCode; | ||
export function obfuscate (sourceCode: string, inputOptions?: ObfuscatorOptions): ObfuscationResult; | ||
@@ -21,0 +21,0 @@ /** |
{ | ||
"name": "javascript-obfuscator", | ||
"version": "2.13.0", | ||
"version": "2.14.0", | ||
"description": "JavaScript obfuscator", | ||
@@ -24,6 +24,6 @@ "keywords": [ | ||
"dependencies": { | ||
"@javascript-obfuscator/escodegen": "2.1.1", | ||
"@javascript-obfuscator/escodegen": "2.2.0", | ||
"@javascript-obfuscator/estraverse": "5.3.0", | ||
"@nuxtjs/opencollective": "0.3.2", | ||
"acorn": "8.2.2", | ||
"acorn": "8.3.0", | ||
"assert": "2.0.0", | ||
@@ -50,4 +50,4 @@ "chalk": "4.1.1", | ||
"@istanbuljs/nyc-config-typescript": "1.0.1", | ||
"@types/chai": "4.2.17", | ||
"@types/chance": "1.1.1", | ||
"@types/chai": "4.2.18", | ||
"@types/chance": "1.1.2", | ||
"@types/escodegen": "0.0.6", | ||
@@ -62,21 +62,21 @@ "@types/eslint-scope": "3.7.0", | ||
"@types/multimatch": "4.0.0", | ||
"@types/node": "15.0.1", | ||
"@types/node": "15.6.1", | ||
"@types/rimraf": "3.0.0", | ||
"@types/sinon": "10.0.0", | ||
"@types/sinon": "10.0.1", | ||
"@types/string-template": "1.0.2", | ||
"@types/webpack-env": "1.16.0", | ||
"@typescript-eslint/eslint-plugin": "4.22.0", | ||
"@typescript-eslint/parser": "4.22.0", | ||
"@typescript-eslint/eslint-plugin": "4.25.0", | ||
"@typescript-eslint/parser": "4.25.0", | ||
"chai": "4.3.4", | ||
"chai-exclude": "2.0.3", | ||
"cross-env": "7.0.3", | ||
"eslint": "7.25.0", | ||
"eslint-plugin-import": "2.22.1", | ||
"eslint-plugin-jsdoc": "33.0.0", | ||
"eslint": "7.27.0", | ||
"eslint-plugin-import": "2.23.4", | ||
"eslint-plugin-jsdoc": "35.1.0", | ||
"eslint-plugin-no-null": "1.0.2", | ||
"eslint-plugin-prefer-arrow": "1.2.3", | ||
"eslint-plugin-unicorn": "31.0.0", | ||
"eslint-plugin-unicorn": "32.0.1", | ||
"fork-ts-checker-notifier-webpack-plugin": "4.0.0", | ||
"fork-ts-checker-webpack-plugin": "6.2.5", | ||
"mocha": "8.3.2", | ||
"fork-ts-checker-webpack-plugin": "6.2.10", | ||
"mocha": "8.4.0", | ||
"nyc": "15.1.0", | ||
@@ -86,9 +86,9 @@ "pjson": "1.0.9", | ||
"rimraf": "3.0.2", | ||
"sinon": "10.0.0", | ||
"sinon": "11.1.1", | ||
"threads": "1.6.4", | ||
"ts-loader": "9.1.1", | ||
"ts-node": "9.1.1", | ||
"typescript": "beta", | ||
"webpack": "5.36.2", | ||
"webpack-cli": "4.6.0", | ||
"ts-loader": "9.2.2", | ||
"ts-node": "10.0.0", | ||
"typescript": "4.3.2", | ||
"webpack": "5.38.1", | ||
"webpack-cli": "4.7.0", | ||
"webpack-node-externals": "3.0.0" | ||
@@ -95,0 +95,0 @@ }, |
@@ -233,3 +233,4 @@ <!-- | ||
* `getObfuscatedCode()` - returns `string` with obfuscated code; | ||
* `getSourceMap()` - if [`sourceMap`](#sourcemap) option is enabled - returns `string` with source map or an empty string if [`sourceMapMode`](#sourcemapmode) option is set as `inline`. | ||
* `getSourceMap()` - if [`sourceMap`](#sourcemap) option is enabled - returns `string` with source map or an empty string if [`sourceMapMode`](#sourcemapmode) option is set as `inline`; | ||
* `getIdentifierNamesCache()` - returns object with identifier names cache if `identifierNamesCache` option is enabled, `null` overwise. | ||
@@ -365,2 +366,3 @@ Calling `toString()` for `ObfuscationResult` object will return `string` with obfuscated code. | ||
forceTransformStrings: [], | ||
identifierNamesCache: null, | ||
identifierNamesGenerator: 'hexadecimal', | ||
@@ -426,2 +428,3 @@ identifiersDictionary: [], | ||
--force-transform-strings '<list>' (comma separated) | ||
--identifier-names-cache-path <string> | ||
--identifier-names-generator <string> [dictionary, hexadecimal, mangled, mangled-shuffled] | ||
@@ -718,2 +721,80 @@ --identifiers-dictionary '<list>' (comma separated) | ||
### `identifierNamesCache` | ||
Type: `Object | null` Default: `null` | ||
The main goal for this option is the ability to use the same identifier names during obfuscation of multiple sources/files. | ||
Currently the two types of the identifiers are supported: | ||
- Global identifiers: | ||
* All global identifiers will be written to the cache; | ||
* All matched **undeclared** global identifiers will be replaced by the values from the cache. | ||
- Property identifiers, only when `renameProperties` option is enabled: | ||
* All property identifiers will be written to the cache; | ||
* All matched property identifiers will be replaced by the values from the cache. | ||
#### Node.js API | ||
If a `null` value is passed, completely disables the cache. | ||
If an empty object (`{}`) is passed, enables the writing identifier names to the cache-object (`TIdentifierNamesCache` type). This cache-object will be accessed through the `getIdentifierNamesCache` method call of `ObfuscationResult` object. | ||
The resulting cache-object can be next used as `identifierNamesGenerator` option value for using these names during obfuscation of all matched identifier names of next sources. | ||
Example: | ||
``` | ||
const source1ObfuscationResult = JavaScriptObfuscator.obfuscate( | ||
` | ||
function foo(arg) { | ||
console.log(arg) | ||
} | ||
function bar() { | ||
var bark = 2; | ||
} | ||
`, | ||
{ | ||
compact: false, | ||
identifierNamesCache: {}, | ||
renameGlobals: true | ||
} | ||
) | ||
console.log(source1ObfuscationResult.getIdentifierNamesCache()); | ||
/*{ | ||
globalIdentifiers: { | ||
foo: '_0x5de86d', | ||
bar: '_0x2a943b' | ||
} | ||
}*/ | ||
const source2ObfuscationResult = JavaScriptObfuscator.obfuscate( | ||
` | ||
// Expecting that these global functions are defined in another obfuscated file | ||
foo(1); | ||
bar(); | ||
// Expecting that this global function is defined in third-party package | ||
baz(); | ||
`, | ||
{ | ||
compact: false, | ||
identifierNamesCache: source1ObfuscationResult.getIdentifierNamesCache(), | ||
renameGlobals: true | ||
} | ||
) | ||
console.log(source2ObfuscationResult.getObfuscatedCode()); | ||
// _0x5de86d(0x1); | ||
// _0x2a943b(); | ||
// baz(); | ||
``` | ||
#### CLI | ||
CLI has a different option `--identifier-names-cache-path` that allows defining a path to the existing `.json` file that will be used to read and write identifier names cache. | ||
If a path to the empty file will be passed - identifier names cache will be written to that file. | ||
This file with existing cache can be used again as `--identifier-names-cache-path` option value for using these names during obfuscation of all matched identifier names of the next files. | ||
### `identifierNamesGenerator` | ||
@@ -841,2 +922,4 @@ Type: `string` Default: `hexadecimal` | ||
If one file is using properties from other file, use [`identifierNamesCache`](#identifiernamescache) option to keep the same property names between these files. | ||
### `reservedNames` | ||
@@ -843,0 +926,0 @@ Type: `string[]` Default: `[]` |
@@ -10,3 +10,3 @@ /* eslint-disable max-lines */ | ||
import { IInitializable } from '../interfaces/IInitializable'; | ||
import { IObfuscatedCode } from '../interfaces/source-code/IObfuscatedCode'; | ||
import { IObfuscationResult } from '../interfaces/source-code/IObfuscationResult'; | ||
@@ -31,6 +31,7 @@ import { initializable } from '../decorators/Initializable'; | ||
import { CLIUtils } from './utils/CLIUtils'; | ||
import { IdentifierNamesCacheFileUtils } from './utils/IdentifierNamesCacheFileUtils'; | ||
import { JavaScriptObfuscator } from '../JavaScriptObfuscatorFacade'; | ||
import { Logger } from '../logger/Logger'; | ||
import { ObfuscatedCodeWriter } from './utils/ObfuscatedCodeWriter'; | ||
import { SourceCodeReader } from './utils/SourceCodeReader'; | ||
import { ObfuscatedCodeFileUtils } from './utils/ObfuscatedCodeFileUtils'; | ||
import { SourceCodeFileUtils } from './utils/SourceCodeFileUtils'; | ||
import { Utils } from '../utils/Utils'; | ||
@@ -63,2 +64,8 @@ | ||
/** | ||
* @type {IdentifierNamesCacheFileUtils} | ||
*/ | ||
@initializable() | ||
private identifierNamesCacheFileUtils!: IdentifierNamesCacheFileUtils; | ||
/** | ||
* @type {TInputCLIOptions} | ||
@@ -76,12 +83,12 @@ */ | ||
/** | ||
* @type {SourceCodeReader} | ||
* @type {SourceCodeFileUtils} | ||
*/ | ||
@initializable() | ||
private sourceCodeReader!: SourceCodeReader; | ||
private sourceCodeFileUtils!: SourceCodeFileUtils; | ||
/** | ||
* @type {ObfuscatedCodeWriter} | ||
* @type {ObfuscatedCodeFileUtils} | ||
*/ | ||
@initializable() | ||
private obfuscatedCodeWriter!: ObfuscatedCodeWriter; | ||
private obfuscatedCodeFileUtils!: ObfuscatedCodeFileUtils; | ||
@@ -151,10 +158,11 @@ /** | ||
this.inputCLIOptions = JavaScriptObfuscatorCLI.buildOptions(this.commands.opts()); | ||
this.sourceCodeReader = new SourceCodeReader( | ||
this.sourceCodeFileUtils = new SourceCodeFileUtils( | ||
this.inputPath, | ||
this.inputCLIOptions | ||
); | ||
this.obfuscatedCodeWriter = new ObfuscatedCodeWriter( | ||
this.obfuscatedCodeFileUtils = new ObfuscatedCodeFileUtils( | ||
this.inputPath, | ||
this.inputCLIOptions | ||
); | ||
this.identifierNamesCacheFileUtils = new IdentifierNamesCacheFileUtils(this.inputCLIOptions.identifierNamesCachePath); | ||
} | ||
@@ -171,3 +179,3 @@ | ||
const sourceCodeData: IFileData[] = this.sourceCodeReader.readSourceCode(); | ||
const sourceCodeData: IFileData[] = this.sourceCodeFileUtils.readSourceCode(); | ||
@@ -248,2 +256,6 @@ this.processSourceCodeData(sourceCodeData); | ||
.option( | ||
'--identifier-names-cache-path <string>', | ||
'Sets path for identifier names cache' | ||
) | ||
.option( | ||
'--identifier-names-generator <string>', | ||
@@ -440,3 +452,3 @@ 'Sets identifier names generator. ' + | ||
sourceCodeData.forEach(({ filePath, content }: IFileData, index: number) => { | ||
const outputCodePath: string = this.obfuscatedCodeWriter.getOutputCodePath(filePath); | ||
const outputCodePath: string = this.obfuscatedCodeFileUtils.getOutputCodePath(filePath); | ||
@@ -477,2 +489,3 @@ try { | ||
...this.inputCLIOptions, | ||
identifierNamesCache: this.identifierNamesCacheFileUtils.readFile(), | ||
inputFileName: path.basename(inputCodePath), | ||
@@ -504,5 +517,6 @@ ...sourceCodeIndex !== null && { | ||
): void { | ||
const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(sourceCode, options).getObfuscatedCode(); | ||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(sourceCode, options); | ||
this.obfuscatedCodeWriter.writeFile(outputCodePath, obfuscatedCode); | ||
this.obfuscatedCodeFileUtils.writeFile(outputCodePath, obfuscationResult.getObfuscatedCode()); | ||
this.identifierNamesCacheFileUtils.writeFile(obfuscationResult.getIdentifierNamesCache()); | ||
} | ||
@@ -520,3 +534,3 @@ | ||
): void { | ||
const outputSourceMapPath: string = this.obfuscatedCodeWriter.getOutputSourceMapPath( | ||
const outputSourceMapPath: string = this.obfuscatedCodeFileUtils.getOutputSourceMapPath( | ||
outputCodePath, | ||
@@ -531,10 +545,11 @@ options.sourceMapFileName ?? '' | ||
const obfuscatedCode: IObfuscatedCode = JavaScriptObfuscator.obfuscate(sourceCode, options); | ||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(sourceCode, options); | ||
this.obfuscatedCodeWriter.writeFile(outputCodePath, obfuscatedCode.getObfuscatedCode()); | ||
this.obfuscatedCodeFileUtils.writeFile(outputCodePath, obfuscationResult.getObfuscatedCode()); | ||
this.identifierNamesCacheFileUtils.writeFile(obfuscationResult.getIdentifierNamesCache()); | ||
if (options.sourceMapMode === SourceMapMode.Separate && obfuscatedCode.getSourceMap()) { | ||
this.obfuscatedCodeWriter.writeFile(outputSourceMapPath, obfuscatedCode.getSourceMap()); | ||
if (options.sourceMapMode === SourceMapMode.Separate && obfuscationResult.getSourceMap()) { | ||
this.obfuscatedCodeFileUtils.writeFile(outputSourceMapPath, obfuscationResult.getSourceMap()); | ||
} | ||
} | ||
} |
@@ -31,3 +31,3 @@ import { Container, interfaces } from 'inversify'; | ||
import { ILogger } from '../interfaces/logger/ILogger'; | ||
import { IObfuscatedCode } from '../interfaces/source-code/IObfuscatedCode'; | ||
import { IObfuscationResult } from '../interfaces/source-code/IObfuscationResult'; | ||
import { ISourceCode } from '../interfaces/source-code/ISourceCode'; | ||
@@ -40,3 +40,3 @@ import { INodeTransformersRunner } from '../interfaces/node-transformers/INodeTransformersRunner'; | ||
import { NodeTransformersRunner } from '../node-transformers/NodeTransformersRunner'; | ||
import { ObfuscatedCode } from '../source-code/ObfuscatedCode'; | ||
import { ObfuscationResult } from '../source-code/ObfuscationResult'; | ||
import { SourceCode } from '../source-code/SourceCode'; | ||
@@ -186,15 +186,15 @@ | ||
this.container | ||
.bind<IObfuscatedCode>(ServiceIdentifiers.IObfuscatedCode) | ||
.to(ObfuscatedCode); | ||
.bind<IObfuscationResult>(ServiceIdentifiers.IObfuscationResult) | ||
.to(ObfuscationResult); | ||
this.container | ||
.bind<IObfuscatedCode>(ServiceIdentifiers.Factory__IObfuscatedCode) | ||
.toFactory<IObfuscatedCode>((context: interfaces.Context) => { | ||
return (obfuscatedCodeAsString: string, sourceMapAsString: string): IObfuscatedCode => { | ||
const obfuscatedCode: IObfuscatedCode = context.container | ||
.get<IObfuscatedCode>(ServiceIdentifiers.IObfuscatedCode); | ||
.bind<IObfuscationResult>(ServiceIdentifiers.Factory__IObfuscationResult) | ||
.toFactory<IObfuscationResult>((context: interfaces.Context) => { | ||
return (obfuscatedCodeAsString: string, sourceMapAsString: string): IObfuscationResult => { | ||
const obfuscationResult: IObfuscationResult = context.container | ||
.get<IObfuscationResult>(ServiceIdentifiers.IObfuscationResult); | ||
obfuscatedCode.initialize(obfuscatedCodeAsString, sourceMapAsString); | ||
obfuscationResult.initialize(obfuscatedCodeAsString, sourceMapAsString); | ||
return obfuscatedCode; | ||
return obfuscationResult; | ||
}; | ||
@@ -201,0 +201,0 @@ }); |
@@ -9,2 +9,3 @@ import { ContainerModule, interfaces } from 'inversify'; | ||
import { DeadCodeInjectionIdentifiersTransformer } from '../../../node-transformers/dead-code-injection-transformers/DeadCodeInjectionIdentifiersTransformer'; | ||
import { IdentifierReplacer } from '../../../node-transformers/rename-identifiers-transformers/replacer/IdentifierReplacer'; | ||
@@ -14,2 +15,4 @@ import { LabeledStatementTransformer } from '../../../node-transformers/rename-identifiers-transformers/LabeledStatementTransformer'; | ||
import { ScopeThroughIdentifiersTransformer } from '../../../node-transformers/rename-identifiers-transformers/ScopeThroughIdentifiersTransformer'; | ||
import { ThroughIdentifierReplacer } from '../../../node-transformers/rename-identifiers-transformers/through-replacer/ThroughIdentifierReplacer'; | ||
import { IThroughIdentifierReplacer } from '../../../interfaces/node-transformers/rename-identifiers-transformers/replacer/IThroughIdentifierReplacer'; | ||
@@ -19,2 +22,6 @@ export const renameIdentifiersTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => { | ||
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer) | ||
.to(DeadCodeInjectionIdentifiersTransformer) | ||
.whenTargetNamed(NodeTransformer.DeadCodeInjectionIdentifiersTransformer); | ||
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer) | ||
.to(LabeledStatementTransformer) | ||
@@ -35,2 +42,6 @@ .whenTargetNamed(NodeTransformer.LabeledStatementTransformer); | ||
.inSingletonScope(); | ||
bind<IThroughIdentifierReplacer>(ServiceIdentifiers.IThroughIdentifierReplacer) | ||
.to(ThroughIdentifierReplacer) | ||
.inSingletonScope(); | ||
}); |
@@ -7,4 +7,6 @@ import { ContainerModule, interfaces } from 'inversify'; | ||
import { IGlobalIdentifierNamesCacheStorage } from '../../../interfaces/storages/identifier-names-cache/IGlobalIdentifierNamesCacheStorage'; | ||
import { ILiteralNodesCacheStorage } from '../../../interfaces/storages/string-array-transformers/ILiteralNodesCacheStorage'; | ||
import { IOptions } from '../../../interfaces/options/IOptions'; | ||
import { IPropertyIdentifierNamesCacheStorage } from '../../../interfaces/storages/identifier-names-cache/IPropertyIdentifierNamesCacheStorage'; | ||
import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator'; | ||
@@ -18,3 +20,5 @@ import { IStringArrayScopeCallsWrapperLexicalScopeDataStorage } from '../../../interfaces/storages/string-array-transformers/IStringArrayScopeCallsWrapperLexicalScopeDataStorage'; | ||
import { CustomCodeHelperGroupStorage } from '../../../storages/custom-code-helpers/CustomCodeHelperGroupStorage'; | ||
import { GlobalIdentifierNamesCacheStorage } from '../../../storages/identifier-names-cache/GlobalIdentifierNamesCacheStorage'; | ||
import { LiteralNodesCacheStorage } from '../../../storages/string-array-transformers/LiteralNodesCacheStorage'; | ||
import { PropertyIdentifierNamesCacheStorage } from '../../../storages/identifier-names-cache/PropertyIdentifierNamesCacheStorage'; | ||
import { StringArrayScopeCallsWrapperLexicalScopeDataStorage } from '../../../storages/string-array-transformers/StringArrayScopeCallsWrapperLexicalScopeDataStorage'; | ||
@@ -31,2 +35,6 @@ import { StringArrayScopeCallsWrapperNamesDataStorage } from '../../../storages/string-array-transformers/StringArrayScopeCallsWrapperNamesDataStorage'; | ||
bind<IGlobalIdentifierNamesCacheStorage>(ServiceIdentifiers.IGlobalIdentifierNamesCacheStorage) | ||
.to(GlobalIdentifierNamesCacheStorage) | ||
.inSingletonScope(); | ||
bind<ILiteralNodesCacheStorage>(ServiceIdentifiers.ILiteralNodesCacheStorage) | ||
@@ -36,2 +44,6 @@ .to(LiteralNodesCacheStorage) | ||
bind<IPropertyIdentifierNamesCacheStorage>(ServiceIdentifiers.IPropertyIdentifierNamesCacheStorage) | ||
.to(PropertyIdentifierNamesCacheStorage) | ||
.inSingletonScope(); | ||
bind<IStringArrayStorage>(ServiceIdentifiers.IStringArrayStorage) | ||
@@ -38,0 +50,0 @@ .to(StringArrayStorage) |
@@ -12,3 +12,3 @@ export enum ServiceIdentifiers { | ||
Factory__INodeTransformer = 'Factory<INodeTransformer[]>', | ||
Factory__IObfuscatedCode = 'Factory<IObfuscatedCode>', | ||
Factory__IObfuscationResult = 'Factory<IObfuscationResult>', | ||
Factory__IObjectExpressionKeysTransformerCustomNode = 'Factory<IObjectExpressionKeysTransformerCustomNode>', | ||
@@ -33,2 +33,3 @@ Factory__IObjectExpressionExtractor = 'Factory<IObjectExpressionExtractor>', | ||
IEscapeSequenceEncoder = 'IEscapeSequenceEncoder', | ||
IGlobalIdentifierNamesCacheStorage = 'IGlobalIdentifierNamesCacheStorage', | ||
IIdentifierNamesGenerator = 'IIdentifierNamesGenerator', | ||
@@ -45,6 +46,7 @@ IIdentifierReplacer = 'IIdentifierReplacer', | ||
INumberNumericalExpressionAnalyzer = 'INumberNumericalExpressionAnalyzer', | ||
IObfuscatedCode = 'IObfuscatedCode', | ||
IObfuscationResult = 'IObfuscationResult', | ||
IOptions = 'IOptions', | ||
IOptionsNormalizer = 'IOptionsNormalizer', | ||
IPrevailingKindOfVariablesAnalyzer = 'IPrevailingKindOfVariablesAnalyzer', | ||
IPropertyIdentifierNamesCacheStorage = 'IPropertyIdentifierNamesCacheStorage', | ||
IObjectExpressionExtractor = 'IObjectExpressionExtractor', | ||
@@ -61,2 +63,3 @@ IRandomGenerator = 'IRandomGenerator', | ||
IStringArrayStorageAnalyzer = 'IStringArrayStorageAnalyzer', | ||
IThroughIdentifierReplacer = 'IThroughIdentifierReplacer', | ||
IVisitedLexicalScopeNodesStackStorage = 'IVisitedLexicalScopeNodesStackStorage', | ||
@@ -63,0 +66,0 @@ Newable__ICustomNode = 'Newable<ICustomNode>', |
@@ -79,3 +79,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
protected getCodeHelperTemplate (): string { | ||
protected override getCodeHelperTemplate (): string { | ||
if (this.nodeTransformationStage === NodeTransformationStage.Finalizing) { | ||
@@ -82,0 +82,0 @@ return this.customCodeHelperObfuscator.obfuscateTemplate( |
@@ -80,3 +80,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
protected getCodeHelperTemplate (): string { | ||
protected override getCodeHelperTemplate (): string { | ||
const globalVariableTemplate: string = this.options.target !== ObfuscationTarget.BrowserNoEval | ||
@@ -83,0 +83,0 @@ ? this.getGlobalVariableTemplate() |
@@ -77,3 +77,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
protected getCodeHelperTemplate (): string { | ||
protected override getCodeHelperTemplate (): string { | ||
return this.customCodeHelperFormatter.formatTemplate(DebugProtectionFunctionCallTemplate(), { | ||
@@ -80,0 +80,0 @@ debugProtectionFunctionName: this.debugProtectionFunctionName, |
@@ -73,3 +73,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
protected getCodeHelperTemplate (): string { | ||
protected override getCodeHelperTemplate (): string { | ||
const debuggerTemplate: string = this.options.target !== ObfuscationTarget.BrowserNoEval | ||
@@ -76,0 +76,0 @@ ? DebuggerTemplate() |
@@ -69,3 +69,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
protected getCodeHelperTemplate (): string { | ||
protected override getCodeHelperTemplate (): string { | ||
return this.customCodeHelperFormatter.formatTemplate(DebugProtectionFunctionIntervalTemplate(), { | ||
@@ -72,0 +72,0 @@ debugProtectionFunctionName: this.debugProtectionFunctionName |
@@ -90,3 +90,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
protected getCodeHelperTemplate (): string { | ||
protected override getCodeHelperTemplate (): string { | ||
const domainsString: string = this.options.domainLock.join(';'); | ||
@@ -93,0 +93,0 @@ const [hiddenDomainsString, diff]: string[] = this.cryptUtils.hideString( |
@@ -81,3 +81,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
protected getCodeHelperTemplate (): string { | ||
protected override getCodeHelperTemplate (): string { | ||
const globalVariableTemplate: string = this.options.target !== ObfuscationTarget.BrowserNoEval | ||
@@ -84,0 +84,0 @@ ? this.getGlobalVariableTemplate() |
@@ -13,3 +13,3 @@ import { injectable, } from 'inversify'; | ||
*/ | ||
protected getDecodeStringArrayTemplate (): string { | ||
protected override getDecodeStringArrayTemplate (): string { | ||
const atobFunctionName: string = this.randomGenerator.getRandomString(6); | ||
@@ -16,0 +16,0 @@ |
@@ -100,3 +100,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
protected getCodeHelperTemplate (): string { | ||
protected override getCodeHelperTemplate (): string { | ||
const decodeCodeHelperTemplate: string = this.getDecodeStringArrayTemplate(); | ||
@@ -103,0 +103,0 @@ |
@@ -14,3 +14,3 @@ import { injectable, } from 'inversify'; | ||
*/ | ||
protected getDecodeStringArrayTemplate (): string { | ||
protected override getDecodeStringArrayTemplate (): string { | ||
const atobFunctionName: string = this.randomGenerator.getRandomString(6); | ||
@@ -17,0 +17,0 @@ |
@@ -83,3 +83,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
protected getCodeHelperTemplate (): string { | ||
protected override getCodeHelperTemplate (): string { | ||
return this.customCodeHelperFormatter.formatTemplate(StringArrayTemplate(), { | ||
@@ -86,0 +86,0 @@ stringArrayName: this.stringArrayName, |
@@ -90,3 +90,3 @@ import type { Expression } from 'estree'; | ||
*/ | ||
protected getCodeHelperTemplate (): string { | ||
protected override getCodeHelperTemplate (): string { | ||
const comparisonExpressionCode: string = NodeUtils.convertStructureToCode([this.comparisonExpressionNode]); | ||
@@ -93,0 +93,0 @@ |
@@ -67,3 +67,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
public getNode (): TStatement[] { | ||
public override getNode (): TStatement[] { | ||
return this.getNodeStructure(); | ||
@@ -70,0 +70,0 @@ } |
@@ -7,2 +7,3 @@ export enum NodeTransformer { | ||
CustomCodeHelpersTransformer = 'CustomCodeHelpersTransformer', | ||
DeadCodeInjectionIdentifiersTransformer = 'DeadCodeInjectionIdentifiersTransformer', | ||
DeadCodeInjectionTransformer = 'DeadCodeInjectionTransformer', | ||
@@ -9,0 +10,0 @@ DirectivePlacementTransformer = 'DirectivePlacementTransformer', |
@@ -168,3 +168,3 @@ import { inject, injectable } from 'inversify'; | ||
*/ | ||
public isValidIdentifierName (mangledName: string): boolean { | ||
public override isValidIdentifierName (mangledName: string): boolean { | ||
return super.isValidIdentifierName(mangledName) | ||
@@ -171,0 +171,0 @@ && !MangledIdentifierNamesGenerator.reservedNamesSet.has(mangledName); |
@@ -61,3 +61,3 @@ import { inject, injectable, postConstruct } from 'inversify'; | ||
*/ | ||
protected getNameSequence (): string[] { | ||
protected override getNameSequence (): string[] { | ||
return MangledShuffledIdentifierNamesGenerator.shuffledNameSequence; | ||
@@ -70,5 +70,5 @@ } | ||
*/ | ||
protected generateNewMangledName (previousMangledName: string): string { | ||
protected override generateNewMangledName (previousMangledName: string): string { | ||
return super.generateNewMangledName(previousMangledName); | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { IObfuscatedCode } from './source-code/IObfuscatedCode'; | ||
import { IObfuscationResult } from './source-code/IObfuscationResult'; | ||
@@ -6,5 +6,5 @@ export interface IJavaScriptObfuscator { | ||
* @param sourceCode | ||
* @returns IObfuscatedCode | ||
* @returns IObfuscationResult | ||
*/ | ||
obfuscate (sourceCode: string): IObfuscatedCode; | ||
obfuscate (sourceCode: string): IObfuscationResult; | ||
} |
@@ -6,4 +6,5 @@ import * as eslintScope from 'eslint-scope'; | ||
export interface IScopeThroughIdentifiersTraverserCallbackData { | ||
isGlobalDeclaration: boolean; | ||
reference: eslintScope.Reference; | ||
variableLexicalScopeNode: TNodeWithLexicalScope; | ||
} |
@@ -6,4 +6,5 @@ import { IOptions } from './IOptions'; | ||
readonly exclude: string[]; | ||
readonly identifierNamesCachePath: string; | ||
readonly output: string; | ||
readonly version: string; | ||
} |
@@ -0,1 +1,2 @@ | ||
import { TIdentifierNamesCache } from '../../types/TIdentifierNamesCache'; | ||
import { TOptionsPreset } from '../../types/options/TOptionsPreset'; | ||
@@ -23,2 +24,3 @@ import { TStringArrayIndexesType } from '../../types/options/TStringArrayIndexesType'; | ||
readonly forceTransformStrings: string[]; | ||
readonly identifierNamesCache: TIdentifierNamesCache; | ||
readonly identifierNamesGenerator: TTypeFromEnum<typeof IdentifierNamesGenerator>; | ||
@@ -25,0 +27,0 @@ readonly identifiersDictionary: string[]; |
@@ -0,1 +1,3 @@ | ||
import { TDictionary } from '../../types/TDictionary'; | ||
import { IInitializable } from '../IInitializable'; | ||
@@ -33,2 +35,7 @@ | ||
/** | ||
* @returns {TDictionary<V>} | ||
*/ | ||
getStorageAsDictionary (): TDictionary<V>; | ||
/** | ||
* @returns string | ||
@@ -35,0 +42,0 @@ */ |
@@ -8,3 +8,3 @@ import { inject, injectable, } from 'inversify'; | ||
import { TObfuscatedCodeFactory } from './types/container/source-code/TObfuscatedCodeFactory'; | ||
import { TObfuscationResultFactory } from './types/container/source-code/TObfuscationResultFactory'; | ||
@@ -15,3 +15,3 @@ import { ICodeTransformersRunner } from './interfaces/code-transformers/ICodeTransformersRunner'; | ||
import { ILogger } from './interfaces/logger/ILogger'; | ||
import { IObfuscatedCode } from './interfaces/source-code/IObfuscatedCode'; | ||
import { IObfuscationResult } from './interfaces/source-code/IObfuscationResult'; | ||
import { IOptions } from './interfaces/options/IOptions'; | ||
@@ -92,2 +92,3 @@ import { IRandomGenerator } from './interfaces/utils/IRandomGenerator'; | ||
NodeTransformer.ScopeIdentifiersTransformer, | ||
NodeTransformer.ScopeThroughIdentifiersTransformer, | ||
NodeTransformer.SplitStringTransformer, | ||
@@ -114,5 +115,5 @@ NodeTransformer.StringArrayRotateFunctionTransformer, | ||
/** | ||
* @type {TObfuscatedCodeFactory} | ||
* @type {TObfuscationResultFactory} | ||
*/ | ||
private readonly obfuscatedCodeFactory: TObfuscatedCodeFactory; | ||
private readonly obfuscationResultFactory: TObfuscationResultFactory; | ||
@@ -138,3 +139,3 @@ /** | ||
* @param {IRandomGenerator} randomGenerator | ||
* @param {TObfuscatedCodeFactory} obfuscatedCodeFactory | ||
* @param {TObfuscationResultFactory} obfuscatedCodeFactory | ||
* @param {ILogger} logger | ||
@@ -147,3 +148,3 @@ * @param {IOptions} options | ||
@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, | ||
@inject(ServiceIdentifiers.Factory__IObfuscatedCode) obfuscatedCodeFactory: TObfuscatedCodeFactory, | ||
@inject(ServiceIdentifiers.Factory__IObfuscationResult) obfuscatedCodeFactory: TObfuscationResultFactory, | ||
@inject(ServiceIdentifiers.ILogger) logger: ILogger, | ||
@@ -155,3 +156,3 @@ @inject(ServiceIdentifiers.IOptions) options: IOptions | ||
this.randomGenerator = randomGenerator; | ||
this.obfuscatedCodeFactory = obfuscatedCodeFactory; | ||
this.obfuscationResultFactory = obfuscatedCodeFactory; | ||
this.logger = logger; | ||
@@ -163,5 +164,5 @@ this.options = options; | ||
* @param {string} sourceCode | ||
* @returns {IObfuscatedCode} | ||
* @returns {IObfuscationResult} | ||
*/ | ||
public obfuscate (sourceCode: string): IObfuscatedCode { | ||
public obfuscate (sourceCode: string): IObfuscationResult { | ||
if (typeof sourceCode !== 'string') { | ||
@@ -194,3 +195,3 @@ sourceCode = ''; | ||
return this.getObfuscatedCode(generatorOutput); | ||
return this.getObfuscationResult(generatorOutput); | ||
} | ||
@@ -280,6 +281,6 @@ | ||
* @param {IGeneratorOutput} generatorOutput | ||
* @returns {IObfuscatedCode} | ||
* @returns {IObfuscationResult} | ||
*/ | ||
private getObfuscatedCode (generatorOutput: IGeneratorOutput): IObfuscatedCode { | ||
return this.obfuscatedCodeFactory(generatorOutput.code, generatorOutput.map); | ||
private getObfuscationResult (generatorOutput: IGeneratorOutput): IObfuscationResult { | ||
return this.obfuscationResultFactory(generatorOutput.code, generatorOutput.map); | ||
} | ||
@@ -286,0 +287,0 @@ |
@@ -12,3 +12,3 @@ import 'reflect-metadata'; | ||
import { IJavaScriptObfuscator } from './interfaces/IJavaScriptObfsucator'; | ||
import { IObfuscatedCode } from './interfaces/source-code/IObfuscatedCode'; | ||
import { IObfuscationResult } from './interfaces/source-code/IObfuscationResult'; | ||
@@ -28,5 +28,5 @@ import { InversifyContainerFacade } from './container/InversifyContainerFacade'; | ||
* @param {TInputOptions} inputOptions | ||
* @returns {IObfuscatedCode} | ||
* @returns {IObfuscationResult} | ||
*/ | ||
public static obfuscate (sourceCode: string, inputOptions: TInputOptions = {}): IObfuscatedCode { | ||
public static obfuscate (sourceCode: string, inputOptions: TInputOptions = {}): IObfuscationResult { | ||
const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade(); | ||
@@ -38,7 +38,7 @@ | ||
.get<IJavaScriptObfuscator>(ServiceIdentifiers.IJavaScriptObfuscator); | ||
const obfuscatedCode: IObfuscatedCode = javaScriptObfuscator.obfuscate(sourceCode); | ||
const obfuscationResult: IObfuscationResult = javaScriptObfuscator.obfuscate(sourceCode); | ||
inversifyContainerFacade.unload(); | ||
return obfuscatedCode; | ||
return obfuscationResult; | ||
} | ||
@@ -45,0 +45,0 @@ |
@@ -25,3 +25,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
public readonly runAfter: NodeTransformer[] = [ | ||
public override readonly runAfter: NodeTransformer[] = [ | ||
NodeTransformer.NumberToNumericalExpressionTransformer | ||
@@ -28,0 +28,0 @@ ]; |
@@ -34,3 +34,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
public runAfter: NodeTransformer[] = [ | ||
public override runAfter: NodeTransformer[] = [ | ||
NodeTransformer.ObjectExpressionKeysTransformer, | ||
@@ -37,0 +37,0 @@ NodeTransformer.TemplateLiteralTransformer |
@@ -50,5 +50,5 @@ import { inject, injectable, } from 'inversify'; | ||
private static readonly transformersToRenameBlockScopeIdentifiers: NodeTransformer[] = [ | ||
NodeTransformer.DeadCodeInjectionIdentifiersTransformer, | ||
NodeTransformer.LabeledStatementTransformer, | ||
NodeTransformer.ScopeIdentifiersTransformer, | ||
NodeTransformer.ScopeThroughIdentifiersTransformer | ||
NodeTransformer.ScopeIdentifiersTransformer | ||
]; | ||
@@ -55,0 +55,0 @@ |
@@ -31,3 +31,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
public readonly runAfter: NodeTransformer[] = [ | ||
public override readonly runAfter: NodeTransformer[] = [ | ||
NodeTransformer.CustomCodeHelpersTransformer | ||
@@ -34,0 +34,0 @@ ]; |
@@ -25,3 +25,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
public readonly runAfter: NodeTransformer[] = [ | ||
public override readonly runAfter: NodeTransformer[] = [ | ||
NodeTransformer.CustomCodeHelpersTransformer | ||
@@ -28,0 +28,0 @@ ]; |
@@ -29,5 +29,5 @@ import { inject, injectable, } from 'inversify'; | ||
/** | ||
* @type {NodeTransformer.ParentificationTransformer[]} | ||
* @type {NodeTransformer[]} | ||
*/ | ||
public readonly runAfter: NodeTransformer[] = [ | ||
public override readonly runAfter: NodeTransformer[] = [ | ||
NodeTransformer.ParentificationTransformer, | ||
@@ -34,0 +34,0 @@ NodeTransformer.VariablePreserveTransformer |
@@ -22,5 +22,5 @@ import { inject, injectable, } from 'inversify'; | ||
/** | ||
* @type {NodeTransformer.NodeTransformer[]} | ||
* @type {NodeTransformer[]} | ||
*/ | ||
public readonly runAfter: NodeTransformer[] = [ | ||
public override readonly runAfter: NodeTransformer[] = [ | ||
NodeTransformer.EscapeSequenceTransformer, | ||
@@ -27,0 +27,0 @@ NodeTransformer.ParentificationTransformer, |
@@ -23,5 +23,5 @@ import { inject, injectable, } from 'inversify'; | ||
/** | ||
* @type {NodeTransformer.ParentificationTransformer[]} | ||
* @type {NodeTransformer[]} | ||
*/ | ||
public readonly runAfter: NodeTransformer[] = [ | ||
public override readonly runAfter: NodeTransformer[] = [ | ||
NodeTransformer.ParentificationTransformer, | ||
@@ -28,0 +28,0 @@ NodeTransformer.VariablePreserveTransformer |
@@ -39,5 +39,5 @@ import { inject, injectable, } from 'inversify'; | ||
/** | ||
* @type {NodeTransformer.ParentificationTransformer[]} | ||
* @type {NodeTransformer[]} | ||
*/ | ||
public readonly runAfter: NodeTransformer[] = [ | ||
public override readonly runAfter: NodeTransformer[] = [ | ||
NodeTransformer.ParentificationTransformer, | ||
@@ -44,0 +44,0 @@ NodeTransformer.VariablePreserveTransformer |
@@ -29,3 +29,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
public readonly runAfter: NodeTransformer[] = [ | ||
public override readonly runAfter: NodeTransformer[] = [ | ||
NodeTransformer.ParentificationTransformer | ||
@@ -32,0 +32,0 @@ ]; |
@@ -9,2 +9,3 @@ import { inject, injectable, } from 'inversify'; | ||
import { IGlobalIdentifierNamesCacheStorage } from '../../../interfaces/storages/identifier-names-cache/IGlobalIdentifierNamesCacheStorage'; | ||
import { IIdentifierNamesGenerator } from '../../../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator'; | ||
@@ -19,2 +20,7 @@ import { IIdentifierReplacer } from '../../../interfaces/node-transformers/rename-identifiers-transformers/replacer/IIdentifierReplacer'; | ||
/** | ||
* @type {IGlobalIdentifierNamesCacheStorage} | ||
*/ | ||
private readonly identifierNamesCacheStorage: IGlobalIdentifierNamesCacheStorage; | ||
/** | ||
* @type {IIdentifierNamesGenerator} | ||
@@ -36,2 +42,3 @@ */ | ||
* @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory | ||
* @param {IGlobalIdentifierNamesCacheStorage} identifierNamesCacheStorage | ||
* @param {IOptions} options | ||
@@ -42,5 +49,8 @@ */ | ||
identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, | ||
@inject(ServiceIdentifiers.IGlobalIdentifierNamesCacheStorage) | ||
identifierNamesCacheStorage: IGlobalIdentifierNamesCacheStorage, | ||
@inject(ServiceIdentifiers.IOptions) options: IOptions | ||
) { | ||
this.options = options; | ||
this.identifierNamesCacheStorage = identifierNamesCacheStorage; | ||
this.identifierNamesGenerator = identifierNamesGeneratorFactory(options); | ||
@@ -50,3 +60,3 @@ } | ||
/** | ||
* Store `nodeName` of global identifiers as key in map with random name as value. | ||
* Store identifier node `name` of global identifiers as key in map with random name as value. | ||
* Reserved name will be ignored. | ||
@@ -73,6 +83,11 @@ * | ||
namesMap.set(identifierName, newIdentifierName); | ||
// Have to write all global identifier names to the identifier names cache storage | ||
if (this.options.identifierNamesCache) { | ||
this.identifierNamesCacheStorage.set(identifierName, newIdentifierName); | ||
} | ||
} | ||
/** | ||
* Store `nodeName` of local identifier as key in map with random name as value. | ||
* Store identifier node `name` of local identifier as key in map with random name as value. | ||
* Reserved name will be ignored. | ||
@@ -79,0 +94,0 @@ * |
@@ -9,3 +9,2 @@ import { inject, injectable, } from 'inversify'; | ||
import { IIdentifierReplacer } from '../../interfaces/node-transformers/rename-identifiers-transformers/replacer/IIdentifierReplacer'; | ||
import { IOptions } from '../../interfaces/options/IOptions'; | ||
@@ -15,2 +14,3 @@ import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator'; | ||
import { IScopeThroughIdentifiersTraverserCallbackData } from '../../interfaces/node/IScopeThroughIdentifiersTraverserCallbackData'; | ||
import { IThroughIdentifierReplacer } from '../../interfaces/node-transformers/rename-identifiers-transformers/replacer/IThroughIdentifierReplacer'; | ||
import { IVisitor } from '../../interfaces/node-transformers/IVisitor'; | ||
@@ -24,3 +24,3 @@ | ||
/** | ||
* Renames all through identifiers. Now used directly from Dead Code Injection transformer | ||
* Renames all through identifiers | ||
*/ | ||
@@ -30,26 +30,26 @@ @injectable() | ||
/** | ||
* @type {IIdentifierReplacer} | ||
* @type {IScopeIdentifiersTraverser} | ||
*/ | ||
private readonly identifierReplacer: IIdentifierReplacer; | ||
protected readonly scopeIdentifiersTraverser: IScopeIdentifiersTraverser; | ||
/** | ||
* @type {IScopeIdentifiersTraverser} | ||
* @type {IThroughIdentifierReplacer} | ||
*/ | ||
private readonly scopeIdentifiersTraverser: IScopeIdentifiersTraverser; | ||
protected readonly throughIdentifierReplacer: IThroughIdentifierReplacer; | ||
/** | ||
* @param {IIdentifierReplacer} identifierReplacer | ||
* @param {IThroughIdentifierReplacer} throughIdentifierReplacer | ||
* @param {IScopeIdentifiersTraverser} scopeIdentifiersTraverser | ||
* @param {IRandomGenerator} randomGenerator | ||
* @param {IOptions} options | ||
* @param {IScopeIdentifiersTraverser} scopeIdentifiersTraverser | ||
*/ | ||
public constructor ( | ||
@inject(ServiceIdentifiers.IIdentifierReplacer) identifierReplacer: IIdentifierReplacer, | ||
@inject(ServiceIdentifiers.IThroughIdentifierReplacer) throughIdentifierReplacer: IThroughIdentifierReplacer, | ||
@inject(ServiceIdentifiers.IScopeIdentifiersTraverser) scopeIdentifiersTraverser: IScopeIdentifiersTraverser, | ||
@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, | ||
@inject(ServiceIdentifiers.IOptions) options: IOptions, | ||
@inject(ServiceIdentifiers.IScopeIdentifiersTraverser) scopeIdentifiersTraverser: IScopeIdentifiersTraverser | ||
@inject(ServiceIdentifiers.IOptions) options: IOptions | ||
) { | ||
super(randomGenerator, options); | ||
this.identifierReplacer = identifierReplacer; | ||
this.throughIdentifierReplacer = throughIdentifierReplacer; | ||
this.scopeIdentifiersTraverser = scopeIdentifiersTraverser; | ||
@@ -93,3 +93,6 @@ } | ||
this.transformScopeThroughIdentifiers(reference, variableLexicalScopeNode); | ||
this.transformScopeThroughIdentifiers( | ||
reference, | ||
variableLexicalScopeNode | ||
); | ||
} | ||
@@ -105,5 +108,5 @@ ); | ||
*/ | ||
private transformScopeThroughIdentifiers ( | ||
protected transformScopeThroughIdentifiers ( | ||
reference: eslintScope.Reference, | ||
lexicalScopeNode: TNodeWithLexicalScope, | ||
lexicalScopeNode: TNodeWithLexicalScope | ||
): void { | ||
@@ -114,31 +117,11 @@ if (reference.resolved) { | ||
const identifier: ESTree.Identifier = reference.identifier; | ||
this.storeIdentifierName(identifier, lexicalScopeNode); | ||
this.replaceIdentifierName(identifier, lexicalScopeNode, reference); | ||
this.replaceIdentifierName(reference); | ||
} | ||
/** | ||
* @param {Identifier} identifierNode | ||
* @param {TNodeWithLexicalScope} lexicalScopeNode | ||
*/ | ||
private storeIdentifierName ( | ||
identifierNode: ESTree.Identifier, | ||
lexicalScopeNode: TNodeWithLexicalScope | ||
): void { | ||
this.identifierReplacer.storeLocalName(identifierNode, lexicalScopeNode); | ||
} | ||
/** | ||
* @param {Identifier} identifierNode | ||
* @param {TNodeWithLexicalScope} lexicalScopeNode | ||
* @param {Variable} reference | ||
*/ | ||
private replaceIdentifierName ( | ||
identifierNode: ESTree.Identifier, | ||
lexicalScopeNode: TNodeWithLexicalScope, | ||
reference: eslintScope.Reference | ||
): void { | ||
const newIdentifier: ESTree.Identifier = this.identifierReplacer | ||
.replace(identifierNode, lexicalScopeNode); | ||
protected replaceIdentifierName (reference: eslintScope.Reference): void { | ||
const identifier: ESTree.Identifier = reference.identifier; | ||
const newIdentifier: ESTree.Identifier = this.throughIdentifierReplacer.replace(identifier); | ||
@@ -145,0 +128,0 @@ // rename of identifier |
@@ -10,4 +10,5 @@ /* eslint-disable no-console */ | ||
import { IIdentifierNamesGenerator } from '../../../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator'; | ||
import { IOptions } from '../../../interfaces/options/IOptions'; | ||
import { IPropertyIdentifierNamesCacheStorage } from '../../../interfaces/storages/identifier-names-cache/IPropertyIdentifierNamesCacheStorage'; | ||
import { IRenamePropertiesReplacer } from '../../../interfaces/node-transformers/rename-properties-transformers/replacer/IRenamePropertiesReplacer'; | ||
import { IOptions } from '../../../interfaces/options/IOptions'; | ||
@@ -43,2 +44,7 @@ // eslint-disable-next-line import/no-internal-modules | ||
/** | ||
* @type {IPropertyIdentifierNamesCacheStorage} | ||
*/ | ||
private readonly propertyIdentifierNamesCacheStorage: IPropertyIdentifierNamesCacheStorage; | ||
/** | ||
* @type {Map<string, string>} | ||
@@ -56,2 +62,3 @@ * @private | ||
* @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory | ||
* @param {IPropertyIdentifierNamesCacheStorage} propertyIdentifierNamesCacheStorage | ||
* @param {IOptions} options | ||
@@ -62,5 +69,8 @@ */ | ||
identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, | ||
@inject(ServiceIdentifiers.IPropertyIdentifierNamesCacheStorage) | ||
propertyIdentifierNamesCacheStorage: IPropertyIdentifierNamesCacheStorage, | ||
@inject(ServiceIdentifiers.IOptions) options: IOptions | ||
) { | ||
this.identifierNamesGenerator = identifierNamesGeneratorFactory(options); | ||
this.propertyIdentifierNamesCacheStorage = propertyIdentifierNamesCacheStorage; | ||
this.options = options; | ||
@@ -106,4 +116,10 @@ } | ||
let renamedPropertyName: string | null = this.propertyNamesMap.get(propertyName) ?? null; | ||
let renamedPropertyName: string | null = this.options.identifierNamesCache | ||
? this.propertyIdentifierNamesCacheStorage.get(propertyName) ?? null | ||
: null; | ||
renamedPropertyName = renamedPropertyName | ||
?? this.propertyNamesMap.get(propertyName) | ||
?? null; | ||
if (renamedPropertyName !== null) { | ||
@@ -116,2 +132,6 @@ return renamedPropertyName; | ||
if (this.options.identifierNamesCache) { | ||
this.propertyIdentifierNamesCacheStorage.set(propertyName, renamedPropertyName); | ||
} | ||
return renamedPropertyName; | ||
@@ -118,0 +138,0 @@ } |
@@ -25,3 +25,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
public readonly runAfter: NodeTransformer[] = [ | ||
public override readonly runAfter: NodeTransformer[] = [ | ||
NodeTransformer.ExpressionStatementsMergeTransformer, | ||
@@ -193,3 +193,3 @@ NodeTransformer.VariableDeclarationsMergeTransformer | ||
*/ | ||
public abstract transformNode ( | ||
public abstract override transformNode ( | ||
statementNode: ESTree.Statement, | ||
@@ -196,0 +196,0 @@ parentNode: ESTree.Node |
@@ -27,3 +27,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
public readonly runAfter: NodeTransformer[] = [ | ||
public override readonly runAfter: NodeTransformer[] = [ | ||
NodeTransformer.VariableDeclarationsMergeTransformer | ||
@@ -30,0 +30,0 @@ ]; |
@@ -265,3 +265,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
protected getPartialStatement (statementSimplifyData: IStatementSimplifyData): ESTree.Statement { | ||
protected override getPartialStatement (statementSimplifyData: IStatementSimplifyData): ESTree.Statement { | ||
const partialStatement: ESTree.Statement = super.getPartialStatement(statementSimplifyData); | ||
@@ -268,0 +268,0 @@ |
@@ -41,3 +41,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
public readonly runAfter: NodeTransformer[] = [ | ||
public override readonly runAfter: NodeTransformer[] = [ | ||
NodeTransformer.StringArrayRotateFunctionTransformer | ||
@@ -44,0 +44,0 @@ ]; |
@@ -56,3 +56,3 @@ import { inject, injectable, } from 'inversify'; | ||
*/ | ||
public readonly runAfter: NodeTransformer[] = [ | ||
public override readonly runAfter: NodeTransformer[] = [ | ||
NodeTransformer.StringArrayRotateFunctionTransformer | ||
@@ -59,0 +59,0 @@ ]; |
@@ -145,2 +145,3 @@ import { inject, injectable, } from 'inversify'; | ||
: null; | ||
const isGlobalDeclaration: boolean = ScopeIdentifiersTraverser.globalScopeNames.includes(variableScope.type); | ||
@@ -153,2 +154,3 @@ if (!variableLexicalScopeNode) { | ||
callback({ | ||
isGlobalDeclaration, | ||
reference, | ||
@@ -155,0 +157,0 @@ variableLexicalScopeNode |
@@ -21,2 +21,3 @@ import { inject, injectable } from 'inversify'; | ||
import { TIdentifierNamesCache } from '../types/TIdentifierNamesCache'; | ||
import { TInputOptions } from '../types/options/TInputOptions'; | ||
@@ -49,2 +50,3 @@ import { TOptionsPreset } from '../types/options/TOptionsPreset'; | ||
import { IsAllowedForObfuscationTargets } from './validators/IsAllowedForObfuscationTargets'; | ||
import { IsIdentifierNamesCache } from './validators/IsIdentifierNamesCache'; | ||
@@ -148,2 +150,8 @@ @injectable() | ||
/** | ||
* @type {TIdentifierNamesCache} | ||
*/ | ||
@IsIdentifierNamesCache() | ||
public readonly identifierNamesCache!: TIdentifierNamesCache; | ||
/** | ||
* @type {IdentifierNamesGenerator} | ||
@@ -150,0 +158,0 @@ */ |
@@ -12,2 +12,3 @@ import { injectable } from 'inversify'; | ||
import { DomainLockRule } from './normalizer-rules/DomainLockRule'; | ||
import { IdentifierNamesCacheRule } from './normalizer-rules/IdentifierNamesCacheRule'; | ||
import { InputFileNameRule } from './normalizer-rules/InputFileNameRule'; | ||
@@ -33,2 +34,3 @@ import { SeedRule } from './normalizer-rules/SeedRule'; | ||
DomainLockRule, | ||
IdentifierNamesCacheRule, | ||
InputFileNameRule, | ||
@@ -35,0 +37,0 @@ SeedRule, |
@@ -25,2 +25,3 @@ import { TInputOptions } from '../../types/options/TInputOptions'; | ||
forceTransformStrings: [], | ||
identifierNamesCache: null, | ||
identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator, | ||
@@ -27,0 +28,0 @@ identifiersPrefix: '', |
@@ -48,3 +48,3 @@ import { inject, injectable, postConstruct } from 'inversify'; | ||
@postConstruct() | ||
public initialize (): void { | ||
public override initialize (): void { | ||
super.initialize(); | ||
@@ -51,0 +51,0 @@ |
@@ -9,2 +9,3 @@ import { inject, injectable, postConstruct } from 'inversify'; | ||
import { initializable } from '../decorators/Initializable'; | ||
import { TDictionary } from '../types/TDictionary'; | ||
@@ -104,2 +105,9 @@ @injectable() | ||
/** | ||
* @returns {TDictionary<V>} | ||
*/ | ||
public getStorageAsDictionary (): TDictionary<V> { | ||
return Object.fromEntries(this.storage); | ||
} | ||
/** | ||
* @returns {string} | ||
@@ -106,0 +114,0 @@ */ |
@@ -133,3 +133,3 @@ import { inject, injectable, postConstruct } from 'inversify'; | ||
@postConstruct() | ||
public initialize (): void { | ||
public override initialize (): void { | ||
super.initialize(); | ||
@@ -154,3 +154,3 @@ | ||
*/ | ||
public get (value: string): IStringArrayStorageItemData { | ||
public override get (value: string): IStringArrayStorageItemData { | ||
return this.getOrSetIfDoesNotExist(value); | ||
@@ -183,3 +183,3 @@ } | ||
*/ | ||
public getStorageId (): string { | ||
public override getStorageId (): string { | ||
if (!this.stringArrayStorageName) { | ||
@@ -186,0 +186,0 @@ this.stringArrayStorageName = this.identifierNamesGenerator |
@@ -1,3 +0,3 @@ | ||
import { IObfuscatedCode } from '../interfaces/source-code/IObfuscatedCode'; | ||
import { IObfuscationResult } from '../interfaces/source-code/IObfuscationResult'; | ||
export type TObfuscationResultsObject <TSourceCodesObject> = {[key in keyof TSourceCodesObject]: IObfuscatedCode}; | ||
export type TObfuscationResultsObject <TSourceCodesObject> = {[key in keyof TSourceCodesObject]: IObfuscationResult}; |
@@ -16,3 +16,3 @@ import { inject, injectable } from 'inversify'; | ||
*/ | ||
protected readonly base64Alphabet: string = base64alphabetSwapped; | ||
protected override readonly base64Alphabet: string = base64alphabetSwapped; | ||
@@ -34,3 +34,3 @@ /** | ||
*/ | ||
public btoa (string: string): string { | ||
public override btoa (string: string): string { | ||
const output = super.btoa(string); | ||
@@ -37,0 +37,0 @@ |
@@ -9,10 +9,10 @@ { | ||
"lib": [ | ||
"es2017", | ||
"es2019", | ||
"dom" | ||
], | ||
"target": "es2017", | ||
"target": "es2018", | ||
"module": "commonjs", | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"noImplicitOverride": false, | ||
"noImplicitOverride": true, | ||
"noImplicitThis": false, | ||
@@ -19,0 +19,0 @@ "noUnusedLocals": true, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
10617669
0.89%412
3%39066
1.56%1624
5.39%+ Added
+ Added
- Removed
- Removed
Updated