mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Merge branch 'master' into fix-issue-273
This commit is contained in:
+144
@@ -342,6 +342,94 @@ describe('ObjectExpressionKeysTransformer', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #5: variable declarator with object call', () => {
|
||||
describe('Variant #1', () => {
|
||||
const match: string = `` +
|
||||
`const *${variableMatch} *= *{}; *` +
|
||||
`${variableMatch}\\['foo'] *= *'foo'; *` +
|
||||
`const *${variableMatch} *= *${variableMatch}\\['foo'];` +
|
||||
``;
|
||||
const regExp: RegExp = new RegExp(match);
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/variable-declarator-with-object-call-1.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
transformObjectKeys: true
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should correctly transform object keys', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2', () => {
|
||||
const match: string = `` +
|
||||
`const *${variableMatch} *= *0x1, *` +
|
||||
`${variableMatch} *= *{}; *` +
|
||||
`${variableMatch}\\['foo'] *= *'foo'; *` +
|
||||
`const *${variableMatch} *= *${variableMatch}\\['foo'];` +
|
||||
``;
|
||||
const regExp: RegExp = new RegExp(match);
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/variable-declarator-with-object-call-2.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
transformObjectKeys: true
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should correctly transform object keys', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #3: two objects', () => {
|
||||
const match: string = `` +
|
||||
`const *${variableMatch} *= *{}, *` +
|
||||
`${variableMatch} *= *{'bar': *'bar'}, *` +
|
||||
`${variableMatch} *= *${variableMatch}\\['bar']; *` +
|
||||
`${variableMatch}\\['foo'] *= *'foo';` +
|
||||
``;
|
||||
const regExp: RegExp = new RegExp(match);
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/variable-declarator-with-object-call-3.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
transformObjectKeys: true
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should correctly transform first object keys and ignore second object keys', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Ignore transformation', () => {
|
||||
@@ -395,5 +483,61 @@ describe('ObjectExpressionKeysTransformer', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #3: variable declarator object call inside other variable declarator', () => {
|
||||
describe('Variant #1', () => {
|
||||
const match: string = `` +
|
||||
`const *${variableMatch} *= *{'foo': *'foo'}, *` +
|
||||
`${variableMatch} *= *${variableMatch}\\['foo'];` +
|
||||
``;
|
||||
const regExp: RegExp = new RegExp(match);
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/variable-declarator-with-object-call-ignore-1.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
transformObjectKeys: true
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('shouldn\'t transform object keys', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2', () => {
|
||||
const match: string = `` +
|
||||
`const *${variableMatch} *= *{'foo': *'foo'}, *` +
|
||||
`${variableMatch} *= *\\[${variableMatch}\\['foo']];` +
|
||||
``;
|
||||
const regExp: RegExp = new RegExp(match);
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/variable-declarator-with-object-call-ignore-2.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
transformObjectKeys: true
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('shouldn\'t transform object keys', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
(function () {
|
||||
const object = {foo: 'foo'};
|
||||
const variable = object.foo;
|
||||
})();
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
(function () {
|
||||
const test = 1,
|
||||
object = {foo: 'foo'};
|
||||
const variable = object.foo;
|
||||
})();
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
(function () {
|
||||
const object1 = {foo: 'foo'},
|
||||
object2 = {bar: 'bar'},
|
||||
variable = object2.bar;
|
||||
})();
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
(function () {
|
||||
const object = {foo: 'foo'},
|
||||
variable = object.foo;
|
||||
})();
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
(function () {
|
||||
const object = {foo: 'foo'},
|
||||
variable = [object.foo];
|
||||
})();
|
||||
Reference in New Issue
Block a user