views:

50

answers:

2

Hi There, I am trying to create an application can modify properties in IL to create a slightly different executable. E.g Client A runs app and a label on the WinForm label Reads "Client A:". Client B runs the app and Label Says "Client B". Easy I know using config files or resource files but thats not an option for this project. The Main program needs to be able to generate .exe file dynamically based on some form fields entered by user.

My solution was to create a standalone executable that contained all the elements which I needed to make dynamic. I then used ildasm to generate the IL and thought that I could use this IL and substitute tags for the elements i wanted to make dynamic. I could then replace those tags at runtime after user filled the form using regex etc. The problem is, the if i re save the IL file generated by ILDASM as an exe and try to run it. I just launches console and does nothing.

Am I going about this the wrong way? I didnt want to delve into Reflection as the dynamic .exe is a really simple one and I thought reverse engineering IL with ildasm would be the quickest way.

You thoughts and pointers are much appreciated. Tony

A: 

Is the executable generated on-site? Or do you generate the executable for a customer and then ship the result?

If you are the one generating the executable, you could put the customer-specific data/code in a separate DLL and embed it in your executable as a resource, and load it when the AppDomain.CurrentDomain.AssemblyResolve event occurs.

That way you can have version control over the customer-specific data.

deltreme
Hi There,Good idea but Im afraid the executable will need to be generated on site :(
TonyNeallon
I would try to avoid sending customer specific data to customers it isn't intended to. Also letting a customer generate an executable sounds a bit fragile, and it feels like it would be impossible to debug if things go wrong. If you're going to modify an executable, I'd try to replace embedded resources instead of generating anything. Just a thought, what about sending them a downloader application that fetches the correct executable from a webserver?
deltreme
A: 

When you say "re-save" the file created by ildasm and run it do you mean you are running all of the IL files through ilasm (the provided Microsoft IL compiler)? If not, you may want to try that. Do be very careful when performing your substitution as IL has some quite specific requirements and ilasm is not as forgiving as the higher level compilers like csc and vbc.

You can also use Mono.Cecil to modify assembly files, that way you don't have to ship IL to your customers.

If you are going to continue on the route of shipping the source and compiling it you can accomplish the same thing without involving IL by shipping the C# source and compiling it onsite since csc is included in the framework.

Joe Kuemerle