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
@ 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.
.org 0 @ Start at offset 0
.byte 0x7F,'E','L','F' @ e_ident
.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.
@ r0 = argv from _start state
ldr r0, [sp, #4] @ e_shoff @ p_align
movs r7, #0x0a @ unlink
svc #0 @ syscall @ e_flags
movs r7, #0x01 @ exit
svc #0 @ syscall @ e_ehsize
@ 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:
int main(int argc, char *argv)
Or if it is easier to read,
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