mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
IdentifierReplacer temp workaround with runtime crash because we caching node transformers
This commit is contained in:
Vendored
+32
-2
@@ -3541,6 +3541,7 @@ var NodeType_1 = __webpack_require__(9);
|
||||
var AbstractNodeTransformer_1 = __webpack_require__(11);
|
||||
var Node_1 = __webpack_require__(4);
|
||||
var NodeUtils_1 = __webpack_require__(10);
|
||||
var Utils_1 = __webpack_require__(0);
|
||||
var CatchClauseObfuscator = function (_AbstractNodeTransfor) {
|
||||
_inherits(CatchClauseObfuscator, _AbstractNodeTransfor);
|
||||
|
||||
@@ -3556,6 +3557,10 @@ var CatchClauseObfuscator = function (_AbstractNodeTransfor) {
|
||||
_createClass(CatchClauseObfuscator, [{
|
||||
key: "transformNode",
|
||||
value: function transformNode(catchClauseNode) {
|
||||
this.identifierReplacer.setPrefix(Utils_1.Utils.getRandomGenerator().string({
|
||||
length: 5,
|
||||
pool: Utils_1.Utils.randomGeneratorPool
|
||||
}));
|
||||
this.storeCatchClauseParam(catchClauseNode);
|
||||
this.replaceCatchClauseParam(catchClauseNode);
|
||||
}
|
||||
@@ -3631,6 +3636,7 @@ var NodeType_1 = __webpack_require__(9);
|
||||
var AbstractNodeTransformer_1 = __webpack_require__(11);
|
||||
var Node_1 = __webpack_require__(4);
|
||||
var NodeUtils_1 = __webpack_require__(10);
|
||||
var Utils_1 = __webpack_require__(0);
|
||||
var FunctionDeclarationObfuscator = function (_AbstractNodeTransfor) {
|
||||
_inherits(FunctionDeclarationObfuscator, _AbstractNodeTransfor);
|
||||
|
||||
@@ -3646,6 +3652,10 @@ var FunctionDeclarationObfuscator = function (_AbstractNodeTransfor) {
|
||||
_createClass(FunctionDeclarationObfuscator, [{
|
||||
key: "transformNode",
|
||||
value: function transformNode(functionDeclarationNode, parentNode) {
|
||||
this.identifierReplacer.setPrefix(Utils_1.Utils.getRandomGenerator().string({
|
||||
length: 5,
|
||||
pool: Utils_1.Utils.randomGeneratorPool
|
||||
}));
|
||||
var blockScopeOfFunctionDeclarationNode = NodeUtils_1.NodeUtils.getBlockScopeOfNode(functionDeclarationNode);
|
||||
if (blockScopeOfFunctionDeclarationNode.type === NodeType_1.NodeType.Program) {
|
||||
return;
|
||||
@@ -3725,6 +3735,7 @@ var NodeType_1 = __webpack_require__(9);
|
||||
var AbstractNodeTransformer_1 = __webpack_require__(11);
|
||||
var Node_1 = __webpack_require__(4);
|
||||
var NodeUtils_1 = __webpack_require__(10);
|
||||
var Utils_1 = __webpack_require__(0);
|
||||
var FunctionObfuscator = function (_AbstractNodeTransfor) {
|
||||
_inherits(FunctionObfuscator, _AbstractNodeTransfor);
|
||||
|
||||
@@ -3740,6 +3751,10 @@ var FunctionObfuscator = function (_AbstractNodeTransfor) {
|
||||
_createClass(FunctionObfuscator, [{
|
||||
key: "transformNode",
|
||||
value: function transformNode(functionNode) {
|
||||
this.identifierReplacer.setPrefix(Utils_1.Utils.getRandomGenerator().string({
|
||||
length: 5,
|
||||
pool: Utils_1.Utils.randomGeneratorPool
|
||||
}));
|
||||
this.storeFunctionParams(functionNode);
|
||||
this.replaceFunctionParams(functionNode);
|
||||
}
|
||||
@@ -3825,6 +3840,7 @@ var NodeType_1 = __webpack_require__(9);
|
||||
var AbstractNodeTransformer_1 = __webpack_require__(11);
|
||||
var Node_1 = __webpack_require__(4);
|
||||
var NodeUtils_1 = __webpack_require__(10);
|
||||
var Utils_1 = __webpack_require__(0);
|
||||
var LabeledStatementObfuscator = function (_AbstractNodeTransfor) {
|
||||
_inherits(LabeledStatementObfuscator, _AbstractNodeTransfor);
|
||||
|
||||
@@ -3840,6 +3856,10 @@ var LabeledStatementObfuscator = function (_AbstractNodeTransfor) {
|
||||
_createClass(LabeledStatementObfuscator, [{
|
||||
key: "transformNode",
|
||||
value: function transformNode(labeledStatementNode) {
|
||||
this.identifierReplacer.setPrefix(Utils_1.Utils.getRandomGenerator().string({
|
||||
length: 5,
|
||||
pool: Utils_1.Utils.randomGeneratorPool
|
||||
}));
|
||||
this.storeLabeledStatementName(labeledStatementNode);
|
||||
this.replaceLabeledStatementName(labeledStatementNode);
|
||||
}
|
||||
@@ -4292,6 +4312,7 @@ var NodeType_1 = __webpack_require__(9);
|
||||
var AbstractNodeTransformer_1 = __webpack_require__(11);
|
||||
var Node_1 = __webpack_require__(4);
|
||||
var NodeUtils_1 = __webpack_require__(10);
|
||||
var Utils_1 = __webpack_require__(0);
|
||||
var VariableDeclarationObfuscator = function (_AbstractNodeTransfor) {
|
||||
_inherits(VariableDeclarationObfuscator, _AbstractNodeTransfor);
|
||||
|
||||
@@ -4307,6 +4328,10 @@ var VariableDeclarationObfuscator = function (_AbstractNodeTransfor) {
|
||||
_createClass(VariableDeclarationObfuscator, [{
|
||||
key: "transformNode",
|
||||
value: function transformNode(variableDeclarationNode, parentNode) {
|
||||
this.identifierReplacer.setPrefix(Utils_1.Utils.getRandomGenerator().string({
|
||||
length: 5,
|
||||
pool: Utils_1.Utils.randomGeneratorPool
|
||||
}));
|
||||
var blockScopeOfVariableDeclarationNode = NodeUtils_1.NodeUtils.getBlockScopeOfNode(variableDeclarationNode);
|
||||
if (blockScopeOfVariableDeclarationNode.type === NodeType_1.NodeType.Program) {
|
||||
return;
|
||||
@@ -4458,17 +4483,22 @@ var IdentifierReplacer = function (_AbstractReplacer_1$A) {
|
||||
_createClass(IdentifierReplacer, [{
|
||||
key: "replace",
|
||||
value: function replace(nodeValue) {
|
||||
var obfuscatedIdentifierName = this.namesMap.get(nodeValue);
|
||||
var obfuscatedIdentifierName = this.namesMap.get(nodeValue + "-" + this.uniquePrefix);
|
||||
if (!obfuscatedIdentifierName) {
|
||||
return nodeValue;
|
||||
}
|
||||
return obfuscatedIdentifierName;
|
||||
}
|
||||
}, {
|
||||
key: "setPrefix",
|
||||
value: function setPrefix(uniquePrefix) {
|
||||
this.uniquePrefix = uniquePrefix;
|
||||
}
|
||||
}, {
|
||||
key: "storeNames",
|
||||
value: function storeNames(nodeName) {
|
||||
if (!this.isReservedName(nodeName)) {
|
||||
this.namesMap.set(nodeName, Utils_1.Utils.getRandomVariableName());
|
||||
this.namesMap.set(nodeName + "-" + this.uniquePrefix, Utils_1.Utils.getRandomVariableName());
|
||||
}
|
||||
}
|
||||
}, {
|
||||
|
||||
@@ -16,6 +16,7 @@ import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
|
||||
import { IdentifierReplacer } from './replacers/IdentifierReplacer';
|
||||
import { Node } from '../../node/Node';
|
||||
import { NodeUtils } from '../../node/NodeUtils';
|
||||
import { Utils } from '../../Utils';
|
||||
|
||||
/**
|
||||
* replaces:
|
||||
@@ -51,6 +52,11 @@ export class CatchClauseObfuscator extends AbstractNodeTransformer {
|
||||
* @param catchClauseNode
|
||||
*/
|
||||
public transformNode (catchClauseNode: ESTree.CatchClause): void {
|
||||
this.identifierReplacer.setPrefix(Utils.getRandomGenerator().string({
|
||||
length: 5,
|
||||
pool: Utils.randomGeneratorPool
|
||||
}));
|
||||
|
||||
this.storeCatchClauseParam(catchClauseNode);
|
||||
this.replaceCatchClauseParam(catchClauseNode);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
|
||||
import { IdentifierReplacer } from './replacers/IdentifierReplacer';
|
||||
import { Node } from '../../node/Node';
|
||||
import { NodeUtils } from '../../node/NodeUtils';
|
||||
import { Utils } from '../../Utils';
|
||||
|
||||
/**
|
||||
* replaces:
|
||||
@@ -55,6 +56,11 @@ export class FunctionDeclarationObfuscator extends AbstractNodeTransformer {
|
||||
* @param parentNode
|
||||
*/
|
||||
public transformNode (functionDeclarationNode: ESTree.FunctionDeclaration, parentNode: ESTree.Node): void {
|
||||
this.identifierReplacer.setPrefix(Utils.getRandomGenerator().string({
|
||||
length: 5,
|
||||
pool: Utils.randomGeneratorPool
|
||||
}));
|
||||
|
||||
const blockScopeOfFunctionDeclarationNode: TNodeWithBlockStatement = NodeUtils
|
||||
.getBlockScopeOfNode(functionDeclarationNode);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
|
||||
import { IdentifierReplacer } from './replacers/IdentifierReplacer';
|
||||
import { Node } from '../../node/Node';
|
||||
import { NodeUtils } from '../../node/NodeUtils';
|
||||
import { Utils } from '../../Utils';
|
||||
|
||||
/**
|
||||
* replaces:
|
||||
@@ -51,6 +52,11 @@ export class FunctionObfuscator extends AbstractNodeTransformer {
|
||||
* @param functionNode
|
||||
*/
|
||||
public transformNode (functionNode: ESTree.Function): void {
|
||||
this.identifierReplacer.setPrefix(Utils.getRandomGenerator().string({
|
||||
length: 5,
|
||||
pool: Utils.randomGeneratorPool
|
||||
}));
|
||||
|
||||
this.storeFunctionParams(functionNode);
|
||||
this.replaceFunctionParams(functionNode);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
|
||||
import { IdentifierReplacer } from './replacers/IdentifierReplacer';
|
||||
import { Node } from '../../node/Node';
|
||||
import { NodeUtils } from '../../node/NodeUtils';
|
||||
import { Utils } from '../../Utils';
|
||||
|
||||
/**
|
||||
* replaces:
|
||||
@@ -59,6 +60,11 @@ export class LabeledStatementObfuscator extends AbstractNodeTransformer {
|
||||
* @param labeledStatementNode
|
||||
*/
|
||||
public transformNode (labeledStatementNode: ESTree.LabeledStatement): void {
|
||||
this.identifierReplacer.setPrefix(Utils.getRandomGenerator().string({
|
||||
length: 5,
|
||||
pool: Utils.randomGeneratorPool
|
||||
}));
|
||||
|
||||
this.storeLabeledStatementName(labeledStatementNode);
|
||||
this.replaceLabeledStatementName(labeledStatementNode);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
|
||||
import { IdentifierReplacer } from './replacers/IdentifierReplacer';
|
||||
import { Node } from '../../node/Node';
|
||||
import { NodeUtils } from '../../node/NodeUtils';
|
||||
import { Utils } from '../../Utils';
|
||||
|
||||
/**
|
||||
* replaces:
|
||||
@@ -56,6 +57,11 @@ export class VariableDeclarationObfuscator extends AbstractNodeTransformer {
|
||||
* @param parentNode
|
||||
*/
|
||||
public transformNode (variableDeclarationNode: ESTree.VariableDeclaration, parentNode: ESTree.Node): void {
|
||||
this.identifierReplacer.setPrefix(Utils.getRandomGenerator().string({
|
||||
length: 5,
|
||||
pool: Utils.randomGeneratorPool
|
||||
}));
|
||||
|
||||
const blockScopeOfVariableDeclarationNode: TNodeWithBlockStatement = NodeUtils
|
||||
.getBlockScopeOfNode(variableDeclarationNode);
|
||||
|
||||
|
||||
@@ -15,6 +15,11 @@ export class IdentifierReplacer extends AbstractReplacer {
|
||||
*/
|
||||
private readonly namesMap: Map<string, string> = new Map<string, string>();
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
private uniquePrefix: string;
|
||||
|
||||
/**
|
||||
* @param customNodesStorage
|
||||
* @param options
|
||||
@@ -31,7 +36,7 @@ export class IdentifierReplacer extends AbstractReplacer {
|
||||
* @returns {string}
|
||||
*/
|
||||
public replace (nodeValue: string): string {
|
||||
const obfuscatedIdentifierName: string|undefined = this.namesMap.get(nodeValue);
|
||||
const obfuscatedIdentifierName: string|undefined = this.namesMap.get(`${nodeValue}-${this.uniquePrefix}`);
|
||||
|
||||
if (!obfuscatedIdentifierName) {
|
||||
return nodeValue;
|
||||
@@ -40,6 +45,13 @@ export class IdentifierReplacer extends AbstractReplacer {
|
||||
return obfuscatedIdentifierName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uniquePrefix
|
||||
*/
|
||||
public setPrefix (uniquePrefix: string): void {
|
||||
this.uniquePrefix = uniquePrefix
|
||||
}
|
||||
|
||||
/**
|
||||
* Store all identifiers names as keys in given `namesMap` with random names as value.
|
||||
* Reserved names will be ignored.
|
||||
@@ -48,7 +60,7 @@ export class IdentifierReplacer extends AbstractReplacer {
|
||||
*/
|
||||
public storeNames (nodeName: string): void {
|
||||
if (!this.isReservedName(nodeName)) {
|
||||
this.namesMap.set(nodeName, Utils.getRandomVariableName());
|
||||
this.namesMap.set(`${nodeName}-${this.uniquePrefix}`, Utils.getRandomVariableName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user