mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Added renameGlobal option
This commit is contained in:
+47
-17
@@ -39,29 +39,59 @@ describe('FunctionDeclarationTransformer', () => {
|
||||
});
|
||||
|
||||
describe('variant #2: `functionDeclaration` parent block scope is a `ProgramNode`', () => {
|
||||
const functionNameIdentifierRegExp: RegExp = /function *foo *\(\) *\{/;
|
||||
const functionCallIdentifierRegExp: RegExp = /foo *\( *\);/;
|
||||
describe('variant #1: `renameGlobals` option is disabled', () => {
|
||||
const functionNameIdentifierRegExp: RegExp = /function *foo *\(\) *\{/;
|
||||
const functionCallIdentifierRegExp: RegExp = /foo *\( *\);/;
|
||||
|
||||
let obfuscatedCode: string;
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/input.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_CUSTOM_NODES_PRESET
|
||||
}
|
||||
);
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/parent-block-scope-is-program-node.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_CUSTOM_NODES_PRESET
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('match #1: shouldn\'t transform function name', () => {
|
||||
assert.match(obfuscatedCode, functionNameIdentifierRegExp);
|
||||
});
|
||||
|
||||
it('match #2: shouldn\'t transform function name', () => {
|
||||
assert.match(obfuscatedCode, functionCallIdentifierRegExp);
|
||||
});
|
||||
});
|
||||
|
||||
it('match #1: shouldn\'t transform function name', () => {
|
||||
assert.match(obfuscatedCode, functionNameIdentifierRegExp);
|
||||
});
|
||||
describe('variant #2: `renameGlobals` option is enabled', () => {
|
||||
const functionNameIdentifierRegExp: RegExp = /function *(_0x[a-f0-9]{4,6}) *\(\) *\{/;
|
||||
const functionCallIdentifierRegExp: RegExp = /(_0x[a-f0-9]{4,6}) *\( *\);/;
|
||||
|
||||
it('match #2: shouldn\'t transform function name', () => {
|
||||
assert.match(obfuscatedCode, functionCallIdentifierRegExp);
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/parent-block-scope-is-program-node.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_CUSTOM_NODES_PRESET,
|
||||
renameGlobals: true
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('match #1: shouldn\'t transform function name', () => {
|
||||
assert.match(obfuscatedCode, functionNameIdentifierRegExp);
|
||||
});
|
||||
|
||||
it('match #2: shouldn\'t transform function name', () => {
|
||||
assert.match(obfuscatedCode, functionCallIdentifierRegExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
function foo () {
|
||||
}
|
||||
|
||||
if (true) {
|
||||
foo();
|
||||
}
|
||||
+47
-17
@@ -38,29 +38,59 @@ describe('VariableDeclarationTransformer', () => {
|
||||
});
|
||||
|
||||
describe('variant #2: parent block scope node is `Program` node', () => {
|
||||
const variableDeclarationRegExp: RegExp = /var *test *= *0xa;/;
|
||||
const variableCallRegExp: RegExp = /console\['log'\]\(test\);/;
|
||||
describe('variant #1: `renameGlobals` option is disabled', () => {
|
||||
const variableDeclarationRegExp: RegExp = /var *test *= *0xa;/;
|
||||
const variableCallRegExp: RegExp = /console\['log'\]\(test\);/;
|
||||
|
||||
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_CUSTOM_NODES_PRESET
|
||||
}
|
||||
);
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/parent-block-scope-is-program-node.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_CUSTOM_NODES_PRESET
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('match #1: shouldn\'t transform `variableDeclaration` node', () => {
|
||||
assert.match(obfuscatedCode, variableDeclarationRegExp);
|
||||
});
|
||||
|
||||
it('match #2: shouldn\'t transform `variableDeclaration` node', () => {
|
||||
assert.match(obfuscatedCode, variableCallRegExp);
|
||||
});
|
||||
});
|
||||
|
||||
it('match #1: shouldn\'t transform `variableDeclaration` node', () => {
|
||||
assert.match(obfuscatedCode, variableDeclarationRegExp);
|
||||
});
|
||||
describe('variant #2: `renameGlobals` option is enabled', () => {
|
||||
const variableDeclarationRegExp: RegExp = /var *_0x([a-f0-9]){4,6} *= *0xa;/;
|
||||
const variableCallRegExp: RegExp = /console\['log'\]\(_0x([a-f0-9]){4,6}\);/;
|
||||
|
||||
it('match #2: shouldn\'t transform `variableDeclaration` node', () => {
|
||||
assert.match(obfuscatedCode, variableCallRegExp);
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/parent-block-scope-is-program-node.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_CUSTOM_NODES_PRESET,
|
||||
renameGlobals: true
|
||||
}
|
||||
);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('match #1: should transform `variableDeclaration` node', () => {
|
||||
assert.match(obfuscatedCode, variableDeclarationRegExp);
|
||||
});
|
||||
|
||||
it('match #2: should transform `variableDeclaration` node', () => {
|
||||
assert.match(obfuscatedCode, variableCallRegExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user