Anti Anti-debugger

Stops most anti-debugging implementations by JavaScript obfuscators and stops the console logs from being automatically cleared. Fixed issue with missing console tab.

目前為 2024-10-07 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Anti Anti-debugger
  3. // @name:vi Chống Anti-debugger
  4. // @name:zh-CN 反反调试
  5. // @namespace https://greasyfork.org/vi/users/1195312-renji-yuusei
  6. // @version 1.2
  7. // @description Stops most anti-debugging implementations by JavaScript obfuscators and stops the console logs from being automatically cleared. Fixed issue with missing console tab.
  8. // @description:vi Ngăn chặn hầu hết các triển khai anti-debugging bằng JavaScript obfuscators và ngăn chặn việc xóa nhật ký console tự động. Đã sửa lỗi mất tab console.
  9. // @description:zh-CN 阻止大多数 JavaScript 混淆器实现的反调试,并阻止控制台日志被自动清除。修复了控制台标签丢失的问题。
  10. // @author Yuusei
  11. // @match *://*/*
  12. // @grant unsafeWindow
  13. // @run-at document-start
  14. // @license GPL-3.0-only
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. const config = {
  21. debugKeywords: ['debugger', 'debug', 'debugging', 'breakpoint'],
  22. consoleProps: ['log', 'warn', 'error', 'info', 'debug', 'assert', 'dir', 'dirxml', 'trace', 'group', 'groupCollapsed', 'groupEnd', 'time', 'timeEnd', 'profile', 'profileEnd', 'count'],
  23. };
  24.  
  25. const originalConsole = { ...console };
  26. let isScriptActive = false;
  27.  
  28. const safeEval = (code, context = {}) => {
  29. const safeContext = { ...context, console: { log: () => {} } };
  30. const safeCode = `
  31. 'use strict';
  32. const alert = () => {};
  33. const confirm = () => {};
  34. const prompt = () => {};
  35. ${Object.keys(safeContext).map(key => `const ${key} = this.${key};`).join('\n')}
  36. return (${code});
  37. `;
  38. try {
  39. return new Function(safeCode).call(safeContext);
  40. } catch (error) {
  41. originalConsole.warn('Failed to evaluate code:', error);
  42. return null;
  43. }
  44. };
  45.  
  46. const modifyFunction = (func) => {
  47. if (typeof func !== 'function') return func;
  48.  
  49. let funcStr = func.toString();
  50. if (config.debugKeywords.some(keyword => funcStr.includes(keyword))) {
  51. funcStr = funcStr.replace(new RegExp(`\\b(${config.debugKeywords.join('|')})\\b`, 'g'), '/* removed */');
  52. return safeEval(funcStr) || func;
  53. }
  54. return func;
  55. };
  56.  
  57. const wrapConsole = () => {
  58. const consoleProxy = new Proxy(originalConsole, {
  59. get: (target, prop) => {
  60. if (config.consoleProps.includes(prop) && typeof target[prop] === 'function') {
  61. return new Proxy(target[prop], {
  62. apply: (targetFunc, thisArg, args) => {
  63. args = args.map(modifyFunction);
  64. return Reflect.apply(targetFunc, thisArg, args);
  65. }
  66. });
  67. }
  68. return Reflect.get(target, prop);
  69. }
  70. });
  71.  
  72. Object.defineProperty(unsafeWindow, 'console', {
  73. value: consoleProxy,
  74. writable: false,
  75. configurable: false
  76. });
  77. };
  78.  
  79. const antiAntiDebugger = () => {
  80. const proxyHandler = {
  81. apply: (target, thisArg, args) => {
  82. args = args.map(modifyFunction);
  83. return Reflect.apply(target, thisArg, args);
  84. },
  85. construct: (target, args) => {
  86. args = args.map(modifyFunction);
  87. return Reflect.construct(target, args);
  88. }
  89. };
  90.  
  91. Function.prototype.constructor = new Proxy(Function.prototype.constructor, proxyHandler);
  92. unsafeWindow.eval = new Proxy(unsafeWindow.eval, proxyHandler);
  93. unsafeWindow.Function = new Proxy(unsafeWindow.Function, proxyHandler);
  94. };
  95.  
  96. const preventDebugging = () => {
  97. const noop = () => {};
  98. const protectedProps = ['pause', 'alert', 'confirm', 'prompt'];
  99. protectedProps.forEach(prop => {
  100. Object.defineProperty(unsafeWindow, prop, {
  101. get: () => noop,
  102. set: () => {},
  103. configurable: false
  104. });
  105. });
  106.  
  107. const originalDate = unsafeWindow.Date;
  108. unsafeWindow.Date = new Proxy(originalDate, {
  109. construct: (target, args) => {
  110. const date = new target(...args);
  111. date.getTime = new Proxy(date.getTime, {
  112. apply: (target, thisArg, args) => {
  113. if (new Error().stack.includes('debugger')) {
  114. return 0; // Return a fake timestamp
  115. }
  116. return Reflect.apply(target, thisArg, args);
  117. }
  118. });
  119. return date;
  120. }
  121. });
  122. };
  123.  
  124. const init = () => {
  125. wrapConsole();
  126. antiAntiDebugger();
  127. preventDebugging();
  128. isScriptActive = true;
  129. originalConsole.log('%cAnti Anti-debugger is active', 'color: #00ff00; font-weight: bold; font-size: 20px;');
  130. };
  131.  
  132. init();
  133.  
  134. // Periodically check and reapply if necessary
  135. setInterval(() => {
  136. if (!isScriptActive) {
  137. init();
  138. }
  139. }, 1000);
  140.  
  141. })();