// ==UserScript==
// @name Anti Anti-debugger
// @name:vi Chống Anti-debugger
// @name:zh-CN 反反调试
// @namespace https://gf.qytechs.cn/vi/users/1195312-renji-yuusei
// @version 1.3
// @description Advanced protection against anti-debugging with improved performance and features
// @description:vi Bảo vệ nâng cao chống anti-debugging với hiệu suất và tính năng được cải thiện
// @description:zh-CN 高级反反调试保护,具有改进的性能和功能
// @author Yuusei
// @match *://*/*
// @grant unsafeWindow
// @run-at document-start
// @license GPL-3.0-only
// ==/UserScript==
(function() {
'use strict';
const config = {
debugKeywords: new Set(['debugger', 'debug', 'debugging', 'breakpoint']),
consoleProps: ['log', 'warn', 'error', 'info', 'debug', 'assert', 'dir', 'dirxml', 'trace', 'group', 'groupCollapsed', 'groupEnd', 'time', 'timeEnd', 'profile', 'profileEnd', 'count'],
maxLogHistory: 100,
};
const originalConsole = Object.fromEntries(
Object.entries(console).map(([key, value]) => [key, value.bind(console)])
);
let logHistory = [];
const safeEval = (code, context = {}) => {
try {
return new Function('context', `with(context) { return (${code}) }`)(context);
} catch (error) {
originalConsole.error('Failed to evaluate code:', error, code);
return null;
}
};
const modifyFunction = (func) => {
if (typeof func !== 'function') return func;
const funcStr = func.toString();
if ([...config.debugKeywords].some(keyword => funcStr.includes(keyword))) {
const modifiedStr = funcStr.replace(
new RegExp(`\\b(${[...config.debugKeywords].join('|')})\\b`, 'g'),
'/* removed */'
);
try {
return safeEval(`(${modifiedStr})`);
} catch (e) {
originalConsole.error("Error modifying function:", e);
return func;
}
}
return func;
};
const formatLogArgument = (arg) => {
if (arg === null) return 'null';
if (arg === undefined) return 'undefined';
if (typeof arg === 'object') {
try {
return JSON.stringify(arg, (key, value) =>
typeof value === 'function' ? value.toString() : value, 2);
} catch (e) {
return '[Circular]';
}
}
return String(arg);
};
const wrapConsole = () => {
config.consoleProps.forEach(prop => {
console[prop] = (...args) => {
originalConsole[prop](...args);
const formattedArgs = args.map(formatLogArgument);
const logMessage = `[${prop.toUpperCase()}] ${formattedArgs.join(' ')}`;
logHistory.push(logMessage);
if (logHistory.length > config.maxLogHistory) logHistory.shift();
};
});
};
const antiAntiDebugger = () => {
const proxyHandler = {
apply: (target, thisArg, args) => Reflect.apply(target, thisArg, args.map(modifyFunction)),
construct: (target, args) => Reflect.construct(target, args.map(modifyFunction))
};
Object.defineProperties(Function.prototype, {
constructor: {
value: new Proxy(Function.prototype.constructor, proxyHandler),
writable: false,
configurable: false,
}
});
unsafeWindow.eval = new Proxy(unsafeWindow.eval, proxyHandler);
unsafeWindow.Function = new Proxy(unsafeWindow.Function, proxyHandler);
};
const preventDebugging = () => {
const noop = () => {};
['alert', 'confirm', 'prompt'].forEach(prop => {
if (prop in unsafeWindow) {
Object.defineProperty(unsafeWindow, prop, {
value: noop,
writable: false,
configurable: false
});
}
});
};
const init = () => {
wrapConsole();
antiAntiDebugger();
preventDebugging();
console.log('%cAnti Anti-debugger is active', 'color: #00ff00; font-weight: bold;');
};
init();
})();