UnicodeArrayRotateFunctionNode.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { INode } from "../../interfaces/nodes/INode";
  2. import { IOptions } from "../../interfaces/IOptions";
  3. import { TNodeWithBlockStatement } from "../../types/TNodeWithBlockStatement";
  4. import { AppendState } from "../../enums/AppendState";
  5. import { JSFuck } from "../../enums/JSFuck";
  6. import { NO_CUSTOM_NODES_PRESET } from "../../preset-options/NoCustomNodesPreset";
  7. import { JavaScriptObfuscator } from "../../JavaScriptObfuscator";
  8. import { Node } from '../Node';
  9. import { NodeUtils } from "../../NodeUtils";
  10. import { Utils } from "../../Utils";
  11. export class UnicodeArrayRotateFunctionNode extends Node {
  12. /**
  13. * @type {AppendState}
  14. */
  15. protected appendState: AppendState = AppendState.AfterObfuscation;
  16. /**
  17. * @type {string[]}
  18. */
  19. private unicodeArray: string[];
  20. /**
  21. * @type {string}
  22. */
  23. private unicodeArrayName: string;
  24. /**
  25. * @param {number}
  26. */
  27. private unicodeArrayRotateValue: number;
  28. /**
  29. * @param unicodeArrayName
  30. * @param unicodeArray
  31. * @param unicodeArrayRotateValue
  32. * @param options
  33. */
  34. constructor (
  35. unicodeArrayName: string,
  36. unicodeArray: string[],
  37. unicodeArrayRotateValue: number,
  38. options: IOptions
  39. ) {
  40. super(options);
  41. this.unicodeArrayName = unicodeArrayName;
  42. this.unicodeArray = unicodeArray;
  43. this.unicodeArrayRotateValue = unicodeArrayRotateValue;
  44. }
  45. /**
  46. * @param blockScopeNode
  47. */
  48. public appendNode (blockScopeNode: TNodeWithBlockStatement): void {
  49. NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), 1);
  50. }
  51. /**
  52. * @returns {INode}
  53. */
  54. public getNode (): INode {
  55. if (!this.unicodeArray.length) {
  56. return;
  57. }
  58. return super.getNode();
  59. }
  60. /**
  61. * @returns {INode}
  62. */
  63. protected getNodeStructure (): INode {
  64. let arrayName: string = Utils.getRandomVariableName(),
  65. code: string = '',
  66. timesName: string = Utils.getRandomVariableName(),
  67. timesArgumentName: string = Utils.getRandomVariableName(),
  68. whileFunctionName: string = Utils.getRandomVariableName();
  69. if (this.options.get('selfDefending')) {
  70. code = JavaScriptObfuscator.obfuscate(`
  71. (function () {
  72. var func = function(){return ${Utils.stringToUnicode('dev')};};
  73. !Function(${Utils.stringToUnicode(`return/\\w+ *\\(\\) *{\\w+ *['|"].+['|"];? *}/`)})().test(func.toString()) ? []['filter']['constructor'](${Utils.stringToJSFuck('while')} + '(${JSFuck.True}){}')() : Function(${Utils.stringToUnicode('a')}, ${Utils.stringToUnicode('b')}, ${Utils.stringToUnicode('a(++b)')})(${whileFunctionName}, ${timesName}) ? []['filter']['constructor'](${Utils.stringToJSFuck('while')} + '(${JSFuck.False}){}')() : []['filter']['constructor'](${Utils.stringToJSFuck('while')} + '(${JSFuck.False}){}')();
  74. })();
  75. `, NO_CUSTOM_NODES_PRESET).getObfuscatedCode();
  76. } else {
  77. code = `${whileFunctionName}(++${timesName})`;
  78. }
  79. return NodeUtils.convertCodeToStructure(`
  80. (function (${arrayName}, ${timesName}) {
  81. var ${whileFunctionName} = function (${timesArgumentName}) {
  82. while (--${timesArgumentName}) {
  83. ${arrayName}[${Utils.stringToUnicode('push')}](${arrayName}[${Utils.stringToUnicode('shift')}]());
  84. }
  85. };
  86. ${code}
  87. })(${this.unicodeArrayName}, 0x${Utils.decToHex(this.unicodeArrayRotateValue)});
  88. `);
  89. }
  90. }