Skip to content

Commit

Permalink
targetfp initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ccev committed May 31, 2024
1 parent 751f4bf commit a5c5055
Show file tree
Hide file tree
Showing 8 changed files with 386 additions and 0 deletions.
10 changes: 10 additions & 0 deletions xilriws-targetfp/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
chrome.webNavigation.onCompleted.addListener((details) => {
console.log(details.tabId)
})

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message === "getTabId") {
sendResponse(sender.tab.id)
}
return true
})
68 changes: 68 additions & 0 deletions xilriws-targetfp/canvas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as utils from "./utils.js"

const typeValues = {
" monospace": 1, " sans-serif": 2, " serif": 3
}

const possibleFonts = ["ArialUnicodeMS", "Calibri", "Century", "Haettenschweiler", "Marlett", "Pristina", "Bauhaus93", "FuturaBkBT", "HelveticaNeue", "LucidaSans", "MYRIADPRO", "SegoeUILight"]

export function block() {
utils.overwriteProp(CanvasRenderingContext2D.prototype, "isPointInPath", () => false)
utils.overwriteProp(CanvasRenderingContext2D.prototype, "globalCompositeOperation", "screen")

function zeroOrOne() {
return utils.randomNumber(0, 2)
}

// utils.overwriteProp(CanvasRenderingContext2D.prototype, "measureText", (s) => {
// const metrics = {}
// metrics.width = zeroOrOne()
// metrics.actualBoundingBoxAscent = zeroOrOne()
// metrics.actualBoundingBoxDescent = zeroOrOne()
// metrics.actualBoundingBoxLeft = zeroOrOne()
// metrics.actualBoundingBoxRight = zeroOrOne()
// return metrics
// })

const goodFonts = utils.randomChooseMultiple(possibleFonts, utils.randomNumber(4, 7))
console.log("good fonts are " + goodFonts.join(","))

CanvasRenderingContext2D.prototype.measureText = function (text) {
let value = -10
for (const typeValue of Object.keys(typeValues)) {
if (this.font.includes(typeValue)) {
value = typeValues[typeValue]
}
}

for (const goodFont of goodFonts) {
if (this.font.includes(" " + goodFont + ",")) {
value = -10
}
}

const metrics = {}
metrics.width = value
metrics.actualBoundingBoxAscent = value
metrics.actualBoundingBoxDescent = value
metrics.actualBoundingBoxLeft = value
metrics.actualBoundingBoxRight = value
return metrics
}

const originalArc = CanvasRenderingContext2D.prototype.arc
CanvasRenderingContext2D.prototype.arc = function (n1, n2, n3, zero, pi2, bool) {
n1 += utils.randomNumber(-1, 2)
n2 += utils.randomNumber(-1, 2)
n3 += utils.randomNumber(-1, 2)
return originalArc.bind(this, n1, n2, n3, zero, pi2, bool)()
}

const originalPutImageData = CanvasRenderingContext2D.prototype.putImageData
CanvasRenderingContext2D.prototype.putImageData = function (img, x, y, ...args) {
// this doesn't actually do anything. however, it doesn't appear this canvas differs between different chromiums
x += utils.randomNumber(-1, 2)
y += utils.randomNumber(-1, 2)
return originalPutImageData.bind(this, img, x, y, ...args)()
}
}
6 changes: 6 additions & 0 deletions xilriws-targetfp/contentScript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(async () => {
const tabId = await chrome.runtime.sendMessage("getTabId")
const div = document.createElement("div")
div.setAttribute("data-xil-tab-id", tabId)
document.body.appendChild(div)
})()
51 changes: 51 additions & 0 deletions xilriws-targetfp/general.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as utils from "./utils.js"

const baseLanguages = [
"en-US",
"fr",
"de",
"es"
]

const extraLanguages = [
"en-GB",
"pt-BR",
"ru",
"tr",
"de",
"fr",
"es",
"hr",
"el",
"hu",
"no",
"ro",
"sr"
]

const englishes = [
"en-US",
"en-GB"
]

export function block() {
utils.overwriteProp(navigator, "platform", "Win32")

// language
const baseLanguage = utils.randomChoose(baseLanguages)
const languages = [baseLanguage]

const randomExtraLangs = utils.randomNumber(0, 10)
if (randomExtraLangs > 3) {
if (englishes.includes(baseLanguage)) {
languages.push(utils.randomChoose(extraLanguages))
} else {
languages.push(utils.randomChoose(englishes))
}
}
console.log("languages are " + languages.join(","))

// TODO: seed Math.random using the tabId (or the url possibly) - the content script will be reloaded by the iframe. in some cases (like the language) this can be detcted by the script
utils.overwriteProp(navigator, "language", baseLanguage)
utils.overwriteProp(navigator, "languages", languages)
}
20 changes: 20 additions & 0 deletions xilriws-targetfp/inject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(async () => {
"use strict"

const utils = await import("./utils.js")
const screen = await import("./screen.js")
const general = await import("./general.js")
const canvas = await import("./canvas.js")

const div = document.querySelector("[data-xil-tab-id]")
const seed = div.getAttribute("data-xil-tab-id")
document.body.removeChild(div)
utils.setSeed(seed)

screen.block()
general.block()
canvas.block()
})()



