A tool to detect and deobfuscate JavaScript code obfuscated using the P.A.C.K.E.R. method. The JsUnpacker
class can identify obfuscated code and convert it back to its original readable form.
- Automatic detection of P.A.C.K.E.R. obfuscation
- JavaScript deobfuscation capability
- Support for multiple numeric bases (up to base 95)
- Handles custom alphabets for conversion
npm install js-unpacker
const JsUnpacker = require('js-unpacker');
const packedJS = "eval(function(p,a,c,k,e,d){...}('packed code',...,...,'symbols|split|by|pipe'))";
const unpacker = new JsUnpacker(packedJS);
if (unpacker.detect()) {
const unpackedCode = unpacker.unpack();
console.log(unpackedCode);
} else {
console.log("Code doesn't appear to be P.A.C.K.E.R. obfuscated");
}
new JsUnpacker(packedJS)
-
packedJS
: String - Obfuscated JavaScript code
Method | Returns | Description |
---|---|---|
detect() |
boolean |
Returns true if code appears to be P.A.C.K.E.R. obfuscated |
unpack() |
`string | null` |
const packedCode = "eval(function(p,a,c,k,e,r){...}('0 1=2',3,3,'var|foo|42'.split('|'),0,{}))";
const unpacker = new JsUnpacker(packedCode);
if (unpacker.detect()) {
console.log(unpacker.unpack());
// Output: var foo=42
}
The unpacker:
- Detects the P.A.C.K.E.R. pattern:
eval(function(p,a,c,k,e,
- Extracts the payload, radix, count and symbol table
- Uses base conversion to map packed tokens to their original values
- Reconstructs the original code
- Only works with P.A.C.K.E.R. style obfuscation
- May not handle all edge cases of heavily modified variants
MIT License