No obfuscation?

Oct 18, 2012 at 3:36 AM

Hi there

Whether I have

ObfuscateJavaScript="True"

or no value set at all, my JavaScript does not seem to be being Obfuscated at all - the function names are all the same as the source JavaScript files, as are the variables.

What am I missing? Or are variables and function names only obfuscated if they fit the right criteria? I don't suppose it has anything to do NOT concatenating my files, instead keeping them separate (by listing numerous <JavaScriptFiles> file nodes in the <ItemGroup> node, and JavaScriptCompressorTask node, specifying OutputFile="%(JavaScriptFiles.Identity).min")?

Any response greatly appreciated.

Cheers
Matt

Coordinator
Oct 18, 2012 at 3:45 AM

Hi Matt - obfuscation has nothing to do with the the bundling.

Lets see. what I'll do first of all is find a website that uses the -original- java code and see if i can obfuscate that. This way, I can use that result as a goal/benchmark/target point.

lets see here...

 

1. search google
2. goto first result: http://refresh-sf.com/yui/

ok. that uses a slightly newer version of YUI Compressor compared to our version. None-the-less, enter your data in there and tell me if you get the same result as with the YUICompressor.NET

i'm also assuming that you're using MSBuild to 'run' a .proj file with all the settings? 

Oct 18, 2012 at 4:51 AM

Hi purekrome, and thanks again.

Yeah I'm using MSBuild and a post-build event, as per the second/last video here: http://yuicompressor.codeplex.com/ (btw the first video in that link no longer works).

Also, yes, using http://refresh-sf.com/yui/ gives the same result as my .NET build task/event, so I must be missing something about what the compressor is obfuscating.

Here is a vastly simplified version of my JS:

var needsSave = false;

$(document).ready(function() {
	setupFront();
});

function setupFront(){
	$('#borderWidth').change(function() {
		changePadding(this);
	});
}

function changePadding(element){
	var photoWidth = parseInt($('#photoWidth').val());
	var photoHeight = parseInt($('#photoHeight').val());
	var borderWidth = parseInt($(element).val());
	updateInterfaceSpacing(photoWidth, photoHeight, borderWidth)
	dataNeedsSave();
}

function updateInterfaceSpacing(photoWidth, photoHeight, borderWidth){
	$('.canvas').width(photoWidth + (2 * borderWidth));
	$('.transparentbox, .backgroundImage img').width(photoWidth + (2 * borderWidth)).height(photoHeight + (2 * borderWidth));
}

function dataNeedsSave(){
	needsSave = true;
	if($('#saveDraft').text() != 'Save Draft'){
		$('#saveDraft').text('Save');
	}
	$('#saveDraft').removeClass('disabled');
}

 

So, I thought that the obfuscation would, for example, swap variables:

var needsSave = false;

for 

var a = false;

and swap function names

function setupFront(){

for

function b(){

Or something along these lines - like the way the jQuery library is unreadable when it's minimised.

So where am I misunderstanding?

Thanks again

Cheers
Matt

Coordinator
Oct 18, 2012 at 6:11 AM
Edited Oct 18, 2012 at 6:12 AM

Wow - interesting!

ok. lets see what google says:

http://yuilibrary.com/forum/viewtopic.php?p=29311

interesting. 2 things. 

1 - eval (which is not the case, above).

2 - errors and warnings? maybe if there are none, it will work.

I'll see if the other dev freeranger jumps in here and has an idea.

long story short => if it doesn't work on the java version, it won't work here. I did a flat warts-and-all conversion (on purpose).

And finally, i would have thought that

ObfuscateJavaScript="True"

 

does exactly what u suggested.

Coordinator
Oct 18, 2012 at 8:16 AM
Edited Oct 18, 2012 at 8:18 AM

Globally scoped thingys don't get obfuscated.  Think about it - I have a function foo() in one .js, and I might call it in another script, but now it has been obfuscated to bar(), so my call fails - doh!

If we look at a code fragment:

var needsSave = false;

function setupFront(){
     $('#borderWidth').change(function() {
                changePadding(this);
     });
}
function changePadding(element){
      var photoWidth = parseInt($('#photoWidth').val());
}

needsSave, setupFront, and changePadding are all globally scoped so the best that you will get is:

var needsSave=false;function setupFront(){$("#borderWidth").change(function(){changePadding(this)})}function changePadding(a){var b=parseInt($("#photoWidth").val())};

You can see that changePadding has had it's parameter and internal variable declaration obfuscated

Inner scoped jobbies are obfuscated as expected, so source code like this:

function setupFront(){
    var needsSave = false;
	                    
    $('#borderWidth').change(function() {
        changePadding(this);
    });

    function changePadding(element) {
        var photoWidth = parseInt($('#photoWidth').val());
    }
};

becomes:

function setupFront(){var b=false;$("#borderWidth").change(function(){a(this)});function a(d){var c=parseInt($("#photoWidth").val())}};

and you can see that whilst setupFront remains as is (beong globally scoped), the inner declarations and params to inner functions have all been obfuscated as expected.

The parseInt call has not because it is not part of this script and is presumably globally scoped elsewhere

hth

Coordinator
Oct 18, 2012 at 9:48 AM

Ah!

Oct 19, 2012 at 12:18 AM

Excellent, thanks freeranger.

I should have realised re Global Scoping - doh!, as you say :)

I will look at inner declarations in order to increase performance (both code-length and memory wise).

Thanks again

Cheers
Matt

Oct 19, 2012 at 1:59 AM

In fact I should probably convert my code in to a jQuery plugin.