From 16068f24d4b53d40975edd1c5181b3313b775dd0 Mon Sep 17 00:00:00 2001 From: adryd Date: Thu, 16 Nov 2023 19:12:03 -0500 Subject: [PATCH] whatever i have rn --- src/magicrequire.js | 40 ++++++++++++++++++++++++++++++++++++++++ src/patcher.js | 32 +++++++++++++++++--------------- 2 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 src/magicrequire.js diff --git a/src/magicrequire.js b/src/magicrequire.js new file mode 100644 index 0000000..c2d89c9 --- /dev/null +++ b/src/magicrequire.js @@ -0,0 +1,40 @@ +import { matchModule } from "./patcher"; + +export default function magicrequire(module, exports, webpackRequire) { + // https://github.com/webpack/webpack/blob/main/lib/RuntimeGlobals.js + // modules: webpackRequire.m + // exports: webpackRequire.c + + function findModulesByExports(keys, maxDepth) {} + + function findModulesByMatches(search) {} + + function inspectModule(moduleId) {} + + // Obfuscated code helpers + function findObjectFromKey(exports, key) {} + + function findObjectFromValue(exports, value) {} + + function findObjectFromKeyValuePair(exports, key, value) {} + + function findFunctionByMatches(exports, search) {} + + + // some cyn magic + window.magicrequire = module.exports.default = exports.default = { + findModulesByExports, + findModulesByMatches, + inspectModule, + webpackRequire, + + findObjectFromKey, + findObjectFromValue, + findObjectFromKeyValuePair, + findFunctionByMatches, + + // magicrequire habits + exportCache: findModulesByExports, + generatorText: findModulesByMatches, + }; +} \ No newline at end of file diff --git a/src/patcher.js b/src/patcher.js index c8a4c55..4ec0f6c 100644 --- a/src/patcher.js +++ b/src/patcher.js @@ -1,12 +1,16 @@ import config from "./config"; +import magicrequire from "./magicrequire" -function matchModule(moduleStr, find) { - if (find instanceof RegExp) { - // todo - return false; - } else { - return moduleStr.indexOf(patch.find) != -1; - } +export function matchModule(moduleStr, find) { + const findArray = find instanceof Array ? find : [find]; + return findArray.some((query) => { + // we like our microoptimizations https://jsben.ch/Zk8aw + if (query instanceof RegExp) { + return moduleStr.match(query) + } else { + return moduleStr.includes(query) != -1 + } + }) } const patchesToApply = new Set(); @@ -53,14 +57,12 @@ for (const module of config.modules) { modulesToInject.add(module); } -//// Expose webpackRequire in global scope -// modulesToInject.add({ -// name: "webpackRequire", -// run: (module, exports, webpackRequire) => { -// window.webpackRequire = webpackRequire; -// }, -// entry: true, -// }); +// add placeholder magicrequire whatever +modulesToInject.add({ + name: "magicrequire", + run: magicrequire, + entry: true, +}); export function injectModules(chunk) { const readyModules = new Set();