diff --git a/src/background.js b/src/background.js index f030bbb..30a93b1 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, @@ -65,8 +66,34 @@ chrome.runtime.onMessage.addListener(function ( if (label.tab_specific) { label.key = `${sender.tab.id}_${label.key}`; } - sendResponse({ status: 'success', value: kvStorage[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..e551382 --- /dev/null +++ b/src/hacktimer.js @@ -0,0 +1,96 @@ +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..79bbbb6 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 @@ -103,6 +104,8 @@ function simulateMouseClick(element, clientX = null, clientY = null) { clientY = box.top + box.height / 2; } + console.log('кликаем', element, clientX, clientY) + if (isNaN(clientX) || isNaN(clientY)) { return; } @@ -145,7 +148,10 @@ function simulateMouseClick(element, clientX = null, clientY = null) { return document.querySelector('h2.prompt-text') !== null; } + let test = false function open_image_frame() { + if (test) return + test = true simulateMouseClick(document.querySelector('#anchor')); } 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