In my gaming project, I implemented embedded ZIP resource file with the method described here in the second answer (using blob.S to embed & mark the ZIP):
Is there any standard way of embedding resources into Linux executable image?
In long run, I would like to simplify build process and get rid of extra dependencies. In this case, at the moment building needs both DMD and GCC. For embedding ZIP without GCC, I have tried approach just to cat ZIP after exe described here (sixth answer):
C/C++ with GCC: Statically add resource files to executable/library
Roughly, it works like this:
$ rdmd project.d
$ zip resources.zip resources/
$ cat resources.zip >> project
And opening the zip inside the exe:
auto exeimage = new MmFile("/proc/self/exe");
archive = new ZipArchive(exeimage[]);
The problem is that ZipArchive does not like the extra "garbage" (executable) at the beginning of the archive:
std.zip.ZipException@std/zip.d(41): ZipException: invalid directory entry 1
Checking the content of the "zip" works from command line (although it warns that extra garbage at the beginning of the file):
$ unzip -l project
Archive: project
warning [project]: 8525231 extra bytes at beginning or within zipfile
(attempting to process anyway)
Length Date Time Name
--------- ---------- ----- ----
0 2014-11-14 08:01 resources/
...
Now, my question is if there any easy and simple way to make ZipArchive to ignore the "garbage" at the beginning?
If no, is there easy way to get the size of the executable image at the beginning of the file, to be able to make the archive creation like this:
archive = new ZipArchive(exeimage[exesize .. exeimage.length]);
As a bonus question, does anyone know if the executable image is already mmap'd in the process' address space as whole, or if it contains only linked sections (text, data, ...)?