Click here to Skip to main content
Click here to Skip to main content

Playing around with System.Reflection.Assembly.LoadFrom

By , 25 Apr 2005
 

Introduction

There are some very nice areas in the CLR, for example the whole area of reflection. Nowadays, developers use reflection, its functionalities for their projects. But it's nearly impossible to know all about these functions.

So I made some test just on the Assembly.LoadFrom and played around with it...

Basics

Private Sub Test()
 Dim extAssembly As System.Reflection.Assembly = _
      System.Reflection.Assembly.LoadFrom("c:\WindowsApplication2.exe")

 Dim extForm as Form = _
      extAssembly.CreateInstance("WindowsApplication2.Form1", True)
 Me.AddOwnedForm(extForm)
 extForm.Show()

End Sub

For those who use system reflection, there is a common piece of code. We load an external assembly from the file system, create an instance of the form within that assembly, and add it to our Forms collection to display it later on.

Naming of the assemblies

Now, if we use references in our projects, we can only reference DLL files. But with System.Reflection, we can refer to any file name. We can give our files any name and it works. This makes hacker's life a bit more complicated.

Dim extAssembly As System.Reflection.Assembly = _
    System.Reflection.Assembly.LoadFrom("c:\x.yz")

Use a web reference to the assembly

We are able to just use a URL instead of locating the assembly in our own network.

Dim extAssembly As System.Reflection.Assembly = _
     System.Reflection.Assembly.LoadFrom("http://www.myweb.ch/" & _ 
     "myTest/WindowsApplication2.exe")

And it works - yes, it works very fast. Now think about using a password protected feature within your app before you download the assembly from the web. And think about the way it works - there is no local assembly. It is just loaded within your app domain, and after you close your application, nothing will be found on the users hard drive. This way, one is not able to de assemble your code or use it on his own with System.Reflection- as long as he does not know where it is....

Use a webpage

This is the most coolest part of it. Instead of directly referencing the assembly, we are calling a webpage on our Web Server (for test purpose just do with classic ASP) and suddenly, we see a wide range of potential in it.

Dim extAssembly As System.Reflection.Assembly = _
   System.Reflection.Assembly.LoadFrom _
   ("http://www.myweb.ch/myTest/CallMyExe.asp")

The content of our callmyexe.asp is that easy:

<%@ Language="VBScript" %>
<%response.redirect 
   "http://www.myweb.ch/mytest/windowsapplication2.exe">

But you'll see the following potential within it:

  • Generate a URL that also provides some security information. (i.e. any keys.)
  • Our website can check some security as well. (i.e. check the calling IP.)
  • We use some parameters in our URL so that the webpage decides what kind of assembly we receive.
  • We can store our assemblies within a database and give them back - and our directories do not contain any of the assemblies.
  • At least, with CodeDom, we are able to generate an assembly ad hoc and give it back to the caller.

So, have fun making your own tests.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Daniel Ch. Bloch (MCSD, MCAD, MCTS)
Software Developer (Senior) http://www.btv-data.ch
Switzerland Switzerland
Member
On software development since 1992, going through the different steps from mainframe computing with VMS/Vax over VB4-6, Access and SQL server, Cold Fusions and ASP programming to my currently status as Chief Solution Developer for Smartclient and Client/Server development with vb.net and SQL Server. MCSD and some other stuff.
 

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generalthanksmemberlallous21 Jun '07 - 21:34 
Generalvc++.net 2003- extract image using assemblymemberminad_78611 Apr '07 - 3:51 
GeneralParametersmembermarco gheri21 Nov '06 - 9:10 
QuestionBut is ofusqued??memberJavea6514 Jun '05 - 6:03 
AnswerRe: But is ofusqued??memberanotherbla00114 Jun '05 - 18:56 
GeneralRe: But is ofusqued??memberJavea6514 Jun '05 - 21:11 
GeneralAssembly.LoadFrom from GACsusstwokids6 Jun '05 - 12:17 
GeneralRe: Assembly.LoadFrom from GACmemberDaniel Bloch14 Jun '05 - 19:03 
GeneralBeautiful work!memberPhan Dung4 May '05 - 16:49 
GeneralCorrectionmemberjdunlap25 Apr '05 - 21:27 
GeneralRe: CorrectionmemberDaniel Bloch25 Apr '05 - 22:39 
GeneralRe: Correctionmemberdshorter14 May '05 - 4:54 
GeneralRe: CorrectionmemberDaniel Bloch5 May '05 - 20:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 26 Apr 2005
Article Copyright 2005 by Daniel Ch. Bloch (MCSD, MCAD, MCTS)
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid