Reputation: 14075
I discovered that I can add Files (*.jpg) to my C# Resources in Visual Studio 2010. As far as I could read it should be possible to re-assemble the exe at runtime. I don't want to strip the exe apart by myself. I'm looking for C# routines that do that for me. Of course I don't want to modify the running exe but a copy of it. I could also live with it putting my source code inside my exe if I need to compile it again at runtime.
My goal:
Edit: C# compiler + Visual Studio 2010 is available at target system.
Upvotes: 4
Views: 3372
Reputation: 13864
You'd have a very hard time modifying your resource section in a way that won't break your executable without the benefit of a full compiler.
What you can do instead however is:
You can read it by opening a FileStream
for your own executable starting at ExecutableLength - ZipLength - 4
and reading ZipLength
bytes - which gives you just the zip portion which can be read using DotNetZip or another library.
Then when you want to modify the stored data:
ExecutableLength - ZipLength - 4
bytes of your executable and write them to a new file with the name your executable had originally before it was renamed.Tadah - an executable that can modify its own stored resources.
Upvotes: 2