In-Memory Assemblies
am 06.11.2007 15:25:22 von 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
Re: In-Memory Assemblies
am 06.11.2007 15:56:13 von 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
"ThunderMusic" wrote in message
news:%232re4EIIIHA.5400@TK2MSFTNGP04.phx.gbl...
> 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
>
Re: In-Memory Assemblies
am 06.11.2007 15:58:27 von Colby Africa
Hey ThunderMusic,
Take a look at this article: http://www.codeproject.com/useritems/LoadExeIntoAssembly.asp
"This example shows how to load an application and run from memory
system. After the application load, you can use it without the source
EXE file (usually blocked from the system). Useful when you don't have
to have the source EXE file on HDD (e.g. on a USB key)."
Colby Africa
http://colbyafrica.blogspot.com
Re: In-Memory Assemblies
am 06.11.2007 16:14:53 von Colby Africa
A RAM disk would be wonderful, but that is implemented as a device
driver... You could take a look at memory mapped files:
http://www.winterdom.com/dev/dotnet/index.html
Re: In-Memory Assemblies
am 06.11.2007 17:18:58 von mvp
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
"ThunderMusic" wrote in message
news:%232re4EIIIHA.5400@TK2MSFTNGP04.phx.gbl...
> 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
>
Re: In-Memory Assemblies
am 06.11.2007 17:21:02 von ThunderMusic
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
"Colby Africa" wrote in message
news:1194361107.396150.214670@k79g2000hse.googlegroups.com.. .
> Hey ThunderMusic,
>
> Take a look at this article:
> http://www.codeproject.com/useritems/LoadExeIntoAssembly.asp
>
> "This example shows how to load an application and run from memory
> system. After the application load, you can use it without the source
> EXE file (usually blocked from the system). Useful when you don't have
> to have the source EXE file on HDD (e.g. on a USB key)."
>
>
> Colby Africa
> http://colbyafrica.blogspot.com
>
>
Re: In-Memory Assemblies
am 06.11.2007 17:41:40 von Colby Africa
LoadModule should do the trick, but you need to provide the exact name
as it appears in the exe's manifest...
Re: In-Memory Assemblies
am 06.11.2007 17:43:48 von ThunderMusic
Thanks
And where can I get this name?
"Colby Africa" wrote in message
news:1194367300.773968.161630@d55g2000hsg.googlegroups.com.. .
> LoadModule should do the trick, but you need to provide the exact name
> as it appears in the exe's manifest...
>
>
Re: In-Memory Assemblies
am 06.11.2007 17:52:54 von Colby Africa
The name will include the namespace + the type name (so, something
like ThunderMusic.Projects.DLL.MyDll).
Does that make sense?
Re: In-Memory Assemblies
am 06.11.2007 18:00:40 von Eugene Mayevski
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
Re: In-Memory Assemblies
am 06.11.2007 19:53:42 von ThunderMusic
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
"Colby Africa" wrote in message
news:1194367974.188180.34340@v3g2000hsg.googlegroups.com...
> The name will include the namespace + the type name (so, something
> like ThunderMusic.Projects.DLL.MyDll).
>
> Does that make sense?
>
>
Re: In-Memory Assemblies
am 06.11.2007 22:42:36 von Sql Agentman
Hi ThunderMusic,
Can you please supply a sample code so I can learn how to do what you did?
Thanks a mill
"ThunderMusic" wrote in message
news:OXRqGaKIIHA.1208@TK2MSFTNGP03.phx.gbl...
>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
>
> "Colby Africa" wrote in message
> news:1194367974.188180.34340@v3g2000hsg.googlegroups.com...
>> The name will include the namespace + the type name (so, something
>> like ThunderMusic.Projects.DLL.MyDll).
>>
>> Does that make sense?
>>
>>
>
>
Re: In-Memory Assemblies
am 09.11.2007 20:30:59 von ThunderMusic
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
"IfThenElse" wrote in message
news:u0UQ03LIIHA.1212@TK2MSFTNGP05.phx.gbl...
> Hi ThunderMusic,
>
> Can you please supply a sample code so I can learn how to do what you did?
>
> Thanks a mill
>
> "ThunderMusic" wrote in message
> news:OXRqGaKIIHA.1208@TK2MSFTNGP03.phx.gbl...
>>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
>>
>> "Colby Africa" wrote in message
>> news:1194367974.188180.34340@v3g2000hsg.googlegroups.com...
>>> The name will include the namespace + the type name (so, something
>>> like ThunderMusic.Projects.DLL.MyDll).
>>>
>>> Does that make sense?
>>>
>>>
>>
>>
>
>