SelfDefendingTemplate.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Utils } from '../../../../Utils';
  2. /**
  3. * @returns {string}
  4. */
  5. export function SelfDefendingTemplate (): string {
  6. return `
  7. var StatesClass = function (rc4Bytes) {
  8. this.rc4Bytes = rc4Bytes;
  9. this.states = [1, 0, 0];
  10. this.newState = function(){return 'newState';};
  11. this.firstState = '${Utils.stringToUnicodeEscapeSequence(`\\w+ *\\(\\) *{\\w+ *`)}';
  12. this.secondState = '${Utils.stringToUnicodeEscapeSequence(`['|"].+['|"];? *}`)}';
  13. };
  14. StatesClass.prototype.checkState = function () {
  15. var regExp = new RegExp(this.firstState + this.secondState);
  16. return this.runState(regExp.test(this.newState.toString()) ? --this.states[1] : --this.states[0]);
  17. };
  18. StatesClass.prototype.runState = function (stateResult) {
  19. if (!Boolean(~stateResult)) {
  20. return stateResult;
  21. }
  22. return this.getState(this.rc4Bytes);
  23. };
  24. StatesClass.prototype.getState = function (rc4Bytes) {
  25. for (var i = 0, len = this.states.length; i < len; i++) {
  26. this.states.push(Math.round(Math.random()));
  27. len = this.states.length;
  28. }
  29. return rc4Bytes(this.states[0]);
  30. };
  31. new StatesClass({stringsArrayCallsWrapperName}).checkState();
  32. `;
  33. }