Skip to content

Commit 26c3c24

Browse files
committed
feat: new func argument analyzer with RegExp
1 parent 2ad3d5c commit 26c3c24

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
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": "@list-kr/tinyshield",
3-
"version": "1.5.58",
3+
"version": "1.6.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/@list-kr/tinyshield@latest/dist/tinyShield.user.js
99
// @license MIT
1010
//
11-
// @version 1.5.58
11+
// @version 1.6.0
1212
// @author PiQuark6046 and contributors
1313
//
1414
// @match *://ygosu.com/*

sources/src/index.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ declare const unsafeWindow: unsafeWindow
55
const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window
66

77
const OriginalArrayToString = Win.Array.prototype.toString
8-
const OriginalStringIncludes = Win.String.prototype.includes
98

109
const ProtectedFunctionStrings = ['toString', 'get', 'set']
1110

@@ -20,24 +19,30 @@ Win.Function.prototype.toString = new Proxy(Win.Function.prototype.toString, {
2019
}
2120
})
2221

22+
const ASInitPositiveRegExps: RegExp[][] = [[
23+
/[a-zA-Z0-9]+ *=> *{ *const *[a-zA-Z0-9]+ *= *[a-zA-Z0-9]+ *; *if/,
24+
/===? *[a-zA-Z0-9]+ *\[ *[a-zA-Z0-9]+\( *[0-9]+ *\) *\] *\) *return *[a-zA-Z0-9]+ *\( *{ *inventoryId *:/,
25+
/{ *inventoryId *: *this *\[[a-zA-Z0-9]+ *\( *[0-9]+ *\) *\] *, *\.\.\. *[a-zA-Z0-9]+ *\[ *[a-zA-Z0-9]+ *\( *[0-9]+ * *\) *\] *} *\)/
26+
]]
2327
Win.Map.prototype.get = new Proxy(Win.Map.prototype.get, {
2428
apply(Target: (key: unknown) => unknown, ThisArg: Map<unknown, unknown>, Args: [unknown]) {
25-
let ArgText = ''
26-
try {
27-
ArgText = OriginalArrayToString.call(Args) as string
28-
} catch {
29-
console.warn('[tinyShield]: Map.prototype.get:', ThisArg, Args)
29+
if (Args.length > 0 && typeof Args[0] !== 'function') {
30+
return Reflect.apply(Target, ThisArg, Args)
3031
}
31-
for (const Item of ['{"inventoryId":', '({inventoryId:this']) {
32-
if (OriginalStringIncludes.call(ArgText, Item)) {
33-
console.debug('[tinyShield]: Map.prototype.get:', ThisArg, Args)
34-
throw new Error()
35-
}
32+
33+
let ArgText = OriginalArrayToString.call(Args) as string
34+
if (ASInitPositiveRegExps.filter(ASInitPositiveRegExp => ASInitPositiveRegExp.filter(Index => Index.test(ArgText)).length >= 2).length === 1) {
35+
console.debug('[tinyShield]: Map.prototype.get:', ThisArg, Args)
36+
throw new Error()
3637
}
38+
3739
return Reflect.apply(Target, ThisArg, Args)
3840
}
3941
})
4042

43+
const ASReinsertedAdvInvenPositiveRegExps: RegExp[][] = [[
44+
new RegExp('inventory_id,[a-zA-Z0-9-]+\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+')
45+
]]
4146
Win.Map.prototype.set = new Proxy(Win.Map.prototype.set, {
4247
apply(Target: (key: unknown, value: unknown) => Map<unknown, unknown>, ThisArg: Map<unknown, unknown>, Args: [unknown, unknown]) {
4348
let ArgText = ''
@@ -46,11 +51,9 @@ Win.Map.prototype.set = new Proxy(Win.Map.prototype.set, {
4651
} catch {
4752
console.warn('[tinyShield]: Map.prototype.get:', ThisArg, Args)
4853
}
49-
for (const Item of ['inventory_id']) {
50-
if (OriginalStringIncludes.call(ArgText, Item)) {
51-
console.debug('[tinyShield]: Map.prototype.set:', ThisArg, Args)
52-
throw new Error()
53-
}
54+
if (ASReinsertedAdvInvenPositiveRegExps.filter(ASReinsertedAdvInvenPositiveRegExp => ASReinsertedAdvInvenPositiveRegExp.filter(Index => Index.test(ArgText)).length >= 1).length === 1) {
55+
console.debug('[tinyShield]: Map.prototype.set:', ThisArg, Args)
56+
throw new Error()
5457
}
5558

5659
return Reflect.apply(Target, ThisArg, Args)

0 commit comments

Comments
 (0)