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:
@@ -1,5 +1,9 @@
|
||||
Change Log
|
||||
===
|
||||
v0.11.0
|
||||
---
|
||||
* **New option:** `renameGlobals` allows to enable obfuscation of global variable and function names with declaration.
|
||||
|
||||
v0.10.0
|
||||
---
|
||||
* **New option:** `deadCodeInjection`. With this option random blocks of dead code will add to the obfuscated code.
|
||||
|
||||
@@ -215,6 +215,7 @@ Following options are available for the JS Obfuscator:
|
||||
debugProtectionInterval: false,
|
||||
disableConsoleOutput: false,
|
||||
mangle: false,
|
||||
renameGlobals: false,
|
||||
reservedNames: [],
|
||||
rotateStringArray: true,
|
||||
seed: 0,
|
||||
@@ -247,6 +248,7 @@ Following options are available for the JS Obfuscator:
|
||||
--debugProtectionInterval <boolean>
|
||||
--disableConsoleOutput <boolean>
|
||||
--mangle <boolean>
|
||||
--renameGlobals <boolean>
|
||||
--reservedNames <list> (comma separated)
|
||||
--rotateStringArray <boolean>
|
||||
--seed <number>
|
||||
@@ -495,6 +497,13 @@ Type: `boolean` Default: `false`
|
||||
|
||||
Enables mangling of variable names.
|
||||
|
||||
### `renameGlobals`
|
||||
Type: `boolean` Default: `false`
|
||||
|
||||
Enables obfuscation of global variable and function names **with declaration**.
|
||||
|
||||
##### :warning: this option can break your code. Enable it only if you know what it does!
|
||||
|
||||
### `reservedNames`
|
||||
Type: `string[]` Default: `[]`
|
||||
|
||||
@@ -632,6 +641,7 @@ Performance will 50-100% slower than without obfuscation
|
||||
debugProtectionInterval: true,
|
||||
disableConsoleOutput: true,
|
||||
mangle: false,
|
||||
renameGlobals: false,
|
||||
rotateStringArray: true,
|
||||
selfDefending: true,
|
||||
stringArray: true,
|
||||
@@ -656,6 +666,7 @@ Performance will 30-35% slower than without obfuscation
|
||||
debugProtectionInterval: false,
|
||||
disableConsoleOutput: true,
|
||||
mangle: false,
|
||||
renameGlobals: false,
|
||||
rotateStringArray: true,
|
||||
selfDefending: true,
|
||||
stringArray: true,
|
||||
@@ -678,6 +689,7 @@ Performance will slightly slower than without obfuscation
|
||||
debugProtectionInterval: false,
|
||||
disableConsoleOutput: true,
|
||||
mangle: true,
|
||||
renameGlobals: false,
|
||||
rotateStringArray: true,
|
||||
selfDefending: true,
|
||||
stringArray: true,
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "javascript-obfuscator",
|
||||
"version": "0.10.0",
|
||||
"version": "0.11.0-beta.1",
|
||||
"description": "JavaScript obfuscator",
|
||||
"keywords": [
|
||||
"obfuscator",
|
||||
|
||||
@@ -175,6 +175,10 @@ export class JavaScriptObfuscatorCLI {
|
||||
'Disable obfuscation of variable names, function names and names of function parameters that match the passed RegExp patterns (comma separated)',
|
||||
(value: string) => value.split(',')
|
||||
)
|
||||
.option(
|
||||
'--renameGlobals <boolean>', 'Allows to enable obfuscation of global variable and function names with declaration.',
|
||||
BooleanSanitizer
|
||||
)
|
||||
.option(
|
||||
'--rotateStringArray <boolean>', 'Disable rotation of unicode array values during obfuscation',
|
||||
BooleanSanitizer
|
||||
|
||||
Vendored
+1
@@ -12,6 +12,7 @@ export interface IOptions {
|
||||
readonly disableConsoleOutput: boolean;
|
||||
readonly domainLock: string[];
|
||||
readonly mangle: boolean;
|
||||
readonly renameGlobals: boolean;
|
||||
readonly reservedNames: string[];
|
||||
readonly rotateStringArray: boolean;
|
||||
readonly seed: number;
|
||||
|
||||
@@ -81,7 +81,7 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
|
||||
const blockScopeOfFunctionDeclarationNode: TNodeWithBlockStatement = NodeUtils
|
||||
.getBlockScopesOfNode(functionDeclarationNode)[0];
|
||||
|
||||
if (blockScopeOfFunctionDeclarationNode.type === NodeType.Program) {
|
||||
if (!this.options.renameGlobals && blockScopeOfFunctionDeclarationNode.type === NodeType.Program) {
|
||||
return functionDeclarationNode;
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ export class VariableDeclarationTransformer extends AbstractNodeTransformer {
|
||||
const blockScopeOfVariableDeclarationNode: TNodeWithBlockStatement = NodeUtils
|
||||
.getBlockScopesOfNode(variableDeclarationNode)[0];
|
||||
|
||||
if (blockScopeOfVariableDeclarationNode.type === NodeType.Program) {
|
||||
if (!this.options.renameGlobals && blockScopeOfVariableDeclarationNode.type === NodeType.Program) {
|
||||
return variableDeclarationNode;
|
||||
}
|
||||
|
||||
|
||||
@@ -105,6 +105,12 @@ export class Options implements IOptions {
|
||||
@IsBoolean()
|
||||
public readonly mangle: boolean;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
@IsBoolean()
|
||||
public readonly renameGlobals: boolean;
|
||||
|
||||
/**
|
||||
* @type {string[]}
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,7 @@ export const DEFAULT_PRESET: TInputOptions = Object.freeze({
|
||||
disableConsoleOutput: false,
|
||||
domainLock: [],
|
||||
mangle: false,
|
||||
renameGlobals: false,
|
||||
reservedNames: [],
|
||||
rotateStringArray: true,
|
||||
seed: 0,
|
||||
|
||||
@@ -13,6 +13,7 @@ export const NO_CUSTOM_NODES_PRESET: TInputOptions = Object.freeze({
|
||||
disableConsoleOutput: false,
|
||||
domainLock: [],
|
||||
mangle: false,
|
||||
renameGlobals: false,
|
||||
reservedNames: [],
|
||||
rotateStringArray: false,
|
||||
seed: 0,
|
||||
|
||||
+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