Using the free Babel Obfuscator in Silverlight projects

by APIJunkie 2/4/2010 5:24:00 AM

One of the problems with Silverlight managed code is that it can easily be reverse engineered using standard .NET reflection tools.

Although no method can completely prevent reverse engineering your code there are ways to slow down and even deter all but the most persistent hackers.

Most of the tools I found that can be used to obfuscate Silverlight code are not free. But the Babel obfuscator by Alberto Ferrazzoli is an open source .NET obfuscator that can be used in Silverlight based projects.

Babel is a command line tool and it can be integrated into your build process. One way to do that is to add it to your post build events.

When you run babel on a target dll (assembly) it will generate an obfuscated version of the dll in the directory “.\BabelOut” relative to your dll output directory.

Usage Example:

"D:\Program Files \Babel\babel.exe" $(TargetPath) --noildasm --nomsil --noinvalidopcodes

Some caveats that apply to current babel version 2.0.0.1:

1.       The current version does not support obfuscating xap files directly but you can unzip the files first or integrate the babel tool into your build process.

 

2.       Not all command line parameters/options are supported in Silverlight projects. The following options work:

       --noildasm --nomsil –noinvalidopcodes

 

3.       Some assemblies (dll’s) that contain resources do not seem to obfuscate correctly (Its very easily detected they are not usable after obfuscation). If you have this problem you can always move all the sensitive code into a separate Silverlight code library and obfuscate only the code library.

Example:

Let’s assume you have one monolithic project called: “MySilverlightApp” that contains all the code and resources (xaml, images etc.) that will not obfuscate. To solve the problem:

1.       Add a new project to the solution called “MySilverlightAppCode” of type “Silverlight Class Library”.

2.       Add a reference to the new Silverlight library from the “MySilverlightApp” project.

3.       Move all the sensitive code files into the new Silverlight code library (“MySilverlightAppCode”).

4.       Obfuscate only the “MySilverlightAppCode” assembly (MySilverlightAppCode.dll).

 

Currently rated 4.7 by 3 people

  • Currently 4.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Silverlight | How To

Running multiple commands on a Visual Studio post-build event using batch files

by APIJunkie 1/31/2010 11:13:00 AM

 Many times it’s more desirable to collect your post build commands into batch files. Some of the reasons include easier maintenance, portability and satisfying the “don’t repeat principle” when multiple projects are sharing the same commands. If you do decide to go down the batch road there are a couple of things you should be aware of:

1.       If you want to run multiple batch files or commands. You will need to use the “call” command to ensure that all the other commands execute. If you don’t do that only the first batch file will run. To use the call command, simply precede each batch file name with “call”.

Example:

Instead of writing:

 C:\MyBatchFile.bat

Write:

call C:\MyBatchFile.bat

 

2.       Sometimes you will need to run external programs that could be installed in different locations on different dev machines. In such cases you might find the batch “start” command very useful. Instead of specifying the path, you just use the external program name or its file associations.

Example:

Let’s say you have several developers that have installed Winrar in different locations.

Writing: “C:\XXX\Winrar.exe” in the batch will not work in cases where developers installed it on another drive or location.

But writing: “start winrar” in the batch will work if it’s installed on the developer’s machine.

 Hope this helps!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.NET | Visual Studio | Portability

_mkdir C runtime library function might return unexpected error values

by APIJunkie 12/22/2009 8:05:00 AM

mkdir is a C runtime library function that creates directories.

In contrary to what could be understood from the MSDN documentation:

“…On an error, the function returns –1 and sets errno as follows.EEXIST Directory was not created because dirname is the name of an existing file, directory, or device.ENOENT Path was not found.For more information about these and other return codes, see _doserrno, errno, _sys_errlist, and _sys_nerr.”

mkdir might return other error values. For example when calling mkdir on an existing directory the function might return EEXIST but can also return EACCES (permission denied). The function error results seem to differ according to user access permissions on the system. This has been tested on Windows 2003/Vista/7. For more information and portability issues check out this discussion about mkdir portability in Kernel trap.

·         Note that this discussion applies to Microsoft’s implementation of the C run time library.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

C++ | C | Microsoft | Portability

MFC OnTimer function does not compile when porting legacy code from 32-bit to 64-bit

