Skip to content

Commit

Permalink
whatever i have rn
Browse files Browse the repository at this point in the history
  • Loading branch information
adryd325 committed Nov 17, 2023
1 parent 0d67694 commit 16068f2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
40 changes: 40 additions & 0 deletions src/magicrequire.js
Original file line number Diff line number Diff line change
@@ -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,
};
}
32 changes: 17 additions & 15 deletions src/patcher.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 16068f2

Please sign in to comment.