In-Memory Assemblies

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ThunderMusic

    #1

    In-Memory Assemblies

    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


  • Colby Africa

    #2
    Re: In-Memory Assemblies

    Hey ThunderMusic,

    Take a look at this article: http://www.codeproject.com/useritems...toAssembly.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
    Blogger ist ein Veröffentlichungs-Tool von Google, mit dem du ganz einfach deine Gedanken der Welt mitteilen kannst. Mit Blogger kannst du problemlos Texte, Fotos und Videos in deinem persönlichen Blog oder deinem Team-Blog veröffentlichen.



    Comment

    • ThunderMusic

      #3
      Re: In-Memory Assemblies

      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


      "ThunderMus ic" <NoSpAmdanlatat hotmaildotcom@N oSpAm.comwrote in message
      news:%232re4EII IHA.5400@TK2MSF TNGP04.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
      >

      Comment

      • Colby Africa

        #4
        Re: In-Memory Assemblies

        A RAM disk would be wonderful, but that is implemented as a device
        driver... You could take a look at memory mapped files:




        Comment

        • Nicholas Paldino [.NET/C# MVP]

          #5
          Re: In-Memory Assemblies

          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.co m

          "ThunderMus ic" <NoSpAmdanlatat hotmaildotcom@N oSpAm.comwrote in message
          news:%232re4EII IHA.5400@TK2MSF TNGP04.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
          >

          Comment

          • ThunderMusic

            #6
            Re: In-Memory Assemblies

            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" <colby.africa@g mail.comwrote in message
            news:1194361107 .396150.214670@ k79g2000hse.goo glegroups.com.. .
            Hey ThunderMusic,
            >
            Take a look at this article:

            >
            "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
            Blogger ist ein Veröffentlichungs-Tool von Google, mit dem du ganz einfach deine Gedanken der Welt mitteilen kannst. Mit Blogger kannst du problemlos Texte, Fotos und Videos in deinem persönlichen Blog oder deinem Team-Blog veröffentlichen.

            >
            >

            Comment

            • Colby Africa

              #7
              Re: In-Memory Assemblies

              LoadModule should do the trick, but you need to provide the exact name
              as it appears in the exe's manifest...


              Comment

              • ThunderMusic

                #8
                Re: In-Memory Assemblies

                Thanks

                And where can I get this name?

                "Colby Africa" <colby.africa@g mail.comwrote in message
                news:1194367300 .773968.161630@ d55g2000hsg.goo glegroups.com.. .
                LoadModule should do the trick, but you need to provide the exact name
                as it appears in the exe's manifest...
                >
                >

                Comment

                • Colby Africa

                  #9
                  Re: In-Memory Assemblies

                  The name will include the namespace + the type name (so, something
                  like ThunderMusic.Pr ojects.DLL.MyDl l).

                  Does that make sense?


                  Comment

                  • Eugene Mayevski

                    #10
                    Re: In-Memory Assemblies

                    Hello!
                    You wrote on Tue, 6 Nov 2007 09:25:22 -0500:

                    TAs an other option... is there some place where I could place the file
                    Ton the disk without the user being able to access them? I mean, like a
                    Tvirtual 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

                    Comment

                    • ThunderMusic

                      #11
                      Re: In-Memory Assemblies

                      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.africa@g mail.comwrote in message
                      news:1194367974 .188180.34340@v 3g2000hsg.googl egroups.com...
                      The name will include the namespace + the type name (so, something
                      like ThunderMusic.Pr ojects.DLL.MyDl l).
                      >
                      Does that make sense?
                      >
                      >

                      Comment

                      • IfThenElse

                        #12
                        Re: In-Memory Assemblies

                        Hi ThunderMusic,

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

                        Thanks a mill

                        "ThunderMus ic" <NoSpAmdanlatat hotmaildotcom@N oSpAm.comwrote in message
                        news:OXRqGaKIIH A.1208@TK2MSFTN GP03.phx.gbl...
                        >I made it... not by loading a module tought... I handle the
                        >AssemblyResolv e event of the AppDomain and load the appropriate assembly
                        >when needed.
                        >
                        Thanks to all..
                        >
                        ThunderMusic
                        >
                        "Colby Africa" <colby.africa@g mail.comwrote in message
                        news:1194367974 .188180.34340@v 3g2000hsg.googl egroups.com...
                        >The name will include the namespace + the type name (so, something
                        >like ThunderMusic.Pr ojects.DLL.MyDl l).
                        >>
                        >Does that make sense?
                        >>
                        >>
                        >
                        >

                        Comment

                        • ThunderMusic

                          #13
                          Re: In-Memory Assemblies

                          Here it is:

                          // try to run the program
                          if (m_Files.Contai nsKey(APPLICATI ON_ASSEMBLY))
                          {
                          // get the file and load it
                          Assembly a = Assembly.Load(m _Files[APPLICATION_ASS EMBLY]);
                          // 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.CreateInstanc e(mi.Name);
                          // handle the Resolve assembly event so we can handle known
                          assemblies
                          AppDomain.Curre ntDomain.Assemb lyResolve += new
                          ResolveEventHan dler(CurrentDom ain_AssemblyRes olve);
                          // invoke the application starting point
                          mi.Invoke(o, null);
                          }
                          }
                          private static Assembly CurrentDomain_A ssemblyResolve( object sender,
                          ResolveEventArg s args)
                          {
                          string AssemblyName = args.Name.Subst ring(0, args.Name.Index Of(','));
                          if (m_Files.Contai nsKey(AssemblyN ame))
                          {
                          // 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 " <sql_agentman@h otmail.comwrote in message
                          news:u0UQ03LIIH A.1212@TK2MSFTN GP05.phx.gbl...
                          Hi ThunderMusic,
                          >
                          Can you please supply a sample code so I can learn how to do what you did?
                          >
                          Thanks a mill
                          >
                          "ThunderMus ic" <NoSpAmdanlatat hotmaildotcom@N oSpAm.comwrote in message
                          news:OXRqGaKIIH A.1208@TK2MSFTN GP03.phx.gbl...
                          >>I made it... not by loading a module tought... I handle the
                          >>AssemblyResol ve event of the AppDomain and load the appropriate assembly
                          >>when needed.
                          >>
                          >Thanks to all..
                          >>
                          >ThunderMusic
                          >>
                          >"Colby Africa" <colby.africa@g mail.comwrote in message
                          >news:119436797 4.188180.34340@ v3g2000hsg.goog legroups.com...
                          >>The name will include the namespace + the type name (so, something
                          >>like ThunderMusic.Pr ojects.DLL.MyDl l).
                          >>>
                          >>Does that make sense?
                          >>>
                          >>>
                          >>
                          >>
                          >
                          >

                          Comment

                          Working...