UnicodeArrayRotateFunctionNode.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. const esprima = require('esprima');
  3. const AppendState_1 = require("../../enums/AppendState");
  4. const Node_1 = require('../Node');
  5. const NodeUtils_1 = require("../../NodeUtils");
  6. const Utils_1 = require("../../Utils");
  7. class UnicodeArrayRotateFunctionNode extends Node_1.Node {
  8. constructor(unicodeArrayName, unicodeArray, unicodeArrayRotateValue) {
  9. super();
  10. this.appendState = AppendState_1.AppendState.AfterObfuscation;
  11. this.unicodeArrayName = unicodeArrayName;
  12. this.unicodeArray = unicodeArray;
  13. this.unicodeArrayRotateValue = unicodeArrayRotateValue;
  14. this.node = this.getNodeStructure();
  15. }
  16. appendNode(blockScopeNode) {
  17. NodeUtils_1.NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), 0);
  18. }
  19. getNode() {
  20. if (!this.unicodeArray.length) {
  21. return;
  22. }
  23. return super.getNode();
  24. }
  25. getNodeStructure() {
  26. let arrayName = Utils_1.Utils.getRandomVariableName(), timesName = Utils_1.Utils.getRandomVariableName(), tempArrayName = Utils_1.Utils.getRandomVariableName(), node = esprima.parse(`
  27. (function (${arrayName}, ${timesName}) {
  28. if (${timesName} < 0x${Utils_1.Utils.decToHex(0)}) {
  29. return;
  30. }
  31. var ${tempArrayName};
  32. while (${timesName}--) {
  33. ${tempArrayName} = ${arrayName}[${Utils_1.Utils.stringToUnicode('shift')}]();
  34. ${arrayName}[${Utils_1.Utils.stringToUnicode('push')}](${tempArrayName});
  35. }
  36. })(${this.unicodeArrayName}, 0x${Utils_1.Utils.decToHex(this.unicodeArrayRotateValue)});
  37. `);
  38. NodeUtils_1.NodeUtils.addXVerbatimPropertyToLiterals(node);
  39. return NodeUtils_1.NodeUtils.getBlockScopeNodeByIndex(node);
  40. }
  41. }
  42. exports.UnicodeArrayRotateFunctionNode = UnicodeArrayRotateFunctionNode;