obfuscation questions

Apr 9, 2012 at 4:11 AM

Hi, I just found this library and have a couple of questions

1) I've played with the exe a bit and I noticed that a lot of things don't get obfuscated, like global variables, function names - how can I force these to obfuscate as well?

2) I want to keep a list of obfuscation constants in a separate file and feed them to the obfuscator as a translation map - can I have numeric values for translations? for example, before minification the code might look like this:

if (direction == PARAM_HORIZONTAL)

and after:

if (n == 5)

Is it possible to feed such a map to the minifier where I have `PARAM_HORIZONTAL=5` ?

 

Thanks!

Coordinator
Apr 13, 2012 at 4:40 PM

1) global variables and functions don't get renamed because they may be referenced by some other JS file or inline script on the page, and I don't have a mechanism right now to create a "table of renamed globals" that can be passed between runs to make sure that everything stays in sync and doesn't collide. Even if I did, I'm not sure it will work because there's no guaratee that AjaxMin will get run on all the scripts of the page every time. For instance, what if your page uses Omniture tracking and I happened to rename a global function in your JS code to "s"? That would cause problems. It's just so risky, I've never put the time into that kind of minification scheme.

If you'd like to do the work yourself (ensuring that renamed globals are consistent, don't collide, etc), you can always use the -rename option to force certain identifiers to be renamed. For instance, if you have a global function "foo" that you want to be renamed to "a" everywhere, and a function bar you want renamed to "b", you can specify -rename:foo=a,bar=b on the command line. That can get a little tedious, though, so there's also the option to put all your rename-mappings into an XML file and just use -rename NFILE switch on the command-line. For the format of the rename file, see the usage message (ajaxmin -?) and look at the syntax for the NFILE construct near the bottom. My example would be: <root><rename from="foo" to="a"/><rename from="bar" to="b"/></root>.

You could use the -a option to get a list of all the global definitions and references in your code first, then use that to generate your rename file. I imagine it wouldn't be too hard to automate that kind of thing. I suppose it would be easier, though, if I provided a command-line switch to generate a simple list-of-globals file automatically. Is that comething you would find useful? Would a simple one-name-per-line text file be sufficient, or would you want more information in the file?

2) I hadn't thought of that. I don't think so, because I believe the application will validate that the target names are valid JavaScript identifiers, and error if they are not. But that could be a really useful! Maybe I should change it so the validation is a valid identifier OR a valid JavaScript primitive constant (numeric, boolean, or null). I assume that you'd like me to do that, no?


Apr 18, 2012 at 2:44 PM

I like you :) Very informative and verbose

1) I'll tell you what my plans are, I plan to use the library for both static and dynamic code, processing the statics once should create a dictionary that will be used also by the dynamic code generator (that's the other post I've made about the "obfuscation mappings"). So there won't be globals at all, everything is obfuscated but javascript internals.

2) It would be really nice if that was supported.

 

Maybe I can help with some of these features? I guess I'll have to make an account and not use this bugmenot account I found :)