by APIJunkie 12/22/2009 7:17:00 AM

I was recently porting an MFC C++ application that compiled on Visual studio 2005 32-bit to VS 2008 64-bit.

It turns out there is a bug in the code generated by older versions of MFC that makes it not compile on 64 bit.

The problem is with the OnTimer function signature:

      afx_msg void OnTimer(UINT nIDEvent); 

It should be changed to ->

      afx_msg void OnTimer(UINT_PTR nIDEvent);

 

You can find Microsoft’s reaction to a similar connect bug report for VS 2005 at:

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101372

Hope this helps!

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

MFC | C++ | Win64

3XH Silverlight high score and in game achievement API is now available to developers

by APIJunkie 11/27/2009 9:19:00 AM

As we mentioned before we have been busy working on our new Silverlight in-game event system, code name 3XH. You can see it in action on our featured games section on Mashooo.com. The system allows Silverlight game developers to work with high scores and user achievements without the hassle of building and maintaining the framework and the system to support them. The system was in closed beta testing until now. We were working with a limited number of developers (Jeff Weber, David Lévesque, Daniel James and Ian Tomlinson) to fine tune the system.  We are happy to announce that as of today we are opening the 3XH developers program and the services it includes. All Silverlight game developers can now start using our new Silverlight high score and in game achievement system (3XH).

3XH highlights include:

1.       Flexible system to store/retrieve high scores, achievements and other game events.

2.       Ability to use the system on any web site.

3.       Multi login support (Facebook, OpenID, AOL, Yahoo, Google and more to come.)

4.       Current player information.

5.       Integrated Reward system to reward users for their game achievements.

6.       Managed prize bearing contests.

7.       100% Silverlight from the ground up and much more.

To participate in the program or to find out more information read the 3XH developers manual.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Silverlight | Games

Fix for ObjectDataSource delete method - object value passed to the delete method is null

by APIJunkie 9/3/2009 7:54:00 PM

I recently stumbled upon a not very well documented "design feature" that took me a couple of hours to track down.

If you are defining a custom delete function for an ObjectDataSource you must also remember to define the DataKeyNames property of the GridView you are working with. If you do not remember to do this, the object’s value passed to your delete function will be null.

You can read more about the ObjectDataSource delete issue here.

Hope this helps!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.NET | PRB | Troubleshoot

Mashooo S Prize Silverlight Game Contest Rating Period

by APIJunkie 6/16/2009 12:06:00 AM

My hat is off to the Silverlight game developers community.

Who would have believed the quality and quantity of Silverlight games produced by this growing, vibrant and amazing community of Silverlight game developers.

If anyone had any doubts about the future of Silverlight game development those doubts will immediately be put to rest once they see what have been achieved in this contest.

The contest is now in the community rating period until Sunday, Jun 21'st. The winners will get some great prizes but they first have to qualify by reaching the top ten community favorites list.

So if you have a few minutes to spare come play the games and rate the S Prize game submissions.

Good luck to all the contestants!

-JB

Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Silverlight | Games

How to add Silverlight version detection to Google Analytics

by APIJunkie 5/15/2009 6:35:00 AM

One of the things that are currently missing from Google Analytics is Silverlight detection. Normally this type of information would appear under the browser capabilities section, the same section that lists Flash and Java versions. While I'm sure this will change eventually, it is something that can be very useful to web sites hosting Silverlight applications today.

In order to bridge this detection hole here is a simple solution that would plug this information into Google analytics.

The solution is based on 2 things:

1. Custom visitor segments  - Google Analytics allows us to create user defined values that can be stored and reported upon.

2. Silverlight JavaScript detection code - Code that allows you to detect the installed Silverlight version on the client's browser.

Awhile back I showed how to detect/report the current Silverlight version in JavaScript. Combining this code with Google analytics code to report user defined values is fairly simple. The following code is a rough example that would do the trick:

////////////////////////////////////////////////////

// Google analytics include files

////////////////////////////////////////////////////

<script type="text/javascript">

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

</script>

////////////////////////////////////////////////////

// Report Silverlight version to Google analytics

////////////////////////////////////////////////////

<script type="text/javascript">

