UnicodeArrayNode.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. const escodegen = require('escodegen');
  3. const AppendState_1 = require('../../enums/AppendState');
  4. const NodeType_1 = require("../../enums/NodeType");
  5. const Node_1 = require('../Node');
  6. const NodeUtils_1 = require("../../NodeUtils");
  7. const Utils_1 = require('../../Utils');
  8. class UnicodeArrayNode extends Node_1.Node {
  9. constructor(unicodeArrayName, unicodeArrayRotateValue = 0) {
  10. super();
  11. this.appendState = AppendState_1.AppendState.AfterObfuscation;
  12. this.unicodeArray = [];
  13. this.unicodeArrayName = unicodeArrayName;
  14. this.unicodeArrayRotateValue = unicodeArrayRotateValue;
  15. this.node = this.getNodeStructure();
  16. }
  17. appendNode(blockScopeNode) {
  18. NodeUtils_1.NodeUtils.prependNode(blockScopeNode.body, this.getNode());
  19. }
  20. getNodeIdentifier() {
  21. return this.unicodeArrayName;
  22. }
  23. getNodeData() {
  24. return this.unicodeArray;
  25. }
  26. getNode() {
  27. if (!this.unicodeArray.length) {
  28. return;
  29. }
  30. Utils_1.Utils.arrayRotate(this.unicodeArray, this.unicodeArrayRotateValue);
  31. this.updateNode();
  32. return super.getNode();
  33. }
  34. getNodeStructure() {
  35. return {
  36. 'type': NodeType_1.NodeType.VariableDeclaration,
  37. 'declarations': [
  38. {
  39. 'type': NodeType_1.NodeType.VariableDeclarator,
  40. 'id': {
  41. 'type': NodeType_1.NodeType.Identifier,
  42. 'name': this.unicodeArrayName
  43. },
  44. 'init': {
  45. 'type': NodeType_1.NodeType.ArrayExpression,
  46. 'elements': this.unicodeArray.map((value) => {
  47. return {
  48. 'type': NodeType_1.NodeType.Literal,
  49. 'value': value,
  50. 'raw': `'${value}'`,
  51. 'x-verbatim-property': {
  52. 'content': value,
  53. precedence: escodegen.Precedence.Primary
  54. }
  55. };
  56. })
  57. }
  58. }
  59. ],
  60. 'kind': 'var'
  61. };
  62. }
  63. }
  64. UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH = 4;
  65. exports.UnicodeArrayNode = UnicodeArrayNode;