Skip to content

Commit 5e0da35

Browse files
committed
docs: add comments and legal notice to readme
1 parent 78f0452 commit 5e0da35

File tree

3 files changed

+40
-37
lines changed

3 files changed

+40
-37
lines changed

README.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# debundle
22

33
This is a tool to decode javascript bundles produced by tools like [Webpack](https://webpack.github.io/) and [Browserify](http://browserify.org/)
4-
into their original, pre-bunded source.
4+
into their original, pre-bundled source.
55

66
[![Build Status](https://travis-ci.org/1egoman/debundler.svg?branch=master)](https://travis-ci.org/1egoman/debundler)
77

88
## Why would I want to debundle my code?
9-
Reasons vary, but I originally developed this to help me with a reverse engineering project I was
10-
working on. Needless to say, sifting through minified bundles to try and figure out how a service
11-
works isn't fun and is a lot easier when that bundle is broken into files and those files have
12-
semantic names.
9+
Reasons vary, but this tool was originally developed to help me with a reverse engineering project.
10+
Needless to say, sifting through minified bundles to try and figure out how a service works isn't
11+
fun and is a lot easier when that bundle is broken into files and those files have semantic names.
1312

1413
## Installation
1514
```
@@ -95,8 +94,14 @@ This is indicated as an array of strings / numbers used to traverse through the
9594
For example, `["foo", "bar", 0, "baz", 1]` would get `ast.foo.bar[0].baz[1]`.
9695

9796
# Contributing
97+
- After cloning down the project, run `npm install` - that should be it.
9898
- Debundler entry point is `./src/index.js` (that's how you run it!)
9999
- A bunch of sample bundles are in `test_bundles/`. A script, `test_bundles/run_test.sh` can run the
100100
debundler against a given bundle and try to debundle it into `dist/`. (CI will, as part of running
101101
tests, debundle all the bundles in that folder.)
102-
- Make sure any contribution passes the tests: `npm test`
102+
- Make sure any contribution pass the tests: `npm test`
103+
104+
# Legal note
105+
Some companies specify in their terms of service that their code cannot be "reverse engineered".
106+
Debundling can definitely (depending on how you're using the code) fall under that umbrella.
107+
Understand what you are doing so you don't break any agreements :smile:

src/index.js

+25-24
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ const inquirer = require('inquirer');
66
const args = require('minimist')(process.argv.slice(2));
77
const convertToIntegerKey = require('./utils/convertToIntegerKey');
88

9+
// ----------------------------------------------------------------------------
10+
// Set up configuration
11+
// ----------------------------------------------------------------------------
12+
913
const bundleLocation = args._[0] || args.input || args.i;
1014
const outputLocation = args.output || args.o;
1115
const configPath = args.config || args.c;
@@ -42,7 +46,9 @@ if (!config.moduleAst) {
4246
console.log(`* Using default AST location for ${config.type}...`);
4347
}
4448

45-
49+
// ----------------------------------------------------------------------------
50+
// Read in bundle
51+
// ----------------------------------------------------------------------------
4652

4753
console.log('* Reading bundle...');
4854
const bundleContents = fs.readFileSync(bundleLocation);
@@ -60,17 +66,9 @@ if (config.entryPoint === undefined) {
6066
}
6167

6268

63-
64-
65-
// TODO
66-
// KNOWN BUGS
67-
// - If a package has a nonstandard location for it's root file (ie, not in index.js), and that
68-
// location is in a folder, then we aren't smart enough to put that in the right location.
69-
// ie, blueprint has it's root in `src/index.js` and it requires `./common` from that file, which
70-
// when the root file is put in `index.js` it can't resolve.
71-
72-
// Browserify bundles start with an IIFE. Fetch the IIFE and get it's arguments (what we care about,
73-
// and where all the module code is located)
69+
// ----------------------------------------------------------------------------
70+
// Find all the modules in the bundle via `moduleAst`
71+
// ----------------------------------------------------------------------------
7472

7573
let iifeModules = ast;
7674
while (true) {
@@ -84,18 +82,10 @@ while (true) {
8482
}
8583
}
8684

87-
// Known paths are inserted absolutely into requires. They need to be made relative.
88-
//
89-
90-
91-
92-
// Webpack bundle
93-
// let iifeModules = ast.body[0].expression.arguments[0];
94-
95-
96-
97-
98-
85+
// ------------------------------------------------------------------------------
86+
// Given the path to the modules in the AST and the AST, pull out the modules and normalize
87+
// them to a predefined format.
88+
// ------------------------------------------------------------------------------
9989

10090
console.log('* Decoding modules...');
10191

@@ -110,14 +100,22 @@ if (config.type === 'browserify') {
110100
modules = webpackDecoder(iifeModules, config.knownPaths);
111101
}
112102

103+
104+
105+
// ------------------------------------------------------------------------------
113106
// Transform the module id in each require call into a relative path to the module.
114107
// var a = require(1) => var a = require('./path/to/a')
108+
// ------------------------------------------------------------------------------
109+
115110
console.log('* Reassembling requires...');
116111
const transformRequires = require('./transformRequires');
117112
modules = transformRequires(modules, config.knownPaths, config.entryPoint, config.type);
118113

114+
// ------------------------------------------------------------------------------
119115
// Take the array of modules and figure out where to put each module on disk.
120116
// module 1 => ./dist/path/to/a.js
117+
// ------------------------------------------------------------------------------
118+
121119
console.log('* Resolving files...');
122120
const lookupTableResolver = require('./lookupTable');
123121
const files = lookupTableResolver(
@@ -128,6 +126,9 @@ const files = lookupTableResolver(
128126
outputLocation
129127
);
130128

129+
// ------------------------------------------------------------------------------
130+
// Finally, write the bundle to disk in the specified output location.
131+
// ------------------------------------------------------------------------------
131132

132133
console.log('* Writing to disk...');
133134
const writeToDisk = require('./writeToDisk');
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
{
22
"type": "webpack",
3+
"entryPoint": 8,
34
"knownPaths": {
4-
"216": "@blueprintjs/core/src/components",
5-
"73": "./blah/querystring",
6-
"70": "./foo/somethingThatImportsQuerystring",
7-
8-
"90": "uuid/v1",
9-
"91": "uuid/rng",
10-
"92": "uuid/bytesToUuid"
5+
"8": "./index",
6+
"4": "./foo",
7+
"0": "uuid"
118
}
129
}

0 commit comments

Comments
 (0)