var pageTracker = _gat._getTracker("UA-xxxxx-x");

pageTracker._setVar('SLVersion ' + getSilverlightVersion() );

</script>

////////////////////////////////////////////////////

Notes:

1. Remember to replace UA-xxxxx-x with your Google analytics code in the code example.

2. The information you report to Google analytics will appear under user defined values in the visitors section.

3. You can use Advanced Segments to integrate your user defined values into other reports.

4. There is normally a time delay in Google analytics reporting so it might take a few hours before you start to see the effects of your new code.

Good Luck!

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Silverlight | How To | Google | Analytics

Mashooo S Prize Silverlight Game Contest Update

by APIJunkie 4/26/2009 10:40:00 PM

Wow it's been an amazing month. The contest has just begun and there are already 15 game submissions to the Mashooo S Prize. To top it all the quality bar for Silverlight games just keeps on rising. Silverlight games are really starting to look like the wave of the future when it comes to casual web games.

I can't wait to see what new games the talented Silverlight developer community is going to come up with next.

You can checkout the latest Silverlight game submission list here and don't forget to comment and rate your favorite games.

-JB

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Silverlight | Games

How to programmatically detect Silverlight version

by APIJunkie 4/24/2009 11:39:00 PM

Two questions that often arise when building Silverlight based websites are:

  A. How do I detect if Silverlight is installed on a visitor's browser?

  B. How do I detect what version of Silverlight is installed on a visitor's browser?

The answer to A is relatively simple since Silverlight.js (the standard Silverlight javaScript include file) contains a function that we can use. The function is called isInstalled and it returns true/false. You can use it the following way to detect if there is any Silverlight version installed:

<script src="Silverlight.js" type="text/javascript"></script>

var isSLInstalled = Silverlight.isInstalled(null)

The answer to B is a little more complex since for some reason there is no direct way to get Silverlight's version number. Basically the only documented way to answer this question is to repeatedly call isInstalled with different version numbers until you get the right version.

Example:

Silverlight.isInstalled('3.0')

Silverlight.isInstalled('2.0')

Silverlight.isInstalled('1.0')

etc.

Every time we call isInstalled the function code goes through the same process of trying to create an ActiveX/Plugin object etc. In some parts of the programming world this kind of inefficiency would be labeled as border line heresy. But luckily Since we are normally only interested in Silverlight's major version we can do things a little more efficiently. The function below will only return 0,1,2,3 where 0 stands for no version and 1 to 3 stand for a Silverlight major version.*

//////////////////////////////////////////////////////////////////

// get major Silverlight version

// Return values:

// 0 -> Silverlight not installed (at least not properly).

// 1 -> Silverlight 1 installed

// 2-> Silverlight 2 installed

// 2-> Silverlight 3 installed

//////////////////////////////////////////////////////////////////

getSilverlightVersion = function() {

var SLVersion;

try {  

       try {

            var control = new ActiveXObject('AgControl.AgControl');

            if (control.IsVersionSupported("3.0"))                

               SLVersion = 3;

            else

            if (control.IsVersionSupported("2.0"))               

               SLVersion = 2;

            else

               SLVersion = 1;           

            control = null;

      }

      catch (e) {      

                     var plugin = navigator.plugins["Silverlight Plug-In"];

                     if (plugin)

                     {         

                       if (plugin.description === "1.0.30226.2")             

                          SLVersion = 2;

                       else

                          SLVersion = parseInt(plugin.description[0]);

                      }

                      else

                         SLVersion = 0;

      }

}

catch (e) { 

      SLVersion = 0;

}

return SLVersion;

}

-------------

* Note that this code will break with future versions of Silverlight/silverlight.js so it needs to be rechecked when a new version is released.

 

Currently rated 5.0 by 4 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Silverlight | How To

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

About the author

Name of author

My name is Bacon…James Bacon.

I am an API wars veteran I was wounded by x86 assembly, recovered and moved on to C. Following a long addiction to C++ and a short stint at rehab I decided to switch to a healthier addiction so I am now happily sniffing .NET and getting hooked on Silverlight.

I am mainly here to ramble about coding, various API’s, Junkies(me especially) and everything else that happens between coders and their significant other.

E-mail me Send mail


Calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Sign in