混淆的代码在Greasemonkey脚本中引发错误

问题描述:

我有一个Greasemonkey脚本,我想对其进行混淆.我想知道可用的.

I have a Greasemonkey script that I want to be obfuscated. I was wondering what goes wrong with the available "Packer" Javascript obfuscator.

它可以很好地压缩脚本,但是安装后,该脚本将无法正常工作.是否有任何PHP类会混淆/打包GM脚本并保留功能?还是我该怎么做?

It compresses the script fine but after installation, the script doesn't work. Is there any PHP Class that would obfuscate/pack GM scripts and retain functionality? Or how do I go about doing this?

错误:

Timestamp: 01-05-2013 13:11:35
Error: missing ; before statement
Source File: file://file_path
Line: 1

脚本:

// ==UserScript==
// @name           Test
// @namespace      http://*
// @description    Test
// @require         http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
// ==/UserScript==

var SomeVar = "Something";
GM_setValue("foo","bar");
var AnotherVar = GM_getValue("foo");
alert(AnotherVar);

打包脚本:

eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('0 3="4";5("1","6");0 2=7("1");8(2);',9,9,'var|foo|AnotherVar|SomeVar|Something|GM_setValue|bar|GM_getValue|alert'.split('|'),0,{}))

实际上,您的打包脚本"在我的测试页上工作正常.您确实保持了元数据块 ,对吗?

Actually, your "Packed Script" works fine on my test page. You did keep the Metadata block as-is, right?

此外,您还应该添加:

// @grant GM_setValue
// @grant GM_getValue

到元数据块以(1)避免jQuery(和其他)冲突,以及(2)确保始终打开那些GM_函数.

to the metadata block to (1) avoid jQuery (and other) conflicts and (2) ensure that those GM_ functions are always switched on.

您的问题是以下一项或多项问题:

Your problem is one or more of:

  1. 您尝试打包或混淆元数据块. 您不能这样做; Greasemonkey附加组件使用这种精确的明文格式来确定如何处理给定脚本.
  2. 与特定页面冲突. (@grant设置应该可以解决此问题.)
  3. 您的代码中有没有显示给我们的东西.
  4. Firefox的编辑错误,安装错误或混淆"实例.

  1. You tried to pack or obfuscate the Metadata block. You cannot do this; the Greasemonkey add-on uses this precise, clear-text format to determine how to handle a given script.
  2. A conflict with a specific page. (The @grant settings, should fix that).
  3. Something in your code that you are not showing us.
  4. An edit error, installation error, or "confused" instance of Firefox.

  1. 卸载脚本.
  2. 完全关闭Firefox,确保所有FF任务都已停止.
  3. 重新启动FF并重新安装脚本.
  4. 按照故障排除提示从脚本错误"开始,向下.
  5. 另请参见问题排查(脚本作者)
  1. Uninstall the script.
  2. Completely shutdown Firefox, make sure all FF tasks have stopped.
  3. Restart FF and reinstall the script.
  4. Follow the troubleshooting tips starting at "Script Errors", on down.
  5. See, also, Troubleshooting (Script Authors)