Skip to content

Instantly share code, notes, and snippets.

@pixeldesu
Created January 2, 2018 23:38
Show Gist options
  • Save pixeldesu/94e996f0ce6b4f0e65555d74c2c72353 to your computer and use it in GitHub Desktop.
Save pixeldesu/94e996f0ce6b4f0e65555d74c2c72353 to your computer and use it in GitHub Desktop.
webcrack successor to mess with webpack modules in a different structured webpackJsonp build
// moduleRaid
// made by @pixeldesu
// based on the idea and initial implemention of this concept from
// no-boot-device, called webcrack
// this self-executing function creates a window.mR object with following properties
// mR.modules contains all modules we were able to get from Webpack
// mR.get(id) allows you to get a module by the specified ID
// mR.findModule(query) allows you to find module(s) by searching for an exact export key
(function moduleRaid () {
// Initialising an array to keep all modules in
mArr = [];
// I actually used magic numbers here at first
// but then the code broke and now it's replaced
// with a while-loop that runs until we get an
// exception from webpack
mEnd = false;
mIter = 0;
while (!mEnd) {
try {
mArr[mIter] = webpackJsonp([],[],[mIter]);
mIter++;
}
catch (err) {
mEnd = true
}
}
// Return a module by its ID
get = function get (id) {
return mArr[id]
}
// Search for a export inside a module (string -> object key)
// and return the correct module(s)
findModule = function findModule (query) {
results = []
mArr.forEach(function(mod) {
if (typeof mod.default === "object") {
for (key in mod.default) {
if (key == query) results.push(mod);
}
}
for (key in mod) {
if (key == query) results.push(mod);
}
})
return results
}
window.mR = { modules: mArr, findModule: findModule, get: get }
})()
!function(){for(mArr=[],mEnd=!1,mIter=0;!mEnd;)try{mArr[mIter]=webpackJsonp([],[],[mIter]),mIter++}catch(r){mEnd=!0}get=function(r){return mArr[r]},findModule=function(r){return results=[],mArr.forEach(function(e){if("object"==typeof e.default)for(key in e.default)key==r&&results.push(e);for(key in e)key==r&&results.push(e)}),results},window.mR={modules:mArr,findModule:findModule,get:get}}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment