最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Obfuscated code throws error in a Greasemonkey Script - Stack Overflow

programmeradmin4浏览0评论

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

It presses 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?

Error:

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

Script:

// ==UserScript==
// @name           Test
// @namespace      http://*
// @description    Test
// @require         .7.1/jquery.min.js
// ==/UserScript==

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

Packed Script:

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,{}))

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

It presses 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?

Error:

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

Script:

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

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

Packed Script:

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,{}))
Share Improve this question edited May 1, 2013 at 9:55 Brock Adams 93.7k23 gold badges241 silver badges305 bronze badges asked May 1, 2013 at 7:31 HrishikeshHrishikesh 1,1831 gold badge8 silver badges23 bronze badges 7
  • 3 Just going to throw it out there - you know those packers won't stop a mildly-determined person from viewing the code, right? – Jonathon Reinhart Commented May 1, 2013 at 7:33
  • Any error codes in the console? – dda Commented May 1, 2013 at 7:34
  • If something does not work, and you decide to ask for help, then mention what problems you are facing (error messages, relevant system information, and do on). – Sverri M. Olsen Commented May 1, 2013 at 7:38
  • I understand that it won't stop determined person from viewing the code, but it still is some level of security, and at least makes it harder for them to decipher. (@ Others: Error obtained didn't seem significant, syntax error, but added it anyway) – Hrishikesh Commented May 1, 2013 at 7:42
  • Packer just makes me curious to see the code. It take 1 second to copy to the console and add console.log. – ColBeseder Commented May 1, 2013 at 7:51
 |  Show 2 more ments

1 Answer 1

Reset to default 12

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

Also, you should add:

// @grant GM_setValue
// @grant GM_getValue

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. 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. 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)
发布评论

评论列表(0)

  1. 暂无评论