DebugProtectionFunctionNode.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. const esprima = require('esprima');
  3. const Node_1 = require('../Node');
  4. const NodeUtils_1 = require('../../NodeUtils');
  5. const Utils_1 = require("../../Utils");
  6. class DebugProtectionFunctionNode extends Node_1.Node {
  7. constructor(debugProtectionFunctionName, options = {}) {
  8. super(options);
  9. this.debugProtectionFunctionName = debugProtectionFunctionName;
  10. this.node = this.getNodeStructure();
  11. }
  12. appendNode(blockScopeNode) {
  13. let programBodyLength = blockScopeNode.body.length, randomIndex = Utils_1.Utils.getRandomInteger(0, programBodyLength);
  14. NodeUtils_1.NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), randomIndex);
  15. }
  16. getNodeIdentifier() {
  17. return this.debugProtectionFunctionName;
  18. }
  19. getNodeStructure() {
  20. return NodeUtils_1.NodeUtils.getBlockScopeNodeByIndex(esprima.parse(`
  21. var ${this.debugProtectionFunctionName} = function () {
  22. function debuggerProtection (counter) {
  23. if (('' + counter / counter)['length'] !== 1 || counter % 20 === 0) {
  24. (function () {}.constructor('debugger')());
  25. } else {
  26. [].filter.constructor(${Utils_1.Utils.stringToJSFuck('debugger')})();
  27. }
  28. debuggerProtection(++counter);
  29. }
  30. try {
  31. debuggerProtection(0);
  32. } catch (y) {}
  33. };
  34. `));
  35. }
  36. }
  37. exports.DebugProtectionFunctionNode = DebugProtectionFunctionNode;