How to restore obfuscated property names?

2020-01-27 08:04发布

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条回答
forever°为你锁心
2楼-- · 2020-01-27 08:37

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.

查看更多
登录 后发表回答