如何在python中使用jsbeautifier解压javascript?

如何在python中使用jsbeautifier解压javascript?,javascript,python,Javascript,Python,我有一个javascript代码,我想解包并美化它,它看起来类似于: eval(function(p,a,c,k,e,r){e=String;if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'^$'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);r

我有一个javascript代码,我想解包并美化它,它看起来类似于:

eval(function(p,a,c,k,e,r){e=String;if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'^$'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('document.body.innerHTML="<iframe width=\'100%\' scrolling=\'no\' height=\'2500\' frameborder=\'0\' src=\'http://www.exmaple.com\'>";',[],1,''.split('|'),0,{}))
eval(函数(p,a,c,k,e,r){e=String;if('0')。替换(0,e)==0{while(c--)r[e(c)]=k[c];k=[function(e){return r[e]| | e};e=function(){return return^$};c=1};而(c--)if(k[c])p=p.replace(new RegExp b'+e(c+++e(c)+++''''\\b','g'),k[c],'return return r[e]e][.html][.html][.split
当我把这个放到jsbeautifier.org上时,我得到:

document.body.innerHTML = "<iframe width='100%' scrolling='no' height='2500' frameborder='0' src='http://www.example.com'>";
document.body.innerHTML=“”;
但是当我尝试使用python库(使用jsbeautifier.beautify)时,它似乎没有正确解包:

print al(function (p, a, c, k, e, r) {
    e = String;
    if ('0'.replace(0, e) == 0) {
        while (c--) r[e(c)] = k[c];
        k = [
            function (e) {
                return r[e] || e
            }
        ];
        e = function () {
            return '^$'
        };
        c = 1
    };
    while (c--) if (k[c]) p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]);
    return p
}('document.body.innerHTML="<iframe width=\'100%\' scrolling=\'no\' height=\'2500\' frameborder=\'0\' src=\'http://www.example.com\'>";', [], 1, ''.split('|'), 0, {}));
打印al(功能(p、a、c、k、e、r){
e=字符串;
如果('0'。替换(0,e)==0){
而(c--)r[e(c)]=k[c];
k=[
职能(e){
返回r[e]| e
}
];
e=函数(){
返回“^$”
};
c=1
};
而(c--)if(k[c])p=p.replace(newregexp('\\b'+e(c)+'\\b',g'),k[c]);
返回p
}('document.body.innerHTML=“””,[],1,,.split('|'),0,{});
我做错了什么

编辑:Python代码是:

import jsbeautifier
#script needs to have '\n' at the beginning otherwise jsbeautifier throws an error
script = """\neval(function(p,a,c,k,e,r){e=String;if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'^$'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('document.body.innerHTML="<iframe width=\'100%\' scrolling=\'no\' height=\'2500\' frameborder=\'0\' src=\'http://www.example.com\'>";',[],1,''.split('|'),0,{}))"""
jsbeautifier.beautify(script)
导入JS美化器
#脚本的开头必须有“\n”,否则jsbeautifier将抛出错误
script=“”\neval(function(p,a,c,k,e,r){e=String;if('0');replace(0,e)==0{while(c--)r[e(c)]=k[c];k=[function(e){return r[e]| | e};e=function(){return return^$};c=1};而(c--)if(k[c])p=p.replace=“”(new exp reg exp('\\b'+e(c'+e(c)'+e(c)+\\b'),'g')、k[c''return r[e]、'html][.html][.html][.split
jsbeautifier.beautify(脚本)

jspeutifier坏了。改用节点js(或幻影js)。工作示例代码如下:

import subprocess
import StringIO

data = r"""eval(function(p,a,c,k,e,r){e=String;if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'^$'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('document.body.innerHTML="<iframe width=\'100%\' scrolling=\'no\' height=\'2500\' frameborder=\'0\' src=\'http://www.exmaple.com\'>";',[],1,''.split('|'),0,{}))"""

data = 'console.log' + data[4:]
p = subprocess.Popen(['node'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
stdout, stderr = p.communicate(data)
print stdout
导入子流程
导入StringIO
data=r“”“eval(函数(p,a,c,k,e,r){e=String;if('0')。替换(0,e)==0{while(c--)r[e(c)]=k[c];k=[function(e){return r[e]| | e};e=function(){return return^$};c=1};而(c--)if(k[c])p=p.replace(new exp reg p('\\b'+e'+e(c'+e(c)''e)(c)\\\\\\\\\b'),'g'),k[c],'return r[e''''.[]html][.html][.html][.html][
数据='console.log'+数据[4:]
p=subprocess.Popen(['node'],stdin=subprocess.PIPE,stdout=subprocess.PIPE)
stdout,stderr=p.communicate(数据)
打印标准

您应该导入此模块:

import jsbeautifier.unpackers.packer as packer
unpack = packer.unpack(some_packed_code)

我已经在Windows 32位JSBeautier 1.54中测试过了。

我认为字符串开头的/n避免了解包程序检测到Js已打包。
试着做jsbeautifier.beautiffy(script.strip())

你的Python代码是什么?@Blender,看我的编辑它看起来是Python端口有问题。啊,好吧,这很烦人。我必须把我的问题提交给他们。用javascript解包是:eval(“String”+packed_String.substr(4))你的答案不清楚,你能详细说明你的建议以及它是如何解决问题的吗?