Loading Assemblies from the GAC

rendari

Member
Joined
Aug 22, 2006
Messages
8
Programming Experience
Beginner
I have read about the GAC and have a pretty basic understanding of how it works, but now I am wondering, is it possible to load and execute a native image in the GAC from a VB.NET application? If so, how? Thank you for your time,

-rendari
 
Are you talking about creating a native image for you application? If so then it's totally possible, infact i'd recommend it. When loading an assembly the first place it is looked for is in the Native Image Cache, then the GAC then locally. Applications that are installed in the NIC will load much faster. There in an App called NGen.exe (Native Image Generator) I think you'll find it in

VB.NET:
C:/Windows/Microsoft.Net

It's a command line utility, you pass it the path to your application and optionally some other arguments and it will generate a native image of your app, the next time you go to load, the CLR will look for it and load it from there.
 
Hello, and thank you for replying :)

Yes, I understand the part about using NGEN to create an image, but I am actually interested in executing my native image from another VB.net application, not executing the application all by itself.
 
You've misunderstood what i have said... When you install an image in NIC that is where it will get executed from, no matter where the app is called from. So if you use System.Diagnostics.Process.Start(Whatever app) to start your app from within another application if the image inside the NIC is valid that is where it will be executed from.
 
Ahh, it seems I have. Thank you so much for explaining this to me. I'll now experiment with this a bit :)

Once again, thank you!
 
Ok, I have done what you suggested. I NGEN'd a exe that I will call "reminder.exe". I then created a simple program that does this:

System.Diagnostics.Process.Start("reminder.exe")

But it returns an error to me saying "System cannot find the file specified". Am I missing something here?
 
You still need to provide that method with the path to where your exe is..


VB.NET:
System.Diagnostics.Process.Start(Some Drive\Some Folder\SomeExe.exe)
 
Ahh, now I see what you mean.

But I think it is you who has misunderstood the question :).

You have suggested to me to load the original exe. Once the original exe is loaded, I know that it will load the NGEN'd exe out of the GAC. But, I want to go around loading the original exe. I want to directly load the NGEN'd exe in the GAC. That is what I am asking for.

Sorry for the mix up :)

-rendari
 
You start the application the regular way, but if it's already compiled to a Native Image this is detected and used instead of the .Net runtime jitting it to native code as normal. This is how it works, you don't address anything directly in GAC/NIC, it the same with GACed assemblies; for development the physical file is referenced, but in runtime the GAC version takes precedence and is used if present. See About NGEN http://visualbasic.about.com/od/usingvbnet/a/FWTools2.htm
 
Yes, I understand all that, but what I am trying to do is bypass the executable, and run directly out of the GAC. If this isn't possible, just say so, and I'll be on my way :)
 
Right ,you cannot create a shortcut from the native image cache or the GAC and place it on your desktop, can you? No, so if you have an assembly that is installed on the GAC and you have five thousand shortcuts that start that executable including the executable itsself, when it is loaded it will still be run from the GAC so in effect installing an assembly in the GAC or the NIC 'bypasses' the executable.
 
My goal here actually is to use NGEN for copy protection. IL code is easy to decompile and a bitch to encrypt... it would be so much easier if I had native code to work with. That is why I want to bypass the original exe and go straight to the native exe in the GAC.

Meanwhile, I've been searching around the internet. It seems people have had the same idea as me before, and haven't had much success. I guess I will have to try another aproach, but still, I'm open to suggestions

Thank you for your help guys :)

-rendari
 
The native .exe is not installed in the GAC it is installed in a separate folder called the 'Native Image Cache', they are in the same assembly folder but they are entirely different folders. Encrypting CIL is hard i agree. But if what you were trying to do were at all possible then i doubt there would be much of a market for Obfuscators. I don't think it is possible to do what you are trying to do.
I must correct myself, it may be possible to create a shortcut from an assembly in the GAC. You just first need to disable the fusion.dll that renders that folder. You would then be able to execute an app directly from the GAC, but why anyone would want to do this is beyond me.
If you are looking into obfuscation technology then check out my weapon of choice which is called 'Code Veil' But there are loads of other ones out there which i'm sure are just as proficient.
 
Actually, I have already been able to access the GAC and the Native Image Cache via windows explorer by changing some values in the registry, but the native executable in the Native Image Cache is corrupt and unusable, even though it is native compiled.

I actually have had some success in encrypting the IL yesterday. I might post an example soon, but don't expect much since school takes up most of my time :(

I might also take a quick peek at 'Code Veil' if the opportunity presents itself.

Thank you for your time

-rendari :)
 
Just as a note, adding that DWord and disabling the cache viewer is ok but only for inspection purposes whilst developing. It's wouldn't be good practice at all to to do it if you ever plan on releasing an app to a company/client etc.
 
Back
Top