Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
346 views
in Technique[技术] by (71.8m points)

javascript - How to restore obfuscated property names?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...