This commit is contained in:
sanex3339
2016-08-29 21:05:44 +03:00
parent d2beb79ec5
commit a23d7f1b6a
9 changed files with 170 additions and 52 deletions
+77 -20
View File
@@ -486,16 +486,16 @@ var NodeObfuscator = function () {
throw new ReferenceError('`unicodeArrayNode` node is not found in Map with custom nodes.');
}
var unicodeArray = unicodeArrayNode.getNodeData(),
valueIndex = unicodeArray.indexOf(value),
literalValueCallIndex = void 0,
indexOfExistingValue = unicodeArray.getIndexOf(value),
indexOfValue = void 0,
hexadecimalIndex = void 0;
if (valueIndex >= 0) {
literalValueCallIndex = valueIndex;
if (indexOfExistingValue >= 0) {
indexOfValue = indexOfExistingValue;
} else {
literalValueCallIndex = unicodeArray.length;
indexOfValue = unicodeArray.getLength();
unicodeArrayNode.updateNodeData(value);
}
hexadecimalIndex = this.replaceLiteralNumberWithHexadecimalValue(literalValueCallIndex);
hexadecimalIndex = this.replaceLiteralNumberWithHexadecimalValue(indexOfValue);
if (this.options.wrapUnicodeArrayCalls) {
var unicodeArrayCallsWrapper = this.nodes.get('unicodeArrayCallsWrapper');
if (!unicodeArrayCallsWrapper) {
@@ -1687,7 +1687,7 @@ var UnicodeArrayCallsWrapper = function (_Node_1$Node) {
_createClass(UnicodeArrayCallsWrapper, [{
key: "appendNode",
value: function appendNode(blockScopeNode) {
if (!this.unicodeArray.length) {
if (!this.unicodeArray.getLength()) {
return;
}
NodeUtils_1.NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), 1);
@@ -1763,7 +1763,7 @@ var UnicodeArrayDecodeNode = function (_Node_1$Node) {
_createClass(UnicodeArrayDecodeNode, [{
key: "appendNode",
value: function appendNode(blockScopeNode) {
if (!this.unicodeArray.length) {
if (!this.unicodeArray.getLength()) {
return;
}
NodeUtils_1.NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), 1);
@@ -1822,21 +1822,20 @@ var AppendState_1 = __webpack_require__(2);
var UnicodeArrayTemplate_1 = __webpack_require__(58);
var Node_1 = __webpack_require__(3);
var NodeUtils_1 = __webpack_require__(1);
var Utils_1 = __webpack_require__(0);
var UnicodeArrayNode = function (_Node_1$Node) {
_inherits(UnicodeArrayNode, _Node_1$Node);
function UnicodeArrayNode(unicodeArrayName) {
var unicodeArrayRotateValue = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
var options = arguments[2];
function UnicodeArrayNode(unicodeArray, unicodeArrayName) {
var unicodeArrayRotateValue = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
var options = arguments[3];
_classCallCheck(this, UnicodeArrayNode);
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(UnicodeArrayNode).call(this, options));
_this.appendState = AppendState_1.AppendState.AfterObfuscation;
_this.unicodeArray = [];
_this.unicodeArray = unicodeArray;
_this.unicodeArrayName = unicodeArrayName;
_this.unicodeArrayRotateValue = unicodeArrayRotateValue;
return _this;
@@ -1845,7 +1844,7 @@ var UnicodeArrayNode = function (_Node_1$Node) {
_createClass(UnicodeArrayNode, [{
key: 'appendNode',
value: function appendNode(blockScopeNode) {
if (!this.unicodeArray.length) {
if (!this.unicodeArray.getLength()) {
return;
}
NodeUtils_1.NodeUtils.prependNode(blockScopeNode.body, this.getNode());
@@ -1863,20 +1862,20 @@ var UnicodeArrayNode = function (_Node_1$Node) {
}, {
key: 'getNode',
value: function getNode() {
Utils_1.Utils.arrayRotate(this.unicodeArray, this.unicodeArrayRotateValue);
this.unicodeArray.rotateArray(this.unicodeArrayRotateValue);
return _get(Object.getPrototypeOf(UnicodeArrayNode.prototype), 'getNode', this).call(this);
}
}, {
key: 'updateNodeData',
value: function updateNodeData(data) {
this.unicodeArray.push(data);
this.unicodeArray.addToArray(data);
}
}, {
key: 'getNodeStructure',
value: function getNodeStructure() {
return NodeUtils_1.NodeUtils.convertCodeToStructure(UnicodeArrayTemplate_1.UnicodeArrayTemplate().formatUnicorn({
unicodeArrayName: this.unicodeArrayName,
unicodeArray: this.unicodeArray.join(',')
unicodeArray: this.unicodeArray.toString()
}));
}
}]);
@@ -1932,7 +1931,7 @@ var UnicodeArrayRotateFunctionNode = function (_Node_1$Node) {
_createClass(UnicodeArrayRotateFunctionNode, [{
key: "appendNode",
value: function appendNode(blockScopeNode) {
if (!this.unicodeArray.length) {
if (!this.unicodeArray.getLength()) {
return;
}
NodeUtils_1.NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), 1);
@@ -2101,6 +2100,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var NodesGroup_1 = __webpack_require__(12);
var UnicodeArray_1 = __webpack_require__(67);
var UnicodeArrayCallsWrapper_1 = __webpack_require__(30);
var UnicodeArrayDecodeNode_1 = __webpack_require__(31);
var UnicodeArrayNode_1 = __webpack_require__(32);
@@ -2128,8 +2128,8 @@ var UnicodeArrayNodesGroup = function (_NodesGroup_1$NodesGr) {
} else {
_this.unicodeArrayRotateValue = 0;
}
var unicodeArrayNode = new UnicodeArrayNode_1.UnicodeArrayNode(_this.unicodeArrayName, _this.unicodeArrayRotateValue, _this.options),
unicodeArray = unicodeArrayNode.getNodeData();
var unicodeArray = new UnicodeArray_1.UnicodeArray(),
unicodeArrayNode = new UnicodeArrayNode_1.UnicodeArrayNode(unicodeArray, _this.unicodeArrayName, _this.unicodeArrayRotateValue, _this.options);
_this.nodes.set('unicodeArrayNode', unicodeArrayNode);
if (_this.options.wrapUnicodeArrayCalls) {
_this.nodes.set('unicodeArrayCallsWrapper', new UnicodeArrayCallsWrapper_1.UnicodeArrayCallsWrapper(_this.unicodeArrayTranslatorName, _this.unicodeArrayName, unicodeArray, _this.options));
@@ -3185,6 +3185,63 @@ if (!global._babelPolyfill) {
}
module.exports = JavaScriptObfuscator_1.JavaScriptObfuscator;
/***/ },
/* 67 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
"use strict";
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Utils_1 = __webpack_require__(0);
var UnicodeArray = function () {
function UnicodeArray() {
_classCallCheck(this, UnicodeArray);
this.array = [];
}
_createClass(UnicodeArray, [{
key: "addToArray",
value: function addToArray(value) {
this.array.push(value);
}
}, {
key: "getArray",
value: function getArray() {
return this.array;
}
}, {
key: "getIndexOf",
value: function getIndexOf(value) {
return this.array.indexOf(value);
}
}, {
key: "getLength",
value: function getLength() {
return this.array.length;
}
}, {
key: "rotateArray",
value: function rotateArray(rotationValue) {
this.array = Utils_1.Utils.arrayRotate(this.array, rotationValue);
}
}, {
key: "toString",
value: function toString() {
return this.array.toString();
}
}]);
return UnicodeArray;
}();
exports.UnicodeArray = UnicodeArray;
/***/ }
/******/ ]);
//# sourceMappingURL=index.js.map
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "javascript-obfuscator",
"version": "0.7.0",
"version": "0.8.0-dev.0",
"description": "JavaScript obfuscator",
"keywords": [
"obfuscator",
+51
View File
@@ -0,0 +1,51 @@
import { Utils } from "./Utils";
export class UnicodeArray {
/**
* @type {string[]}
*/
private array: string[] = [];
/**
* @param value
*/
public addToArray (value: string): void {
this.array.push(value);
}
/**
* @returns {string[]}
*/
public getArray (): string[] {
return this.array;
}
/**
* @param value
* @returns {number}
*/
public getIndexOf(value: string): number {
return this.array.indexOf(value);
}
/**
* @returns {number}
*/
public getLength (): number {
return this.array.length;
}
/**
* @param rotationValue
*/
public rotateArray (rotationValue: number): void {
this.array = Utils.arrayRotate(this.array, rotationValue);
}
/**
* @returns {string}
*/
public toString (): string {
return this.array.toString();
}
}
@@ -11,6 +11,7 @@ import { UnicodeArrayCallsWrapperTemplate } from "../../templates/custom-nodes/u
import { Node } from '../Node';
import { NodeUtils } from "../../NodeUtils";
import { UnicodeArray } from "../../UnicodeArray";
import { Utils } from "../../Utils";
export class UnicodeArrayCallsWrapper extends Node {
@@ -20,9 +21,9 @@ export class UnicodeArrayCallsWrapper extends Node {
protected appendState: AppendState = AppendState.AfterObfuscation;
/**
* @type {string[]}
* @type {UnicodeArray}
*/
private unicodeArray: string[];
private unicodeArray: UnicodeArray;
/**
* @type {string}
@@ -43,7 +44,7 @@ export class UnicodeArrayCallsWrapper extends Node {
constructor (
unicodeArrayCallsWrapperName: string,
unicodeArrayName: string,
unicodeArray: string[],
unicodeArray: UnicodeArray,
options: IOptions
) {
super(options);
@@ -57,7 +58,7 @@ export class UnicodeArrayCallsWrapper extends Node {
* @param blockScopeNode
*/
public appendNode (blockScopeNode: TNodeWithBlockStatement): void {
if (!this.unicodeArray.length) {
if (!this.unicodeArray.getLength()) {
return;
}
@@ -16,6 +16,7 @@ import { UnicodeArrayDecodeTemplate } from "../../templates/custom-nodes/unicode
import { JavaScriptObfuscator } from '../../JavaScriptObfuscator';
import { Node } from '../Node';
import { NodeUtils } from "../../NodeUtils";
import { UnicodeArray } from "../../UnicodeArray";
export class UnicodeArrayDecodeNode extends Node {
/**
@@ -24,9 +25,9 @@ export class UnicodeArrayDecodeNode extends Node {
protected appendState: AppendState = AppendState.AfterObfuscation;
/**
* @type {string[]}
* @type {UnicodeArray}
*/
private unicodeArray: string[];
private unicodeArray: UnicodeArray;
/**
* @type {string}
@@ -40,7 +41,7 @@ export class UnicodeArrayDecodeNode extends Node {
*/
constructor (
unicodeArrayName: string,
unicodeArray: string[],
unicodeArray: UnicodeArray,
options: IOptions
) {
super(options);
@@ -53,7 +54,7 @@ export class UnicodeArrayDecodeNode extends Node {
* @param blockScopeNode
*/
public appendNode (blockScopeNode: TNodeWithBlockStatement): void {
if (!this.unicodeArray.length) {
if (!this.unicodeArray.getLength()) {
return;
}
@@ -7,11 +7,12 @@ import { TNodeWithBlockStatement } from "../../types/TNodeWithBlockStatement";
import { AppendState } from '../../enums/AppendState';
import { UnicodeArray } from '../../UnicodeArray';
import { UnicodeArrayTemplate } from "../../templates/custom-nodes/unicode-array-nodes/unicode-array-node/UnicodeArrayTemplate";
import { Node } from '../Node';
import { NodeUtils } from "../../NodeUtils";
import { Utils } from '../../Utils';
export class UnicodeArrayNode extends Node {
/**
@@ -25,9 +26,9 @@ export class UnicodeArrayNode extends Node {
protected appendState: AppendState = AppendState.AfterObfuscation;
/**
* @type {string[]}
* @type {UnicodeArray}
*/
private unicodeArray: string[] = [];
private unicodeArray: UnicodeArray;
/**
* @type {string}
@@ -40,17 +41,20 @@ export class UnicodeArrayNode extends Node {
private unicodeArrayRotateValue: number;
/**
* @param unicodeArray
* @param unicodeArrayName
* @param unicodeArrayRotateValue
* @param options
*/
constructor (
unicodeArray: UnicodeArray,
unicodeArrayName: string,
unicodeArrayRotateValue: number = 0,
options: IOptions
) {
super(options);
this.unicodeArray = unicodeArray;
this.unicodeArrayName = unicodeArrayName;
this.unicodeArrayRotateValue = unicodeArrayRotateValue;
}
@@ -59,7 +63,7 @@ export class UnicodeArrayNode extends Node {
* @param blockScopeNode
*/
public appendNode (blockScopeNode: TNodeWithBlockStatement): void {
if (!this.unicodeArray.length) {
if (!this.unicodeArray.getLength()) {
return;
}
@@ -74,9 +78,9 @@ export class UnicodeArrayNode extends Node {
}
/**
* @returns {string[]}
* @returns {UnicodeArray}
*/
public getNodeData (): string[] {
public getNodeData (): UnicodeArray {
return this.unicodeArray;
}
@@ -84,7 +88,7 @@ export class UnicodeArrayNode extends Node {
* @returns {INode}
*/
public getNode (): INode {
Utils.arrayRotate <string> (this.unicodeArray, this.unicodeArrayRotateValue);
this.unicodeArray.rotateArray(this.unicodeArrayRotateValue);
return super.getNode();
}
@@ -93,7 +97,7 @@ export class UnicodeArrayNode extends Node {
* @param data
*/
public updateNodeData (data: string): void {
this.unicodeArray.push(data);
this.unicodeArray.addToArray(data);
}
/**
@@ -103,7 +107,7 @@ export class UnicodeArrayNode extends Node {
return NodeUtils.convertCodeToStructure(
UnicodeArrayTemplate().formatUnicorn({
unicodeArrayName: this.unicodeArrayName,
unicodeArray: this.unicodeArray.join(',')
unicodeArray: this.unicodeArray.toString()
})
);
}
@@ -15,6 +15,7 @@ import { UnicodeArrayRotateFunctionTemplate } from "../../templates/custom-nodes
import { JavaScriptObfuscator } from "../../JavaScriptObfuscator";
import { Node } from '../Node';
import { NodeUtils } from "../../NodeUtils";
import { UnicodeArray } from "../../UnicodeArray";
import { Utils } from "../../Utils";
export class UnicodeArrayRotateFunctionNode extends Node {
@@ -24,9 +25,9 @@ export class UnicodeArrayRotateFunctionNode extends Node {
protected appendState: AppendState = AppendState.AfterObfuscation;
/**
* @type {string[]}
* @type {UnicodeArray}
*/
private unicodeArray: string[];
private unicodeArray: UnicodeArray;
/**
* @type {string}
@@ -46,7 +47,7 @@ export class UnicodeArrayRotateFunctionNode extends Node {
*/
constructor (
unicodeArrayName: string,
unicodeArray: string[],
unicodeArray: UnicodeArray,
unicodeArrayRotateValue: number,
options: IOptions
) {
@@ -61,7 +62,7 @@ export class UnicodeArrayRotateFunctionNode extends Node {
* @param blockScopeNode
*/
public appendNode (blockScopeNode: TNodeWithBlockStatement): void {
if (!this.unicodeArray.length) {
if (!this.unicodeArray.getLength()) {
return;
}
+5 -3
View File
@@ -1,6 +1,7 @@
import { IOptions } from "../interfaces/IOptions";
import { NodesGroup } from './NodesGroup';
import { UnicodeArray } from "../UnicodeArray";
import { UnicodeArrayCallsWrapper } from "../custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper";
import { UnicodeArrayDecodeNode } from "../custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNode";
import { UnicodeArrayNode } from '../custom-nodes/unicode-array-nodes/UnicodeArrayNode';
@@ -42,12 +43,13 @@ export class UnicodeArrayNodesGroup extends NodesGroup {
this.unicodeArrayRotateValue = 0;
}
let unicodeArrayNode: UnicodeArrayNode = new UnicodeArrayNode(
let unicodeArray: UnicodeArray = new UnicodeArray(),
unicodeArrayNode: UnicodeArrayNode = new UnicodeArrayNode(
unicodeArray,
this.unicodeArrayName,
this.unicodeArrayRotateValue,
this.options
),
unicodeArray: string [] = unicodeArrayNode.getNodeData();
);
this.nodes.set(
'unicodeArrayNode',
+8 -7
View File
@@ -9,6 +9,7 @@ import { TUnicodeArrayNode } from "../types/custom-nodes/TUnicodeArrayNode";
import { JSFuck } from "../enums/JSFuck";
import { Nodes } from "../Nodes";
import { UnicodeArray } from "../UnicodeArray";
import { Utils } from '../Utils';
export abstract class NodeObfuscator implements INodeObfuscator {
@@ -146,19 +147,19 @@ export abstract class NodeObfuscator implements INodeObfuscator {
throw new ReferenceError('`unicodeArrayNode` node is not found in Map with custom nodes.');
}
let unicodeArray: string[] = unicodeArrayNode.getNodeData(),
valueIndex: number = unicodeArray.indexOf(value),
literalValueCallIndex: number,
let unicodeArray: UnicodeArray = unicodeArrayNode.getNodeData(),
indexOfExistingValue: number = unicodeArray.getIndexOf(value),
indexOfValue: number,
hexadecimalIndex: string;
if (valueIndex >= 0) {
literalValueCallIndex = valueIndex;
if (indexOfExistingValue >= 0) {
indexOfValue = indexOfExistingValue;
} else {
literalValueCallIndex = unicodeArray.length;
indexOfValue = unicodeArray.getLength();
unicodeArrayNode.updateNodeData(value);
}
hexadecimalIndex = this.replaceLiteralNumberWithHexadecimalValue(literalValueCallIndex);
hexadecimalIndex = this.replaceLiteralNumberWithHexadecimalValue(indexOfValue);
if (this.options.wrapUnicodeArrayCalls) {
let unicodeArrayCallsWrapper: TUnicodeArrayCallsWrapper = <TUnicodeArrayCallsWrapper>this.nodes.get('unicodeArrayCallsWrapper');