ARM Linux full standalone ELF, 50 46 45 bytes
7f 45 4c 46 01 00 00 00 00 00 00 00 00 00 01 00
02 00 28 00 21 00 01 00 21 00 01 00 04 00 00 00
01 98 0a 27 00 df 01 27 00 df 20 00 01
Adapted version of the code used in A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux.
Assembler source (with raw encoded ELF header and comments, most of which are the same as in the article)
@ Adaptation of
@ https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
@ for an ARM binary which deletes itself. XD
@ $ arm-none-eabi-as -march=armv4t -mthumb runonce-arm.s -o runonce-arm.o
@ $ arm-none-eabi-ld -Ttext 0x00010000 runonce-arm.o -o runonce-arm.elf
@ $ arm-none-eabi-objcopy -O binary runonce-arm.elf runonce-arm
.text @ A lie.
.arch armv4t @ Set architecture version
.thumb @ Needs to be Thumb to fit. ARM is too thicc.
.syntax unified
.org 0 @ Start at offset 0
Elf32_Ehdr:
.byte 0x7F,'E','L','F' @ e_ident
Elf32_Phdr:
.word 1 @ p_type
.word 0 @ p_offset
.word 0x00010000 @ same as -Ttext @ p_vaddr
.short 2 @ ET_EXEC @ e_type @ p_paddr
.short 40 @ EM_ARM @ e_machine
.word _start @ e_version @ p_filesz
.word _start @ e_entry @ p_memsz
.word 4 @ Elf32_Phdr @ e_phoff @ p_flags
@ Here is some space to put our code in.
.thumb_func
.globl _start
_start:
@ r0 = argv[0] from _start state
ldr r0, [sp, #4] @ e_shoff @ p_align
@ unlink(argv[0])
movs r7, #0x0a @ unlink
svc #0 @ syscall @ e_flags
@ exit(dontcare)
movs r7, #0x01 @ exit
svc #0 @ syscall @ e_ehsize
@ unreachable
@ finish the header
.short 0x20 @ e_phentsize
.byte 1 @ e_phnum
@ Truncated header because for some reason, Linux accepts this.
Basically, I took this program:
#include <unistd.h>
int main(int argc, char *argv[])
{
unlink(argv[0]);
}
Or if it is easier to read,
main(c,v)int*v;{unlink(*v);}
And squeezed it into an ELF header using the method in that article, so it is 45 bytes with no dependencies on libc.
Works every time except when it is called from $PATH
.
vi
in a single terminal environment has this effect, no escape from it unless you reboot :) Just a joke here. \$\endgroup\$echo "If you try to execute me again, it means you are an idiot.";
<-- Nobody will execute more than once :P \$\endgroup\$