|
@@ -1,46 +1,59 @@
|
|
import { IEscapeSequenceEncoder } from '../../../interfaces/utils/IEscapeSequenceEncoder';
|
|
import { IEscapeSequenceEncoder } from '../../../interfaces/utils/IEscapeSequenceEncoder';
|
|
|
|
+import { Utils } from '../../../utils/Utils';
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param {IEscapeSequenceEncoder} escapeSequenceEncoder
|
|
* @param {IEscapeSequenceEncoder} escapeSequenceEncoder
|
|
* @returns {string}
|
|
* @returns {string}
|
|
*/
|
|
*/
|
|
export function SelfDefendingTemplate (escapeSequenceEncoder: IEscapeSequenceEncoder): string {
|
|
export function SelfDefendingTemplate (escapeSequenceEncoder: IEscapeSequenceEncoder): string {
|
|
|
|
+ const symTbl: { [key: string]: string } = {
|
|
|
|
+ 'rc4Bytes': Utils.generateIden(),
|
|
|
|
+ 'states': Utils.generateIden(),
|
|
|
|
+ 'newState': Utils.generateIden(),
|
|
|
|
+ 'firstState': Utils.generateIden(),
|
|
|
|
+ 'secondState': Utils.generateIden(),
|
|
|
|
+ 'checkState': Utils.generateIden(),
|
|
|
|
+ 'runState': Utils.generateIden(),
|
|
|
|
+ 'getState': Utils.generateIden(),
|
|
|
|
+ 'stateResult': Utils.generateIden()
|
|
|
|
+ };
|
|
|
|
+
|
|
return `
|
|
return `
|
|
- var StatesClass = function (rc4Bytes) {
|
|
|
|
- this.rc4Bytes = rc4Bytes;
|
|
|
|
- this.states = [1, 0, 0];
|
|
|
|
- this.newState = function(){return 'newState';};
|
|
|
|
- this.firstState = '${
|
|
|
|
|
|
+ var StatesClass = function (${symTbl.rc4Bytes}) {
|
|
|
|
+ this.${symTbl.rc4Bytes} = ${symTbl.rc4Bytes};
|
|
|
|
+ this.${symTbl.states} = [1, 0, 0];
|
|
|
|
+ this.${symTbl.newState} = function(){return 'newState';};
|
|
|
|
+ this.${symTbl.firstState} = '${
|
|
escapeSequenceEncoder.encode(`\\w+ *\\(\\) *{\\w+ *`, true)
|
|
escapeSequenceEncoder.encode(`\\w+ *\\(\\) *{\\w+ *`, true)
|
|
}';
|
|
}';
|
|
- this.secondState = '${
|
|
|
|
|
|
+ this.${symTbl.secondState} = '${
|
|
escapeSequenceEncoder.encode(`['|"].+['|"];? *}`, true)
|
|
escapeSequenceEncoder.encode(`['|"].+['|"];? *}`, true)
|
|
}';
|
|
}';
|
|
};
|
|
};
|
|
|
|
|
|
- StatesClass.prototype.checkState = function () {
|
|
|
|
- var regExp = new RegExp(this.firstState + this.secondState);
|
|
|
|
|
|
+ StatesClass.prototype.${symTbl.checkState} = function () {
|
|
|
|
+ var regExp = new RegExp(this.${symTbl.firstState} + this.${symTbl.secondState});
|
|
|
|
|
|
- return this.runState(regExp.test(this.newState.toString()) ? --this.states[1] : --this.states[0]);
|
|
|
|
|
|
+ return this.${symTbl.runState}(regExp.test(this.${symTbl.newState}.toString()) ? --this.${symTbl.states}[1] : --this.${symTbl.states}[0]);
|
|
};
|
|
};
|
|
|
|
|
|
- StatesClass.prototype.runState = function (stateResult) {
|
|
|
|
- if (!Boolean(~stateResult)) {
|
|
|
|
- return stateResult;
|
|
|
|
|
|
+ StatesClass.prototype.${symTbl.runState} = function (${symTbl.stateResult}) {
|
|
|
|
+ if (!Boolean(~${symTbl.stateResult})) {
|
|
|
|
+ return ${symTbl.stateResult};
|
|
}
|
|
}
|
|
|
|
|
|
- return this.getState(this.rc4Bytes);
|
|
|
|
|
|
+ return this.${symTbl.getState}(this.${symTbl.rc4Bytes});
|
|
};
|
|
};
|
|
|
|
|
|
- StatesClass.prototype.getState = function (rc4Bytes) {
|
|
|
|
- for (var i = 0, len = this.states.length; i < len; i++) {
|
|
|
|
- this.states.push(Math.round(Math.random()));
|
|
|
|
- len = this.states.length;
|
|
|
|
|
|
+ StatesClass.prototype.${symTbl.getState} = function (${symTbl.rc4Bytes}) {
|
|
|
|
+ for (var i = 0, len = this.${symTbl.states}.length; i < len; i++) {
|
|
|
|
+ this.${symTbl.states}.push(Math.round(Math.random()));
|
|
|
|
+ len = this.${symTbl.states}.length;
|
|
}
|
|
}
|
|
|
|
|
|
- return rc4Bytes(this.states[0]);
|
|
|
|
|
|
+ return ${symTbl.rc4Bytes}(this.${symTbl.states}[0]);
|
|
};
|
|
};
|
|
|
|
|
|
- new StatesClass({stringArrayCallsWrapperName}).checkState();
|
|
|
|
|
|
+ new StatesClass({stringArrayCallsWrapperName}).${symTbl.checkState}();
|
|
`;
|
|
`;
|
|
}
|
|
}
|