tags:

views:

637

answers:

5

I would like to use NGEN.EXE in order to generate native images of my assemblies before I create my installer. I am hoping this will keep my binaries Reflector-proof. Am I correct about this?

I have just come to understand that all native images are now being stored in the Native Image Cache. Is there a way to get native binaries which I can then package with an installer? On the other hand, is it possible to get rid of the original assemblies after generating the native images?

EDIT: I am using an application which uses a hard-coded key for encryption when talking to a server. With .NET, it becomes ridiculously easy for folks to lay their hands on the key.

+1  A: 

This is very much not supported by NGEN and the .net framework, but there are 3rd party tools that can do this, google for ".net linker".

I recommend not doing it, MS have valid reasons for not supporting this.

Nir
"MS have valid reasons for not supporting this." I've heard that a little more often than I'd like. If only MS would allow me to take the risks I feel like taking, I could leave work a little earlier each day.
Vulcan Eager
Some of the reasons are security related, if they let you do that you could bypass the .net security system, now you may be trustworthy but if you can bypass the system so can the bad guys.
Nir
+1  A: 

You cannot ship only the ngen image of the assembly. The runtime still requires the actual assembly to exist even when it has a native image of it. The reason is the assembly metadata is not carried over to the native image.

Mehrdad Afshari
"The reason is the assembly metadata is not carried over to the native image." That is exactly what I want. A native image with no metadata.
Vulcan Eager
But it's not what the CLR wants. CLR requires the metadata. Basically, things like .NET linker don't directly use the CLR. They somehow used a *hacked* version to work.
Mehrdad Afshari
+3  A: 

I can see several problems with what you trying to achive.

1) As has been mentioned by @Mehrdad the assembly is still required for metadata, even if a native image exists.
2) A native image is only valid on the machine it was compiled on. The JIT compiler does optimisations that normally cannot be done because it knows EXACTLY what hardware the code will need to run on.
3) Even a native image can be de-compiled. It is just slightly easier to take appart a managed dll.

Do you mind telling us why do you want to hide your source code?

EDIT: Judging by how quickly each new version of WGA gets hacked, i suspect, if your software is remotely useful, someone will have the key out and on the internet (or p2p or whatever) within hours of each new version of your software, and they are going to be the people that are quite happy to disassemble a native image. Or maybe just read the machine code :)
My personal approch would be to make sure your application works well and is fairly priced. The honest people will not steal it, the dishonest will find a way regardless of what you do. Ultimatly if they have your application to run there is nothing you can do to completly control what they do with it, although you can make it slightly harder for them to use reflector by using an obfuscator first, but in the end its just like real life really, locks only keep out honest people.

Of course, if you can move some important part of your applications functionality out of the client and into a web service then you stand more chance. You can create accounts with usernames and passwords for clients, the application requests this when it is run and uses it to authenticate to the web service. If their use of this application has expired then the web service refuses their request.

pipTheGeek
"A native image is only valid on the machine it was compiled on." We can handle this issue by calling NGEN post-install.
Vulcan Eager
"Even a native image can be de-compiled. It is just slightly easier to take appart a managed dll." At the very least, it is not as easy as opening the assembly using Reflector.
Vulcan Eager
Some of my code is used to contact a license server. It uses a hard coded encryption key (an array of bytes) within the assembly. Reflector lays bare the entire license scheme. Keys, registry locations, timers and all.
Vulcan Eager
You probably should implement that component in a native dll. As already stated the MSIL assembly needs to be present on the target system plus the native compilation needs to be done post-install.
0xA3
A: 

There's no reason why you should use Native image. This tool is made for developement to speed up things. It's not an application, it's an image so changing Computer CPU, Dot net configuration will make your image non valid, so it's not really usable. Cracking your software is possible, any software is cracked, there is ones that weren't? Don't care about piracy, suppose it exists :)

Omar Abid
A: 

Hahaha! All you people who need to know why would someone want to "hide" their source code. Why do you need a reason for that? If a developer chooses to do so, then so be it. Did M$ make the source code for Office available? I don't think so. Yes, software can be cracked, as in break the password and suchs, but that's different from making your algorithms and data structures visible to all the software developers and companies in the world.