Home All Groups Group Topic Archive Search About

In-Memory Assemblies

Author
6 Nov 2007 2:25 PM
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

Author
6 Nov 2007 2:56 PM
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


Show quote
"ThunderMusic" <NoSpAmdanlatathotmaildotcom@NoSpAm.com> 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
>
Author
6 Nov 2007 3:14 PM
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
Author
6 Nov 2007 2:58 PM
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
Author
6 Nov 2007 4:21 PM
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

Show quote
"Colby Africa" <colby.afr***@gmail.com> 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
>
>
Author
6 Nov 2007 4:41 PM
Colby Africa
LoadModule should do the trick, but you need to provide the exact name
as it appears in the exe's manifest...
Author
6 Nov 2007 4:43 PM
ThunderMusic
Thanks

And where can I get this name?

Show quote
"Colby Africa" <colby.afr***@gmail.com> 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...
>
>
Author
6 Nov 2007 4:52 PM
Colby Africa
The name will include the namespace + the type name (so, something
like ThunderMusic.Projects.DLL.MyDll).

Does that make sense?
Author
6 Nov 2007 6:53 PM
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

Show quote
"Colby Africa" <colby.afr***@gmail.com> 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?
>
>
Author
6 Nov 2007 9:42 PM
IfThenElse
Hi ThunderMusic,

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

Thanks a mill

Show quote
"ThunderMusic" <NoSpAmdanlatathotmaildotcom@NoSpAm.com> 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" <colby.afr***@gmail.com> 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?
>>
>>
>
>
Author
9 Nov 2007 7:30 PM
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



Show quote
"IfThenElse" <sql_agent***@hotmail.com> 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" <NoSpAmdanlatathotmaildotcom@NoSpAm.com> 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" <colby.afr***@gmail.com> 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?
>>>
>>>
>>
>>
>
>
Author
6 Nov 2007 4:18 PM
Nicholas Paldino [.NET/C# 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

Show quote
"ThunderMusic" <NoSpAmdanlatathotmaildotcom@NoSpAm.com> 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
>
Author
6 Nov 2007 5:00 PM
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

AddThis Social Bookmark Button