News for hackers. Stuff that matters.
Re:Shebang Quine by JoshTriplett on Friday May 20, 2016 @05:24PM (#11741647)
Here's a quine written as an ld linker script:

    TARGET(binary)
    OUTPUT_FORMAT(elf32-i386)
    ENTRY(_start)
    SECTIONS
    {
        . = 2M;
        .text 2M: {
            _start = .;
            BYTE(0xb8); LONG(4)         /* mov $4, %eax */
            BYTE(0xbb); LONG(1)         /* mov $1, %ebx */
            BYTE(0xb9); LONG(data);     /* mov data, %ecx */
            BYTE(0xba); LONG(data_len); /* mov data_len, %edx */
            BYTE(0xcd); BYTE(0x80);     /* int $0x80 */
            BYTE(0xb8); LONG(1)         /* mov $1, %eax */
            BYTE(0x31); BYTE(0xdb);     /* xor %ebx, %ebx */
            BYTE(0xcd); BYTE(0x80);     /* int $0x80 */
            data = .;
            *(.data);
            data_len = ABSOLUTE(. - data);
        }
    }
Building and running it:

    /tmp$ ld -T quine.ld quine.ld -o quine
    /tmp$ ./quine | diff -s quine.ld -
    Files quine.ld and - are identical

There are no comments on this comment yet.