mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Merge pull request #776 from javascript-obfuscator/webpack-5
2.6.0: issue 777, issue 778, Webpack 5 migration.
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
Change Log
|
||||
|
||||
v2.6.0
|
||||
---
|
||||
* Migration to `webpack@5`
|
||||
* Optimized performance of `ExpressionStatementsMergeTransformer` when `simplify` option is enabled. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/777
|
||||
* Fixed broken `identifierNamesGenerator: 'mangled-shuffled'` after `2.2.0`. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/778
|
||||
|
||||
v2.5.0
|
||||
---
|
||||
* Improved hierarchy of generated directories when `--output` is a directory path
|
||||
|
||||
Vendored
+2
-78
File diff suppressed because one or more lines are too long
Vendored
+67
@@ -0,0 +1,67 @@
|
||||
/*!
|
||||
* Determine if an object is a Buffer
|
||||
*
|
||||
* @author Feross Aboukhadijeh <https://feross.org>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/*!
|
||||
* The buffer module from node.js, for the browser.
|
||||
*
|
||||
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/*!
|
||||
Copyright (C) 2016-2020 Timofey Kachalov <sanex3339@yandex.ru>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*! *****************************************************************************
|
||||
Copyright (C) Microsoft. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
Vendored
+2
-24
File diff suppressed because one or more lines are too long
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
/*!
|
||||
Copyright (C) 2016-2020 Timofey Kachalov <sanex3339@yandex.ru>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
Vendored
+2
-24
File diff suppressed because one or more lines are too long
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
/*!
|
||||
Copyright (C) 2016-2020 Timofey Kachalov <sanex3339@yandex.ru>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
+16
-15
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "javascript-obfuscator",
|
||||
"version": "2.5.0",
|
||||
"version": "2.6.0",
|
||||
"description": "JavaScript obfuscator",
|
||||
"keywords": [
|
||||
"obfuscator",
|
||||
@@ -21,9 +21,9 @@
|
||||
},
|
||||
"types": "index.d.ts",
|
||||
"dependencies": {
|
||||
"@gradecam/tsenum": "1.2.0",
|
||||
"@nuxtjs/opencollective": "0.2.2",
|
||||
"acorn": "8.0.3",
|
||||
"acorn": "8.0.4",
|
||||
"assert": "2.0.0",
|
||||
"chalk": "4.1.0",
|
||||
"chance": "1.1.7",
|
||||
"class-validator": "0.12.2",
|
||||
@@ -37,12 +37,13 @@
|
||||
"js-string-escape": "1.0.1",
|
||||
"md5": "2.3.0",
|
||||
"mkdirp": "1.0.4",
|
||||
"multimatch": "4.0.0",
|
||||
"multimatch": "5.0.0",
|
||||
"process": "0.11.10",
|
||||
"reflect-metadata": "0.1.13",
|
||||
"source-map-support": "0.5.19",
|
||||
"string-template": "1.0.0",
|
||||
"stringz": "2.1.0",
|
||||
"tslib": "2.0.2"
|
||||
"tslib": "2.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@istanbuljs/nyc-config-typescript": "1.0.1",
|
||||
@@ -57,20 +58,20 @@
|
||||
"@types/mkdirp": "1.0.1",
|
||||
"@types/mocha": "8.0.3",
|
||||
"@types/multimatch": "4.0.0",
|
||||
"@types/node": "14.11.5",
|
||||
"@types/node": "14.11.8",
|
||||
"@types/rimraf": "3.0.0",
|
||||
"@types/sinon": "9.0.8",
|
||||
"@types/string-template": "1.0.2",
|
||||
"@types/webpack-env": "1.15.3",
|
||||
"@typescript-eslint/eslint-plugin": "4.4.0",
|
||||
"@typescript-eslint/parser": "4.4.0",
|
||||
"@typescript-eslint/eslint-plugin": "4.4.1",
|
||||
"@typescript-eslint/parser": "4.4.1",
|
||||
"chai": "4.2.0",
|
||||
"chai-exclude": "2.0.2",
|
||||
"coveralls": "3.1.0",
|
||||
"cross-env": "7.0.2",
|
||||
"eslint": "7.10.0",
|
||||
"eslint": "7.11.0",
|
||||
"eslint-plugin-import": "2.22.1",
|
||||
"eslint-plugin-jsdoc": "30.6.3",
|
||||
"eslint-plugin-jsdoc": "30.6.4",
|
||||
"eslint-plugin-no-null": "1.0.2",
|
||||
"eslint-plugin-prefer-arrow": "1.2.2",
|
||||
"eslint-plugin-unicorn": "22.0.0",
|
||||
@@ -83,11 +84,11 @@
|
||||
"rimraf": "3.0.2",
|
||||
"sinon": "9.2.0",
|
||||
"threads": "1.6.3",
|
||||
"ts-loader": "8.0.4",
|
||||
"ts-loader": "8.0.5",
|
||||
"ts-node": "9.0.0",
|
||||
"typescript": "4.1.0-beta",
|
||||
"webpack": "4.44.2",
|
||||
"webpack-cli": "3.3.12",
|
||||
"webpack": "5.1.0",
|
||||
"webpack-cli": "4.0.0",
|
||||
"webpack-node-externals": "2.5.2"
|
||||
},
|
||||
"repository": {
|
||||
@@ -97,9 +98,9 @@
|
||||
"homepage": "https://obfuscator.io/",
|
||||
"scripts": {
|
||||
"start": "yarn run watch",
|
||||
"webpack:prod": "webpack --config webpack/webpack.node.config.js --config webpack/webpack.browser.config.js --mode production",
|
||||
"webpack:prod": "webpack --config ./webpack/webpack.node.config.js --config ./webpack/webpack.browser.config.js --mode production",
|
||||
"build": "yarn run webpack:prod && yarn run eslint && yarn test",
|
||||
"watch": "webpack --config webpack/webpack.node.config.js --mode development --watch",
|
||||
"watch": "webpack --config ./webpack/webpack.node.config.js --mode development --watch",
|
||||
"test:dev": "ts-node --type-check test/dev/dev.ts",
|
||||
"test:devCompilePerformance": "ts-node test/dev/dev-compile-performance.ts",
|
||||
"test:devRuntimePerformance": "ts-node test/dev/dev-runtime-performance.ts",
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { MakeEnum } from '@gradecam/tsenum';
|
||||
import { Utils } from '../utils/Utils';
|
||||
|
||||
export const ObfuscationTarget: Readonly<{
|
||||
Browser: 'browser';
|
||||
BrowserNoEval: 'browser-no-eval';
|
||||
Node: 'node';
|
||||
}> = MakeEnum({
|
||||
}> = Utils.makeEnum({
|
||||
Browser: 'browser',
|
||||
BrowserNoEval: 'browser-no-eval',
|
||||
Node: 'node'
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { MakeEnum } from '@gradecam/tsenum';
|
||||
import { Utils } from '../../../utils/Utils';
|
||||
|
||||
export const IdentifierNamesGenerator: Readonly<{
|
||||
DictionaryIdentifierNamesGenerator: 'dictionary';
|
||||
HexadecimalIdentifierNamesGenerator: 'hexadecimal';
|
||||
MangledIdentifierNamesGenerator: 'mangled';
|
||||
MangledShuffledIdentifierNamesGenerator: 'mangled-shuffled';
|
||||
}> = MakeEnum({
|
||||
}> = Utils.makeEnum({
|
||||
DictionaryIdentifierNamesGenerator: 'dictionary',
|
||||
HexadecimalIdentifierNamesGenerator: 'hexadecimal',
|
||||
MangledIdentifierNamesGenerator: 'mangled',
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { MakeEnum } from '@gradecam/tsenum';
|
||||
import { Utils } from '../../../utils/Utils';
|
||||
|
||||
export const StringArrayEncoding: Readonly<{
|
||||
None: 'none';
|
||||
Base64: 'base64';
|
||||
Rc4: 'rc4';
|
||||
}> = MakeEnum({
|
||||
}> = Utils.makeEnum({
|
||||
None: 'none',
|
||||
Base64: 'base64',
|
||||
Rc4: 'rc4'
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { MakeEnum } from '@gradecam/tsenum';
|
||||
import { Utils } from '../../../utils/Utils';
|
||||
|
||||
export const StringArrayWrappersType: Readonly<{
|
||||
Variable: 'variable';
|
||||
Function: 'function';
|
||||
}> = MakeEnum({
|
||||
}> = Utils.makeEnum({
|
||||
Variable: 'variable',
|
||||
Function: 'function',
|
||||
});
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { MakeEnum } from '@gradecam/tsenum';
|
||||
import { Utils } from '../../../utils/Utils';
|
||||
|
||||
export const OptionsPreset: Readonly<{
|
||||
Default: 'default';
|
||||
LowObfuscation: 'low-obfuscation';
|
||||
MediumObfuscation: 'medium-obfuscation';
|
||||
HighObfuscation: 'high-obfuscation';
|
||||
}> = MakeEnum({
|
||||
}> = Utils.makeEnum({
|
||||
Default: 'default',
|
||||
LowObfuscation: 'low-obfuscation',
|
||||
MediumObfuscation: 'medium-obfuscation',
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { MakeEnum } from '@gradecam/tsenum';
|
||||
import { Utils } from '../../utils/Utils';
|
||||
|
||||
export const SourceMapMode: Readonly<{
|
||||
Inline: 'inline';
|
||||
Separate: 'separate';
|
||||
}> = MakeEnum({
|
||||
}> = Utils.makeEnum({
|
||||
Inline: 'inline',
|
||||
Separate: 'separate'
|
||||
});
|
||||
|
||||
@@ -59,86 +59,6 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
||||
super(randomGenerator, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} nextName
|
||||
* @param {string} prevName
|
||||
* @returns {boolean}
|
||||
*/
|
||||
// eslint-disable-next-line complexity
|
||||
public static isIncrementedMangledName (nextName: string, prevName: string): boolean {
|
||||
if (nextName === prevName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const nextNameLength: number = nextName.length;
|
||||
const prevNameLength: number = prevName.length;
|
||||
|
||||
if (nextNameLength !== prevNameLength) {
|
||||
return nextNameLength > prevNameLength;
|
||||
}
|
||||
|
||||
let isIncrementedPrevCharacter: boolean = false;
|
||||
|
||||
for (let i: number = 0; i < nextNameLength; i++) {
|
||||
const nextNameCharacter: string = nextName[i];
|
||||
const prevNameCharacter: string = prevName[i];
|
||||
|
||||
if (nextNameCharacter === prevNameCharacter) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const isDigitNextNameCharacter: boolean = MangledIdentifierNamesGenerator.isDigitCharacter(nextNameCharacter);
|
||||
const isDigitPrevNameCharacter: boolean = MangledIdentifierNamesGenerator.isDigitCharacter(prevNameCharacter);
|
||||
|
||||
if (
|
||||
isIncrementedPrevCharacter
|
||||
&& isDigitNextNameCharacter
|
||||
&& !isDigitPrevNameCharacter
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const isUpperCaseNextNameCharacter: boolean = MangledIdentifierNamesGenerator.isUpperCaseCharacter(nextNameCharacter);
|
||||
const isUpperCasePrevNameCharacter: boolean = MangledIdentifierNamesGenerator.isUpperCaseCharacter(prevNameCharacter);
|
||||
|
||||
if (
|
||||
isUpperCaseNextNameCharacter
|
||||
&& !isUpperCasePrevNameCharacter
|
||||
) {
|
||||
return true;
|
||||
} else if (
|
||||
!isUpperCaseNextNameCharacter
|
||||
&& isUpperCasePrevNameCharacter
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
isIncrementedPrevCharacter = nextNameCharacter > prevNameCharacter;
|
||||
|
||||
if (nextNameCharacter < prevNameCharacter) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return nextName > prevName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} character
|
||||
* @returns {boolean}
|
||||
*/
|
||||
private static isUpperCaseCharacter (string: string): boolean {
|
||||
return /^[A-Z]*$/.test(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} character
|
||||
* @returns {boolean}
|
||||
*/
|
||||
private static isDigitCharacter (string: string): boolean {
|
||||
return /^[0-9]*$/.test(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates next name based on a global previous mangled name
|
||||
* We can ignore nameLength parameter here, it hasn't sense with this generator
|
||||
@@ -204,6 +124,43 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
||||
return identifierName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} nextName
|
||||
* @param {string} prevName
|
||||
* @returns {boolean}
|
||||
*/
|
||||
// eslint-disable-next-line complexity
|
||||
public isIncrementedMangledName (nextName: string, prevName: string): boolean {
|
||||
if (nextName === prevName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const nextNameLength: number = nextName.length;
|
||||
const prevNameLength: number = prevName.length;
|
||||
|
||||
if (nextNameLength !== prevNameLength) {
|
||||
return nextNameLength > prevNameLength;
|
||||
}
|
||||
|
||||
const nameSequence: string[] = this.getNameSequence();
|
||||
|
||||
for (let i: number = 0; i < nextNameLength; i++) {
|
||||
const nextNameCharacter: string = nextName[i];
|
||||
const prevNameCharacter: string = prevName[i];
|
||||
|
||||
if (nextNameCharacter === prevNameCharacter) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const indexOfNextNameCharacter: number = nameSequence.indexOf(nextNameCharacter);
|
||||
const indexOfPrevNameCharacter: number = nameSequence.indexOf(prevNameCharacter);
|
||||
|
||||
return indexOfNextNameCharacter > indexOfPrevNameCharacter;
|
||||
}
|
||||
|
||||
throw new Error('Something goes wrong during comparison of mangled names');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} mangledName
|
||||
* @returns {boolean}
|
||||
@@ -224,7 +181,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
|
||||
* @param {string} name
|
||||
*/
|
||||
protected updatePreviousMangledName (name: string): void {
|
||||
if (!MangledIdentifierNamesGenerator.isIncrementedMangledName(name, this.previousMangledName)) {
|
||||
if (!this.isIncrementedMangledName(name, this.previousMangledName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { TypeFromEnum } from '@gradecam/tsenum';
|
||||
|
||||
import { TOptionsPreset } from '../../types/options/TOptionsPreset';
|
||||
import { TStringArrayEncoding } from '../../types/options/TStringArrayEncoding';
|
||||
import { TStringArrayWrappersType } from '../../types/options/TStringArrayWrappersType';
|
||||
import { TTypeFromEnum } from '../../types/utils/TTypeFromEnum';
|
||||
|
||||
import { IdentifierNamesGenerator } from '../../enums/generators/identifier-names-generators/IdentifierNamesGenerator';
|
||||
import { ObfuscationTarget } from '../../enums/ObfuscationTarget';
|
||||
@@ -19,7 +18,7 @@ export interface IOptions {
|
||||
readonly disableConsoleOutput: boolean;
|
||||
readonly domainLock: string[];
|
||||
readonly forceTransformStrings: string[];
|
||||
readonly identifierNamesGenerator: TypeFromEnum<typeof IdentifierNamesGenerator>;
|
||||
readonly identifierNamesGenerator: TTypeFromEnum<typeof IdentifierNamesGenerator>;
|
||||
readonly identifiersDictionary: string[];
|
||||
readonly identifiersPrefix: string;
|
||||
readonly inputFileName: string;
|
||||
@@ -38,7 +37,7 @@ export interface IOptions {
|
||||
readonly sourceMap: boolean;
|
||||
readonly sourceMapBaseUrl: string;
|
||||
readonly sourceMapFileName: string;
|
||||
readonly sourceMapMode: TypeFromEnum<typeof SourceMapMode>;
|
||||
readonly sourceMapMode: TTypeFromEnum<typeof SourceMapMode>;
|
||||
readonly splitStrings: boolean;
|
||||
readonly splitStringsChunkLength: number;
|
||||
readonly stringArray: boolean;
|
||||
@@ -47,7 +46,7 @@ export interface IOptions {
|
||||
readonly stringArrayWrappersCount: number;
|
||||
readonly stringArrayWrappersType: TStringArrayWrappersType;
|
||||
readonly stringArrayThreshold: number;
|
||||
readonly target: TypeFromEnum<typeof ObfuscationTarget>;
|
||||
readonly target: TTypeFromEnum<typeof ObfuscationTarget>;
|
||||
readonly transformObjectKeys: boolean;
|
||||
readonly unicodeEscapeSequence: boolean;
|
||||
}
|
||||
|
||||
+4
-2
@@ -83,14 +83,16 @@ export class ExpressionStatementsMergeTransformer extends AbstractNodeTransforme
|
||||
|
||||
if (NodeGuards.isSequenceExpressionNode(prevStatement.expression)) {
|
||||
prevStatement.expression.expressions.push(expressionStatementNode.expression);
|
||||
NodeUtils.parentizeNode(expressionStatementNode.expression, prevStatement.expression);
|
||||
} else {
|
||||
prevStatement.expression = NodeFactory.sequenceExpressionNode([
|
||||
prevStatement.expression,
|
||||
expressionStatementNode.expression
|
||||
]);
|
||||
}
|
||||
|
||||
NodeUtils.parentizeAst(prevStatement);
|
||||
NodeUtils.parentizeAst(prevStatement.expression);
|
||||
NodeUtils.parentizeNode(prevStatement.expression, prevStatement);
|
||||
}
|
||||
|
||||
return estraverse.VisitorOption.Remove;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { TypeFromEnum } from '@gradecam/tsenum';
|
||||
|
||||
import { inject, injectable } from 'inversify';
|
||||
import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
|
||||
|
||||
@@ -24,6 +22,7 @@ import { TInputOptions } from '../types/options/TInputOptions';
|
||||
import { TOptionsPreset } from '../types/options/TOptionsPreset';
|
||||
import { TStringArrayEncoding } from '../types/options/TStringArrayEncoding';
|
||||
import { TStringArrayWrappersType } from '../types/options/TStringArrayWrappersType';
|
||||
import { TTypeFromEnum } from '../types/utils/TTypeFromEnum';
|
||||
|
||||
import { IOptions } from '../interfaces/options/IOptions';
|
||||
import { IOptionsNormalizer } from '../interfaces/options/IOptionsNormalizer';
|
||||
@@ -147,7 +146,7 @@ export class Options implements IOptions {
|
||||
IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
|
||||
IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator
|
||||
])
|
||||
public readonly identifierNamesGenerator!: TypeFromEnum<typeof IdentifierNamesGenerator>;
|
||||
public readonly identifierNamesGenerator!: TTypeFromEnum<typeof IdentifierNamesGenerator>;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
@@ -279,7 +278,7 @@ export class Options implements IOptions {
|
||||
* @type {SourceMapMode}
|
||||
*/
|
||||
@IsIn([SourceMapMode.Inline, SourceMapMode.Separate])
|
||||
public readonly sourceMapMode!: TypeFromEnum<typeof SourceMapMode>;
|
||||
public readonly sourceMapMode!: TTypeFromEnum<typeof SourceMapMode>;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
@@ -340,7 +339,7 @@ export class Options implements IOptions {
|
||||
* @type {ObfuscationTarget}
|
||||
*/
|
||||
@IsIn([ObfuscationTarget.Browser, ObfuscationTarget.BrowserNoEval, ObfuscationTarget.Node])
|
||||
public readonly target!: TypeFromEnum<typeof ObfuscationTarget>;
|
||||
public readonly target!: TTypeFromEnum<typeof ObfuscationTarget>;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { registerDecorator, ValidationArguments, ValidationOptions } from 'class-validator';
|
||||
import { TypeFromEnum } from '@gradecam/tsenum';
|
||||
import equal from 'fast-deep-equal';
|
||||
|
||||
import { TTypeFromEnum } from '../../types/utils/TTypeFromEnum';
|
||||
|
||||
import { IOptions } from '../../interfaces/options/IOptions';
|
||||
|
||||
import { ObfuscationTarget } from '../../enums/ObfuscationTarget';
|
||||
@@ -15,7 +16,7 @@ import { DEFAULT_PRESET } from '../presets/Default';
|
||||
* @returns {(options: IOptions, propertyName: keyof IOptions) => void}
|
||||
*/
|
||||
export function IsAllowedForObfuscationTargets (
|
||||
obfuscationTargets: TypeFromEnum<typeof ObfuscationTarget>[],
|
||||
obfuscationTargets: TTypeFromEnum<typeof ObfuscationTarget>[],
|
||||
validationOptions?: ValidationOptions
|
||||
): (options: IOptions, propertyName: keyof IOptions) => void {
|
||||
return (optionsObject: IOptions, propertyName: keyof IOptions): void => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { TypeFromEnum } from '@gradecam/tsenum';
|
||||
import { TTypeFromEnum } from '../utils/TTypeFromEnum';
|
||||
|
||||
import { OptionsPreset } from '../../enums/options/presets/OptionsPreset';
|
||||
|
||||
export type TOptionsPreset = TypeFromEnum<typeof OptionsPreset>;
|
||||
export type TOptionsPreset = TTypeFromEnum<typeof OptionsPreset>;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { TypeFromEnum } from '@gradecam/tsenum';
|
||||
import { TTypeFromEnum } from '../utils/TTypeFromEnum';
|
||||
|
||||
import { StringArrayEncoding } from '../../enums/node-transformers/string-array-transformers/StringArrayEncoding';
|
||||
|
||||
export type TStringArrayEncoding = TypeFromEnum<typeof StringArrayEncoding>;
|
||||
export type TStringArrayEncoding = TTypeFromEnum<typeof StringArrayEncoding>;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { TypeFromEnum } from '@gradecam/tsenum';
|
||||
import { TTypeFromEnum } from '../utils/TTypeFromEnum';
|
||||
|
||||
import { StringArrayWrappersType } from '../../enums/node-transformers/string-array-transformers/StringArrayWrappersType';
|
||||
|
||||
export type TStringArrayWrappersType = TypeFromEnum<typeof StringArrayWrappersType>;
|
||||
export type TStringArrayWrappersType = TTypeFromEnum<typeof StringArrayWrappersType>;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export type TTypeFromEnum<T extends object> = (T)[keyof T];
|
||||
@@ -57,4 +57,15 @@ export class Utils {
|
||||
|
||||
return `${baseIdentifiersPrefix}${sourceCodeIndex}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TObject} enumLikeObject
|
||||
* @returns {Readonly<TObject>}
|
||||
*/
|
||||
public static makeEnum<
|
||||
TObject extends {[index: string]: TValue},
|
||||
TValue extends string
|
||||
> (enumLikeObject: TObject): Readonly<TObject> {
|
||||
return Object.freeze({...enumLikeObject});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { assert } from 'chai';
|
||||
import { TypeFromEnum } from '@gradecam/tsenum';
|
||||
|
||||
import { TDictionary } from '../../../src/types/TDictionary';
|
||||
import { TInputOptions } from '../../../src/types/options/TInputOptions';
|
||||
import { TOptionsPreset } from '../../../src/types/options/TOptionsPreset';
|
||||
import { TTypeFromEnum } from '../../../src/types/utils/TTypeFromEnum';
|
||||
|
||||
import { IObfuscatedCode } from '../../../src/interfaces/source-code/IObfuscatedCode';
|
||||
|
||||
@@ -921,12 +921,12 @@ describe('JavaScriptObfuscator', () => {
|
||||
const samplesCount: number = 30;
|
||||
|
||||
let areCollisionsExists: boolean = false;
|
||||
let obfuscateFunc: (identifierNamesGenerator: TypeFromEnum<typeof IdentifierNamesGenerator>) => string;
|
||||
let obfuscateFunc: (identifierNamesGenerator: TTypeFromEnum<typeof IdentifierNamesGenerator>) => string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/custom-nodes-identifier-names-collision.js');
|
||||
|
||||
obfuscateFunc = (identifierNamesGenerator: TypeFromEnum<typeof IdentifierNamesGenerator>) => {
|
||||
obfuscateFunc = (identifierNamesGenerator: TTypeFromEnum<typeof IdentifierNamesGenerator>) => {
|
||||
const obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
@@ -945,7 +945,7 @@ describe('JavaScriptObfuscator', () => {
|
||||
[
|
||||
IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator,
|
||||
IdentifierNamesGenerator.MangledIdentifierNamesGenerator
|
||||
].forEach((identifierNamesGenerator: TypeFromEnum<typeof IdentifierNamesGenerator>) => {
|
||||
].forEach((identifierNamesGenerator: TTypeFromEnum<typeof IdentifierNamesGenerator>) => {
|
||||
for (let i = 0; i < samplesCount; i++) {
|
||||
try {
|
||||
eval(obfuscateFunc(identifierNamesGenerator));
|
||||
|
||||
+40
@@ -10,6 +10,7 @@ import { IInversifyContainerFacade } from '../../../../src/interfaces/container/
|
||||
import { IdentifierNamesGenerator } from '../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
|
||||
|
||||
import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade';
|
||||
import { MangledShuffledIdentifierNamesGenerator } from '../../../../src/generators/identifier-names-generators/MangledShuffledIdentifierNamesGenerator';
|
||||
|
||||
describe('MangledShuffledIdentifierNamesGenerator', () => {
|
||||
describe('generateNext', () => {
|
||||
@@ -112,4 +113,43 @@ describe('MangledShuffledIdentifierNamesGenerator', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isIncrementedMangledName', function () {
|
||||
this.timeout(60000);
|
||||
|
||||
const samplesCount: number = 1000000;
|
||||
const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
|
||||
|
||||
inversifyContainerFacade.load('', '', {});
|
||||
const identifierNamesGenerator: IIdentifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
|
||||
ServiceIdentifiers.IIdentifierNamesGenerator,
|
||||
IdentifierNamesGenerator.MangledShuffledIdentifierNamesGenerator
|
||||
);
|
||||
|
||||
let isSuccessComparison: boolean = true;
|
||||
let mangledName: string = '';
|
||||
let prevMangledName: string = '9';
|
||||
|
||||
for (let sample = 0; sample <= samplesCount; sample++) {
|
||||
let resultNormal: boolean;
|
||||
let resultReversed: boolean;
|
||||
|
||||
mangledName = identifierNamesGenerator.generateNext();
|
||||
resultNormal = (<MangledShuffledIdentifierNamesGenerator>identifierNamesGenerator)
|
||||
.isIncrementedMangledName(mangledName, prevMangledName);
|
||||
resultReversed = (<MangledShuffledIdentifierNamesGenerator>identifierNamesGenerator)
|
||||
.isIncrementedMangledName(prevMangledName, mangledName);
|
||||
|
||||
if (!resultNormal || resultReversed) {
|
||||
isSuccessComparison = false;
|
||||
break;
|
||||
}
|
||||
|
||||
prevMangledName = mangledName;
|
||||
}
|
||||
|
||||
it('should correctly compare mangled names', () => {
|
||||
assert.isTrue(isSuccessComparison);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+4
-2
@@ -192,8 +192,10 @@ describe('MangledIdentifierNamesGenerator', () => {
|
||||
let resultReversed: boolean;
|
||||
|
||||
mangledName = identifierNamesGenerator.generateNext();
|
||||
resultNormal = MangledIdentifierNamesGenerator.isIncrementedMangledName(mangledName, prevMangledName);
|
||||
resultReversed = MangledIdentifierNamesGenerator.isIncrementedMangledName(prevMangledName, mangledName);
|
||||
resultNormal = (<MangledIdentifierNamesGenerator>identifierNamesGenerator)
|
||||
.isIncrementedMangledName(mangledName, prevMangledName);
|
||||
resultReversed = (<MangledIdentifierNamesGenerator>identifierNamesGenerator)
|
||||
.isIncrementedMangledName(prevMangledName, mangledName);
|
||||
|
||||
if (!resultNormal || resultReversed) {
|
||||
isSuccessComparison = false;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import 'reflect-metadata';
|
||||
import { TypeFromEnum } from '@gradecam/tsenum';
|
||||
|
||||
import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers';
|
||||
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { TTypeFromEnum } from '../../../src/types/utils/TTypeFromEnum';
|
||||
|
||||
import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade';
|
||||
import { IObfuscatedCode } from '../../../src/interfaces/source-code/IObfuscatedCode';
|
||||
|
||||
@@ -24,7 +25,7 @@ function getObfuscatedCode (
|
||||
sourceMap: string,
|
||||
sourceMapBaseUrl: string,
|
||||
sourceMapFileName: string,
|
||||
sourceMapMode: TypeFromEnum<typeof SourceMapMode>
|
||||
sourceMapMode: TTypeFromEnum<typeof SourceMapMode>
|
||||
): IObfuscatedCode {
|
||||
const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ module.exports = {
|
||||
]
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
assert: 'assert'
|
||||
},
|
||||
extensions: ['.ts', '.js']
|
||||
},
|
||||
plugins: [
|
||||
@@ -33,6 +36,9 @@ module.exports = {
|
||||
),
|
||||
new webpack.EnvironmentPlugin({
|
||||
VERSION: packageJson.version
|
||||
}),
|
||||
new webpack.ProvidePlugin({
|
||||
process: ['process']
|
||||
})
|
||||
],
|
||||
output: {
|
||||
@@ -44,7 +50,7 @@ module.exports = {
|
||||
hints: false
|
||||
},
|
||||
stats: {
|
||||
maxModules: 0,
|
||||
excludeModules: true,
|
||||
warnings: false
|
||||
}
|
||||
};
|
||||
|
||||
@@ -34,6 +34,14 @@ module.exports = {
|
||||
resolve: {
|
||||
extensions: ['.ts']
|
||||
},
|
||||
cache: {
|
||||
type: 'filesystem',
|
||||
buildDependencies: {
|
||||
config: [
|
||||
__filename
|
||||
]
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
new webpack.BannerPlugin(
|
||||
{
|
||||
@@ -62,10 +70,9 @@ module.exports = {
|
||||
})
|
||||
],
|
||||
output: {
|
||||
libraryTarget: 'commonjs2',
|
||||
library: 'JavaScriptObfuscator'
|
||||
libraryTarget: 'commonjs2'
|
||||
},
|
||||
stats: {
|
||||
maxModules: 0
|
||||
excludeModules: true
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user