Patching toString -> String

This commit is contained in:
Nuckyz 2024-05-23 20:02:41 -03:00
parent bd95cc449f
commit f5be78d101
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
5 changed files with 14 additions and 14 deletions

View file

@ -441,7 +441,7 @@ async function runtime(token: string) {
Vencord.Webpack.factoryListeners.add(factory => {
let isResolved = false;
searchAndLoadLazyChunks(factory.toString()).then(() => isResolved = true);
searchAndLoadLazyChunks(String(factory)).then(() => isResolved = true);
chunksSearchPromises.push(() => isResolved);
});
@ -451,7 +451,7 @@ async function runtime(token: string) {
setTimeout(() => {
for (const factoryId in wreq.m) {
let isResolved = false;
searchAndLoadLazyChunks(wreq.m[factoryId].toString()).then(() => isResolved = true);
searchAndLoadLazyChunks(String(wreq.m[factoryId])).then(() => isResolved = true);
chunksSearchPromises.push(() => isResolved);
}
@ -470,7 +470,7 @@ async function runtime(token: string) {
const allChunks = [] as string[];
// Matches "id" or id:
for (const currentMatch of wreq.u.toString().matchAll(/(?:"(\d+?)")|(?:(\d+?):)/g)) {
for (const currentMatch of String(wreq.u).matchAll(/(?:"(\d+?)")|(?:(\d+?):)/g)) {
const id = currentMatch[1] ?? currentMatch[2];
if (id == null) continue;
@ -525,7 +525,7 @@ async function runtime(token: string) {
const [code, matcher] = args;
const module = Vencord.Webpack.findModuleFactory(...code);
if (module) result = module.toString().match(canonicalizeMatch(matcher));
if (module) result = String(module).match(canonicalizeMatch(matcher));
} else {
// @ts-ignore
result = Vencord.Webpack[method](...args);
@ -534,8 +534,8 @@ async function runtime(token: string) {
if (result == null || ("$$vencordInternal" in result && result.$$vencordInternal() == null)) throw "a rock at ben shapiro";
} catch (e) {
let logMessage = searchType;
if (method === "find" || method === "proxyLazyWebpack" || method === "LazyComponentWebpack") logMessage += `(${args[0].toString().slice(0, 147)}...)`;
else if (method === "extractAndLoadChunks") logMessage += `([${args[0].map(arg => `"${arg}"`).join(", ")}], ${args[1].toString()})`;
if (method === "find" || method === "proxyLazyWebpack" || method === "LazyComponentWebpack") logMessage += `(${String(args[0]).slice(0, 147)}...)`;
else if (method === "extractAndLoadChunks") logMessage += `([${args[0].map(arg => `"${arg}"`).join(", ")}], ${String(args[1])})`;
else logMessage += `(${args.map(arg => `"${arg}"`).join(", ")})`;
console.log("[PUP_WEBPACK_FIND_FAIL]", logMessage);

View file

@ -56,7 +56,7 @@ function ReplacementComponent({ module, match, replacement, setReplacementError
const [compileResult, setCompileResult] = React.useState<[boolean, string]>();
const [patchedCode, matchResult, diff] = React.useMemo(() => {
const src: string = fact.toString().replaceAll("\n", "");
const src: string = String(fact).replaceAll("\n", "");
try {
new RegExp(match);

View file

@ -160,7 +160,7 @@ function initWs(isManual = false) {
return reply("Expected exactly one 'find' matches, found " + keys.length);
const mod = candidates[keys[0]];
let src = mod.toString().replaceAll("\n", "");
let src = String(mod).replaceAll("\n", "");
if (src.startsWith("function(")) {
src = "0," + src;

View file

@ -91,7 +91,7 @@ Object.defineProperty(Function.prototype, "O", {
const originalOnChunksLoaded = onChunksLoaded;
onChunksLoaded = function (result, chunkIds, callback, priority) {
if (callback != null && initCallbackRegex.test(callback.toString())) {
if (callback != null && initCallbackRegex.test(String(callback))) {
Object.defineProperty(this, "O", {
value: originalOnChunksLoaded,
configurable: true,
@ -218,7 +218,7 @@ function patchFactory(id: PropertyKey, factory: ModuleFactory) {
// cause issues.
//
// 0, prefix is to turn it into an expression: 0,function(){} would be invalid syntax without the 0,
let code: string = "0," + factory.toString().replaceAll("\n", "");
let code: string = "0," + String(factory).replaceAll("\n", "");
for (let i = 0; i < patches.length; i++) {
const patch = patches[i];

View file

@ -218,7 +218,7 @@ export const findBulk = traceFunction("findBulk", function findBulk(...filterFns
export const findModuleId = traceFunction("findModuleId", function findModuleId(...code: string[]) {
outer:
for (const id in wreq.m) {
const str = wreq.m[id].toString();
const str = String(wreq.m[id]);
for (const c of code) {
if (!str.includes(c)) continue outer;
@ -420,7 +420,7 @@ export async function extractAndLoadChunks(code: string[], matcher: RegExp = Def
return;
}
const match = module.toString().match(canonicalizeMatch(matcher));
const match = String(module).match(canonicalizeMatch(matcher));
if (!match) {
const err = new Error("extractAndLoadChunks: Couldn't find chunk loading in module factory code");
logger.warn(err, "Code:", code, "Matcher:", matcher);
@ -501,7 +501,7 @@ export function search(...filters: Array<string | RegExp>) {
outer:
for (const id in factories) {
const factory = factories[id];
const str: string = factory.toString();
const str: string = String(factory);
for (const filter of filters) {
if (typeof filter === "string" && !str.includes(filter)) continue outer;
if (filter instanceof RegExp && !filter.test(str)) continue outer;
@ -529,7 +529,7 @@ export function extract(id: PropertyKey) {
// WARNING: This module was extracted to be more easily readable.
// This module is NOT ACTUALLY USED! This means putting breakpoints will have NO EFFECT!!
0,${mod.toString()}
0,${String(mod)}
//# sourceURL=ExtractedWebpackModule${String(id)}
`;
const extracted: ModuleFactory = (0, eval)(code);