javascript-obfuscator / grunt-contrib-obfuscator

Grunt plugin for the javascript-obfuscator package.
MIT License
29 stars 20 forks source link

Add identifiers prefix generation #20

Open sanex3339 opened 4 years ago

sanex3339 commented 4 years ago

Hi. https://github.com/javascript-obfuscator/javascript-obfuscator/issues/568

It would be nice if you add a unique identifier names prefix generation for each obfuscated file. The prefix should be as aX, where X - number or counter of the current obfuscated file (0, 1, 2, ...)

The prefix can be overridden by the user prefix.

I just implemented this logic for webpack-obfuscator, you can see example: https://github.com/javascript-obfuscator/webpack-obfuscator/commit/2b227b27bc1e10c687ed656d25a9efb6d16f1a0f#diff-ed009b6b86b017532ef0489c77de5100

Thank you!

slig commented 4 years ago

Hi,

I believe that grunt works differently from webpack. Here each task is specific for a group of files, so the prefix should be specified directly in that task options. On webpack each plugin works on multiple bundles, so there's no way to specify a prefix for each one individually and thus your new logic was necessary.

Inside each task, all the source files are concatenated together and then obfuscated, so there's no issues of duplicated identifiers inside each task https://github.com/javascript-obfuscator/grunt-contrib-obfuscator/blob/master/tasks/obfuscator.js#L58-L60

Please let me know what you think and if I got this right.

Thanks!

softworkz commented 1 year ago

Inside each task, all the source files are concatenated together and then obfuscated, so there's no issues of duplicated identifiers inside each task master/tasks/obfuscator.js#L58-L60

Please let me know what you think and if I got this right.

This is not right, because depending on the task setup you can have many output files, even one output file for each input file and each output file needs its own identifiersPrefix.

I've created a PR here: https://github.com/javascript-obfuscator/grunt-contrib-obfuscator/pull/41 and for those who cannot wait (like me) a new Grunt task: https://www.npmjs.com/package/grunt-contrib-obfuscator-4