|
@@ -1,18 +1,18 @@
|
|
import { assert } from 'chai';
|
|
import { assert } from 'chai';
|
|
|
|
|
|
-import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult';
|
|
|
|
|
|
+import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
|
|
|
|
|
|
-import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
|
|
|
|
|
|
+import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
|
|
|
|
|
|
-import { readFileAsString } from '../../../helpers/readFileAsString';
|
|
|
|
|
|
+import { readFileAsString } from '../../../../helpers/readFileAsString';
|
|
|
|
|
|
-import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator';
|
|
|
|
|
|
+import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscator';
|
|
|
|
|
|
describe('LiteralTransformer', () => {
|
|
describe('LiteralTransformer', () => {
|
|
- describe('obfuscation of literal node with string value', () => {
|
|
|
|
|
|
+ describe('transformation of literal node with string value', () => {
|
|
it('should replace literal node value with unicode escape sequence', () => {
|
|
it('should replace literal node value with unicode escape sequence', () => {
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
- `var test = 'test';`,
|
|
|
|
|
|
+ readFileAsString(__dirname + '/fixtures/simple-input.js'),
|
|
{
|
|
{
|
|
...NO_CUSTOM_NODES_PRESET
|
|
...NO_CUSTOM_NODES_PRESET
|
|
}
|
|
}
|
|
@@ -23,7 +23,7 @@ describe('LiteralTransformer', () => {
|
|
|
|
|
|
it('should replace literal node value with unicode escape sequence from string array', () => {
|
|
it('should replace literal node value with unicode escape sequence from string array', () => {
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
- `var test = 'test';`,
|
|
|
|
|
|
+ readFileAsString(__dirname + '/fixtures/simple-input.js'),
|
|
{
|
|
{
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
stringArray: true,
|
|
stringArray: true,
|
|
@@ -40,11 +40,7 @@ describe('LiteralTransformer', () => {
|
|
|
|
|
|
it('should create only one item in string array for same literal node values', () => {
|
|
it('should create only one item in string array for same literal node values', () => {
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
- `
|
|
|
|
- var test = 'test';
|
|
|
|
- var test = 'test';
|
|
|
|
- object.test();
|
|
|
|
- `,
|
|
|
|
|
|
+ readFileAsString(__dirname + '/fixtures/same-literal-values.js'),
|
|
{
|
|
{
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
stringArray: true,
|
|
stringArray: true,
|
|
@@ -61,7 +57,7 @@ describe('LiteralTransformer', () => {
|
|
|
|
|
|
it('should replace literal node value with raw value from string array if `unicodeEscapeSequence` is disabled', () => {
|
|
it('should replace literal node value with raw value from string array if `unicodeEscapeSequence` is disabled', () => {
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
- `var test = 'test';`,
|
|
|
|
|
|
+ readFileAsString(__dirname + '/fixtures/simple-input.js'),
|
|
{
|
|
{
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
stringArray: true,
|
|
stringArray: true,
|
|
@@ -79,7 +75,7 @@ describe('LiteralTransformer', () => {
|
|
|
|
|
|
it('should replace literal node value with raw value from string array if `unicodeEscapeSequence` and `stringArray` are disabled', () => {
|
|
it('should replace literal node value with raw value from string array if `unicodeEscapeSequence` and `stringArray` are disabled', () => {
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
- `var test = 'test';`,
|
|
|
|
|
|
+ readFileAsString(__dirname + '/fixtures/simple-input.js'),
|
|
{
|
|
{
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
unicodeEscapeSequence: false
|
|
unicodeEscapeSequence: false
|
|
@@ -94,7 +90,7 @@ describe('LiteralTransformer', () => {
|
|
|
|
|
|
it('should\'t throw an error when string contains non-latin and non-digit characters and `unicodeEscapeSequence` is disabled', () => {
|
|
it('should\'t throw an error when string contains non-latin and non-digit characters and `unicodeEscapeSequence` is disabled', () => {
|
|
assert.doesNotThrow(() => JavaScriptObfuscator.obfuscate(
|
|
assert.doesNotThrow(() => JavaScriptObfuscator.obfuscate(
|
|
- readFileAsString('./test/fixtures/node-transformers/obfuscation-transformers/literal-transformer-unicode-sequence.js'),
|
|
|
|
|
|
+ readFileAsString(__dirname + '/fixtures/error-when-non-latin.js'),
|
|
{
|
|
{
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
stringArray: true,
|
|
stringArray: true,
|
|
@@ -106,7 +102,7 @@ describe('LiteralTransformer', () => {
|
|
|
|
|
|
it('shouldn\'t replace short literal node value with value from string array', () => {
|
|
it('shouldn\'t replace short literal node value with value from string array', () => {
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
- `var test = 'te';`,
|
|
|
|
|
|
+ readFileAsString(__dirname + '/fixtures/short-literal-value.js'),
|
|
{
|
|
{
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
stringArray: true,
|
|
stringArray: true,
|
|
@@ -119,7 +115,7 @@ describe('LiteralTransformer', () => {
|
|
|
|
|
|
it('should replace literal node value with value from string array encoded using base64', () => {
|
|
it('should replace literal node value with value from string array encoded using base64', () => {
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
- `var test = 'test';`,
|
|
|
|
|
|
+ readFileAsString(__dirname + '/fixtures/simple-input.js'),
|
|
{
|
|
{
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
stringArray: true,
|
|
stringArray: true,
|
|
@@ -137,7 +133,7 @@ describe('LiteralTransformer', () => {
|
|
|
|
|
|
it('should replace literal node value with value from string array encoded using rc4', () => {
|
|
it('should replace literal node value with value from string array encoded using rc4', () => {
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
- `var test = 'test';`,
|
|
|
|
|
|
+ readFileAsString(__dirname + '/fixtures/simple-input.js'),
|
|
{
|
|
{
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
stringArray: true,
|
|
stringArray: true,
|
|
@@ -157,7 +153,7 @@ describe('LiteralTransformer', () => {
|
|
const stringArrayThreshold: number = 0.5;
|
|
const stringArrayThreshold: number = 0.5;
|
|
const delta: number = 0.1;
|
|
const delta: number = 0.1;
|
|
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
- `var test = 'test';\n`.repeat(samples),
|
|
|
|
|
|
+ `${readFileAsString(__dirname + '/fixtures/simple-input.js')}\n`.repeat(samples),
|
|
{
|
|
{
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
stringArray: true,
|
|
stringArray: true,
|
|
@@ -175,9 +171,9 @@ describe('LiteralTransformer', () => {
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
- it('should obfuscate literal node with boolean value', () => {
|
|
|
|
|
|
+ it('should transform literal node with boolean value', () => {
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
- `var test = true;`,
|
|
|
|
|
|
+ readFileAsString(__dirname + '/fixtures/boolean-value.js'),
|
|
{
|
|
{
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
stringArray: true,
|
|
stringArray: true,
|
|
@@ -188,9 +184,9 @@ describe('LiteralTransformer', () => {
|
|
assert.match(obfuscationResult.getObfuscatedCode(), /^var *test *= *!!\[\];$/);
|
|
assert.match(obfuscationResult.getObfuscatedCode(), /^var *test *= *!!\[\];$/);
|
|
});
|
|
});
|
|
|
|
|
|
- it('should obfuscate literal node with number value', () => {
|
|
|
|
|
|
+ it('should transform literal node with number value', () => {
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
|
- `var test = 0;`,
|
|
|
|
|
|
+ readFileAsString(__dirname + '/fixtures/number-value.js'),
|
|
{
|
|
{
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
...NO_CUSTOM_NODES_PRESET,
|
|
stringArray: true,
|
|
stringArray: true,
|