UnicodeArrayNode.js 2.6 KB

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