Skip to content

Commit d0859db

Browse files
committed
feat: mock some functions and update regexps
1 parent 34c7445 commit d0859db

File tree

6 files changed

+74
-5
lines changed

6 files changed

+74
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@filteringdev/tinyshield",
3-
"version": "1.8.3",
3+
"version": "2.0.0",
44
"description": "",
55
"type": "module",
66
"scripts": {

sources/banner.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// @downloadURL https://cdn.jsdelivr.net/npm/@filteringdev/tinyshield@latest/dist/tinyShield.user.js
99
// @license MIT
1010
//
11-
// @version 1.8.3
11+
// @version 2.0.0
1212
// @author PiQuark6046 and contributors
1313
//
1414
// @match *://ygosu.com/*

sources/src/as-weakmap.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as Utils from './utils.js'
2+
import { OriginalRegExpTest } from './index.js'
3+
4+
export function CheckDepthInASWeakMap(Args: [object, unknown]) {
5+
if (typeof Args[0] !== 'object') {
6+
return false
7+
}
8+
if (Utils.CountCommonStrings(['device', 'id', 'imp', 'regs', 'site', 'source'], Object.keys(Args[0])) < 5) {
9+
return false
10+
}
11+
12+
let ASBannerFrameIdRegExp = /^[0-9]+\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+\/[a-z0-9-\(\)]+\/[a-zA-Z0-9_]+_slot[0-9]+_+/
13+
let ASBannerFrameKey: string = Object.keys(Args[0]).find(Arg => typeof Args[0][Arg] === 'object' && Array.isArray(Args[0][Arg]) &&
14+
Args[0][Arg].filter(SubArg => typeof SubArg === 'object' && Object.keys(SubArg).filter(InnerArg => {
15+
return typeof InnerArg === 'string' && OriginalRegExpTest.call(ASBannerFrameIdRegExp, InnerArg) as boolean
16+
})).length >= 1)
17+
if (typeof ASBannerFrameKey === 'undefined') {
18+
return false
19+
}
20+
21+
return true
22+
}

sources/src/index.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ declare const unsafeWindow: unsafeWindow
44

55
const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window
66

7+
import { CheckDepthInASWeakMap } from './as-weakmap.js'
8+
79
const OriginalArrayToString = Win.Array.prototype.toString
8-
const OriginalRegExpTest = Win.RegExp.prototype.test
10+
export const OriginalRegExpTest = Win.RegExp.prototype.test
911

1012
const ProtectedFunctionStrings = ['toString', 'get', 'set']
1113

@@ -42,7 +44,13 @@ Win.Map.prototype.get = new Proxy(Win.Map.prototype.get, {
4244
})
4345

4446
const ASReinsertedAdvInvenPositiveRegExps: RegExp[][] = [[
47+
/inventory_id,[a-zA-Z0-9-]+\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+/,
48+
/inventory_id,[a-zA-Z0-9-]+\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+/,
4549
/inventory_id,[a-zA-Z0-9-]+\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+/
50+
], [
51+
/[a-z0-9A-Z]+\.setAttribute\( *('|")onload('|") *, *('|")! *async *function\( *\) *\{ *let */,
52+
/confirm\( *[A-Za-z0-9]+ *\) *\) *{ *const *[A-Za-z0-9]+ *= *new *[A-Za-z0-9]+\.URL\(('|")https:\/\/report\.error-report\.com\//,
53+
/\.forEach *\( *\( *[A-Za-z0-9]+ *=> *[A-Za-z0-9]+\.remove *\( *\) *\) *\) *\) *, *[0-9a-f]+ *\) *; *const *[A-Za-z0-9]+ *= *await *\( *await *fetch *\(/
4654
]]
4755
Win.Map.prototype.set = new Proxy(Win.Map.prototype.set, {
4856
apply(Target: (key: unknown, value: unknown) => Map<unknown, unknown>, ThisArg: Map<unknown, unknown>, Args: [unknown, unknown]) {
@@ -52,11 +60,45 @@ Win.Map.prototype.set = new Proxy(Win.Map.prototype.set, {
5260
} catch {
5361
console.warn('[tinyShield]: Map.prototype.set:', ThisArg, Args)
5462
}
55-
if (ASReinsertedAdvInvenPositiveRegExps.filter(ASReinsertedAdvInvenPositiveRegExp => ASReinsertedAdvInvenPositiveRegExp.filter(Index => OriginalRegExpTest.call(Index, ArgText) as boolean).length >= 1).length === 1) {
63+
if (ASReinsertedAdvInvenPositiveRegExps.filter(ASReinsertedAdvInvenPositiveRegExp => ASReinsertedAdvInvenPositiveRegExp.filter(Index => OriginalRegExpTest.call(Index, ArgText) as boolean).length >= 3).length === 1) {
5664
console.debug('[tinyShield]: Map.prototype.set:', ThisArg, Args)
5765
throw new Error()
5866
}
67+
return Reflect.apply(Target, ThisArg, Args)
68+
}
69+
})
5970

71+
Win.WeakMap.prototype.set = new Proxy(Win.WeakMap.prototype.set, {
72+
apply(Target: (key: object, value: unknown) => WeakMap<object, unknown>, ThisArg: WeakMap<object, unknown>, Args: [object, unknown]) {
73+
if (CheckDepthInASWeakMap(Args)) {
74+
console.debug('[tinyShield]: WeakMap.prototype.set:', ThisArg, Args)
75+
throw new Error()
76+
}
77+
78+
return Reflect.apply(Target, ThisArg, Args)
79+
}
80+
})
81+
82+
let ASTimerRegExps: RegExp[][] = [[
83+
/function *\( *\) *{ *const *[a-zA-Z0-9]+ *= *[a-zA-Z0-9]+ *; *for *\( *var *[a-zA-Z0-9]+ *= *[a-zA-Z0-9]+ *\[ *[a-zA-Z0-9]+ *\( *0x[a-f0-9]+ *\) *\] *,/,
84+
/ *,[a-zA-Z0-9]+ *= *new *Array *\( *[A-Za-z0-9]+ *\) *, *[A-Za-z0-9]+ *= *0x[a-f0-9]+ *; *[A-Za-z0-9]+ *< *[A-Za-z0-9]+ *; *[A-Za-z0-9]+ *\+\+ *\)/,
85+
/\) *\? *[A-Za-z0-9]+ *\[ *[A-Za-z0-9]+ *\( *0x[a-f0-9]+ *\) *\] *\[ *[A-Za-z0-9]+ *\( *0x[a-f0-9]+ *\) *\] * *\([A-Za-z0-9]+ *, *\.\.\. *[A-Za-z0-9]+ *\) *: *void *0x[a-f0-9]+/
86+
]]
87+
Win.setTimeout = new Proxy(Win.setTimeout, {
88+
apply(Target: typeof Win.setTimeout, ThisArg: undefined, Args: Parameters<typeof setTimeout>) {
89+
if (ASTimerRegExps.filter(ASTimerRegExp => ASTimerRegExp.filter(Index => Index.test(Args[0].toString())).length >= 3).length === 1) {
90+
console.debug('[tinyShield]: setTimeout:', Args)
91+
return
92+
}
93+
return Reflect.apply(Target, ThisArg, Args)
94+
}
95+
})
96+
Win.setInterval = new Proxy(Win.setInterval, {
97+
apply(Target: typeof Win.setInterval, ThisArg: undefined, Args: Parameters<typeof setInterval>) {
98+
if (ASTimerRegExps.filter(ASTimerRegExp => ASTimerRegExp.filter(Index => Index.test(Args[0].toString())).length >= 3).length === 1) {
99+
console.debug('[tinyShield]: setInterval:', Args)
100+
return
101+
}
60102
return Reflect.apply(Target, ThisArg, Args)
61103
}
62104
})

sources/src/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function CountCommonStrings(ArrayA: string[], ArrayB: string[]): number {
2+
let SetB = new Set(ArrayB)
3+
const Common = new Set(ArrayA.filter(Item => SetB.has(Item)))
4+
return Common.size
5+
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"module": "NodeNext",
4-
"target": "ES2022",
4+
"target": "ES2024",
55
"moduleResolution": "NodeNext",
66
"removeComments": false,
77
"alwaysStrict": false,

0 commit comments

Comments
 (0)