mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Merge pull request #311 from javascript-obfuscator/function-obfuscation-bugs
Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/…
This commit is contained in:
@@ -3,6 +3,7 @@ Change Log
|
||||
v0.18.0
|
||||
---
|
||||
* **New option:** `reservedStrings` disables transformation of string literals, which being matched by passed RegExp patterns
|
||||
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/309
|
||||
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/307
|
||||
|
||||
v0.17.3
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -160,7 +160,14 @@ export class FunctionTransformer extends AbstractNodeTransformer {
|
||||
const replaceVisitor: estraverse.Visitor = {
|
||||
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void | estraverse.VisitorOption => {
|
||||
/**
|
||||
* Should to process nested functions in different traverse loop to avoid wrong code generation
|
||||
* Should skip function node itself
|
||||
*/
|
||||
if (node === functionNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should process nested functions in different traverse loop to avoid wrong code generation
|
||||
*/
|
||||
if (NodeGuards.isFunctionNode(node)) {
|
||||
this.replaceFunctionParams(node, lexicalScopeNode, new Set(ignoredIdentifierNamesSet));
|
||||
@@ -194,8 +201,6 @@ export class FunctionTransformer extends AbstractNodeTransformer {
|
||||
}
|
||||
};
|
||||
|
||||
functionNode.params.forEach((paramsNode: ESTree.Node) => estraverse.replace(paramsNode, replaceVisitor));
|
||||
|
||||
estraverse.replace(functionNode.body, replaceVisitor);
|
||||
estraverse.replace(functionNode, replaceVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -6,12 +6,12 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNo
|
||||
|
||||
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
`
|
||||
(function(){
|
||||
function foo ({id}) {
|
||||
function bar ({id: baz}) {
|
||||
return id !== baz;
|
||||
}
|
||||
(function(foo){
|
||||
function foo () {
|
||||
|
||||
}
|
||||
|
||||
return new foo();
|
||||
})();
|
||||
`,
|
||||
{
|
||||
|
||||
+60
-3
@@ -45,6 +45,63 @@ describe('FunctionTransformer', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('function id name obfuscation', () => {
|
||||
const functionExpressionParamIdentifierRegExp: RegExp = /\(function *\((_0x[a-f0-9]{4,6})\) *\{/;
|
||||
const functionParamIdentifierRegExp: RegExp = /function *(_0x[a-f0-9]{4,6}) *\(\) *\{/;
|
||||
const functionObjectIdentifierRegExp: RegExp = /return new (_0x[a-f0-9]{4,6}) *\(\);/;
|
||||
|
||||
let obfuscatedCode: string,
|
||||
functionExpressionParamIdentifierName: string,
|
||||
functionParamIdentifierName: string,
|
||||
functionObjectIdentifierName: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/function-id-name.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
|
||||
const functionExpressionParamIdentifierMatch: RegExpMatchArray|null = obfuscatedCode
|
||||
.match(functionExpressionParamIdentifierRegExp);
|
||||
const functionParamIdentifierMatch: RegExpMatchArray|null = obfuscatedCode
|
||||
.match(functionParamIdentifierRegExp);
|
||||
const functionObjectIdentifierMatch: RegExpMatchArray|null = obfuscatedCode
|
||||
.match(functionObjectIdentifierRegExp);
|
||||
|
||||
functionParamIdentifierName = (<RegExpMatchArray>functionParamIdentifierMatch)[1];
|
||||
functionExpressionParamIdentifierName = (<RegExpMatchArray>functionExpressionParamIdentifierMatch)[1];
|
||||
functionObjectIdentifierName = (<RegExpMatchArray>functionObjectIdentifierMatch)[1];
|
||||
});
|
||||
|
||||
it('should correctly transform function expression parameter identifier', () => {
|
||||
assert.match(obfuscatedCode, functionExpressionParamIdentifierRegExp);
|
||||
});
|
||||
|
||||
it('should correctly transform function parameter identifier', () => {
|
||||
assert.match(obfuscatedCode, functionParamIdentifierRegExp);
|
||||
});
|
||||
|
||||
it('should correctly transform function object parameter identifier', () => {
|
||||
assert.match(obfuscatedCode, functionObjectIdentifierRegExp);
|
||||
});
|
||||
|
||||
it('should generate same names for function parameter and function object identifiers', () => {
|
||||
assert.equal(functionParamIdentifierName, functionObjectIdentifierName);
|
||||
});
|
||||
|
||||
it('should generate same names for function parameter identifiers', () => {
|
||||
assert.equal(functionExpressionParamIdentifierName, functionParamIdentifierName);
|
||||
});
|
||||
|
||||
it('should generate same names for function expression parameter and function object identifiers', () => {
|
||||
assert.equal(functionExpressionParamIdentifierName, functionObjectIdentifierName);
|
||||
});
|
||||
});
|
||||
|
||||
describe('object pattern as parameter', () => {
|
||||
describe('Variant #1: simple', () => {
|
||||
const functionParameterRegExp: RegExp = /function *\(\{ *bar *\}\) *\{/;
|
||||
@@ -299,15 +356,15 @@ describe('FunctionTransformer', () => {
|
||||
assert.match(obfuscatedCode, functionBodyRegExp);
|
||||
});
|
||||
|
||||
it('equal #1: shouldn\'t keep same names variable declaration identifier and function parameters identifiers', () => {
|
||||
it('equal #1: shouldn\'t keep same names for variable declaration identifier and function parameters identifiers', () => {
|
||||
assert.notEqual(variableDeclarationIdentifierName, functionParameterIdentifierName);
|
||||
});
|
||||
|
||||
it('equal #2: shouldn\'t keep same names variable declaration identifier and function parameters identifiers', () => {
|
||||
it('equal #2: shouldn\'t keep same names for variable declaration identifier and function parameters identifiers', () => {
|
||||
assert.notEqual(variableDeclarationIdentifierName, functionDefaultParameterIdentifierName1);
|
||||
});
|
||||
|
||||
it('equal #3: shouldn\'t keep same names variable declaration identifier and function parameters identifiers', () => {
|
||||
it('equal #3: shouldn\'t keep same names for variable declaration identifier and function parameters identifiers', () => {
|
||||
assert.notEqual(variableDeclarationIdentifierName, functionDefaultParameterIdentifierName2);
|
||||
});
|
||||
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
(function(foo){
|
||||
function foo () {
|
||||
|
||||
}
|
||||
|
||||
return new foo();
|
||||
})();
|
||||
Reference in New Issue
Block a user