Introduce new jartsr=' ape prefix

Files beginning with "MZqFpD" are Actually Portable Executables,
which have a printf statement in the first 4096 bytes with octal
codes that specify the ELF header. APE also specifies `jartsr='`
as an alternative prefix, intended for binaries that do not want
to be identified as Windows executables. Like the \177ELF magic,
all these prefixes decode as x86 jump instructions that could be
used for 16-bit bootloaders or 32-bit / 64-bit flat executables.
Most importantly they provide a fallback path for Thompson shell
copmatible command interpreters, which do not require a shebang,
e.g. bash, zsh, fish, bourne, almquist, etc. Please note that in
order to meet the requirements of POSIX.1, the single quote must
be followed by a newline character, before any null bytes occur.
See also: https://www.austingroupbugs.net/view.php?id=1250
This commit is contained in:
Justine Tunney 2022-11-10 20:58:48 -08:00
parent cee6871710
commit b46ac13504
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
3 changed files with 34 additions and 15 deletions

View file

@ -116,11 +116,29 @@ cstr: .endobj cstr,globl,hidden # ←for gdb readability
ape_mz: ape_mz:
#if SupportsWindows() || SupportsMetal() #if SupportsWindows() || SupportsMetal()
.asciz "MZqFpD='\n" # Mark 'Zibo' Joseph Zbikowski .asciz "MZqFpD='\n" # Mark 'Zibo' Joseph Zbikowski
// # in real mode
// dec %bp
// pop %dx
// jno 0x4a
// jo 0x4a
//
// # in legacy mode
// push %ebp
// pop %edx
// jno 0x4a
// jo 0x4a
//
// # 64-bit mode
// rex.WRB
// pop %r10
// jno 0x4a
// jo 0x4a
#else #else
// Avoid virus scanner reputation damage when targeting System Five. // Avoid virus scanner reputation damage when targeting System Five.
// WARNING: This prefix is experimental; it may be removed sometime. .asciz "jartsr='\n" # Justine Alexandra Roberts Tunney
// TODO(jart): Find another prefix that will work with BIOS loading. // push $0x61
.asciz "JTqFpD='\n" # Mark 'Zibo' Joseph Zbikowski // jb 0x78
// jae 0x78
#endif #endif
.short 0x1000 # MZ: lowers upper bound load / 16 .short 0x1000 # MZ: lowers upper bound load / 16
.short 0xf800 # MZ: roll greed on bss .short 0xf800 # MZ: roll greed on bss
@ -140,6 +158,9 @@ ape_mz:
.long RVA(ape_pe) # PE: the new technology .long RVA(ape_pe) # PE: the new technology
#else #else
.long 0 .long 0
.org 0x78
pop %rax
jmp _start
#endif #endif
.endfn ape_mz,globl,hidden .endfn ape_mz,globl,hidden

View file

@ -97,8 +97,8 @@ if [ x"$(uname -s)" = xLinux ]; then
echo you may need to edit configs to persist across reboot >&2 echo you may need to edit configs to persist across reboot >&2
echo '$SUDO sh -c "echo '"'"':APE:M::MZqFpD::/usr/bin/ape:'"'"' >/proc/sys/fs/binfmt_misc/register"' >&2 echo '$SUDO sh -c "echo '"'"':APE:M::MZqFpD::/usr/bin/ape:'"'"' >/proc/sys/fs/binfmt_misc/register"' >&2
$SUDO sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register" || exit $SUDO sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register" || exit
echo '$SUDO sh -c "echo '"'"':APE-sysv:M::JTqFpD::/usr/bin/ape:'"'"' >/proc/sys/fs/binfmt_misc/register"' >&2 echo '$SUDO sh -c "echo '"'"':APE-jart:M::jartsr::/usr/bin/ape:'"'"' >/proc/sys/fs/binfmt_misc/register"' >&2
$SUDO sh -c "echo ':APE-sysv:M::JTqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register" || exit $SUDO sh -c "echo ':APE-jart:M::jartsr::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register" || exit
echo done >&2 echo done >&2
if [ x"$(cat /proc/sys/fs/binfmt_misc/status)" = xdisabled ]; then if [ x"$(cat /proc/sys/fs/binfmt_misc/status)" = xdisabled ]; then

View file

@ -8,21 +8,19 @@ fi
{ {
echo echo
echo "APE Uninstaller intends to run" echo "APE Uninstaller intends to run (in pseudo-shell)"
echo echo
echo " $SUDO sh -c 'echo -1 >/proc/sys/fs/binfmt_misc/APE'" echo " sudo echo -1 into /proc/sys/fs/binfmt_misc/APE*"
echo " $SUDO sh -c 'echo -1 >/proc/sys/fs/binfmt_misc/APE-sysv'" echo " sudo rm -f /usr/bin/ape ~/.ape o/tmp/.ape /tmp/.ape"
echo " $SUDO rm -f /usr/bin/ape ~/.ape o/tmp/.ape /tmp/.ape"
echo echo
echo "You may then use ape/apeinstall.sh to reinstall it" echo "You may then use ape/apeinstall.sh to reinstall it"
echo echo
} >&2 } >&2
set -ex set -ex
if [ -f /proc/sys/fs/binfmt_misc/APE ]; then for f in /proc/sys/fs/binfmt_misc/APE*; do
$SUDO sh -c 'echo -1 >/proc/sys/fs/binfmt_misc/APE' || exit if [ -f $f ]; then
fi $SUDO sh -c "echo -1 >$f" || exit
if [ -f /proc/sys/fs/binfmt_misc/APE-sysv ]; then
$SUDO sh -c 'echo -1 >/proc/sys/fs/binfmt_misc/APE-sysv' || exit
fi fi
done
$SUDO rm -f /usr/bin/ape ~/.ape o/tmp/.ape o/tmp/ape /tmp/.ape /tmp/ape || exit $SUDO rm -f /usr/bin/ape ~/.ape o/tmp/.ape o/tmp/ape /tmp/.ape /tmp/ape || exit