In-Memory Assemblies

  • Thread starter Thread starter ThunderMusic
  • Start date Start date
T

ThunderMusic

Hi,
I'm trying to make something work and I'm pretty sure it can be done, but I
can't get it working.

I have a encrypted file that contains everything my software needs: exe,
dlls, et al. I want to make a "loader" that will decrypt the file and get
all parts in memory and run the exe in-memory without dropping it to the
disk. Is it possible or not? and how can I do it? I absolutely dont need to
reference the dlls from my loader, it only needs to call the exe and then
the exe could find it's own dlls.

As an other option... is there some place where I could place the file on
the disk without the user being able to access them? I mean, like a virtual
disk reserved exclusively to my own "Loader" application?

thanks

ThunderMusic
 
Hi,
ok, now... since C# seems to require an on-disk assembly, would it be
possible to create like a virtual disk in-memory (like a virtual drive)
where C# could read what it needs to but where the user could not have
access to?

Thanks

ThunderMusic
 
Yes, it is possible, but it is not pretty. You are going to have to
create a custom host for the assembly, which would probe the encyrpted exe
and tell the CLR which assemblies are loaded, etc, etc.

Look into custom CLR hosts for more information.
 
This is great if you load an exe with no dll attached. but I have a some
dll... I tried to use the LoadModule method but the name I specify is not
what is expected from the method. How can I load the dlls the exe needs to
run? the dlls are in memory too.

Thanks

ThunderMusic
 
LoadModule should do the trick, but you need to provide the exact name
as it appears in the exe's manifest...
 
The name will include the namespace + the type name (so, something
like ThunderMusic.Projects.DLL.MyDll).

Does that make sense?
 
Hello!
You wrote on Tue, 6 Nov 2007 09:25:22 -0500:

T> As an other option... is there some place where I could place the file
T> on the disk without the user being able to access them? I mean, like a
T> virtual disk reserved exclusively to my own "Loader" application?

You can implement what you need using Solid File System Driver Edition (
http://www.eldos.com/solfs/driver.php ) however this would require
installation of the custom driver to the system. Installation is done once
(usually during installation of your own application) and rquires
administrator privileges. But you need them to install software anyway.

With best regards,
Eugene Mayevski
http://www.SecureBlackbox.com - the comprehensive component suite for
network security
 
I made it... not by loading a module tought... I handle the
AssemblyResolve event of the AppDomain and load the appropriate assembly
when needed.

Thanks to all..

ThunderMusic
 
Hi ThunderMusic,

Can you please supply a sample code so I can learn how to do what you did?

Thanks a mill
 
Here it is:

// try to run the program
if (m_Files.ContainsKey(APPLICATION_ASSEMBLY))
{
// get the file and load it
Assembly a = Assembly.Load(m_Files[APPLICATION_ASSEMBLY]);
// find the entry point of the file (Main)
MethodInfo mi = a.EntryPoint;
if (mi != null)
{
// create an istance of the Startup form Main method
object o = a.CreateInstance(mi.Name);
// handle the Resolve assembly event so we can handle known
assemblies
AppDomain.CurrentDomain.AssemblyResolve += new
ResolveEventHandler(CurrentDomain_AssemblyResolve);
// invoke the application starting point
mi.Invoke(o, null);
}
}
private static Assembly CurrentDomain_AssemblyResolve(object sender,
ResolveEventArgs args)
{
string AssemblyName = args.Name.Substring(0, args.Name.IndexOf(','));
if (m_Files.ContainsKey(AssemblyName))
{
// Load the requested assembly from our files
Assembly a = Assembly.Load(m_Files[AssemblyName]);
return a;
}
else return null; // unknown assembly (often in the GAC)
}

I hope it helps
 
Back
Top