MCPcopy
hub / github.com/LibreScore/dl-librescore / hookNative

Function hookNative

src/anti-detection.ts:35–59  ·  view source on GitHub ↗
(
    target: T,
    method: M,
    hook: (originalFn: T[M], detach: () => void) => T[M],
    async = false
)

Source from the content-addressed store, hash-verified

33})();
34
35export function hookNative<T extends object, M extends keyof T>(
36 target: T,
37 method: M,
38 hook: (originalFn: T[M], detach: () => void) => T[M],
39 async = false
40): void {
41 // reserve for future hook update
42 const _fn = target[method];
43 const detach = () => {
44 target[method] = _fn; // detach
45 };
46
47 // This script can run before anything on the page,
48 // so setting this function to be non-configurable and non-writable is no use.
49 const hookedFn = hook(_fn, detach);
50 target[method] = hookedFn;
51
52 if (!async) {
53 makeNative(hookedFn as any, _fn as any);
54 } else {
55 setTimeout(() => {
56 makeNative(hookedFn as any, _fn as any);
57 });
58 }
59}

Callers 3

file-magics.tsFile · 0.90
setFunction · 0.90
anti-detection.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected