mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Merge remote-tracking branch 'origin/dev'
This commit is contained in:
@@ -35,35 +35,21 @@ class VariableDeclarationObfuscator extends NodeObfuscator_1.NodeObfuscator {
|
|||||||
}
|
}
|
||||||
replaceVariableCalls(variableDeclarationNode, variableParentNode) {
|
replaceVariableCalls(variableDeclarationNode, variableParentNode) {
|
||||||
let scopeNode;
|
let scopeNode;
|
||||||
if (variableDeclarationNode.kind === 'var') {
|
scopeNode = variableDeclarationNode.kind === 'var' ? NodeUtils_1.NodeUtils.getNodeScope(variableDeclarationNode) : variableParentNode;
|
||||||
scopeNode = NodeUtils_1.NodeUtils.getNodeScope(variableDeclarationNode);
|
let isNodeAfterVariableDeclaratorFlag = false;
|
||||||
}
|
|
||||||
else {
|
|
||||||
scopeNode = variableParentNode;
|
|
||||||
}
|
|
||||||
let isNodeAfterVariableDeclaratorFlag = false, isNodeBeforeVariableDeclaratorFlag = true, functionParentScope, functionNextNode, functionIndex = -1;
|
|
||||||
estraverse.replace(scopeNode, {
|
estraverse.replace(scopeNode, {
|
||||||
enter: (node, parentNode) => {
|
enter: (node, parentNode) => {
|
||||||
if (node.type === 'FunctionDeclaration' ||
|
if (node.type === 'FunctionDeclaration' ||
|
||||||
node.type === 'FunctionExpression' ||
|
node.type === 'FunctionExpression' ||
|
||||||
node.type === 'ArrowFunctionExpression') {
|
node.type === 'ArrowFunctionExpression') {
|
||||||
functionParentScope = NodeUtils_1.NodeUtils.getNodeScope(node);
|
estraverse.replace(node, {
|
||||||
if (NodeUtils_1.NodeUtils.isBlockStatementNode(functionParentScope)) {
|
enter: (node, parentNode) => {
|
||||||
functionIndex = functionParentScope.body.indexOf(node);
|
this.replaceNodeIdentifierByNewValue(node, parentNode, this.variableNames);
|
||||||
if (functionIndex >= 0) {
|
|
||||||
functionNextNode = functionParentScope.body[functionIndex + 1];
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
isNodeAfterVariableDeclaratorFlag = true;
|
|
||||||
}
|
|
||||||
if (functionNextNode && isNodeBeforeVariableDeclaratorFlag && node === functionNextNode) {
|
|
||||||
isNodeAfterVariableDeclaratorFlag = false;
|
|
||||||
functionNextNode = undefined;
|
|
||||||
functionIndex = -1;
|
|
||||||
}
|
}
|
||||||
if (node === variableDeclarationNode) {
|
if (node === variableDeclarationNode) {
|
||||||
isNodeAfterVariableDeclaratorFlag = true;
|
isNodeAfterVariableDeclaratorFlag = true;
|
||||||
isNodeBeforeVariableDeclaratorFlag = false;
|
|
||||||
}
|
}
|
||||||
if (isNodeAfterVariableDeclaratorFlag) {
|
if (isNodeAfterVariableDeclaratorFlag) {
|
||||||
this.replaceNodeIdentifierByNewValue(node, parentNode, this.variableNames);
|
this.replaceNodeIdentifierByNewValue(node, parentNode, this.variableNames);
|
||||||
|
|||||||
@@ -68,21 +68,12 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
|
|||||||
private replaceVariableCalls (variableDeclarationNode: IVariableDeclarationNode, variableParentNode: ITreeNode): void {
|
private replaceVariableCalls (variableDeclarationNode: IVariableDeclarationNode, variableParentNode: ITreeNode): void {
|
||||||
let scopeNode: ITreeNode;
|
let scopeNode: ITreeNode;
|
||||||
|
|
||||||
if (variableDeclarationNode.kind === 'var') {
|
scopeNode = variableDeclarationNode.kind === 'var' ? NodeUtils.getNodeScope(
|
||||||
scopeNode = NodeUtils.getNodeScope(
|
variableDeclarationNode
|
||||||
variableDeclarationNode
|
) : variableParentNode;
|
||||||
);
|
|
||||||
} else {
|
|
||||||
scopeNode = variableParentNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
let isNodeAfterVariableDeclaratorFlag: boolean = false,
|
let isNodeAfterVariableDeclaratorFlag: boolean = false;
|
||||||
isNodeBeforeVariableDeclaratorFlag: boolean = true,
|
|
||||||
functionParentScope: ITreeNode,
|
|
||||||
functionNextNode: ITreeNode,
|
|
||||||
functionIndex: number = -1;
|
|
||||||
|
|
||||||
//TODO: REFACTOR THIS
|
|
||||||
estraverse.replace(scopeNode, {
|
estraverse.replace(scopeNode, {
|
||||||
enter: (node: ITreeNode, parentNode: ITreeNode) => {
|
enter: (node: ITreeNode, parentNode: ITreeNode) => {
|
||||||
if (
|
if (
|
||||||
@@ -90,28 +81,15 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
|
|||||||
node.type === 'FunctionExpression' ||
|
node.type === 'FunctionExpression' ||
|
||||||
node.type === 'ArrowFunctionExpression'
|
node.type === 'ArrowFunctionExpression'
|
||||||
) {
|
) {
|
||||||
functionParentScope = NodeUtils.getNodeScope(node);
|
estraverse.replace(node, {
|
||||||
|
enter: (node: ITreeNode, parentNode: ITreeNode) => {
|
||||||
if (NodeUtils.isBlockStatementNode(functionParentScope)) {
|
this.replaceNodeIdentifierByNewValue(node, parentNode, this.variableNames);
|
||||||
functionIndex = functionParentScope.body.indexOf(node);
|
|
||||||
|
|
||||||
if (functionIndex >= 0) {
|
|
||||||
functionNextNode = functionParentScope.body[functionIndex + 1];
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
isNodeAfterVariableDeclaratorFlag = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (functionNextNode && isNodeBeforeVariableDeclaratorFlag && node === functionNextNode) {
|
|
||||||
isNodeAfterVariableDeclaratorFlag = false;
|
|
||||||
functionNextNode = undefined;
|
|
||||||
functionIndex = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node === variableDeclarationNode) {
|
if (node === variableDeclarationNode) {
|
||||||
isNodeAfterVariableDeclaratorFlag = true;
|
isNodeAfterVariableDeclaratorFlag = true;
|
||||||
isNodeBeforeVariableDeclaratorFlag = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNodeAfterVariableDeclaratorFlag) {
|
if (isNodeAfterVariableDeclaratorFlag) {
|
||||||
@@ -120,4 +98,4 @@ export class VariableDeclarationObfuscator extends NodeObfuscator {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
var JavaScriptObfuscator = require('../index.js');
|
var JavaScriptObfuscator = require('../index.js');
|
||||||
var obfuscatedCode = JavaScriptObfuscator.obfuscate(`
|
var obfuscatedCode = JavaScriptObfuscator.obfuscate(`
|
||||||
(function(){
|
(function(){
|
||||||
var result = 1,
|
var result = 1,
|
||||||
term1 = 0,
|
term1 = 0,
|
||||||
term2 = 1,
|
term2 = 1,
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ var JavaScriptObfuscator = require('../index.js');
|
|||||||
|
|
||||||
var obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
var obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||||
`
|
`
|
||||||
(function(){
|
(function(){
|
||||||
var result = 1,
|
var result = 1,
|
||||||
term1 = 0,
|
term1 = 0,
|
||||||
term2 = 1,
|
term2 = 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user