UnicodeArrayNode.js 2.4 KB

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