Skip to content

Commit 63ac5f1

Browse files
committed
fix: restore most mocking native func to prevent PowerLink recovery behavior
1 parent 2aac511 commit 63ac5f1

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

sources/src/index.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,48 @@ const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window
1919
export function RunNamuLinkUserscript(BrowserWindow: typeof window, UserscriptName: string = 'NamuLink'): void {
2020
const ProtectedFunctionPrototypeToString = BrowserWindow.Function.prototype.toString
2121

22+
let PowerLinkGenerationPositiveRegExps: RegExp[][] = [[
23+
/for *\( *; *; *\) *switch *\( *_[a-z0-9]+\[_[a-z0-9]+\([a-z0-9]+\)\] *=_[a-z0-9]+/,
24+
/_[a-z0-9]+\[('|")[A-Z]+('|")\]\)\(\[ *\]\)/,
25+
/0x[a-z0-9]+ *\) *; *case/
26+
], [
27+
/; *return *this\[_0x[a-z0-9]+\( *0x[0-9a-z]+ *\)/,
28+
/; *if *\( *_0x[a-z0-9]+ *&& *\( *_0x[a-z0-9]+ *= *_0x[a-z0-9]+/,
29+
/\) *, *void *\( *this *\[ *_0x[a-z0-9]+\( *0x[0-9a-z]+ *\) *\] *= *_0x[a-z0-9]+ *\[/
30+
]]
31+
32+
BrowserWindow.Function.prototype.bind = new Proxy(BrowserWindow.Function.prototype.bind, {
33+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
34+
apply(Target: typeof Function.prototype.bind, ThisArg: Function, Args: Parameters<typeof Function.prototype.bind>) {
35+
let StringifiedFunc = Reflect.apply(ProtectedFunctionPrototypeToString, ThisArg, Args) as string
36+
if (PowerLinkGenerationPositiveRegExps.filter(PowerLinkGenerationPositiveRegExp => PowerLinkGenerationPositiveRegExp.filter(Index => Index.test(StringifiedFunc)).length >= 3).length === 1) {
37+
console.debug(`[${UserscriptName}]: Function.prototype.bind:`, ThisArg)
38+
return Reflect.apply(Target, () => {}, [])
39+
}
40+
return Reflect.apply(Target, ThisArg, Args)
41+
}
42+
})
43+
44+
let PowerLinkGenerationSkeletionPositiveRegExps: RegExp[][] = [[
45+
/\( *\) *=> *{ *var *_0x[0-9a-z]+ *= *a0_0x[0-9a-f]+ *; *this\[ *_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\]\(\); *}/,
46+
/\( *\) *=> *{ *var *_0x[0-9a-z]+ *= *a0_0x[0-9a-f]+ *; *this\[ *_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\]\(\); *}/
47+
], [
48+
/\( *\) *=> *{ *var _0x[a-z0-9]+ *= *_0x[a-z0-9]+ *; *if *\( *this\[ *_0x[a-z0-9]+ *\( *0x[0-9a-f]+ *\) *\] *\) *return *clearTimeout/,
49+
/\( *0x[0-9a-f]+ *\) *\] *\) *, *void *\( *this\[ *_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\] *= *void *\([x0-9a-f*+-]+ *\) *\) *; *this\[_0x[a-z0-9]+\( *0x[0-9a-f]+ *\) *\] *\(\) *;/
50+
]]
51+
52+
BrowserWindow.setTimeout = new Proxy(BrowserWindow.setTimeout, {
53+
apply(Target: typeof setTimeout, ThisArg: undefined, Args: Parameters<typeof setTimeout>) {
54+
let StringifiedFunc = Reflect.apply(ProtectedFunctionPrototypeToString, Args[0], Args) as string
55+
if (PowerLinkGenerationSkeletionPositiveRegExps.filter(PowerLinkGenerationSkeletionPositiveRegExp => PowerLinkGenerationSkeletionPositiveRegExp.filter(Index => Index.test(StringifiedFunc)).length >= 1).length === 1) {
56+
console.debug(`[${UserscriptName}]: setTimeout:`, Args[0])
57+
return
58+
}
59+
60+
return Reflect.apply(Target, ThisArg, Args)
61+
}
62+
})
63+
2264
if (document.readyState === 'loading') {
2365
window.addEventListener('DOMContentLoaded', () => {
2466
SPA.InstallSpaNavigationBridge({

0 commit comments

Comments
 (0)