mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Merge tag '0.17.1' into 0.17.2
# Conflicts: # dist/index.browser.js # dist/index.cli.js # dist/index.js # package.json # yarn.lock
This commit is contained in:
+103
-27
@@ -10,24 +10,50 @@ import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFac
|
||||
|
||||
describe('ObjectExpressionTransformer', () => {
|
||||
describe('default behaviour', () => {
|
||||
const regExp: RegExp = /var *test *= *\{'foo':0x0\};/;
|
||||
describe('Variant #1: `unicodeEscapeSequence` option is disabled\'', () => {
|
||||
const regExp: RegExp = /var *test *= *\{'foo':0x0\};/;
|
||||
|
||||
let obfuscatedCode: string;
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/property-with-identifier-value.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET
|
||||
}
|
||||
);
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/property-with-identifier-value.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
unicodeEscapeSequence: false
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should replace object expression node `key` property with identifier value by property with literal value', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
it('should replace object expression node `key` property with identifier value by property with literal value', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: `unicodeEscapeSequence` option is enabled', () => {
|
||||
const regExp: RegExp = /var *test *= *\{'\\x66\\x6f\\x6f':0x0\};/;
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/property-with-identifier-value.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
unicodeEscapeSequence: true
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should replace object expression node `key` property with identifier value by property with encoded literal value', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -54,24 +80,74 @@ describe('ObjectExpressionTransformer', () => {
|
||||
});
|
||||
|
||||
describe('computed property name', () => {
|
||||
const regExp: RegExp = /var *_0x[a-f0-9]{4,6} *= *\{\[_0x[a-f0-9]{4,6}\]: *0x1\};/;
|
||||
describe('Variant #1: computed property name with identifier', () => {
|
||||
const regExp: RegExp = /var *_0x[a-f0-9]{4,6} *= *\{\[_0x[a-f0-9]{4,6}\]: *0x1\};/;
|
||||
|
||||
let obfuscatedCode: string;
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/computed-property-name.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET
|
||||
}
|
||||
);
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/computed-property-name-identifier.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should ignore computed property identifier', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore computed property identifier', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
describe('Variant #2: computed property name with literal', () => {
|
||||
describe('Variant #1: `unicodeEscapeSequence` option is disabled', () => {
|
||||
const regExp: RegExp = /var *_0x[a-f0-9]{4,6} *= *\{\['foo'\]: *0x1\};/;
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/computed-property-name-literal.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
unicodeEscapeSequence: false
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should ignore computed property literal value', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: `unicodeEscapeSequence` option is enabled', () => {
|
||||
const regExp: RegExp = /var *_0x[a-f0-9]{4,6} *= *\{\['\\x66\\x6f\\x6f'\]: *0x1\};/;
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/computed-property-name-literal.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
unicodeEscapeSequence: true
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should encode computed property literal value', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
(function () {
|
||||
var test = {
|
||||
['foo']: 1
|
||||
};
|
||||
})();
|
||||
+15
@@ -156,4 +156,19 @@ describe('TemplateLiteralTransformer', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #7: template literal parentize', () => {
|
||||
it('should parentize transformed template literal node', () => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/template-literal-parentize.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
unicodeEscapeSequence: false
|
||||
}
|
||||
);
|
||||
|
||||
assert.match(obfuscationResult.getObfuscatedCode(), /^\[]\['map']\(\(\) *=> *'foo'\);$/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
[].map(() => `foo`);
|
||||
+48
-18
@@ -68,30 +68,60 @@ describe('ClassDeclarationTransformer', () => {
|
||||
});
|
||||
|
||||
describe('Variant #2: `renameGlobals` option is enabled', () => {
|
||||
const classNameIdentifierRegExp: RegExp = /class *(_0x[a-f0-9]{4,6}) *\{/;
|
||||
const classCallIdentifierRegExp: RegExp = /new *(_0x[a-f0-9]{4,6}) *\( *\);/;
|
||||
describe('Variant #1: Base', () => {
|
||||
const classNameIdentifierRegExp: RegExp = /class *(_0x[a-f0-9]{4,6}) *\{/;
|
||||
const classCallIdentifierRegExp: RegExp = /new *(_0x[a-f0-9]{4,6}) *\( *\);/;
|
||||
|
||||
let obfuscatedCode: string;
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/parent-block-scope-is-program-node.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
renameGlobals: true
|
||||
}
|
||||
);
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/parent-block-scope-is-program-node.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
renameGlobals: true
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('match #1: should transform class name', () => {
|
||||
assert.match(obfuscatedCode, classNameIdentifierRegExp);
|
||||
});
|
||||
|
||||
it('match #2: should transform class name', () => {
|
||||
assert.match(obfuscatedCode, classCallIdentifierRegExp);
|
||||
});
|
||||
});
|
||||
|
||||
it('match #1: should transform class name', () => {
|
||||
assert.match(obfuscatedCode, classNameIdentifierRegExp);
|
||||
});
|
||||
describe('Variant #2: Two classes. Transformation of identifier inside class method', () => {
|
||||
const identifierRegExp1: RegExp = /const (?:_0x[a-f0-9]{4,6}) *= *0x1;/;
|
||||
const identifierRegExp2: RegExp = /const (?:_0x[a-f0-9]{4,6}) *= *0x2;/;
|
||||
|
||||
it('match #2: should transform class name', () => {
|
||||
assert.match(obfuscatedCode, classCallIdentifierRegExp);
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/rename-globals-identifier-transformation.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
renameGlobals: true
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('match #1: should transform identifier name inside class method', () => {
|
||||
assert.match(obfuscatedCode, identifierRegExp1);
|
||||
});
|
||||
|
||||
it('match #2: should transform identifier name inside class method', () => {
|
||||
assert.match(obfuscatedCode, identifierRegExp2);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class Foo {
|
||||
foo() {
|
||||
const foo = 1;
|
||||
}
|
||||
}
|
||||
|
||||
class Bar {
|
||||
bar() {
|
||||
const bar = 2;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user