How to restore obfuscated property names?

3k views Asked by At

So I'm decrypting a javascript code, and after long time of looking on the internet I have no clue on how to decrypt this a quick way.

The code starts off with a large Array containing all strings of the entire script.

 var _$_21e2 = ["jQuery", "userAgent", "test", "onmouseup", "onmousemove", "pink", "greenyellow", "gold"]

There are more string in the array, but this is just an example.

And then in the rest of the code it just calls the string from the array, by id.

_$_21e2[29]

I know I can just do this manually but there are around 120 strings so it would be taking too much time to do this. Is there a way to quickly decrypt this? Thanks in advance.

1

There are 1 answers

4
Bergi On BEST ANSWER

A simple regex replace will do:

var _$_21e2 = ["jQuery", "userAgent", "test", "onmouseup", "onmousemove", "pink", "greenyellow", "gold"];
return code.replace(/\[_\$_21e2\[(\d+)\]\]/g, function(_, i) {
    return "."+_$_21e2[i];
}).replace(/_\$_21e2\[(\d+)\]/g, function(_, i) {
    return JSON.stringify(_$_21e2[i]);
});

Given the code as a string, this will yield a code string with human-readable property names and literals.