开发者

how to create self-extracting_archive ( programmatically )

So, how to do it?

How to pack files to self-extracting_ar开发者_如何学编程chive. What is algorithm?


You can create self-extracting archives for windows with 7-zip, if you want to create them programmatically you can use the SDK.


If you're more interested in ways to implement this yourself: you could have a statically linked application which has the compressed data linked into the executable (as a resource, for instance - for smaller archives a plain static const char data[] array might be sufficient). At runtime, you feed the data to a decompression library which then actually extracts files.

To keep the overhead of the executable small, I'd try to use system API (e.g. plain WIndows controls on Windows) a possible so that you don't have to link in a toolkit. Also, for the decompression, I would use bzip2 since it provides a good compromise between compression size and decompression speed. You might also want to look at minilzo since it has a smaller code footprint than bzip2 (so the executable file is smaller) and a much higher decompression speed - it doesn't compress as well though.


A self extracting archive is just some extractor program, but instead of taking it's data from an archive file it takes it from constants defined in the program itself. That is really something very simple at conceptual/algorithmic level.

If you don't care about size you can have something as simple as below (exemple in python to keep it simple, an actual unarchiver will probably be a compiled program from C or C++ source):

hello_prog = """print "Hello, World"\n""";

f = file("./hello.py", "w");
f.write(hello_prog);
f.close();

when you run it it creates a file hello.py that is also a python executable.

But when actually creating an auto-extracting archive, you usually want the internal data to be compressed to make the whole archive as small as possible. You also want to keep the extractor program as small as possible and also as independant as possible of what is already available on the target system... and that's where the problems really begin.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