diff --git a/public/popup.html b/public/popup.html index b50dcfc..d506342 100644 --- a/public/popup.html +++ b/public/popup.html @@ -204,7 +204,7 @@ data-settings="reload_delay_time" /> - +
diff --git a/src/background.js b/src/background.js index f030bbb..2bf95bf 100644 --- a/src/background.js +++ b/src/background.js @@ -49,6 +49,7 @@ chrome.runtime.onInstalled.addListener(async () => { }); const kvStorage = {}; +let fakeIdToId = {}; chrome.runtime.onMessage.addListener(function ( { type, label }, sender, @@ -66,7 +67,36 @@ chrome.runtime.onMessage.addListener(function ( label.key = `${sender.tab.id}_${label.key}`; } sendResponse({ status: 'success', value: kvStorage[label.key] }); + } else if (type === 'HackTimer') { + if (label.name === 'setInterval') { + fakeIdToId[label.fakeId] = setInterval(function () { + triggerTimer(label.name, sender.tab.id, label.fakeId); + }, label.time); + } else if (label.name === 'clearInterval') { + clearInterval(fakeIdToId[label.fakeId]); + delete fakeIdToId[label.fakeId]; + } else if (label.name === 'setTimeout') { + fakeIdToId[label.fakeId] = setTimeout(function () { + triggerTimer(label.name, sender.tab.id, label.fakeId); + delete fakeIdToId[label.fakeId]; + }, label.time); + } else if (label.name === 'clearTimeout') { + clearTimeout(fakeIdToId[label.fakeId]); + delete fakeIdToId[label.fakeId]; + } } })(); return true; }); + +async function triggerTimer(name, tabId, fakeId) { + try { + await chrome.tabs.sendMessage(tabId, { + type: 'HackTimer', + label: { fakeId }, + }); + } catch (error) { + if (name === 'setInterval') clearInterval(fakeIdToId[fakeId]); + delete fakeIdToId[fakeId]; + } +} diff --git a/src/hacktimer.js b/src/hacktimer.js new file mode 100644 index 0000000..f80aeb8 --- /dev/null +++ b/src/hacktimer.js @@ -0,0 +1,98 @@ +let fakeIdToCallback = {}, + lastFakeId = 0, + maxFakeId = 0x7fffffff; // 2 ^ 31 - 1, 31 bit, positive values of signed 32 bit integer +window.fakeIdToCallback = fakeIdToCallback; + +function getFakeId() { + do { + if (lastFakeId === maxFakeId) { + lastFakeId = 0; + } else { + lastFakeId++; + } + } while (fakeIdToCallback.hasOwnProperty(lastFakeId)); + return lastFakeId; +} + +window.setInterval = function (callback, time /* , parameters */) { + let fakeId = getFakeId(); + fakeIdToCallback[fakeId] = { + callback: callback, + parameters: Array.prototype.slice.call(arguments, 2), + }; + chrome.runtime.sendMessage({ + type: 'HackTimer', + label: { + name: 'setInterval', + fakeId, + time, + }, + }); + return fakeId; +}; +window.clearInterval = function (fakeId) { + if (fakeIdToCallback.hasOwnProperty(fakeId)) { + delete fakeIdToCallback[fakeId]; + chrome.runtime.sendMessage({ + type: 'HackTimer', + label: { + name: 'clearInterval', + fakeId, + }, + }); + } +}; +window.setTimeout = function (callback, time /* , parameters */) { + let fakeId = getFakeId(); + fakeIdToCallback[fakeId] = { + callback: callback, + parameters: Array.prototype.slice.call(arguments, 2), + isTimeout: true, + }; + chrome.runtime.sendMessage({ + type: 'HackTimer', + label: { + name: 'setTimeout', + fakeId, + time, + }, + }); + return fakeId; +}; +window.clearTimeout = function (fakeId) { + if (fakeIdToCallback.hasOwnProperty(fakeId)) { + delete fakeIdToCallback[fakeId]; + chrome.runtime.sendMessage({ + type: 'HackTimer', + label: { + name: 'clearTimeout', + fakeId, + }, + }); + } +}; + +chrome.runtime.onMessage.addListener(function ( + { type, label } /*, sender, sendResponse*/ +) { + if (type === 'HackTimer') { + let fakeId = label.fakeId, + request, + parameters, + callback; + if (fakeIdToCallback.hasOwnProperty(fakeId)) { + request = fakeIdToCallback[fakeId]; + callback = request.callback; + parameters = request.parameters; + if (request.hasOwnProperty('isTimeout') && request.isTimeout) { + delete fakeIdToCallback[fakeId]; + } + } + if (typeof callback === 'string') { + console.error('Callback is not supported as string'); + } + if (typeof callback === 'function') { + callback.apply(window, parameters); + } + } +}); diff --git a/src/hcaptcha.js b/src/hcaptcha.js index 94ab173..fadb6dc 100644 --- a/src/hcaptcha.js +++ b/src/hcaptcha.js @@ -13,6 +13,7 @@ import Jimp from 'jimp'; import { Time } from './utils'; +require('./hacktimer.js'); const ort = require('onnxruntime-web'); // Modify ort wasm path diff --git a/src/recaptcha.js b/src/recaptcha.js index efdd870..40f4b97 100644 --- a/src/recaptcha.js +++ b/src/recaptcha.js @@ -14,6 +14,7 @@ import Jimp from 'jimp'; import { KVStorage, Time } from './utils.js'; +require('./hacktimer.js'); const ort = require('onnxruntime-web'); // Modify ort wasm path