• Stars
    star
    702
  • Rank 64,499 (Top 2 %)
  • Language
    JavaScript
  • Created almost 8 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🗃️ A javascript debundler. Takes a Browserify or Webpack bundle and recreates the initial, pre-bundled source.

Debundle

debundle

This is a tool built to unpack javascript bundles prudiced by webpack and browserify.

Build Status


🐉 HERE BE DRAGONS! 🐉

This was a research project that is no longer maintained. I built to help me understand how javascript bundles are strutured. It works in a labratory environment most of the time, but often fails on real-world javascript bundles. It's been a while since I worked on this project so if you run into issues, I might not really be able to help you out all that much.


Why would I want to debundle my code?

Reasons vary, but this tool was originally developed to help me with a reverse engineering project. Needless to say, sifting through minified bundles to try and figure out how a service works isn't fun and is a lot easier when that bundle is broken into files and those files have semantic names.

Installation

npm i -g debundle

Running

$ debundle
Usage: debundle [input file] {OPTIONS}

Options:
   --input,  -i  Bundle to debundle
   --output, -o  Directory to debundle code into.
   --config, -c  Configuration file

$ curl https://raw.githubusercontent.com/1egoman/debundle/master/test_bundles/browserify/bundle.js > bundle.js
$ curl https://raw.githubusercontent.com/1egoman/debundle/master/test_bundles/browserify/debundle.config.json > debundle.config.json
$ cat debundle.config.json
{
  "type": "browserify",
  "knownPaths": {}
}
$ debundle -i bundle.js -o dist/ -c debundle.config.json
$ tree dist/
dist/
├── index.js
└── node_modules
    ├── number
    │   └── index.js
    └── uuid
        ├── index.js
        ├── lib
        │   ├── bytesToUuid.js
        │   └── rng.js
        ├── v1.js
        └── v4.js
4 directories, 7 files

Configuration

Simple configuration

{
  "type": "browserify",
  "entryPoint": 1,
  "knownPaths": {}
}

(To debundle a simple Webpack bundle, replace browserify the above configuration with webpack)

A configuration can have a number of flags - they are documented in DOCS.md.

FAQ

Is debundling lossless? Ie, if I bundle my code then debundle, will I get the same source that was originally bundled?

No. There a bunch of metadata that's lost when bundling:

  • Any custom package.json settings for each node_module and the root package.
  • In a webpack bundle, the names of modules aren't in the bundle. By default, debundling will produce files named after the module id (ie, 1.js) unless manually overridden.
  • If your code was minified, the output files from the debundling process will also be minified (ie, no whitespace, single letter variables, etc). It's up to you to run source through other tools to make it look nicer.

My debundled code can't be run!

  • Make sure that either when rebundling or running with node that you're using the correct file as your entrypoint.
  • Read through all the configuration options. Some of them have caveats.
  • You could have run into an edge case that I haven't seen yet. Feel free to open an issue if you believe that to be the case.

Does this tool support bundles made by tools other than Browserify and Webpack?

Not officially. However, if a bundle shares the same type module layout as Browserify or Webpack it may be possible to set the moduleAst configuration option to point to the location of the modules.

Contributing

  • After cloning down the project, run npm install - that should be it.
  • Debundler entry point is ./src/index.js (that's how you run it!)
  • A bunch of sample bundles are in test_bundles/. A script, test_bundles/run_test.sh can run the debundler against a given bundle and try to debundle it into dist/. (CI will, as part of running tests, debundle all the bundles in that folder.)
  • Make sure any contribution pass the tests: npm test

Legal note

Some companies specify in their terms of service that their code cannot be "reverse engineered". Debundling can definitely (depending on how you're using the code) fall under that umbrella. Understand what you are doing so you don't break any agreements 😄

More Repositories

1

funnies

😜 Make users laugh when your app loads.
JavaScript
178
star
2

fuzzy-picker

🔍 React component that implements a fuzzy picker (like sublime text's command pallete, or slack's channel switcher).
JavaScript
75
star
3

biome

🎄 A script to manage an isolated shell environment for a project.
Shell
52
star
4

slackpgp

A slackbot for sending pgp-encrypted messages.
Go
11
star
5

dotfiles

📮 All of my dotfiles. I aim to maintain compatibility with the latest Ubuntu LTS and macOS release.
Shell
4
star
6

mconmanager

Terminal app for managing multiple minecraft servers
Python
4
star
7

wtf-todo

A terminal based jira client.
Shell
4
star
8

cena2

(Old Cena) += 100
HTML
3
star
9

slick

A modular and extendable slack client.
Go
3
star
10

candycrowd

My Hack Upstate (hackupstate.com) project - candy tracking during halloween. Won Hack Upstate 2015 (in fall) and got an Amazon Echo!
CSS
2
star
11

8tracks-scraper

Scrape an 8tracks mix to plaintext and an rss feed
JavaScript
2
star
12

waltz

Manage your project development time.
JavaScript
2
star
13

emoji-bookmarklet

CSS
2
star
14

pgiso

3d isometric engine, written in python and pygame
Python
2
star
15

asidebar

A dead simple aside / sidebar for jQuery and React
CSS
2
star
16

ar-wikipedia

JavaScript
1
star
17

echoparser

emulation of the way an amazon echo works inside
CoffeeScript
1
star
18

gate-language

A language to express logic diagrams and create machines out of binary gates. Built by me to help me understand how computers work.
Go
1
star
19

qlists

list management plugin
Python
1
star
20

tunein

tunein radio scraper for javascript (built for node)
CoffeeScript
1
star
21

deployman

deploy apps really easily onto a server heroku style
CoffeeScript
1
star
22

homebrew-tap

Some of my projects are installable via homebrew.
Ruby
1
star
23

empty-fork

An empty fork
Python
1
star
24

que

life automation
JavaScript
1
star
25

how-to-network

How to use networking tools and the surrounding networking details required to understand what's happening.
1
star
26

widevine-initializer

Make sure that widevine (or any other eme plugin) is initialized before trying to access a drm'd stream.
JavaScript
1
star
27

quail

Ask a question, get a response
Python
1
star
28

familyhub

DIY Samsung Family Hub with Raspberry Pi and Webcam
Python
1
star
29

list-scripts

A small script to list all `scripts` in a package.json file from the command line
JavaScript
1
star
30

git-design

A small shim for managing design assets (sketch and invision studio) with git.
Shell
1
star
31

hackfrost

Snow day calculator for hack frost 2016
JavaScript
1
star