diff --git a/preload/src/api/filesystem.js b/preload/src/api/filesystem.js index 3ea4ccac..39fbd2d9 100644 --- a/preload/src/api/filesystem.js +++ b/preload/src/api/filesystem.js @@ -40,6 +40,10 @@ export function rename(oldPath, newPath) { return fs.renameSync(oldPath, newPath); } +export function unlinkSync(fileToDelete) { + return fs.unlinkSync(fileToDelete); +} + export function createWriteStream(path, options) { return cloneObject(fs.createWriteStream(path, options)); } diff --git a/preload/src/api/index.js b/preload/src/api/index.js index e96ae7a6..a397ec7b 100644 --- a/preload/src/api/index.js +++ b/preload/src/api/index.js @@ -1,7 +1,36 @@ +import fs from "fs"; import path from "path"; import Module from "module"; +// const Module = require("module"); Module.globalPaths.push(path.resolve(process.env.DISCORD_APP_PATH, "..", "app.asar", "node_modules")); +// module.paths.push(path.resolve(process.env.DISCORD_APP_PATH, "..", "app.asar", "node_modules")); + +Module._load = (load => (req, parent, isMain) => { + if (req.includes("./") || req.includes("..")) return load(req, parent, isMain); + const found = Module.globalPaths.find(m => fs.existsSync(path.resolve(m, req))); + + return found ? load(path.resolve(found, req), parent, isMain) : load(req, parent, isMain); +})(Module._load); + +// const originalLoad = Module.prototype.load; +// Module.prototype.load = function() { +// const returnValue = Reflect.apply(originalLoad, this, arguments); +// console.log(this, arguments, returnValue); +// return returnValue; +// }; + + +// const nodeModulePaths = Module._nodeModulePaths; +// console.log(nodeModulePaths); +// Module._nodeModulePaths = (from) => { +// return nodeModulePaths(from).concat([path.resolve(process.env.DISCORD_APP_PATH, "..", "app.asar", "node_modules")]); +// }; + +// console.log(Module._nodeModulePaths, Module._nodeModulePaths("request")); +// console.dir(Module); +// console.log(Object.keys(Module)); +// console.log(require("request")); export * as filesystem from "./filesystem"; export * as https from "./https"; @@ -11,4 +40,4 @@ export * as crypto from "./crypto"; // We can expose that without any issues. export * as path from "path"; export * as net from "net"; // TODO: evaluate need and create wrapper -export * as os from "os"; \ No newline at end of file +export * as os from "os"; diff --git a/preload/src/process.js b/preload/src/process.js index 40e24cb6..404f0640 100644 --- a/preload/src/process.js +++ b/preload/src/process.js @@ -1,3 +1,3 @@ -import cloneObject from "common/clone"; +import cloneObject, {getKeys} from "common/clone"; -export default cloneObject(process, {}); \ No newline at end of file +export default cloneObject(process, {}, getKeys(process).filter(p => p !== "config")); \ No newline at end of file diff --git a/renderer/src/modules/addonmanager.js b/renderer/src/modules/addonmanager.js index 81c6386d..e9a45eff 100644 --- a/renderer/src/modules/addonmanager.js +++ b/renderer/src/modules/addonmanager.js @@ -68,7 +68,9 @@ export default class AddonManager { if (this.watcher) return Logger.err(this.name, `Already watching ${this.prefix} addons.`); Logger.log(this.name, `Starting to watch ${this.prefix} addons.`); this.watcher = fs.watch(this.addonFolder, {persistent: false}, async (eventType, filename) => { + // console.log("watcher", eventType, filename, !eventType || !filename, !filename.endsWith(this.extension)); if (!eventType || !filename) return; + // console.log(eventType, filename) const absolutePath = path.resolve(this.addonFolder, filename); if (!filename.endsWith(this.extension)) { @@ -93,10 +95,11 @@ export default class AddonManager { Logger.err(this.name, `Could not rename file: ${filename} ${newFilename}`, error); } } - + // console.log("watcher", "before promise"); await new Promise(r => setTimeout(r, 100)); try { const stats = fs.statSync(absolutePath); + // console.log("watcher", stats); if (!stats.isFile()) return; if (!stats || !stats.mtime || !stats.mtime.getTime()) return; if (typeof(stats.mtime.getTime()) !== "number") return; @@ -106,7 +109,10 @@ export default class AddonManager { if (eventType == "change") this.reloadAddon(filename, true); } catch (err) { - if (err.code !== "ENOENT") return; + // window.watcherError = err; + // console.log("watcher", err); + // console.dir(err); + if (err.code !== "ENOENT" && !err?.message.startsWith("ENOENT")) return; delete this.timeCache[filename]; this.unloadAddon(filename, true); } @@ -207,6 +213,7 @@ export default class AddonManager { unloadAddon(idOrFileOrAddon, shouldToast = true, isReload = false) { const addon = typeof(idOrFileOrAddon) == "string" ? this.addonList.find(c => c.id == idOrFileOrAddon || c.filename == idOrFileOrAddon) : idOrFileOrAddon; + // console.log("watcher", "unloadAddon", idOrFileOrAddon, addon); if (!addon) return false; if (this.state[addon.id]) isReload ? this.stopAddon(addon) : this.disableAddon(addon); @@ -314,6 +321,7 @@ export default class AddonManager { deleteAddon(idOrFileOrAddon) { const addon = typeof(idOrFileOrAddon) == "string" ? this.addonList.find(c => c.id == idOrFileOrAddon || c.filename == idOrFileOrAddon) : idOrFileOrAddon; + // console.log(path.resolve(this.addonFolder, addon.filename), fs.unlinkSync) return fs.unlinkSync(path.resolve(this.addonFolder, addon.filename)); } diff --git a/renderer/src/modules/webpackmodules.js b/renderer/src/modules/webpackmodules.js index 98c5a51b..14eb6ca5 100644 --- a/renderer/src/modules/webpackmodules.js +++ b/renderer/src/modules/webpackmodules.js @@ -113,24 +113,6 @@ export class Filters { } } -const protect = theModule => { - if (theModule.remove && theModule.set && theModule.clear && theModule.get && !theModule.sort) return null; - if (!theModule.getToken && !theModule.getEmail && !theModule.showToken) return theModule; - const proxy = new Proxy(theModule, { - getOwnPropertyDescriptor: function(obj, prop) { - if (prop === "getToken" || prop === "getEmail" || prop === "showToken") return undefined; - return Object.getOwnPropertyDescriptor(obj, prop); - }, - get: function(obj, func) { - if (func == "getToken") return () => "mfa.XCnbKzo0CLIqdJzBnL0D8PfDruqkJNHjwHXtr39UU3F8hHx43jojISyi5jdjO52e9_e9MjmafZFFpc-seOMa"; - if (func == "getEmail") return () => "puppet11112@gmail.com"; - if (func == "showToken") return () => true; - // if (func == "__proto__") return proxy; - return obj[func]; - } - }); - return proxy; -}; const hasThrown = new WeakSet(); @@ -152,6 +134,10 @@ export default class WebpackModules { const {first = true, defaultExport = true} = options; const wrappedFilter = (exports, module, moduleId) => { try { + if (exports?.default?.remove && exports?.default?.set && exports?.default?.clear && exports?.default?.get && !exports?.default?.sort) return false; + if (exports.remove && exports.set && exports.clear && exports.get && !exports.sort) return false; + if (exports?.default?.getToken || exports?.default?.getEmail || exports?.default?.showToken) return false; + if (exports.getToken || exports.getEmail || exports.showToken) return false; return filter(exports, module, moduleId); } catch (err) { @@ -174,8 +160,8 @@ export default class WebpackModules { if (exports.__esModule && exports.default && wrappedFilter(exports.default, module, index)) foundModule = defaultExport ? exports.default : exports; if (wrappedFilter(exports, module, index)) foundModule = exports; if (!foundModule) continue; - if (first) return protect(foundModule); - rm.push(protect(foundModule)); + if (first) return foundModule; + rm.push(foundModule); } return first || rm.length == 0 ? undefined : rm; diff --git a/renderer/src/polyfill/fs.js b/renderer/src/polyfill/fs.js index 1cc86118..3aa5f24c 100644 --- a/renderer/src/polyfill/fs.js +++ b/renderer/src/polyfill/fs.js @@ -143,6 +143,9 @@ export const createWriteStream = (path, options) => { return Remote.filesystem.createWriteStream(path, options); }; +export const unlinkSync = (path) => Remote.filesystem.unlinkSync(path); +export const unlink = (path) => Remote.filesystem.unlinkSync(path); + export default { readFile, exists, @@ -160,6 +163,8 @@ export default { renameSync, rmdir, rmdirSync, + unlink, + unlinkSync, watch, writeFile, writeFileSync,