diff --git a/Makefile b/Makefile index d9c46cd..18e1d2a 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ VERSION:= v0.1.0 -all: clean generator trust +all: clean sign trust trust: if [[ ! -f generator-$(VERSION) ]]; then \ - make -B generator || exit 1; \ + make -B sign || exit 1; \ fi ln -sf generator-$(VERSION) generator @@ -12,6 +12,9 @@ generator: cd generator-native && cargo build --release ln -sf generator-native/target/release/generator-native generator cp -f `readlink generator` ./generator-$(VERSION) + +sign: generator + sha256sum ./generator-$(VERSION) | cut -d\ -f1 > generator-$(VERSION).sha256 gpg --sign ./generator-$(VERSION) clean: diff --git a/README.md b/README.md new file mode 100644 index 0000000..7744564 --- /dev/null +++ b/README.md @@ -0,0 +1,63 @@ +# `sfexec` - Self Extracting Executable + +`sfexec` is a simple tool to create archive-like native binaries that extract contents from their static memory to temporary files when ran. +It is useful for packaging a bunch of binaries into a single one. +Temporary files are cleaned up after the post-extraction script hook. + +## Example + +``` shell +$ echo "Hello world!" > file.txt +$ sfexec-create -e 'cat %location/file.txt' - file.txt +Writing to /home/avril/work/sfexec/file.h... + + test.txt OK +Adding lengths... +Adding names... + - "test.txt" OK +Compiling binary... +Complete. +$ ./sfexec +Extracting 1 files to "/tmp/eda0bd22-9565-7e3c-e1d0-f7cdff96770e"... + <- test.txt (13) +exec: cat /tmp/eda0bd22-9565-7e3c-e1d0-f7cdff96770e/test.txt +Hello world! +``` + +## Usage + +It comes with 2 scripts, `sfexec-create` and `sfexec-create-compress`. Both take the same arguments: +| Argument | Description | +|---------------|-----------------------------------------------------| +| `-s` | Silent mode. Do not output anything when extracting | +| `-e ` | Post-extraction hook. See below for details. | +| `-` | Stop reading argument flags | + +`sfexec-create-compress` compresses the binary with `gzip`, and decompresses when executed. + +### Post-extraction hook + +The post extraction hook is passed to `/bin/sh`, with some input changes: +| Argument | Usage | +|-------------|-------------------------------------------------------------------------------------------------------| +| `%location` | The directory root that the files are extracted to | +| `%argc` | The number of command line arguments passed to `sfexec` | +| `%argv` | A list of all args passed to `sfexec` | +| `%arg[n]` | The `n`th argument passed to `sfexec`, if `n` is outside the range of arguments, nothing is replaced. | + +## Building +To build the `sfexec` binary, g++ is used, along with [sha256_literal] for verifying the post-extraction hook. +Included in the repo is a pre-built generator binary, signed with [my GPG key] at `generator-v.gpg` with a checksum in `generator-v.sha256`. Alternatively you can build it yourself like so: + +[sha256_literal]: https://github.com/aguinet/sha256_literal +[my gpg key]: https://flanchan.moe/flanchan.asc + +### Building the generator +To build the generator yourself, Rust and Cargo are needed. +``` shell +$ make clean && make generator +``` +Will remove the pre-built generator binaries, build the generator, and symlink accordingly. + +## License +GPL'd with love <3 + diff --git a/generator-v0.1.0.gpg b/generator-v0.1.0.gpg index 538f790..c524d72 100644 Binary files a/generator-v0.1.0.gpg and b/generator-v0.1.0.gpg differ diff --git a/generator-v0.1.0.sha256 b/generator-v0.1.0.sha256 new file mode 100644 index 0000000..ecc6188 --- /dev/null +++ b/generator-v0.1.0.sha256 @@ -0,0 +1 @@ +621638ffc2740f90112e1b977dfcb91b20195cb86427b2d15275682ce8e82618