Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
Attempt to fix #53
Browse files Browse the repository at this point in the history
  • Loading branch information
Serega007RU committed Oct 1, 2023
1 parent 037b03f commit 23c3a68
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ chrome.runtime.onInstalled.addListener(async () => {
});

const kvStorage = {};
let fakeIdToId = {};
chrome.runtime.onMessage.addListener(function (
{ type, label },
sender,
Expand All @@ -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];
}
}
96 changes: 96 additions & 0 deletions src/hacktimer.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
})
6 changes: 6 additions & 0 deletions src/hcaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import Jimp from 'jimp';
import { Time } from './utils';
require('./hacktimer.js');
const ort = require('onnxruntime-web');

// Modify ort wasm path
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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'));
}

Expand Down
1 change: 1 addition & 0 deletions src/recaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 23c3a68

Please sign in to comment.