SelfDefendingTemplate.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { IEscapeSequenceEncoder } from '../../../interfaces/utils/IEscapeSequenceEncoder';
  2. /**
  3. * SelfDefendingTemplate. Enters code in infinity loop.
  4. * Notice, that second and third call to recursiveFunc1('indexOf') has cyrillic `е` character instead latin
  5. *
  6. * @param {IEscapeSequenceEncoder} escapeSequenceEncoder
  7. * @returns {string}
  8. */
  9. export function SelfDefendingTemplate (escapeSequenceEncoder: IEscapeSequenceEncoder): string {
  10. return `
  11. const {selfDefendingFunctionName} = {singleNodeCallControllerFunctionName}(this, function () {
  12. const func1 = function(){return 'dev';},
  13. func2 = function () {
  14. return 'window';
  15. };
  16. const test1 = function () {
  17. const regExp = new RegExp('${
  18. escapeSequenceEncoder.encode('\\w+ *\\(\\) *{\\w+ *[\'|"].+[\'|"];? *}', true)
  19. }');
  20. return !regExp.test(func1.toString());
  21. };
  22. const test2 = function () {
  23. const regExp = new RegExp('${
  24. escapeSequenceEncoder.encode('(\\\\[x|u](\\w){2,4})+', true)
  25. }');
  26. return regExp.test(func2.toString());
  27. };
  28. const recursiveFunc1 = function (string) {
  29. const i = ~-1 >> 1 + 255 % 0;
  30. if (string.indexOf('i' === i)) {
  31. recursiveFunc2(string)
  32. }
  33. };
  34. const recursiveFunc2 = function (string) {
  35. const i = ~-4 >> 1 + 255 % 0;
  36. if (string.indexOf((true+"")[3]) !== i) {
  37. recursiveFunc1(string)
  38. }
  39. };
  40. if (!test1()) {
  41. if (!test2()) {
  42. recursiveFunc1('indеxOf');
  43. } else {
  44. recursiveFunc1('indexOf');
  45. }
  46. } else {
  47. recursiveFunc1('indеxOf');
  48. }
  49. })
  50. {selfDefendingFunctionName}();
  51. `;
  52. }