From 06583fb0b224d62eccbefd185f9f97749ccaa2f1 Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Thu, 5 Dec 2024 04:17:50 +0000 Subject: [PATCH] fix: function proxy and frame elements --- package.json | 2 +- src/client/dom/element.ts | 67 ++++++++++++++++++++++++++--------- src/client/shared/function.ts | 10 ++++-- 3 files changed, 60 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 3b2e309..304a4f0 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ ], "keywords": [], "author": "", - "license": "ISC", + "license": "MIT", "devDependencies": { "@eslint/eslintrc": "^3.2.0", "@eslint/js": "^9.16.0", diff --git a/src/client/dom/element.ts b/src/client/dom/element.ts index f5d2a4b..7aaee62 100644 --- a/src/client/dom/element.ts +++ b/src/client/dom/element.ts @@ -263,6 +263,57 @@ export default function (client: ScramjetClient, self: typeof window) { }, }); + client.Trap("HTMLFrameElement.prototype.contentWindow", { + get(ctx) { + const realwin = ctx.get() as Window; + if (!realwin) return realwin; + + if (SCRAMJETCLIENT in realwin) { + return realwin[SCRAMJETCLIENT].globalProxy; + } else { + // hook the iframe + const newclient = new ScramjetClient(realwin); + newclient.hook(); + + return newclient.globalProxy; + } + }, + }); + + client.Trap("HTMLFrameElement.prototype.contentDocument", { + get(ctx) { + const contentwindow = + client.descriptors["HTMLFrameElement.prototype.contentWindow"].get; + const realwin = contentwindow.apply(ctx.this); + if (!realwin) return realwin; + + if (SCRAMJETCLIENT in realwin) { + return realwin[SCRAMJETCLIENT].documentProxy; + } else { + const newclient = new ScramjetClient(realwin); + newclient.hook(); + + return newclient.documentProxy; + } + }, + }); + + client.Proxy( + [ + "HTMLIFrameElement.prototype.getSVGDocument", + "HTMLObjectElement.prototype.getSVGDocument", + "HTMLEmbedElement.prototype.getSVGDocument", + ], + { + apply(ctx) { + const doc = ctx.call(); + if (doc) { + ctx.return(ctx.this.contentDocument); + } + }, + } + ); + client.Trap("TreeWalker.prototype.currentNode", { get(ctx) { return ctx.get(); @@ -312,22 +363,6 @@ export default function (client: ScramjetClient, self: typeof window) { } ); - client.Proxy( - [ - "HTMLIFrameElement.prototype.getSVGDocument", - "HTMLObjectElement.prototype.getSVGDocument", - "HTMLEmbedElement.prototype.getSVGDocument", - ], - { - apply(ctx) { - const doc = ctx.call(); - if (doc) { - ctx.return(ctx.this.contentDocument); - } - }, - } - ); - client.Proxy("Node.prototype.getRootNode", { apply(ctx) { const n = ctx.call() as Node; diff --git a/src/client/shared/function.ts b/src/client/shared/function.ts index 7a2f9ec..b423ba0 100644 --- a/src/client/shared/function.ts +++ b/src/client/shared/function.ts @@ -10,7 +10,12 @@ function rewriteFunction(ctx: ProxyCtx, client: ScramjetClient) { export default function (client: ScramjetClient, _self: Self) { const handler: Proxy = { - apply(ctx) { + apply(ctx: ProxyCtx) { + if ((ctx.fn as any).alreadyProxied) { + debugger; + throw new Error("blah slop"); + } + (ctx.fn as any).alreadyProxied = true; rewriteFunction(ctx, client); }, construct(ctx) { @@ -19,7 +24,7 @@ export default function (client: ScramjetClient, _self: Self) { }; client.Proxy("Function", handler); - + /* // god i love javascript client.RawProxy(function () {}.constructor.prototype, "constructor", handler); client.RawProxy( @@ -37,4 +42,5 @@ export default function (client: ScramjetClient, _self: Self) { "constructor", handler ); + */ }