How JSNice works
Joint predictions: all unknown properties of a program are predicted simultaneously so that the result is likely and internally consistent. Names that cannot be safely changed such as globals, object properties and API names are held fixed, and no two distinct locals in one scope are given the same name.
Minified input
function f(a, b, c){b.open('GET',a,false);b.send(c);}
Predicted names
function f(fileUrl, req, message) {
req.open('GET', fileUrl, false);
req.send(message);
}
Input without annotations
function f(a) {
return a + 1;
}
Inferred JSDoc
/**
* @param {number} n
* @return {?}
*/
function f(n) {
return n + 1;
}
Paper
Predicting Program Properties from “Big Code” (POPL 2015).
- 63.4%of identifier names reconstructed exactly, against 25.3% for leaving the minified code untouched
- 81.6%precision on predicted type annotations, at 66.9% recall
- 30,000+developers used JSNice in the first week after its 2014 release, per the paper
Get the code
-
Nice2Predict
“Learning framework for program property prediction.” The language-agnostic structured-prediction core — training and MAP inference — that served as the backend for JSNice. Language-specific parsing and feature extraction are left to a front end.
-
UnuglifyJS
“A simpler open-source version of JavaScript deobfuscator JSNice.” A fork of UglifyJS that parses JavaScript, emits the dependency network, and applies the names Nice2Predict returns. Name prediction only — it does not do type inference. Published on npm as
unuglify-js. -
JSNice artifact
The artifact published alongside the paper, containing an engine, a trained model and the evaluation dataset. The list of GitHub repositories used for training is published separately.
-
debin
“Machine Learning to Deobfuscate Binaries.” The same idea carried to stripped binaries: recovering names and types as predictions. Built, like DeGuard for Android, on top of Nice2Predict.
More resources
- BigCode: Statistical Programming Engines The umbrella project page, with the full publication and talk lists, datasets, and the related engines Nice2Predict, DeGuard and DEBIN. Funded by ERC grant BIGCODE — #680358.
- Programming tools with big data and conditional random fields The SRI Lab page for JSNice and the POPL’15 framework: motivation, how it works, and the paper.
- 150k JavaScript Dataset 150,000 JavaScript files and their parsed ASTs, released by the lab. A 150k Python dataset is also available.
- SRI Lab, ETH Zurich The Secure, Reliable, and Intelligent Systems Lab, formerly the Software Reliability Lab, in the Department of Computer Science.