3 ms·
Make a ZIP file containing the blob, and catenate it to the end of the executable binary. The ZIP format specifically puts all of the key metadata at the back o
by amethyst 4y ago
Make a ZIP file containing the blob, and catenate it to the end of the executable binary. The ZIP format specifically puts all of the key metadata at the back of the file, so pretty much any ZIP tool can correctly read/list/extract data from the ZIP portion of the file. Anything that needs to be linked at runtime can just be extracted to a temp dir, and then cleaned up on exit. Bonus points for getting "free" compression on text data blobs.
We do this for Python applications, by combining a ZIP containing the "link tree" of sources/packages/modules, with a shell bootstrap script that automatically sets up the environment, import path, etc, and Python itself has built in support for importing pure-python modules from a ZIP file. All that's needed for native modules is a simple import hook that extracts the native objects into temp space and then loads them appropriately.
- deivid 4y agoJust in case you are unaware, take a look at shiv: https://github.com/linkedin/shiv https://github.com/linkedin/shiv which does this quite neatly
- titzer 4y agoIndeed, JARs are just ZIP files (and can even be uncompressed), so this trick works to make self-executable JAR files that consist of a shell script concatenated with the actual JAR. https://blog.frankel.ch/creating-self-contained-executable-jars/ https://blog.frankel.ch/creating-self-contained-executable-j... https://coderwall.com/p/ssuaxa/how-to-make-a-jar-file-linux-executable https://coderwall.com/p/ssuaxa/how-to-make-a-jar-file-linux-...
- deleted 4y ago[deleted]
- EdSchouten 4y agoI think that approach only works on general purpose operating systems, right? It can’t be used to add assets to executables that are used on, say, embedded systems. Or WebAssembly apps.