97 changes: 97 additions & 0 deletions xilriws-targetfp/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"manifest_version": 3,
"name": "xilriws-targetfp",
"version": "1.0",
"permissions": [
"proxy",
"tabs",
"unlimitedStorage",
"storage",
"<all_urls>",
"webRequest",
"webRequestBlocking",
"devtools",
"cookies",
"storage",
"scripting",
"tabs",
"activeTab",
"webNavigation",
"runtime"
],
"host_permissions": [
"<all_urls>"
],
"background": {
"service_worker": "background.js",
"type": "module"
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"contentScript.js"
],
"run_at": "document_start",
"all_frames": true,
"match_origin_as_fallback": true
},
{
"matches": [
"<all_urls>"
],
"js": [
"inject.js"
],
"run_at": "document_start",
"all_frames": true,
"match_origin_as_fallback": true,
"world": "MAIN",
"type": "module"
}
],
"web_accessible_resources": [
{
"resources": [
"inject.js"
],
"matches": [
"<all_urls>"
]
},
{
"resources": [
"utils.js"
],
"matches": [
"<all_urls>"
]
},
{
"resources": [
"screen.js"
],
"matches": [
"<all_urls>"
]
},
{
"resources": [
"general.js"
],
"matches": [
"<all_urls>"
]
},
{
"resources": [
"canvas.js"
],
"matches": [
"<all_urls>"
]
}
]
}
69 changes: 69 additions & 0 deletions xilriws-targetfp/screen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as utils from "./utils.js"

const screenSizes = [
[1680, 1050],
[1776, 1000],
[1600, 1200],
[1600, 1280],
[1920, 1080],
[1440, 1440],
[2048, 1080],
[1920, 1200],
[2048, 1152],
[1792, 1344],
[1920, 1280],
[2280, 1080],
[1856, 1392],
[2400, 1080],
[1800, 1440],
[2880, 900],
[2160, 1200],
[2048, 1280],
[1920, 1400],
[2520, 1080],
[2436, 1125],
[2538, 1080],
[1920, 1440],
[2560, 1080],
[2160, 1440],
[2048, 1536],
[2304, 1440],
[2256, 1504],
[2560, 1440],
[2576, 1450],
[2304, 1728],
[2560, 1600],
[2880, 1440],
[2960, 1440],
[2560, 1700],
[2560, 1800],
[2880, 1620],
[2560, 1920],
[3440, 1440],
[2736, 1824],
[2880, 1800],
[2880, 1920],
[2560, 2048],
[2732, 2048]
]

export function block() {
const [screenWidth, screenHeight] = utils.randomChoose(screenSizes)
console.log("screen size is " + screenWidth + "x" + screenHeight)
utils.overwriteProp(window.screen, "width", screenWidth)
utils.overwriteProp(window.screen, "height", screenHeight)
utils.overwriteProp(window.screen, "availWidth", screenWidth)
utils.overwriteProp(window.screen, "availHeight", screenHeight - 48)
utils.overwriteProp(window.screen, "availLeft", 0)
utils.overwriteProp(window.screen, "availTop", 0)
utils.overwriteProp(window.screen, "pixelDepth", 24)
utils.overwriteProp(window.screen.orientation, "type", "landscape-primary")

utils.overwriteProp(window, "outerWidth", screenWidth)
utils.overwriteProp(window, "outerHeight", screenHeight)
utils.overwriteProp(window, "innerWidth", screenWidth)
utils.overwriteProp(window, "innerHeight", screenHeight - 86)
utils.overwriteProp(window, "screenX", 0)
utils.overwriteProp(window, "screenY", 0)
utils.overwriteProp(window, "devicePixelRatio", 1)
}
65 changes: 65 additions & 0 deletions xilriws-targetfp/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
let random = null

export function setSeed(newSeed) {
random = seededRandom(newSeed)
}

function seededRandom(seed) {
let m = 0x80000000; // 2^31
let a = 1103515245;
let c = 12345;
let state = seed ? seed : Math.floor(Math.random() * (m - 1));

return function() {
state = (a * state + c) % m;
return state / (m - 1);
};
}

/**
* @param {Object} object
* @param {string} propName
* @param {any} propValue
*/
export function overwriteProp(object, propName, propValue) {
Object.defineProperty(object, propName, {
get: () => propValue,
set: () => {},
configurable: true
});
}


export function overwriteFunc(object, funcName, func) {
object[funcName] = func
}

/**
* @template T
* @param {T[]} array
* @returns {T}
*/
export function randomChoose(array) {
return array[Math.floor(random() * array.length)]
}

/**
* Generates a random number within the given bounds.
* @param {number} min - The lower bound (inclusive).
* @param {number} max - The upper bound (exclusive).
* @returns {number} A random number between min (inclusive) and max (exclusive).
*/
export function randomNumber(min, max) {
return Math.floor(random() * (max - min)) + min;
}

/**
* @template T
* @param {T[]} arr
* @param {number} amount
* @returns {T[]}
*/
export function randomChooseMultiple(arr, amount) {
const shuffledArray = arr.sort(() => 0.5 - random());
return shuffledArray.slice(0, amount);
}

0 comments on commit a5c5055

Please sign in to comment.