mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Fixed wrong source-map: 'inline' encoding after 1.3.0
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
import { alphabetStringUppercase } from './AlphabetStringUppercase';
|
||||
import { alphabetString } from './AlphabetString';
|
||||
import { numbersString } from './NumbersString';
|
||||
|
||||
export const base64alphabet: string = `${alphabetStringUppercase}${alphabetString}${numbersString}+/=`;
|
||||
@@ -0,0 +1,8 @@
|
||||
import { alphabetStringUppercase } from './AlphabetStringUppercase';
|
||||
import { alphabetString } from './AlphabetString';
|
||||
import { numbersString } from './NumbersString';
|
||||
|
||||
/**
|
||||
* Swapped lowercase and uppercase groups of alphabet to prevent easy decode
|
||||
*/
|
||||
export const base64alphabetSwapped: string = `${alphabetString}${alphabetStringUppercase}${numbersString}+/=`;
|
||||
@@ -22,6 +22,7 @@ export enum ServiceIdentifiers {
|
||||
ICodeTransformerNamesGroupsBuilder = 'ICodeTransformerNamesGroupsBuilder',
|
||||
ICodeTransformersRunner = 'ICodeTransformersRunner',
|
||||
ICryptUtils = 'ICryptUtils',
|
||||
ICryptUtilsSwappedAlphabet = 'ICryptUtilsSwappedAlphabet',
|
||||
ICustomCodeHelper = 'ICustomCodeHelper',
|
||||
ICustomCodeHelperGroup = 'ICustomCodeHelperGroup',
|
||||
IControlFlowReplacer = 'IControlFlowReplacer',
|
||||
|
||||
@@ -3,12 +3,14 @@ import { ServiceIdentifiers } from '../../ServiceIdentifiers';
|
||||
|
||||
import { IArrayUtils } from '../../../interfaces/utils/IArrayUtils';
|
||||
import { ICryptUtils } from '../../../interfaces/utils/ICryptUtils';
|
||||
import { ICryptUtilsSwappedAlphabet } from '../../../interfaces/utils/ICryptUtilsSwappedAlphabet';
|
||||
import { IEscapeSequenceEncoder } from '../../../interfaces/utils/IEscapeSequenceEncoder';
|
||||
import { ILevelledTopologicalSorter } from '../../../interfaces/utils/ILevelledTopologicalSorter';
|
||||
import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
|
||||
|
||||
import { ArrayUtils } from '../../../utils/ArrayUtils';
|
||||
import { CryptUtils } from '../../../utils/CryptUtils';
|
||||
import { CryptUtilsSwappedAlphabet } from '../../../utils/CryptUtilsSwappedAlphabet';
|
||||
import { EscapeSequenceEncoder } from '../../../utils/EscapeSequenceEncoder';
|
||||
import { LevelledTopologicalSorter } from '../../../utils/LevelledTopologicalSorter';
|
||||
import { RandomGenerator } from '../../../utils/RandomGenerator';
|
||||
@@ -29,6 +31,11 @@ export const utilsModule: interfaces.ContainerModule = new ContainerModule((bind
|
||||
.to(CryptUtils)
|
||||
.inSingletonScope();
|
||||
|
||||
// crypt utils with swapped alphabet
|
||||
bind<ICryptUtilsSwappedAlphabet>(ServiceIdentifiers.ICryptUtilsSwappedAlphabet)
|
||||
.to(CryptUtilsSwappedAlphabet)
|
||||
.inSingletonScope();
|
||||
|
||||
// escape sequence encoder
|
||||
bind<IEscapeSequenceEncoder>(ServiceIdentifiers.IEscapeSequenceEncoder)
|
||||
.to(EscapeSequenceEncoder)
|
||||
|
||||
+2
-5
@@ -1,15 +1,12 @@
|
||||
import { alphabetStringUppercase } from '../../../../constants/AlphabetStringUppercase';
|
||||
import { alphabetString } from '../../../../constants/AlphabetString';
|
||||
import { numbersString } from '../../../../constants/NumbersString';
|
||||
import { base64alphabetSwapped } from '../../../../constants/Base64AlphabetSwapped';
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
export function AtobTemplate (): string {
|
||||
// swapped lowercase and uppercase groups of alphabet to prevent easy decode!!!!
|
||||
return `
|
||||
var {atobFunctionName} = function (input) {
|
||||
const chars = '${alphabetString}${alphabetStringUppercase}${numbersString}+/=';
|
||||
const chars = '${base64alphabetSwapped}';
|
||||
|
||||
const str = String(input).replace(/=+$/, '');
|
||||
let output = '';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export interface ICryptUtils {
|
||||
/**
|
||||
* @param string
|
||||
* @param {string} string
|
||||
* @returns {string}
|
||||
*/
|
||||
btoa (string: string): string;
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
import { ICryptUtils } from './ICryptUtils';
|
||||
|
||||
export interface ICryptUtilsSwappedAlphabet extends ICryptUtils {}
|
||||
@@ -5,7 +5,7 @@ import { TIdentifierNamesGeneratorFactory } from '../../types/container/generato
|
||||
import { IIdentifierNamesGenerator } from '../../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator';
|
||||
|
||||
import { IArrayUtils } from '../../interfaces/utils/IArrayUtils';
|
||||
import { ICryptUtils } from '../../interfaces/utils/ICryptUtils';
|
||||
import { ICryptUtilsSwappedAlphabet } from '../../interfaces/utils/ICryptUtilsSwappedAlphabet';
|
||||
import { IEncodedValue } from '../../interfaces/IEncodedValue';
|
||||
import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEncoder';
|
||||
import { IOptions } from '../../interfaces/options/IOptions';
|
||||
@@ -50,9 +50,9 @@ export class StringArrayStorage extends MapStorage <string, IStringArrayStorageI
|
||||
private readonly arrayUtils: IArrayUtils;
|
||||
|
||||
/**
|
||||
* @type {ICryptUtils}
|
||||
* @type {ICryptUtilsSwappedAlphabet}
|
||||
*/
|
||||
private readonly cryptUtils: ICryptUtils;
|
||||
private readonly cryptUtilsSwappedAlphabet: ICryptUtilsSwappedAlphabet;
|
||||
|
||||
/**
|
||||
* @type {IEscapeSequenceEncoder}
|
||||
@@ -94,7 +94,7 @@ export class StringArrayStorage extends MapStorage <string, IStringArrayStorageI
|
||||
* @param {IArrayUtils} arrayUtils
|
||||
* @param {IRandomGenerator} randomGenerator
|
||||
* @param {IOptions} options
|
||||
* @param {ICryptUtils} cryptUtils
|
||||
* @param {ICryptUtilsSwappedAlphabet} cryptUtilsSwappedAlphabet
|
||||
* @param {IEscapeSequenceEncoder} escapeSequenceEncoder
|
||||
*/
|
||||
public constructor (
|
||||
@@ -103,14 +103,14 @@ export class StringArrayStorage extends MapStorage <string, IStringArrayStorageI
|
||||
@inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils,
|
||||
@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
|
||||
@inject(ServiceIdentifiers.IOptions) options: IOptions,
|
||||
@inject(ServiceIdentifiers.ICryptUtils) cryptUtils: ICryptUtils,
|
||||
@inject(ServiceIdentifiers.ICryptUtilsSwappedAlphabet) cryptUtilsSwappedAlphabet: ICryptUtilsSwappedAlphabet,
|
||||
@inject(ServiceIdentifiers.IEscapeSequenceEncoder) escapeSequenceEncoder: IEscapeSequenceEncoder
|
||||
) {
|
||||
super(randomGenerator, options);
|
||||
|
||||
this.identifierNamesGenerator = identifierNamesGeneratorFactory(options);
|
||||
this.arrayUtils = arrayUtils;
|
||||
this.cryptUtils = cryptUtils;
|
||||
this.cryptUtilsSwappedAlphabet = cryptUtilsSwappedAlphabet;
|
||||
this.escapeSequenceEncoder = escapeSequenceEncoder;
|
||||
|
||||
this.rc4Keys = this.randomGenerator.getRandomGenerator()
|
||||
@@ -275,7 +275,7 @@ export class StringArrayStorage extends MapStorage <string, IStringArrayStorageI
|
||||
*/
|
||||
case StringArrayEncoding.Rc4: {
|
||||
const decodeKey: string = this.randomGenerator.getRandomGenerator().pickone(this.rc4Keys);
|
||||
const encodedValue: string = this.cryptUtils.btoa(this.cryptUtils.rc4(value, decodeKey));
|
||||
const encodedValue: string = this.cryptUtilsSwappedAlphabet.btoa(this.cryptUtilsSwappedAlphabet.rc4(value, decodeKey));
|
||||
|
||||
const encodedValueSources: string[] = this.rc4EncodedValuesSourcesCache.get(encodedValue) ?? [];
|
||||
let encodedValueSourcesLength: number = encodedValueSources.length;
|
||||
@@ -298,7 +298,7 @@ export class StringArrayStorage extends MapStorage <string, IStringArrayStorageI
|
||||
|
||||
case StringArrayEncoding.Base64: {
|
||||
const decodeKey: null = null;
|
||||
const encodedValue: string = this.cryptUtils.btoa(value);
|
||||
const encodedValue: string = this.cryptUtilsSwappedAlphabet.btoa(value);
|
||||
|
||||
return { encodedValue, decodeKey };
|
||||
}
|
||||
|
||||
@@ -4,15 +4,18 @@ import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
|
||||
import { ICryptUtils } from '../interfaces/utils/ICryptUtils';
|
||||
import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
|
||||
|
||||
import { alphabetStringUppercase } from '../constants/AlphabetStringUppercase';
|
||||
import { alphabetString } from '../constants/AlphabetString';
|
||||
import { numbersString } from '../constants/NumbersString';
|
||||
import { base64alphabet } from '../constants/Base64Alphabet';
|
||||
|
||||
import { RandomGenerator } from './RandomGenerator';
|
||||
import { Utils } from './Utils';
|
||||
|
||||
@injectable()
|
||||
export class CryptUtils implements ICryptUtils {
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
protected readonly base64Alphabet: string = base64alphabet;
|
||||
|
||||
/**
|
||||
* @type {IRandomGenerator}
|
||||
*/
|
||||
@@ -32,8 +35,7 @@ export class CryptUtils implements ICryptUtils {
|
||||
* @returns {string}
|
||||
*/
|
||||
public btoa (string: string): string {
|
||||
// swapped lowercase and uppercase groups of alphabet to prevent easy decode!!!!
|
||||
const chars: string = `${alphabetString}${alphabetStringUppercase}${numbersString}+/=`;
|
||||
const chars: string = this.base64Alphabet;
|
||||
|
||||
let output: string = '';
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { inject, injectable } from 'inversify';
|
||||
import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
|
||||
|
||||
import { ICryptUtilsSwappedAlphabet } from '../interfaces/utils/ICryptUtilsSwappedAlphabet';
|
||||
import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
|
||||
|
||||
import { base64alphabetSwapped } from '../constants/Base64AlphabetSwapped';
|
||||
|
||||
import { CryptUtils } from './CryptUtils';
|
||||
|
||||
@injectable()
|
||||
export class CryptUtilsSwappedAlphabet extends CryptUtils implements ICryptUtilsSwappedAlphabet {
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
protected readonly base64Alphabet: string = base64alphabetSwapped;
|
||||
|
||||
/**
|
||||
* @param {IRandomGenerator} randomGenerator
|
||||
*/
|
||||
public constructor (
|
||||
@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator
|
||||
) {
|
||||
super(randomGenerator);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user