• Stars
    star
    260
  • Rank 151,832 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created 11 months ago
  • Updated about 2 months ago

Reviews

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

Repository Details

Deobfuscate Javascript code using ChatGPT

Humanify

Un-minify Javascript code using LLMs ("AI")

This tool uses large language modeles (like ChatGPT & llama2) and other tools to un-minify Javascript code. Note that LLMs don't perform any structural changes โ€“ they only provide hints to rename variables and functions. The heavy lifting is done by Babel on AST level to ensure code stays 1-1 equivalent.

โžก๏ธ Check out the introduction blog post for in-depth explanation!

Example

Given the following minified code:

function a(e,t){var n=[];var r=e.length;var i=0;for(;i<r;i+=t){if(i+t<r){n.push(e.substring(i,i+t))}else{n.push(e.substring(i,r))}}return n}

The tool will output a human-readable version:

function splitString(inputString, chunkSize) {
  var chunks = [];
  var stringLength = inputString.length;
  var startIndex = 0;
  for (; startIndex < stringLength; startIndex += chunkSize) {
    if (startIndex + chunkSize < stringLength) {
      chunks.push(inputString.substring(startIndex, startIndex + chunkSize));
    } else {
      chunks.push(inputString.substring(startIndex, stringLength));
    }
  }
  return chunks;
}

๐Ÿšจ NOTE: ๐Ÿšจ

Large files may take some time to process and use a lot of tokens if you use ChatGPT. For a rough estimate, the tool takes about 2 tokens per character to process a file:

echo "$((2 * $(wc -c < yourscript.min.js)))"

So for refrence: a minified bootstrap.min.js would take about $0.5 to un-minify using ChatGPT.

Using --local flag is of course free, but may take more time, be less accurate and not possible with your existing hardware.

Getting started

First install the dependencies:

npm install

Next you'll need to decide whether to use ChatGPT or llama2. In a nutshell:

  • ChatGPT
    • Runs on someone else's computer that's specifically optimized for this kind of things
    • Costs money depending on the length of your code
    • Is more accurate
    • Is (probably) faster
  • llama2
    • Runs locally
    • Is free
    • Is less accurate
    • Needs a local GPU with ~60gb RAM (M1 Mac works just fine)
    • Runs as fast as your GPU does

See instructions below for each option:

ChatGPT

You'll need a ChatGPT API key. You can get one by signing up at https://openai.com/.

There are several ways to provide the API key to the tool:

echo "OPENAI_TOKEN=your-token" > .env && npm start --  -o unminified.js minified-file.js
export OPENAI_TOKEN="your-token" && npm start --  -o unminified.js minified-file.js
OPENAI_TOKEN=your-token npm start --  -o unminified.js minified-file.js
npm start -- --key="your-token"  -o unminified.js minified-file.js

Use your preferred way to provide the API key. Use npm start -- --help to see all available options.

llama2

Prerequisites:

  • You'll need to have a Python 3 environment with conda installed.
  • You need a Huggingface account with access to llama-2-7b-chat-hf model. Make sure to read the instructions on the model page about how to access the model.

Run the following command to install the required Python packages and activate the environment:

conda env create -f environment.yaml
conda activate base

You can now run the tool with:

npm start -- --local -o unminified.js minified-file.js

Note: this downloads ~13gb of model data to your computer on the first run.

Features

The main features of the tool are:

  • Uses ChatGPT functions/llama2 to get smart suggestions to rename variable and function names
  • Uses custom and off-the-shelf Babel plugins to perform AST-level unmanging
  • Uses Webcrack to unbundle Webpack bundles

Contributing

If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.

Licensing

The code in this project is licensed under MIT license.

More Repositories

1

readme-best-practices

Best practices for writing a README for your open source project
853
star
2

ga-lite

Small, cacheable and open version of Google Analytics JS client
JavaScript
639
star
3

mastofeeder

RSS to ActivityPub bridge
TypeScript
102
star
4

stable-diffusion-training-tutorial

A tutorial for training Stable Diffusion with your own images
76
star
5

uQuery

jQuery port to Unity3D
JavaScript
31
star
6

longwood

Experimental rendering library
TypeScript
25
star
7

notepadlet

A simple bookmarklet notepad
17
star
8

putrats.com

Webcomic template that uses Bootstrap, Grunt and Google App Engine. Used at:
CSS
15
star
9

AsciiCube

A simple rotating ASCII Cube
12
star
10

img2chr

Convert any image to NES .chr file
JavaScript
11
star
11

objective-facebook

A better, object-oriented Facebook JS SDK
JavaScript
10
star
12

nosx

JavaScript
9
star
13

static-saas-boilerplate

Static SaaS boilerplate
JavaScript
7
star
14

thejunkland.com

Personal blog and portfolio of Jesse Luoto
TypeScript
6
star
15

nes-bootstrap

Everything to start coding to NES with C
Assembly
6
star
16

calc-o-pad

A notepad calculator
Dart
6
star
17

wikigolf

Find shortest amount of clicks between two Wikipedia pages
TypeScript
5
star
18

maso

Masochist template for web development
JavaScript
5
star
19

pewpewpew

RxJS/BaconJS, but with functions
JavaScript
4
star
20

rust-archive-org-downloader

Rust
3
star
21

conways-game-of-life-3d

Conway's Game Of Life in 3D.
JavaScript
3
star
22

Facebook-Page-Engagement-Rate

facebook-page-engagement-rate
PHP
3
star
23

casi

Composable Asynchronous Iterators โ€” casi
TypeScript
3
star
24

facebook-image-downloader

Download images from your Facebook albums with correct timestamps
JavaScript
3
star
25

pitchbender

TypeScript
3
star
26

metroforce

JS library to generate subway maps with automatic force graph solving
JavaScript
2
star
27

snafuzz

TypeScript
2
star
28

muumishader

Testing out Moomin style shading in 3d
2
star
29

my-terminal-config

Shell
2
star
30

mailigraaferi

Draw graphs from your Thunderbird email inbox
HTML
2
star
31

cobol-testing

Sometimes you just cannot stop to think if you should if you totally could
COBOL
2
star
32

mjolekyl

A Mjรถlekyl busting game!
C#
1
star
33

impossible-hamsters

Reaktor Game Jam 2020 game
C#
1
star
34

tweet-hashtag-app

Hashtags is an app that allows you to easily track and Tweet on hashtags
JavaScript
1
star
35

saas-site

A SaaS site template
HTML
1
star
36

putt-e

A minigolf game made in 12 hours
C#
1
star
37

babble2blog

TypeScript
1
star
38

perlin-pinch

JavaScript
1
star
39

ai-chat-game

TypeScript
1
star
40

website-change-checker

Keep track of websites for their changes
JavaScript
1
star
41

bumper-car-deluxe

C#
1
star
42

neverending-story

TypeScript
1
star
43

labour-calculator

Caluculate probability of labour from vicinity of due date
HTML
1
star
44

pacman-ai-based-game

A simple mobile game based on Pac-Man's AI
C#
1
star
45

tori-fi-karttahaku

TypeScript
1
star
46

pipes

Blender-like pipes system, built with JavaScript
JavaScript
1
star
47

unity-shader-tests

Testing Unity shaders
GLSL
1
star
48

longwood-usestate

TypeScript
1
star
49

legtris

A tetris game in 3 dimensions with Lego blocks
JavaScript
1
star