The Teensy Executable Revisited
6 hours ago
- #ELF Executable
- #Code Optimization
- #System Programming
- The author's original 45-byte file was not a proper ELF executable but was mistakenly accepted by the Linux kernel.
- To conform to ELF standards, the author revisits a 91-byte version and reduces it by overlapping headers and exploiting unused fields.
- By overlapping the ELF header and program header table by 8 bytes, the size is reduced to 83 bytes.
- Exploiting the 'p_paddr' field (with unspecified contents) allows embedding a 2-byte instruction and a jump, reducing to 81 bytes.
- Changing the load address to 0x2AB30000 and rearranging instructions reduces the size to 79 bytes.
- Using a jump into the 'p_memsz' field and adding a dummy byte achieves a 76-byte version, but with an 8MB memory allocation.
- Replacing the jump with a 5-byte 'cmp' instruction allows crossing the 'p_filesz' field without extra memory overhead, finalizing at 76 bytes.
- Purists note that direct system calls (e.g., 'int 0x80') are not part of the documented ABI, suggesting dynamic linking with libc is needed for full compliance.
- Future work will explore dynamic linking to adhere strictly to ELF standards, adding complexity but ensuring compatibility.