Compare commits

..

No commits in common. "2117ad85ab1d128961f42f929b8da95cc572a3af" and "35d955683e82158365c2e34bac741254a0ba3d06" have entirely different histories.

4 changed files with 24 additions and 31 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
tests/**
**/pcmi/**
**/badwolf/**

View File

@ -1,27 +0,0 @@
#!/bin/sh -e
# TODO: verify checksum before extracting
# TODO: extract self without resolving to $0 because it doesn't resolve links
if [ -z "$XDG_CACHE_HOME" ]; then
destdir=/tmp
else
destdir="$XDG_CACHE_HOME"
fi
if ! [ "$(head -n 1 "$destdir"/ID/checksum 2>/dev/null)" = 'SUM' ]; then
tail -c +BYTES "$0" | lz4 -dc | tar -x -C "$destdir"
echo "SUM" > "$destdir"/ID/checksum
fi
ORIGIN="$destdir"/ID
LD_LIBRARY_PATH="$ORIGIN/lib"
PATH="$ORIGIN/bin":$PATH
export ORIGIN
export LD_LIBRARY_PATH
export PATH
# export LD_DEBUG='libs'
# TODO: use $0 instead
exec "$destdir"/ID/bin/"$(basename "$1")"

19
posix/preload Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh -e
# TODO: verify checksum before extracting
# SUM
# TODO: extract self without resolving to $0 because it doesn't resolve links
tail -c +"$(expr BYTES + 1)" $0 | lz4 -dc | tar -x
# TODO: remove hardcoded directory
# TODO: use a different extraction path
cd ID
export ORIGIN="$(pwd)"
export LD_LIBRARY_PATH="$ORIGIN/lib"
export PATH="$ORIGIN/bin":$PATH
#export LD_DEBUG='libs'
# TODO: use $0 instead
# FIXME: uses the system's basename
exec bin/"$(basename "$1")"

View File

@ -6,7 +6,7 @@ WORKDIR="$(basename "$1")"
if [ -z "$LIBPATH" ]; then
LIBPATH='/lib'
fi
PAYLOAD_SCRIPT='payload'
PRELOAD_SCRIPT='preload'
LIBLIST="$WORKDIR"/liblist
SUMFILE="$WORKDIR"/checksum
tmpfile="$WORKDIR"/tt
@ -141,14 +141,14 @@ md5sum -b "$DIRNAME".tar | cut -d " " -f1 > "$SUMFILE"
lz4 --rm -9 -c "$DIRNAME.tar" > "$DIRNAME".tar.lz4
echo "Injecting payload..."
sed s/SUM/"$(cat "$SUMFILE")"/ "$PAYLOAD_SCRIPT" |
sed s/SUM/"$(cat "$SUMFILE")"/ "$PRELOAD_SCRIPT" |
sed s/ID/"$(basename "$DIRNAME")"/ |
awk '!/^ *#/ && NF' > tpp
size="$(wc -c tpp | cut -d " " -f1)"
strsize="$(echo "BYTES" | wc -c)"
numsize="$(echo "$size" | wc -c)"
normsize="$((size - (strsize - numsize) + 1))"
normsize="$((size - (strsize - numsize)))"
sed s/BYTES/"$normsize"/ tpp > tpr
cat tpr "$DIRNAME".tar.lz4 > "$DIRNAME".ti