Search code examples
c#self-extracting

How to programmatically create a self extracting archive?


I was trying to create a utility that generates an self extracting executable, containing a pregenerated executable and a dynamically generated text file.

I have looked, i may be looking with the wrong keywords, but i have not been able to find anything that would help.


Solution

  • Quick-n-dirty way

    You can append whatever you want to an exe and it will work. So you have your pre-made fixed exe unpacker. You append to it an easily-to-find byte sequence, then you append the file. Or better, you append the file to the stub and then append the length as an int64. So in the unpacker you take a look at the last 8 bytes, see how much big is the payload, then you read the payload. No magic sequence necessary. See appending data to an exe for some suggestions.

    Better way

    You use mono.cecil to modify the exe stub and add as a resource the compressed content. Here there is a question about the argument.