mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Switched from escodegen to escodegen-wallaby
This commit is contained in:
@@ -2,15 +2,15 @@ import * as commander from 'commander';
|
||||
import * as path from 'path';
|
||||
|
||||
import { TInputOptions } from '../types/options/TInputOptions';
|
||||
import { TStringArrayEncoding } from '../types/options/TStringArrayEncoding';
|
||||
|
||||
import { IObfuscationResult } from '../interfaces/IObfuscationResult';
|
||||
|
||||
import { SourceMapMode } from '../enums/SourceMapMode';
|
||||
import { StringArrayEncoding } from '../enums/StringArrayEncoding';
|
||||
|
||||
import { DEFAULT_PRESET } from '../options/presets/Default';
|
||||
|
||||
import { BooleanSanitizer } from './sanitizers/BooleanSanitizer';
|
||||
import { SourceMapModeSanitizer } from './sanitizers/SourceMapModeSanitizer';
|
||||
import { StringArrayEncodingSanitizer } from './sanitizers/StringArrayEncodingSanitizer';
|
||||
|
||||
import { CLIUtils } from './CLIUtils';
|
||||
import { JavaScriptObfuscator } from '../JavaScriptObfuscator';
|
||||
|
||||
@@ -55,51 +55,6 @@ export class JavaScriptObfuscatorCLI {
|
||||
return CLIUtils.getPackageConfig().version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value
|
||||
* @returns {boolean}
|
||||
*/
|
||||
private static parseBoolean (value: string): boolean {
|
||||
return value === 'true' || value === '1';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value
|
||||
* @returns {string}
|
||||
*/
|
||||
private static parseSourceMapMode (value: string): string {
|
||||
const availableMode: boolean = Object
|
||||
.keys(SourceMapMode)
|
||||
.some((key: string): boolean => {
|
||||
return SourceMapMode[key] === value;
|
||||
});
|
||||
|
||||
if (!availableMode) {
|
||||
throw new ReferenceError('Invalid value of `--sourceMapMode` option');
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value
|
||||
* @returns {TStringArrayEncoding}
|
||||
*/
|
||||
private static parseStringArrayEncoding (value: string): TStringArrayEncoding {
|
||||
switch (value) {
|
||||
case 'true':
|
||||
case '1':
|
||||
case StringArrayEncoding.base64:
|
||||
return true;
|
||||
|
||||
case StringArrayEncoding.rc4:
|
||||
return StringArrayEncoding.rc4;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public run (): void {
|
||||
this.configureCommands();
|
||||
|
||||
@@ -152,38 +107,52 @@ export class JavaScriptObfuscatorCLI {
|
||||
.option(
|
||||
'--compact <boolean>',
|
||||
'Disable one line output code compacting',
|
||||
JavaScriptObfuscatorCLI.parseBoolean
|
||||
BooleanSanitizer
|
||||
)
|
||||
.option(
|
||||
'--controlFlowFlattening <boolean>',
|
||||
'Enables control flow flattening',
|
||||
JavaScriptObfuscatorCLI.parseBoolean
|
||||
BooleanSanitizer
|
||||
)
|
||||
.option(
|
||||
'--controlFlowFlatteningThreshold <number>',
|
||||
'The probability that the control flow flattening transformation will be applied to the node',
|
||||
parseFloat
|
||||
)
|
||||
.option(
|
||||
'--deadCodeInjection <boolean>',
|
||||
'Enables dead code injection',
|
||||
BooleanSanitizer
|
||||
)
|
||||
.option(
|
||||
'--deadCodeInjectionThreshold <number>',
|
||||
'The probability that the dead code injection transformation will be applied to the node',
|
||||
parseFloat
|
||||
)
|
||||
.option(
|
||||
'--debugProtection <boolean>',
|
||||
'Disable browser Debug panel (can cause DevTools enabled browser freeze)',
|
||||
JavaScriptObfuscatorCLI.parseBoolean
|
||||
BooleanSanitizer
|
||||
)
|
||||
.option(
|
||||
'--debugProtectionInterval <boolean>',
|
||||
'Disable browser Debug panel even after page was loaded (can cause DevTools enabled browser freeze)',
|
||||
JavaScriptObfuscatorCLI.parseBoolean
|
||||
BooleanSanitizer
|
||||
)
|
||||
.option(
|
||||
'--disableConsoleOutput <boolean>',
|
||||
'Allow console.log, console.info, console.error and console.warn messages output into browser console',
|
||||
JavaScriptObfuscatorCLI.parseBoolean
|
||||
BooleanSanitizer
|
||||
)
|
||||
.option(
|
||||
'--domainLock <list>',
|
||||
'Blocks the execution of the code in domains that do not match the passed RegExp patterns (comma separated)',
|
||||
(value: string) => value.split(',')
|
||||
)
|
||||
.option(
|
||||
'--mangle <boolean>', 'Enables mangling of variable names',
|
||||
BooleanSanitizer
|
||||
)
|
||||
.option(
|
||||
'--reservedNames <list>',
|
||||
'Disable obfuscation of variable names, function names and names of function parameters that match the passed RegExp patterns (comma separated)',
|
||||
@@ -191,7 +160,7 @@ export class JavaScriptObfuscatorCLI {
|
||||
)
|
||||
.option(
|
||||
'--rotateStringArray <boolean>', 'Disable rotation of unicode array values during obfuscation',
|
||||
JavaScriptObfuscatorCLI.parseBoolean
|
||||
BooleanSanitizer
|
||||
)
|
||||
.option(
|
||||
'--seed <number>',
|
||||
@@ -201,12 +170,12 @@ export class JavaScriptObfuscatorCLI {
|
||||
.option(
|
||||
'--selfDefending <boolean>',
|
||||
'Disables self-defending for obfuscated code',
|
||||
JavaScriptObfuscatorCLI.parseBoolean
|
||||
BooleanSanitizer
|
||||
)
|
||||
.option(
|
||||
'--sourceMap <boolean>',
|
||||
'Enables source map generation',
|
||||
JavaScriptObfuscatorCLI.parseBoolean
|
||||
BooleanSanitizer
|
||||
)
|
||||
.option(
|
||||
'--sourceMapBaseUrl <string>',
|
||||
@@ -219,17 +188,17 @@ export class JavaScriptObfuscatorCLI {
|
||||
.option(
|
||||
'--sourceMapMode <string> [inline, separate]',
|
||||
'Specify source map output mode',
|
||||
JavaScriptObfuscatorCLI.parseSourceMapMode
|
||||
SourceMapModeSanitizer
|
||||
)
|
||||
.option(
|
||||
'--stringArray <boolean>',
|
||||
'Disables gathering of all literal strings into an array and replacing every literal string with an array call',
|
||||
JavaScriptObfuscatorCLI.parseBoolean
|
||||
BooleanSanitizer
|
||||
)
|
||||
.option(
|
||||
'--stringArrayEncoding <boolean|string> [true, false, base64, rc4]',
|
||||
'Encodes all strings in strings array using base64 or rc4 (this option can slow down your code speed',
|
||||
JavaScriptObfuscatorCLI.parseStringArrayEncoding
|
||||
StringArrayEncodingSanitizer
|
||||
)
|
||||
.option(
|
||||
'--stringArrayThreshold <number>',
|
||||
@@ -239,7 +208,7 @@ export class JavaScriptObfuscatorCLI {
|
||||
.option(
|
||||
'--unicodeEscapeSequence <boolean>',
|
||||
'Allows to enable/disable string conversion to unicode escape sequence',
|
||||
JavaScriptObfuscatorCLI.parseBoolean
|
||||
BooleanSanitizer
|
||||
)
|
||||
.parse(this.rawArguments);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user